include/vcl/embeddedfontshelper.hxx          |   19 +++++++++++++++----
 oox/source/export/drawingml.cxx              |    5 +++--
 sd/qa/unit/FontEmbeddingTest.cxx             |    4 ++--
 sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp |binary
 sd/source/filter/eppt/pptx-epptooxml.cxx     |    9 ++++++---
 vcl/source/gdi/embeddedfontshelper.cxx       |   26 +++++++++++++++++++++++++-
 6 files changed, 51 insertions(+), 12 deletions(-)

New commits:
commit b7aac9a459b304d0ac3f18c76c30361f988d296e
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Mon May 26 14:20:14 2025 +0900
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue May 27 14:23:01 2025 +0200

    sd: PPTX embedded fonts - skip common fonts
    
    Skip embedding common fonts that are considered to be always
    available or are substituted for a metric compatible fonts in a
    LO or MSO.
    
    Change-Id: Ic970e25e464517fa44f446492c1fdfce29379c77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185761
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/vcl/embeddedfontshelper.hxx 
b/include/vcl/embeddedfontshelper.hxx
index 404afac13ec1..6082144a3c30 100644
--- a/include/vcl/embeddedfontshelper.hxx
+++ b/include/vcl/embeddedfontshelper.hxx
@@ -22,10 +22,7 @@
 namespace com::sun::star::io { class XInputStream; }
 namespace com::sun::star::uno { template <typename > class Reference; }
 
