sw/qa/extras/odfexport/data/embedded-font-props.odt       |binary
 sw/qa/extras/odfexport/data/font_used_in_header_only.fodt |    6 -
 sw/qa/extras/odfexport/odfexport2.cxx                     |   49 +++++++++-----
 sw/qa/extras/uiwriter/data/testFontEmbedding.odt          |binary
 sw/qa/extras/uiwriter/uiwriter6.cxx                       |   41 ++++++-----
 xmloff/source/style/XMLFontAutoStylePool.cxx              |    3 
 6 files changed, 59 insertions(+), 40 deletions(-)

New commits:
commit a0ae1b0cf2661e7be9ea042e5357530f5fb412f5
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Aug 6 12:20:10 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Aug 7 06:28:22 2025 +0200

    ODF embedded fonts - skip common fonts
    
    Similar to commit 0e9091b6db0d6192a0369ddff71f05d37c29ce98
      2025-05-26
      sd: PPTX embedded fonts - skip common fonts
    
    Tests for font embedding were modified to embed fonts not in the
    common font list.
    
    Change-Id: Ia0d95bc8be7cf6b590f8074cabe3568271ef18f9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188989
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/odfexport/data/embedded-font-props.odt 
b/sw/qa/extras/odfexport/data/embedded-font-props.odt
index 6eb073e29fe0..c191223424bf 100644
Binary files a/sw/qa/extras/odfexport/data/embedded-font-props.odt and 
b/sw/qa/extras/odfexport/data/embedded-font-props.odt differ
diff --git a/sw/qa/extras/odfexport/data/font_used_in_header_only.fodt 
b/sw/qa/extras/odfexport/data/font_used_in_header_only.fodt
index 17f7feed9e93..3ef2c2791cfe 100644
--- a/sw/qa/extras/odfexport/data/font_used_in_header_only.fodt
+++ b/sw/qa/extras/odfexport/data/font_used_in_header_only.fodt
@@ -11,7 +11,7 @@
   </config:config-item-set>
  </office:settings>
  <office:font-face-decls>
-  <style:font-face style:name="Liberation Sans" 
svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" 
style:font-pitch="variable"/>
+  <style:font-face style:name="DejaVu Sans" svg:font-family="&apos;DejaVu 
Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/>
   <style:font-face style:name="Liberation Serif" 
svg:font-family="&apos;Liberation Serif&apos;" 
style:font-family-generic="roman" style:font-pitch="variable"/>
  </office:font-face-decls>
  <office:styles>
@@ -22,7 +22,7 @@
  </office:styles>
  <office:automatic-styles>
   <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
-   <style:text-properties style:font-name="Liberation Sans"/>
+   <style:text-properties style:font-name="DejaVu Sans"/>
   </style:style>
   <style:page-layout style:name="pm1">
    <style:header-style>
@@ -33,7 +33,7 @@
  <office:master-styles>
   <style:master-page style:name="Standard" style:page-layout-name="pm1">
    <style:header>
-    <text:p text:style-name="P1">Header: Liberation Sans</text:p>
+    <text:p text:style-name="P1">Header: DejaVu Sans</text:p>
    </style:header>
   </style:master-page>
  </office:master-styles>
