sd/source/filter/eppt/pptx-epptooxml.cxx |   99 ++++++++++---------------------
 1 file changed, 32 insertions(+), 67 deletions(-)

New commits:
commit 777ff280670ddbeb4e68bdd2ef4a684e35a5fd66
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon May 26 14:31:05 2025 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Fri Jun 6 17:43:12 2025 +0200

    sd: better way to check if a font is used for PPTX font embedding
    
    Check all the objects and style that is accosiated with the object
    if the font is used. This way we don't include fonts that are not
    actually used in the document. The isUsed on the document is not
    percise enough in this case.
    
    Change-Id: If11d80ffe04b28688698babb560ac0be84bbed12
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185764
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    (cherry picked from commit e888a6d9eb2af220a9c8c0a3483e37d1f53f628f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186223
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index 8709631cfe47..06f99d33e661 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -578,6 +578,12 @@ private:
         return nullptr;
     }
 
+    void addFontItem(const SvxFontItem* pItem)
+    {
+        OUString aFontName = pItem->GetFamilyName();
+        mrUsedFontNames.insert(aFontName);
+    }
+
     void traverseEditEng(SdrTextObj* pTextObject)
     {
         OutlinerParaObject* pOutlinerParagraphObject = 
pTextObject->GetOutlinerParaObject();
@@ -588,19 +594,36 @@ private:
         std::vector<editeng::Section> aSections;
         rEditText.GetAllSections(aSections);
 
+        {
+            SfxStyleSheet* pStyleSheet = 
pTextObject->getSdrPageFromSdrObject()->GetTextStyleSheetForObject(pTextObject);
+            auto aItemSet = pStyleSheet->GetItemSet();
+            if (const SvxFontItem* pItem = 
aItemSet.GetItemIfSet(EE_CHAR_FONTINFO, false))
+            {
+                addFontItem(pItem);
+            }
+            if (const SvxFontItem* pItem = 
aItemSet.GetItemIfSet(EE_CHAR_FONTINFO_CJK, false))
+            {
+                addFontItem(pItem);
+            }
+            if (const SvxFontItem* pItem = 
aItemSet.GetItemIfSet(EE_CHAR_FONTINFO_CTL, false))
+            {
+                addFontItem(pItem);
+            }
+        }
+
         for (editeng::Section const& rSection : aSections)
         {
             if (SvxFontItem const* pFontItem = getFontItem(rSection, 
EE_CHAR_FONTINFO); pFontItem && mbEmbedLatinScript)
             {
-                mrUsedFontNames.insert(pFontItem->GetFamilyName());
+                addFontItem(pFontItem);
             }
             if (SvxFontItem const * pFontItem = getFontItem(rSection, 
EE_CHAR_FONTINFO_CJK); pFontItem && mbEmbedAsianScript)
             {
-                mrUsedFontNames.insert(pFontItem->GetFamilyName());
+                addFontItem(pFontItem);
             }
             if (SvxFontItem const* pFontItem = getFontItem(rSection, 
EE_CHAR_FONTINFO_CTL); pFontItem && mbEmbedComplexScript)
             {
-                mrUsedFontNames.insert(pFontItem->GetFamilyName());
+                addFontItem(pFontItem);
             }
         }
     }
@@ -617,22 +640,23 @@ protected:
     void handleSdrObject(SdrObject* pObject) override
     {
         SdrTextObj* pTextShape = DynCastSdrTextObj(pObject);
-        if (pTextShape && !pTextShape->IsEmptyPresObj())
+        if (pTextShape)
         {
             auto& rItemSet = pTextShape->GetMergedItemSet();
 
             if (SvxFontItem const* pFontItem = 
rItemSet.GetItemIfSet(EE_CHAR_FONTINFO, true); pFontItem && mbEmbedLatinScript)
             {
-                mrUsedFontNames.insert(pFontItem->GetFamilyName());
+                addFontItem(pFontItem);
             }
             if (SvxFontItem const* pFontItem = 
rItemSet.GetItemIfSet(EE_CHAR_FONTINFO_CJK, true); pFontItem && 
mbEmbedAsianScript)
             {
-                mrUsedFontNames.insert(pFontItem->GetFamilyName());
+                addFontItem(pFontItem);
             }
             if (SvxFontItem const* pFontItem = 
rItemSet.GetItemIfSet(EE_CHAR_FONTINFO_CTL, true); pFontItem && 
mbEmbedComplexScript)
             {
-                mrUsedFontNames.insert(pFontItem->GetFamilyName());
+                addFontItem(pFontItem);
             }
+
             traverseEditEng(pTextShape);
         }
     }
