sd/CppunitTest_sd_font_embedding_tests.mk | 75 +++++++++++++++ sd/Module_sd.mk | 1 sd/qa/unit/FontEmbeddingTest.cxx | 150 ++++++++++++++++++++++++++++++ sd/qa/unit/data/BoldonseFontEmbedded.pptx |binary 4 files changed, 226 insertions(+)
New commits: commit dcd74c1eabfddb4dbc139d853e178c27fe78881f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue May 6 14:25:27 2025 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu May 8 10:54:23 2025 +0200 sd: Test OOXML embedded fonts - import, export and round-trip Import and round-trip tests don't run when libeot is not available. Export test doesn't depend on libeot, so it can run. Change-Id: I71d290b3f93a0ccdb9f8a5bdb9c933464c7059ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184974 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sd/CppunitTest_sd_font_embedding_tests.mk b/sd/CppunitTest_sd_font_embedding_tests.mk new file mode 100644 index 000000000000..16a637ecae0c --- /dev/null +++ b/sd/CppunitTest_sd_font_embedding_tests.mk @@ -0,0 +1,75 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sd_font_embedding_tests)) + +$(eval $(call gb_CppunitTest_use_externals,sd_font_embedding_tests,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sd_font_embedding_tests)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sd_font_embedding_tests, \ + sd/qa/unit/FontEmbeddingTest \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sd_font_embedding_tests, \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + docmodel \ + editeng \ + for \ + forui \ + i18nlangtag \ + sal \ + salhelper \ + sax \ + sd \ + sfx \ + sot \ + subsequenttest \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tl \ + tk \ + ucbhelper \ + unotest \ + utl \ + vcl \ + xo \ +)) + +$(eval $(call gb_CppunitTest_set_include,sd_font_embedding_tests,\ + -I$(SRCDIR)/sd/source/ui/inc \ + -I$(SRCDIR)/sd/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sd_font_embedding_tests,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,sd_font_embedding_tests)) +$(eval $(call gb_CppunitTest_use_ure,sd_font_embedding_tests)) +$(eval $(call gb_CppunitTest_use_vcl,sd_font_embedding_tests)) +$(eval $(call gb_CppunitTest_use_rdb,sd_font_embedding_tests,services)) +$(eval $(call gb_CppunitTest_use_configuration,sd_font_embedding_tests)) + + + +# vim: set noet sw=4 ts=4: diff --git a/sd/Module_sd.mk b/sd/Module_sd.mk index 827e5f51ea92..aefdbb587dd4 100644 --- a/sd/Module_sd.mk +++ b/sd/Module_sd.mk @@ -41,6 +41,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sd,\ CppunitTest_sd_export_tests-ooxml4 \ CppunitTest_sd_export_tests \ CppunitTest_sd_filters_test \ + CppunitTest_sd_font_embedding_tests \ CppunitTest_sd_layout_tests \ CppunitTest_sd_misc_tests \ CppunitTest_sd_uiimpress \ diff --git a/sd/qa/unit/FontEmbeddingTest.cxx b/sd/qa/unit/FontEmbeddingTest.cxx new file mode 100644 index 000000000000..9c1b2571376c --- /dev/null +++ b/sd/qa/unit/FontEmbeddingTest.cxx @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "sdmodeltestbase.hxx" +#include <test/unoapi_test.hxx> +#include <config_eot.h> +#include <config_fonts.h> +#include <vcl/embeddedfontshelper.hxx> + +using namespace css; + +class FontEmbeddingTest : public SdModelTestBase +{ +public: + FontEmbeddingTest() + : SdModelTestBase(u"/sd/qa/unit/data/"_ustr) + { + } +}; + +namespace +{ +constexpr OString xPath_Presentation = "/p:presentation"_ostr; +constexpr OString xPath_EmbeddedFont + = "/p:presentation/p:embeddedFontLst/p:embeddedFont/p:font"_ostr; +constexpr OString xPath_Relationship = "/rels:Relationships/rels:Relationship"_ostr; +} + +CPPUNIT_TEST_FIXTURE(FontEmbeddingTest, testRoundtripEmbeddedFontsPPTX) +{ +#if ENABLE_EOT + // Test Import first + + // Expect the font to not be available + { + OUString aUrl = EmbeddedFontsHelper::fontFileUrl( + u"Boldonse", FAMILY_ROMAN, ITALIC_NONE, WEIGHT_NORMAL, PITCH_VARIABLE, + EmbeddedFontsHelper::FontRights::ViewingAllowed); + CPPUNIT_ASSERT(aUrl.isEmpty()); + } + + // Load the document + createSdImpressDoc("BoldonseFontEmbedded.pptx"); + +// FIXME: for some reason it doesn't work in macOS (see testSubsettedFullEmbeddedFont for asimilar case) +#if !defined(MACOSX) + // Expect the font to be available now, if we imported the embedded fonts correctly + { + OUString aUrl = EmbeddedFontsHelper::fontFileUrl( + u"Boldonse", FAMILY_ROMAN, ITALIC_NONE, WEIGHT_NORMAL, PITCH_VARIABLE, + EmbeddedFontsHelper::FontRights::ViewingAllowed); + + CPPUNIT_ASSERT(!aUrl.isEmpty()); + } +#endif + + // Check the document settings for embedded fonts are as expected + { + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xFactory.is()); + uno::Reference<beans::XPropertySet> xSettings( + xFactory->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY); + CPPUNIT_ASSERT(xSettings.is()); + + bool bEmbedFonts = false; + bool bEmbedUsedOnly = false; + bool bEmbedLatinScript = false; + bool bEmbedAsianScript = false; + bool bEmbedComplexScript = false; + + xSettings->getPropertyValue(u"EmbedFonts"_ustr) >>= bEmbedFonts; + xSettings->getPropertyValue(u"EmbedOnlyUsedFonts"_ustr) >>= bEmbedUsedOnly; + xSettings->getPropertyValue(u"EmbedLatinScriptFonts"_ustr) >>= bEmbedLatinScript; + xSettings->getPropertyValue(u"EmbedAsianScriptFonts"_ustr) >>= bEmbedAsianScript; + xSettings->getPropertyValue(u"EmbedComplexScriptFonts"_ustr) >>= bEmbedComplexScript; + + CPPUNIT_ASSERT_EQUAL(true, bEmbedFonts); + CPPUNIT_ASSERT_EQUAL(false, bEmbedUsedOnly); + CPPUNIT_ASSERT_EQUAL(true, bEmbedLatinScript); + CPPUNIT_ASSERT_EQUAL(true, bEmbedAsianScript); + CPPUNIT_ASSERT_EQUAL(true, bEmbedComplexScript); + } + + // Test Export + save(u"Impress Office Open XML"_ustr); + + // Check the exported document has the font + { + xmlDocUniquePtr pXmlDoc = parseExport(u"ppt/presentation.xml"_ustr); + assertXPath(pXmlDoc, xPath_Presentation, "embedTrueTypeFonts", u"1"); + assertXPath(pXmlDoc, xPath_EmbeddedFont + "[@typeface='Boldonse']"); + } +#endif +} + +CPPUNIT_TEST_FIXTURE(FontEmbeddingTest, testExportEmbeddedFontsPPTX) +{ +#if HAVE_MORE_FONTS + + createSdImpressDoc(); + + 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); + + // Check state of the font embedding settings + CPPUNIT_ASSERT_EQUAL(false, xProps->getPropertyValue(u"EmbedFonts"_ustr).get<bool>()); + CPPUNIT_ASSERT_EQUAL(false, xProps->getPropertyValue(u"EmbedOnlyUsedFonts"_ustr).get<bool>()); + CPPUNIT_ASSERT_EQUAL(true, xProps->getPropertyValue(u"EmbedLatinScriptFonts"_ustr).get<bool>()); + CPPUNIT_ASSERT_EQUAL(true, xProps->getPropertyValue(u"EmbedAsianScriptFonts"_ustr).get<bool>()); + CPPUNIT_ASSERT_EQUAL(true, + xProps->getPropertyValue(u"EmbedComplexScriptFonts"_ustr).get<bool>()); + + // Enable font embedding, only used and latin script fonts + xProps->setPropertyValue(u"EmbedFonts"_ustr, uno::Any(true)); + xProps->setPropertyValue(u"EmbedOnlyUsedFonts"_ustr, uno::Any(true)); + xProps->setPropertyValue(u"EmbedLatinScriptFonts"_ustr, uno::Any(true)); + xProps->setPropertyValue(u"EmbedAsianScriptFonts"_ustr, uno::Any(false)); + xProps->setPropertyValue(u"EmbedComplexScriptFonts"_ustr, uno::Any(false)); + + save(u"Impress Office Open XML"_ustr); + + // Check the exported document has the embedded fonts enabled and has entries + { + xmlDocUniquePtr pXmlDoc = parseExport(u"ppt/presentation.xml"_ustr); + assertXPath(pXmlDoc, xPath_Presentation, "embedTrueTypeFonts", u"1"); + assertXPath(pXmlDoc, xPath_EmbeddedFont + "[@typeface='Liberation Sans']"); + } + + // Check the relationships to the embedded fonts + { + xmlDocUniquePtr pXmlDoc = parseExport(u"ppt/_rels/presentation.xml.rels"_ustr); + + static constexpr auto sFontType + = u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/font"; + assertXPath(pXmlDoc, xPath_Relationship + "[@Target='fonts/font1.fntdata']", "Type", + sFontType); + } +#endif +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/data/BoldonseFontEmbedded.pptx b/sd/qa/unit/data/BoldonseFontEmbedded.pptx new file mode 100644 index 000000000000..9e8ed3551226 Binary files /dev/null and b/sd/qa/unit/data/BoldonseFontEmbedded.pptx differ