sw/qa/extras/ooxmlexport/data/font_used_in_header_only.fodt |   45 ++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlexport25.cxx                  |   35 +++++++++
 2 files changed, 80 insertions(+)

New commits:
commit 1f397c6ee328d577fc9294779185341b24820492
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Aug 12 08:46:29 2025 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Aug 15 08:25:08 2025 +0200

    DOCX embedded fonts - skip common fonts - unit test
    
    After commit 32e14c68df3a8cbb8fc7c35ad4c1bfb5af521188
    (DOCX embedded fonts - skip common fonts, 2025-08-07).
    
    Change-Id: If6dad48e9d4b82127fc6fabe908762bf46b9b327
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189396
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 87a49d0e3214000fdff6ef7f047606cef647da2a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189429
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/font_used_in_header_only.fodt 
b/sw/qa/extras/ooxmlexport/data/font_used_in_header_only.fodt
new file mode 100644
index 000000000000..3ef2c2791cfe
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/font_used_in_header_only.fodt
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:settings>
+  <config:config-item-set config:name="ooo:configuration-settings">
+   <config:config-item config:name="EmbedFonts" 
config:type="boolean">true</config:config-item>
+   <config:config-item config:name="EmbedOnlyUsedFonts" 
config:type="boolean">true</config:config-item>
+   <config:config-item config:name="EmbedLatinScriptFonts" 
config:type="boolean">true</config:config-item>
+   <config:config-item config:name="EmbedAsianScriptFonts" 
config:type="boolean">false</config:config-item>
+   <config:config-item config:name="EmbedComplexScriptFonts" 
config:type="boolean">false</config:config-item>
+  </config:config-item-set>
+ </office:settings>
+ <office:font-face-decls>
+  <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>
+  <style:default-style style:family="paragraph">
+   <style:text-properties style:font-name="Liberation Serif" 
fo:font-size="12pt" fo:language="en" fo:country="US"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties style:font-name="DejaVu Sans"/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:header-style>
+    <style:header-footer-properties fo:min-height="0" fo:margin-left="0" 
fo:margin-right="0" fo:margin-bottom="5mm"/>
+   </style:header-style>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1">
+   <style:header>
+    <text:p text:style-name="P1">Header: DejaVu Sans</text:p>
+   </style:header>
+  </style:master-page>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p>Body: Liberation Serif</text:p>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
index 895eb8879719..bdbc66cdd764 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx
@@ -176,6 +176,41 @@ CPPUNIT_TEST_FIXTURE(Test, 
testFloatingTableAnchorPosExport)
     CPPUNIT_ASSERT_EQUAL(u"D"_ustr, getXPathContent(pXmlDoc, 
"//w:body/w:p/w:r/w:t"));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testFontEmbeddingDOCX)
+{
+    createSwDoc("font_used_in_header_only.fodt");
+    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);
+    CPPUNIT_ASSERT_EQUAL(uno::Any(true), 
xProps->getPropertyValue(u"EmbedFonts"_ustr));
+
+    save(mpFilter);
+
+    xmlDocUniquePtr pXml = parseExport(u"word/fontTable.xml"_ustr);
+
+    // Test that DejaVu Sans is embedded
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='DejaVu Sans']/w:embedRegular");
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='DejaVu Sans']/w:embedBold");
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='DejaVu Sans']/w:embedItalic");
+// It is strange that DejaVu is different on Linux: see e.g. tdf166627 in 
odfexport2.cxx
+#if defined(_WIN32) || defined(MACOSX)
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='DejaVu 
Sans']/w:embedBoldItalic");
+#endif
+
+    // Test that common fonts (here: Liberation Serif, Liberation Sans) are 
not embedded
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation Serif']");
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Serif']/w:embedRegular", 0);
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Serif']/w:embedBold", 0);
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Serif']/w:embedItalic", 0);
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Serif']/w:embedBoldItalic", 0);
+
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation Sans']");
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Sans']/w:embedRegular", 0);
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Sans']/w:embedBold", 0);
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Sans']/w:embedItalic", 0);
+    assertXPath(pXml, "/w:fonts/w:font[@w:name='Liberation 
Sans']/w:embedBoldItalic", 0);
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 

Reply via email to