@@ -652,66 +676,6 @@ std::unordered_set<OUString> 
PowerPointExport::getUsedFontList()
     if (!pDocument)
         return aReturnSet;
 
-    uno::Reference<style::XStyleFamiliesSupplier> xFamiliesSupp(getModel(), 
UNO_QUERY);
-    if (!xFamiliesSupp.is())
-        return aReturnSet;
-
-    // Check styles first
-    uno::Reference<container::XNameAccess> xFamilies = 
xFamiliesSupp->getStyleFamilies();
-    if (!xFamilies.is())
-        return aReturnSet;
-
-    const uno::Sequence<OUString> aFamilyNames = xFamilies->getElementNames();
-    for (OUString const & sFamilyName : aFamilyNames)
-    {
-        uno::Reference<container::XNameAccess> xStyleContainer;
-        xFamilies->getByName(sFamilyName) >>= xStyleContainer;
-
-        if (!xStyleContainer.is())
-            continue;
-
-        for (OUString const& rName : xStyleContainer->getElementNames())
-        {
-            uno::Reference<style::XStyle> xStyle;
-            xStyleContainer->getByName(rName) >>= xStyle;
-            if (!xStyle->isInUse())
-                continue;
-
-            uno::Reference<beans::XPropertySet> xPropertySet(xStyle, 
UNO_QUERY);
-            if (!xPropertySet.is())
-                continue;
-
-            uno::Reference<beans::XPropertySetInfo> xInfo = 
xPropertySet->getPropertySetInfo();
-            if (!xInfo.is())
-                continue;
-
-            if (mbEmbedLatinScript && 
xInfo->hasPropertyByName(u"CharFontName"_ustr))
-            {
-                OUString sCharFontName;
-                Any aFontAny = 
xPropertySet->getPropertyValue(u"CharFontName"_ustr);
-                aFontAny >>= sCharFontName;
-                if (!sCharFontName.isEmpty())
-                    aReturnSet.insert(sCharFontName);
-            }
-            if (mbEmbedAsianScript && 
xInfo->hasPropertyByName(u"CharFontNameAsian"_ustr))
-            {
-                OUString sCharFontNameAsian;
-                Any aFontAny = 
xPropertySet->getPropertyValue(u"CharFontNameAsian"_ustr);
-                aFontAny >>= sCharFontNameAsian;
-                if (!sCharFontNameAsian.isEmpty())
-                    aReturnSet.insert(sCharFontNameAsian);
-            }
-            if (mbEmbedComplexScript && 
xInfo->hasPropertyByName(u"CharFontNameComplex"_ustr))
-            {
-                OUString sCharFontNameComplex;
-                Any aFontAny = 
xPropertySet->getPropertyValue(u"CharFontNameComplex"_ustr);
-                aFontAny >>= sCharFontNameComplex;
-                if (!sCharFontNameComplex.isEmpty())
-                    aReturnSet.insert(sCharFontNameComplex);
-            }
-        }
-    }
-
     auto pCollector = std::make_shared<FontNameCollector>(aReturnSet, 
mbEmbedLatinScript, mbEmbedAsianScript, mbEmbedComplexScript);
     sd::ModelTraverser aModelTraverser(pDocument, { .mbPages = true, 
.mbMasterPages = true });
     aModelTraverser.addNodeHandler(pCollector);
@@ -784,6 +748,7 @@ void PowerPointExport::WriteEmbeddedFontList()
 
         EmbeddedFont aInfo;
         aInfo.sFamilyName = sFamilyName;
+        SAL_INFO("sd.eppt", "Embedding font: " << sFamilyName);
 
         for (auto [eItalic, eWeight] : aFontVariantCombinations)
         {

Reply via email to