summaryrefslogtreecommitdiff
path: root/sc/source/filter/xml/xmlexprt.cxx
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-06-12 21:48:58 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2022-06-13 16:26:40 +0200
commit32dd76143bdf55ac73f03f705097453521b4bf2c (patch)
tree26c63d378836adf3b8651ea66f62b65aff5643af /sc/source/filter/xml/xmlexprt.cxx
parentb7c260aee331474d993bf96a72bf31f5af350ef3 (diff)
sc: ODF export: fix style:font-name on EE text/paragraph styles
The problem is that sc contains its own duplicate export of EditEngine styles, where the SvxFontItem aFamilyName is exported directly to style:font-name. But style:font-name refers to a style:font-face, and for a given font family name there may be multiple font-face elements whose names have a counter appended, and they are written in some non-deterministic order, so effectively this picks font-face at random. In XMLTextExportPropertySetMapper::ContextFontFilter() there is already code to do the lookup, and also a fallback when the lookup fails to a set of individual attributes fo:font-family style:font-style-name style:font-family-generic etc., which is actually used for fonts in control shapes, which have "unknown" for one of the components, so there could be some other problem with them. It doesn't look possible for the lookup to fail for EditEngine items, as ScXMLFontAutoStylePool_Impl should have added all of them. This problem was detected by current ODFunDiff in 22 of 2000 ODS files; with this fix only other problems remain. Change-Id: I276f705296df628b0869526f4ea676c47a014328 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135684 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sc/source/filter/xml/xmlexprt.cxx')
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx28
1 files changed, 19 insertions, 9 deletions
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 654299294d71..023165f56c95 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -924,6 +924,7 @@ void ScXMLExport::ExportExternalRefCacheStyles()
namespace {
void handleFont(
+ SvXMLExport & rExport,
std::vector<XMLPropertyState>& rPropStates,
const SfxPoolItem* p, const rtl::Reference<XMLPropertySetMapper>& xMapper, std::u16string_view rXMLName )
{
@@ -937,14 +938,23 @@ void handleFont(
if (nIndexFontName == -1 || nIndexFontName >= nEntryCount)
return;
- uno::Any aAny;
- if (!pItem->QueryValue(aAny, MID_FONT_FAMILY_NAME))
- return;
+ OUString const sFamilyName(pItem->GetFamilyName());
+ OUString const sStyleName(pItem->GetStyleName());
+ auto const nFamily(pItem->GetFamily());
+ auto const nPitch(pItem->GetPitch());
+ auto const eEnc(pItem->GetCharSet());
+ OUString const sName(rExport.GetFontAutoStylePool()->Find(
+ sFamilyName, sStyleName, nFamily, nPitch, eEnc));
+ if (sName.isEmpty())
+ {
+ assert(false); // fallback to fo:font-family etc. probably not needed
+ }
- rPropStates.emplace_back(nIndexFontName, aAny);
+ rPropStates.emplace_back(nIndexFontName, uno::Any(sName));
}
const SvxFieldData* toXMLPropertyStates(
+ SvXMLExport & rExport,
std::vector<XMLPropertyState>& rPropStates, const std::vector<const SfxPoolItem*>& rSecAttrs,
const rtl::Reference<XMLPropertySetMapper>& xMapper, const ScXMLEditAttributeMap& rAttrMap )
{
@@ -973,13 +983,13 @@ const SvxFieldData* toXMLPropertyStates(
switch (p->Which())
{
case EE_CHAR_FONTINFO:
- handleFont(rPropStates, p, xMapper, u"font-name");
+ handleFont(rExport, rPropStates, p, xMapper, u"font-name");
break;
case EE_CHAR_FONTINFO_CJK:
- handleFont(rPropStates, p, xMapper, u"font-name-asian");
+ handleFont(rExport, rPropStates, p, xMapper, u"font-name-asian");
break;
case EE_CHAR_FONTINFO_CTL:
- handleFont(rPropStates, p, xMapper, u"font-name-complex");
+ handleFont(rExport, rPropStates, p, xMapper, u"font-name-complex");
break;
case EE_CHAR_WEIGHT:
case EE_CHAR_WEIGHT_CJK:
@@ -1264,7 +1274,7 @@ void ScXMLExport::ExportCellTextAutoStyles(sal_Int32 nTable)
continue;
std::vector<XMLPropertyState> aPropStates;
- toXMLPropertyStates(aPropStates, rSecAttrs, xMapper, rAttrMap);
+ toXMLPropertyStates(*this, aPropStates, rSecAttrs, xMapper, rAttrMap);
if (!aPropStates.empty())
xStylePool->Add(XmlStyleFamily::TEXT_TEXT, OUString(), std::move(aPropStates));
}
@@ -3101,7 +3111,7 @@ void flushParagraph(
OUString aContent(rParaText.substr(rSec.mnStart, rSec.mnEnd - rSec.mnStart));
std::vector<XMLPropertyState> aPropStates;
- const SvxFieldData* pField = toXMLPropertyStates(aPropStates, rSec.maAttributes, xMapper, rAttrMap);
+ const SvxFieldData* pField = toXMLPropertyStates(rExport, aPropStates, rSec.maAttributes, xMapper, rAttrMap);
OUString aStyleName = xStylePool->Find(XmlStyleFamily::TEXT_TEXT, OUString(), aPropStates);
writeContent(rExport, aStyleName, aContent, pField);
}