sw/qa/extras/embedded_fonts/embedded_fonts.cxx | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
New commits: commit d0cb0b2563d2c0de14e430eeef625b686213d489 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Aug 13 02:16:07 2025 +0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Aug 15 10:57:54 2025 +0200 Documents with restricted fonts: unit tests for not embedding on save Change-Id: Ib670a79fafea50c84cbc0c3054451a526877d514 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189459 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit b7855d36b51d72e4f7f957690e8a9558ec6aaa6c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189465 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/embedded_fonts/embedded_fonts.cxx b/sw/qa/extras/embedded_fonts/embedded_fonts.cxx index 4cb5e261e6ab..c0c26a44df8f 100644 --- a/sw/qa/extras/embedded_fonts/embedded_fonts.cxx +++ b/sw/qa/extras/embedded_fonts/embedded_fonts.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/awt/Toolkit.hpp> #include <com/sun/star/awt/XFontMappingUse.hpp> #include <com/sun/star/document/FontsDisallowEditingRequest.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <com/sun/star/task/XInteractionApprove.hpp> #include <com/sun/star/task/XInteractionDisapprove.hpp> #include <com/sun/star/task/XInteractionHandler.hpp> @@ -179,6 +180,18 @@ CPPUNIT_TEST_FIXTURE(Test, testOpenODTWithRestrictedEmbeddedFont) // The request was disapproved, and the font didn't load; so it was substituted: CPPUNIT_ASSERT(fontMappingData.wasUsed(u"Naftalene")); CPPUNIT_ASSERT(fontMappingData.wasSubstituted(u"Naftalene")); + + // Make sure that saving doesn't somehow embed the font + save(u"writer8"_ustr); + xmlDocUniquePtr pXml = parseExport(u"content.xml"_ustr); + assertXPath(pXml, "//style:font-face[@style:name='Naftalene']"); + assertXPath(pXml, "//style:font-face[@style:name='Naftalene']/svg:font-face-src", 0); + + auto xZipFile = packages::zip::ZipFileAccess::createWithURL( + comphelper::getProcessComponentContext(), maTempFile.GetURL()); + CPPUNIT_ASSERT(xZipFile); + for (const OUString& name : xZipFile->getElementNames()) + CPPUNIT_ASSERT(name.indexOf("Naftalene") < 0); } { @@ -201,6 +214,18 @@ CPPUNIT_TEST_FIXTURE(Test, testOpenODTWithRestrictedEmbeddedFont) // The request was approved, and the font loaded; no substitution happened: CPPUNIT_ASSERT(fontMappingData.wasUsed(u"Naftalene")); CPPUNIT_ASSERT(!fontMappingData.wasSubstituted(u"Naftalene")); + + // Make sure that saving doesn't somehow embed the font + save(u"writer8"_ustr); + xmlDocUniquePtr pXml = parseExport(u"content.xml"_ustr); + assertXPath(pXml, "//style:font-face[@style:name='Naftalene']"); + assertXPath(pXml, "//style:font-face[@style:name='Naftalene']/svg:font-face-src", 0); + + auto xZipFile = packages::zip::ZipFileAccess::createWithURL( + comphelper::getProcessComponentContext(), maTempFile.GetURL()); + CPPUNIT_ASSERT(xZipFile); + for (const OUString& name : xZipFile->getElementNames()) + CPPUNIT_ASSERT(name.indexOf("Naftalene") < 0); } } @@ -226,6 +251,15 @@ CPPUNIT_TEST_FIXTURE(Test, testOpenDOCXWithRestrictedEmbeddedFont) // Unrestricted font was loaded and used without substitution: CPPUNIT_ASSERT(fontMappingData.wasUsed(u"Unsteady Oversteer")); CPPUNIT_ASSERT(!fontMappingData.wasSubstituted(u"Unsteady Oversteer")); + + // Make sure that saving doesn't somehow embed the font + save(u"Office Open XML Text"_ustr); + xmlDocUniquePtr pXml = parseExport(u"word/fontTable.xml"_ustr); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']"); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedRegular", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedBold", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedItalic", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedBoldItalic", 0); } { @@ -253,6 +287,15 @@ CPPUNIT_TEST_FIXTURE(Test, testOpenDOCXWithRestrictedEmbeddedFont) // Unrestricted font was loaded and used without substitution: CPPUNIT_ASSERT(fontMappingData.wasUsed(u"Unsteady Oversteer")); CPPUNIT_ASSERT(!fontMappingData.wasSubstituted(u"Unsteady Oversteer")); + + // Make sure that saving doesn't somehow embed the font + save(u"Office Open XML Text"_ustr); + xmlDocUniquePtr pXml = parseExport(u"word/fontTable.xml"_ustr); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']"); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedRegular", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedBold", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedItalic", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedBoldItalic", 0); } { @@ -280,6 +323,15 @@ CPPUNIT_TEST_FIXTURE(Test, testOpenDOCXWithRestrictedEmbeddedFont) // Unrestricted font was loaded and used without substitution: CPPUNIT_ASSERT(fontMappingData.wasUsed(u"Unsteady Oversteer")); CPPUNIT_ASSERT(!fontMappingData.wasSubstituted(u"Unsteady Oversteer")); + + // Make sure that saving doesn't somehow embed the font + save(u"Office Open XML Text"_ustr); + xmlDocUniquePtr pXml = parseExport(u"word/fontTable.xml"_ustr); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']"); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedRegular", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedBold", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedItalic", 0); + assertXPath(pXml, "/w:fonts/w:font[@w:name='Naftalene']/w:embedBoldItalic", 0); } }