diff --git a/sw/qa/extras/odfexport/odfexport2.cxx 
b/sw/qa/extras/odfexport/odfexport2.cxx
index 287185bf67e6..12f2f32b6fd8 100644
--- a/sw/qa/extras/odfexport/odfexport2.cxx
+++ b/sw/qa/extras/odfexport/odfexport2.cxx
@@ -39,35 +39,48 @@ public:
 
 CPPUNIT_TEST_FIXTURE(Test, testEmbeddedFontProps)
 {
-    loadAndReload("embedded-font-props.odt");
+    createSwDoc("embedded-font-props.odt");
+    uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, 
uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> xProps(
+        xFactory->createInstance(u"com.sun.star.document.Settings"_ustr), 
uno::UNO_QUERY_THROW);
+    xProps->setPropertyValue(u"EmbedFonts"_ustr, uno::Any(true));
+
+    saveAndReload(mpFilter);
     CPPUNIT_ASSERT_EQUAL(1, getPages());
 #if !defined(MACOSX)
     // Test that font style/weight of embedded fonts is exposed.
-    // Test file is a normal ODT, except EmbedFonts is set to true in 
settings.xml.
     xmlDocUniquePtr pXmlDoc = parseExport(u"styles.xml"_ustr);
     // These failed, the attributes were missing.
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-style", u"normal");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-weight", u"normal");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-style", u"normal");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-weight", u"bold");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-style", u"italic");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-weight", u"normal");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-style", u"italic");
-    assertXPath(pXmlDoc, "//style:font-face[@style:name='Liberation 
Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-weight", u"bold");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-style", u"normal");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[1]", "font-weight", u"normal");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-style", u"normal");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[2]", "font-weight", u"bold");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-style", u"italic");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[3]", "font-weight", u"normal");
+#if defined _WIN32
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-style", u"italic");
+    assertXPath(pXmlDoc, "//style:font-face[@style:name='DejaVu 
Serif']/svg:font-face-src/svg:font-face-uri[4]", "font-weight", u"bold");
+#endif
 #endif
 }
 
 CPPUNIT_TEST_FIXTURE(Test, tdf166627)
 {
     loadAndReload("font_used_in_header_only.fodt");
-    // Liberation Sans wasn't embedded before fix, because it was only seen 
used in header
+    // DejaVu Sans wasn't embedded before fix, because it was only seen used 
in header
 
     xmlDocUniquePtr pXmlDoc = parseExport(u"styles.xml"_ustr);
 
-    // There should be four files embedded for the font
+    // There should be four (three on Linux? Why DejaVu differs there?) files 
embedded for the font
+#if defined(_WIN32) || defined(MACOSX)
+    assertXPath(
+        pXmlDoc,
+        "//style:font-face[@style:name='DejaVu 
Sans']/svg:font-face-src/svg:font-face-uri", 4);
+#else
     assertXPath(
         pXmlDoc,
-        "//style:font-face[@style:name='Liberation 
Sans']/svg:font-face-src/svg:font-face-uri", 4);
+        "//style:font-face[@style:name='DejaVu 
Sans']/svg:font-face-src/svg:font-face-uri", 3);
+#endif
 
     uno::Reference<container::XNameAccess> xZipNames(
         
packages::zip::ZipFileAccess::createWithURL(comphelper::getProcessComponentContext(),
@@ -76,24 +89,26 @@ CPPUNIT_TEST_FIXTURE(Test, tdf166627)
 
     OUString url = getXPath(
         pXmlDoc,
-        "//style:font-face[@style:name='Liberation 
Sans']/svg:font-face-src/svg:font-face-uri[1]",
+        "//style:font-face[@style:name='DejaVu 
Sans']/svg:font-face-src/svg:font-face-uri[1]",
         "href");
     CPPUNIT_ASSERT(xZipNames->hasByName(url));
     url = getXPath(
         pXmlDoc,
-        "//style:font-face[@style:name='Liberation 
Sans']/svg:font-face-src/svg:font-face-uri[2]",
+        "//style:font-face[@style:name='DejaVu 
Sans']/svg:font-face-src/svg:font-face-uri[2]",
         "href");
     CPPUNIT_ASSERT(xZipNames->hasByName(url));
     url = getXPath(
         pXmlDoc,
-        "//style:font-face[@style:name='Liberation 
Sans']/svg:font-face-src/svg:font-face-uri[3]",
+        "//style:font-face[@style:name='DejaVu 
Sans']/svg:font-face-src/svg:font-face-uri[3]",
         "href");
     CPPUNIT_ASSERT(xZipNames->hasByName(url));
+#if defined(_WIN32) || defined(MACOSX)
     url = getXPath(
         pXmlDoc,
-        "//style:font-face[@style:name='Liberation 
Sans']/svg:font-face-src/svg:font-face-uri[4]",
+        "//style:font-face[@style:name='DejaVu 
Sans']/svg:font-face-src/svg:font-face-uri[4]",
         "href");
     CPPUNIT_ASSERT(xZipNames->hasByName(url));
+#endif
 }
 
 DECLARE_ODFEXPORT_TEST(testTdf100492, "tdf100492.odt")
diff --git a/sw/qa/extras/uiwriter/data/testFontEmbedding.odt 
b/sw/qa/extras/uiwriter/data/testFontEmbedding.odt
index 17471af39b9f..1971254c257c 100644
Binary files a/sw/qa/extras/uiwriter/data/testFontEmbedding.odt and 
b/sw/qa/extras/uiwriter/data/testFontEmbedding.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx 
b/sw/qa/extras/uiwriter/uiwriter6.cxx
index 2c0069a7e65a..690c9b087ae0 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -2298,9 +2298,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testFontEmbedding)
     pXmlDoc = parseExport(u"styles.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    assertXPath(pXmlDoc, aStylesBaseXpath + "/style:font-face['CASE 1']", 6);
-    for (auto fontName : { "Caladea", "Carlito", "Liberation Sans", 
"Liberation Sans1",
-                           "Liberation Serif", "Liberation Serif1" })
+    assertXPath(pXmlDoc, aStylesBaseXpath + "/style:font-face['CASE 1']", 5);
+    for (auto fontName : { "DejaVu Sans", "DejaVu Sans Mono", "DejaVu Serif",
+                           "DejaVu Serif Condensed", "DejaVu Serif Condensed1" 
})
     {
         OString prefix = aStylesBaseXpath + "/style:font-face[@style:name='" + 
fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 1']");
@@ -2311,9 +2311,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testFontEmbedding)
     pXmlDoc = parseExport(u"content.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face['CASE 1']", 6);
-    for (auto fontName : { "Caladea", "Carlito", "Liberation Sans", 
"Liberation Sans1",
-                           "Liberation Serif", "Liberation Serif1" })
+    assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face['CASE 1']", 5);
+    for (auto fontName : { "DejaVu Sans", "DejaVu Sans Mono", "DejaVu Serif",
+                           "DejaVu Serif Condensed", "DejaVu Serif Condensed1" 
})
     {
         OString prefix = aContentBaseXpath + "/style:font-face[@style:name='" 
+ fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 1']");
@@ -2352,9 +2352,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testFontEmbedding)
     pXmlDoc = parseExport(u"styles.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    assertXPath(pXmlDoc, aStylesBaseXpath + "/style:font-face['CASE 2']", 6);
-    for (auto fontName : { "Caladea", "Carlito", "Liberation Sans", 
"Liberation Sans1",
-                           "Liberation Serif", "Liberation Serif1" })
+    assertXPath(pXmlDoc, aStylesBaseXpath + "/style:font-face['CASE 2']", 5);
+    for (auto fontName : { "DejaVu Sans", "DejaVu Sans Mono", "DejaVu Serif",
+                           "DejaVu Serif Condensed", "DejaVu Serif Condensed1" 
})
     {
         OString prefix = aStylesBaseXpath + "/style:font-face[@style:name='" + 
fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 2']");
@@ -2365,9 +2365,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testFontEmbedding)
     pXmlDoc = parseExport(u"content.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face['CASE 2']", 6);
-    for (auto fontName : { "Caladea", "Carlito", "Liberation Sans", 
"Liberation Sans1",
-                           "Liberation Serif", "Liberation Serif1" })
+    assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face['CASE 2']", 5);
+    for (auto fontName : { "DejaVu Sans", "DejaVu Sans Mono", "DejaVu Serif",
+                           "DejaVu Serif Condensed", "DejaVu Serif Condensed1" 
})
     {
         OString prefix = aContentBaseXpath + "/style:font-face[@style:name='" 
+ fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 2']");
@@ -2405,37 +2405,38 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testFontEmbedding)
         pXmlDoc, aSettingsBaseXpath + 
"/config:config-item[@config:name='EmbedComplexScriptFonts']",
         u"true");
 
-    // Check styles - font-face-src should be present only for "Liberation 
Serif" fonts
+    // Check styles - font-face-src should be present only for "DejaVu Serif"
     pXmlDoc = parseExport(u"styles.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    assertXPath(pXmlDoc, aStylesBaseXpath + "/style:font-face['CASE 3']", 6);
-    for (auto fontName : { "Caladea", "Carlito", "Liberation Sans", 
"Liberation Sans1" })
+    assertXPath(pXmlDoc, aStylesBaseXpath + "/style:font-face['CASE 3']", 5);
+    for (auto fontName :
+         { "DejaVu Sans", "DejaVu Sans Mono", "DejaVu Serif Condensed", 
"DejaVu Serif Condensed1" })
     {
         OString prefix = aStylesBaseXpath + "/style:font-face[@style:name='" + 
fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 3']");
         assertXPath(pXmlDoc, prefix + "/svg:font-face-src['CASE 3']", 0);
     }
-    for (auto fontName : { "Liberation Serif", "Liberation Serif1" })
+    for (auto fontName : { "DejaVu Serif" })
     {
         OString prefix = aStylesBaseXpath + "/style:font-face[@style:name='" + 
fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 3']");
         assertXPath(pXmlDoc, prefix + "/svg:font-face-src['CASE 3']", 1);
     }
 
-    // Check content - font-face-src should be present only for Carlito and 
Liberation Serif fonts
+    // Check content - font-face-src should be present only for DejaVu Sans 
Mono and DejaVu Serif
     // Note that the used sets of fonts are different for styles.xml and 
content.xml
     pXmlDoc = parseExport(u"content.xml"_ustr);
     CPPUNIT_ASSERT(pXmlDoc);
 
-    assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face['CASE 3']", 6);
-    for (auto fontName : { "Caladea", "Liberation Sans", "Liberation Sans1" })
+    assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face['CASE 3']", 5);
+    for (auto fontName : { "DejaVu Sans", "DejaVu Serif Condensed", "DejaVu 
Serif Condensed1" })
     {
         OString prefix = aContentBaseXpath + "/style:font-face[@style:name='" 
+ fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 3']");
         assertXPath(pXmlDoc, prefix + "/svg:font-face-src['CASE 3']", 0);
     }
-    for (auto fontName : { "Carlito", "Liberation Serif", "Liberation Serif1" 
})
+    for (auto fontName : { "DejaVu Sans Mono", "DejaVu Serif" })
     {
         OString prefix = aContentBaseXpath + "/style:font-face[@style:name='" 
+ fontName + "']";
         assertXPath(pXmlDoc, prefix + "['CASE 3']");
diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx 
b/xmloff/source/style/XMLFontAutoStylePool.cxx
index 410ff63c8b45..60036d1342ea 100644
--- a/xmloff/source/style/XMLFontAutoStylePool.cxx
+++ b/xmloff/source/style/XMLFontAutoStylePool.cxx
@@ -428,6 +428,9 @@ void SvXMLExport::exportFonts(const 
std::vector<XMLFontAutoStylePoolEntry_Impl*>
         // When embedding is requested, and embedded only is not set or font 
is used
         if (bEmbedFonts && (!bEmbedUsedOnly || 
aUsedFontNames.contains(pEntry->GetFamilyName())))
         {
+            if (EmbeddedFontsHelper::isCommonFont(pEntry->GetFamilyName()))
+                continue;
+
             const bool bExportFlat(getExportFlags() & 
SvXMLExportFlags::EMBEDDED);
 
             /// Contains information about a single variant of an embedded 
font.

Reply via email to