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

New commits:
commit 3c921ea2f33dbd04dcde2dedac2b103aeefee053
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:05:28 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 22e3fafb95072cd7027ad64c474a9709037402ea)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135713
    Reviewed-by: Eike Rathke <er...@redhat.com>

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);
     }

Reply via email to