sc/source/filter/xml/xmlexprt.cxx |   28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

New commits:
commit 1c9e7e9342612f9db59eb8b2d6dc28d475459e34
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Sun Jun 12 21:48:58 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Jun 14 14:02:11 2022 +0200

    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.st...@allotropia.de>
    (cherry picked from commit 32dd76143bdf55ac73f03f705097453521b4bf2c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135735
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/source/filter/xml/xmlexprt.cxx 
b/sc/source/filter/xml/xmlexprt.cxx
index bdae3a1f94d0..31a2e5530186 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -926,6 +926,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 )
 {
@@ -939,14 +940,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 )
 {
@@ -975,13 +985,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:
@@ -1266,7 +1276,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));
         }
@@ -3102,7 +3112,7 @@ void flushParagraph(
         OUString aContent(rParaText.copy(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);
     }

Reply via email to