-/**
- Helper functions for handling embedded fonts in documents.
-
-*/
+/** Helper functions for handling embedded fonts in documents. */
 class VCL_DLLPUBLIC EmbeddedFontsHelper
 {
 private:
@@ -100,6 +97,20 @@ public:
     */
     static void clearTemporaryFontFiles();
 
+    /** True if the font is common and doesn't need to be embedded
+     *
+     * A font is common is a font that is available or can be substituted
+     * for a metric compatible font on common platforms and editors. Not
+     * embedding such a font should not cause any issues with the document
+     * format and rendering.
+     *
+     * For example "Liberation Serif" is a common font because it's available
+     * in any typical LibreOffice installation or is substituted for the
+     * "Times New Roman" metric compatible font for compatibility with other
+     * editors.
+     */
+    static bool isCommonFont(std::u16string_view aFontName);
+
     ~EmbeddedFontsHelper() COVERITY_NOEXCEPT_FALSE
     {
         activateFonts();
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 787a0325ea18..1f562d1c295a 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -118,6 +118,7 @@
 #include <unotools/fontdefs.hxx>
 #include <vcl/cvtgrf.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/embeddedfontshelper.hxx>
 #include <rtl/strbuf.hxx>
 #include <filter/msfilter/escherex.hxx>
 #include <filter/msfilter/util.hxx>
@@ -2836,7 +2837,7 @@ void DrawingML::WriteRunProperties( const Reference< 
XPropertySet >& rRun, bool
 
         mAny >>= usTypeface;
 
-        if (!mbEmbedFonts)
+        if (!mbEmbedFonts || EmbeddedFontsHelper::isCommonFont(usTypeface))
         {
             OUString aSubstName( GetSubsFontName( usTypeface, 
SubsFontFlags::ONLYONE | SubsFontFlags::MS ) );
             if (!aSubstName.isEmpty())
@@ -2861,7 +2862,7 @@ void DrawingML::WriteRunProperties( const Reference< 
XPropertySet >& rRun, bool
         OUString usTypeface;
 
         mAny >>= usTypeface;
-        if (!mbEmbedFonts)
+        if (!mbEmbedFonts || EmbeddedFontsHelper::isCommonFont(usTypeface))
         {
             OUString aSubstName( GetSubsFontName( usTypeface, 
SubsFontFlags::ONLYONE | SubsFontFlags::MS ) );
             if (!aSubstName.isEmpty())
diff --git a/sd/qa/unit/FontEmbeddingTest.cxx b/sd/qa/unit/FontEmbeddingTest.cxx
index 9c1b2571376c..bcbfc81345c9 100644
--- a/sd/qa/unit/FontEmbeddingTest.cxx
+++ b/sd/qa/unit/FontEmbeddingTest.cxx
@@ -103,7 +103,7 @@ CPPUNIT_TEST_FIXTURE(FontEmbeddingTest, 
testExportEmbeddedFontsPPTX)
 {
 #if HAVE_MORE_FONTS
 
-    createSdImpressDoc();
+    createSdImpressDoc("TestEmbeddedFonts_DejaVu.odp");
 
     uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, 
uno::UNO_QUERY_THROW);
     uno::Reference<beans::XPropertySet> xProps(
@@ -130,7 +130,7 @@ CPPUNIT_TEST_FIXTURE(FontEmbeddingTest, 
testExportEmbeddedFontsPPTX)
     {
         xmlDocUniquePtr pXmlDoc = parseExport(u"ppt/presentation.xml"_ustr);
         assertXPath(pXmlDoc, xPath_Presentation, "embedTrueTypeFonts", u"1");
-        assertXPath(pXmlDoc, xPath_EmbeddedFont + "[@typeface='Liberation 
Sans']");
+        assertXPath(pXmlDoc, xPath_EmbeddedFont + "[@typeface='DejaVu Sans']");
     }
 
     // Check the relationships to the embedded fonts
diff --git a/sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp 
b/sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp
new file mode 100644
index 000000000000..df90920bf3f7
Binary files /dev/null and b/sd/qa/unit/data/TestEmbeddedFonts_DejaVu.odp differ
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx 
b/sd/source/filter/eppt/pptx-epptooxml.cxx
index 71763d973ca2..d3a55f5ae441 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -765,6 +765,9 @@ void PowerPointExport::WriteEmbeddedFontList()
         aAnySeq[nSeqIndex++] >>= ePitch;
         aAnySeq[nSeqIndex++] >>= eCharSet;
 
+        if (EmbeddedFontsHelper::isCommonFont(sFamilyName))
+            continue;
+
         if (mbEmbedUsedOnly && !aUsedFonts.contains(sFamilyName))
             continue;
 
@@ -811,7 +814,7 @@ void PowerPointExport::WriteEmbeddedFontList()
 
                 if (aFile.isEndOfFile(&eof) != osl::File::E_None)
                 {
-                    SAL_WARN("sw.ww8", "Error reading font file " << sFontUrl);
+                    SAL_WARN("sd.eppt", "Error reading font file " << 
sFontUrl);
                     break;
                 }
                 if (eof)
@@ -819,7 +822,7 @@ void PowerPointExport::WriteEmbeddedFontList()
 
                 if (aFile.read(buffer.data(), 4096, readSize) != 
osl::File::E_None)
                 {
-                    SAL_WARN("sw.ww8", "Error reading font file " << sFontUrl);
+                    SAL_WARN("sd.eppt", "Error reading font file " << 
sFontUrl);
                     break;
                 }
 
@@ -830,7 +833,7 @@ void PowerPointExport::WriteEmbeddedFontList()
                 aHashCalc.update(reinterpret_cast<const unsigned 
char*>(buffer.data()), readSize);
             }
 
-            std::string aHash =  
comphelper::hashToString(aHashCalc.finalize());
+            std::string aHash = comphelper::hashToString(aHashCalc.finalize());
             auto iterator = aFontDeduplicationMap.find(aHash);
             if (iterator == aFontDeduplicationMap.end())
             {
diff --git a/vcl/source/gdi/embeddedfontshelper.cxx 
b/vcl/source/gdi/embeddedfontshelper.cxx
index 8053d80bc455..e30244ce0a33 100644
--- a/vcl/source/gdi/embeddedfontshelper.cxx
+++ b/vcl/source/gdi/embeddedfontshelper.cxx
@@ -10,6 +10,9 @@
 #include <sal/config.h>
 
 #include <memory>
+#include <frozen/bits/defines.h>
+#include <frozen/bits/elsa_std.h>
+#include <frozen/unordered_set.h>
 #include <config_folders.h>
 #include <config_eot.h>
 
@@ -26,7 +29,6 @@
 #include <salgdi.hxx>
 #include <sft.hxx>
 
-
 #if ENABLE_EOT
 extern "C"
 {
@@ -400,4 +402,26 @@ OUString EmbeddedFontsHelper::fontFileUrl( 
std::u16string_view familyName, FontF
     return ok ? url : u""_ustr;
 }
 
+bool EmbeddedFontsHelper::isCommonFont(std::u16string_view aFontName)
+{
+    static constexpr auto aCommonFontsList = 
frozen::make_unordered_set<std::u16string_view>({
+        // LO Common
+        u"Liberation Sans",
+        u"Liberation Serif",
+        u"Liberation Sans Narrow",
+        u"Liberation Mono",
+        u"Caladea",
+        u"Carlito",
+        // MSO
+        u"Times New Roman",
+        u"Arial",
+        u"Arial Narrow",
+        u"Courier New",
+        u"Cambria",
+        u"Calibri",
+    });
+
+    return aCommonFontsList.contains(aFontName);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to