cui/source/dialogs/FontFeaturesDialog.cxx | 2 sw/qa/extras/inc/swmodeltestbase.hxx | 1 sw/qa/extras/uiwriter/data/testFontEmbedding.odt |binary sw/qa/extras/uiwriter/uiwriter.cxx | 139 +++++++++++++++++++++++ vcl/inc/font/FeatureCollector.hxx | 6 vcl/qa/cppunit/FontFeatureTest.cxx | 11 + vcl/source/font/FeatureCollector.cxx | 38 ++---- vcl/source/outdev/font.cxx | 5 8 files changed, 175 insertions(+), 27 deletions(-)
New commits: commit 39e5b2c174c6a27b5c3e2a08b00dd4c26677e07f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Mon Jul 9 01:02:22 2018 +0200 tdf#65353 test for font embedding in ODF documents Change-Id: I97fdb9ffb506a005dac08f7c78a3fa4383098b0b Reviewed-on: https://gerrit.libreoffice.org/57169 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx index e0d304beabc8..19090189510c 100644 --- a/sw/qa/extras/inc/swmodeltestbase.hxx +++ b/sw/qa/extras/inc/swmodeltestbase.hxx @@ -937,6 +937,7 @@ protected: xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("table"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:table:1.0")); xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("draw"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0")); xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("fo"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("config"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:config:1.0")); xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xlink"), BAD_CAST("http://www.w3.org/1999/xlink")); xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/")); xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("meta"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:meta:1.0")); diff --git a/sw/qa/extras/uiwriter/data/testFontEmbedding.odt b/sw/qa/extras/uiwriter/data/testFontEmbedding.odt new file mode 100644 index 000000000000..17471af39b9f Binary files /dev/null and b/sw/qa/extras/uiwriter/data/testFontEmbedding.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index b51fa7483bd8..b80820a29115 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -323,6 +323,7 @@ public: void testTdf113287(); void testTdf113445(); void testTdf113686(); + void testFontEmbedding(); #endif void testLinesInSectionInTable(); void testParagraphOfTextRange(); @@ -520,6 +521,7 @@ public: CPPUNIT_TEST(testTdf113287); CPPUNIT_TEST(testTdf113445); CPPUNIT_TEST(testTdf113686); + CPPUNIT_TEST(testFontEmbedding); #endif CPPUNIT_TEST(testLinesInSectionInTable); CPPUNIT_TEST(testParagraphOfTextRange); @@ -6333,6 +6335,143 @@ void SwUiWriterTest::testTdf51223() CPPUNIT_ASSERT_EQUAL(OUString("i"), static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); } + +void SwUiWriterTest::testFontEmbedding() +{ +#if HAVE_MORE_FONTS && !defined(MACOSX) + createDoc("testFontEmbedding.odt"); + + OString aContentBaseXpath("/office:document-content/office:font-face-decls"); + OString aSettingsBaseXpath("/office:document-settings/office:settings/config:config-item-set"); + + xmlDocPtr pXmlDoc = nullptr; + uno::Sequence<beans::PropertyValue> aDescriptor; + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + + // Get document settings + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xProps(xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY_THROW); + + // Check font embedding state + CPPUNIT_ASSERT_EQUAL(false, xProps->getPropertyValue("EmbedFonts").get<bool>()); + CPPUNIT_ASSERT_EQUAL(false, xProps->getPropertyValue("EmbedOnlyUsedFonts").get<bool>()); + // Font scripts should be enabled by default, however this has no effect unless "EmbedOnlyUsedFonts" is enabled + CPPUNIT_ASSERT_EQUAL(true, xProps->getPropertyValue("EmbedLatinScriptFonts").get<bool>()); + CPPUNIT_ASSERT_EQUAL(true, xProps->getPropertyValue("EmbedAsianScriptFonts").get<bool>()); + CPPUNIT_ASSERT_EQUAL(true, xProps->getPropertyValue("EmbedComplexScriptFonts").get<bool>()); + + // CASE 1 - no font embedding enabled + + // Save the document + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + xStorable->storeToURL(aTempFile.GetURL(), aDescriptor); + CPPUNIT_ASSERT(aTempFile.IsValid()); + + // Check setting - No font enbedding should be enabled + pXmlDoc = parseExportInternal(aTempFile.GetURL(),"settings.xml"); + CPPUNIT_ASSERT(pXmlDoc); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedFonts']", "false"); + + // Check content - No font-face-src nodes should be present + pXmlDoc = parseExportInternal(aTempFile.GetURL(),"content.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face", 6); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans1']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans1']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif1']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif1']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Carlito']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Carlito']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Caladea']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Caladea']/svg:font-face-src", 0); + + // CASE 2 - font embedding enabled, but embed used fonts disabled + + // Enable font embedding, diable embedding used font only + xProps->setPropertyValue("EmbedFonts", uno::makeAny(true)); + xProps->setPropertyValue("EmbedOnlyUsedFonts", uno::makeAny(false)); + + // Save the document again + xStorable->storeToURL(aTempFile.GetURL(), aDescriptor); + CPPUNIT_ASSERT(aTempFile.IsValid()); + + // Check setting - font embedding should be enabled + embed only used fonts and scripts + pXmlDoc = parseExportInternal(aTempFile.GetURL(),"settings.xml"); + CPPUNIT_ASSERT(pXmlDoc); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedOnlyUsedFonts']", "false"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedLatinScriptFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedAsianScriptFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedComplexScriptFonts']", "true"); + + // Check content - font-face-src should be present only for "Liberation Sans" fonts + + pXmlDoc = parseExportInternal(aTempFile.GetURL(),"content.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face", 6); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans1']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans1']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif1']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif1']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Carlito']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Carlito']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Caladea']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Caladea']/svg:font-face-src", 1); + + // CASE 3 - font embedding enabled, embed only used fonts enabled + + // Enable font embedding and setting to embed used fonts only + xProps->setPropertyValue("EmbedFonts", uno::makeAny(true)); + xProps->setPropertyValue("EmbedOnlyUsedFonts", uno::makeAny(true)); + xProps->setPropertyValue("EmbedLatinScriptFonts", uno::makeAny(true)); + xProps->setPropertyValue("EmbedAsianScriptFonts", uno::makeAny(true)); + xProps->setPropertyValue("EmbedComplexScriptFonts", uno::makeAny(true)); + + // Save the document again + xStorable->storeToURL(aTempFile.GetURL(), aDescriptor); + CPPUNIT_ASSERT(aTempFile.IsValid()); + + // Check setting - font embedding should be enabled + embed only used fonts and scripts + pXmlDoc = parseExportInternal(aTempFile.GetURL(),"settings.xml"); + CPPUNIT_ASSERT(pXmlDoc); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedOnlyUsedFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedLatinScriptFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedAsianScriptFonts']", "true"); + assertXPathContent(pXmlDoc, aSettingsBaseXpath + "/config:config-item[@config:name='EmbedComplexScriptFonts']", "true"); + + // Check content - font-face-src should be present only for "Liberation Sans" fonts + + pXmlDoc = parseExportInternal(aTempFile.GetURL(),"content.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face", 6); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans1']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Sans1']/svg:font-face-src", 0); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif1']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Liberation Serif1']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Carlito']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Carlito']/svg:font-face-src", 1); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Caladea']"); + assertXPath(pXmlDoc, aContentBaseXpath + "/style:font-face[@style:name='Caladea']/svg:font-face-src", 0); +#endif +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); commit 28493a04f0fa63a76c096c62a3141d86edbac964 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Jul 10 23:47:36 2018 +0200 font feat: prioritize Graphite descriptions, use UI lang., fixes When collecting font feature description do prioritize Graphite collected descriptions over OT. This is important for descriptions for ssxx and cvxx only contain general description and not what exactly they do. When collecting for Graphite use the UI language for descriptions. Fix gathering the descriptions with graphite to include all of the descriptions available. Change-Id: I6b3b92eb160fc3fd70214edf0d37095865f9c563 Reviewed-on: https://gerrit.libreoffice.org/57250 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/cui/source/dialogs/FontFeaturesDialog.cxx b/cui/source/dialogs/FontFeaturesDialog.cxx index 6f9543c13109..676f216e25ec 100644 --- a/cui/source/dialogs/FontFeaturesDialog.cxx +++ b/cui/source/dialogs/FontFeaturesDialog.cxx @@ -11,7 +11,6 @@ #include <FontFeaturesDialog.hxx> #include <vcl/font/FeatureParser.hxx> -#include <svx/strings.hrc> #include <svx/dialmgr.hxx> using namespace css; @@ -34,7 +33,6 @@ VclPtr<ComboBox> makeEnumComboBox(vcl::Window* pParent, { VclPtr<ComboBox> aNameBox( VclPtr<ComboBox>::Create(pParent, WB_TABSTOP | WB_DROPDOWN | WB_AUTOHSCROLL)); - aNameBox->InsertEntry(SvxResId(RID_SVXSTR_NONE)); for (vcl::font::FeatureParameter const& rParameter : rFeatureDefinition.getEnumParameters()) { aNameBox->InsertEntry(rParameter.getDescription()); diff --git a/vcl/inc/font/FeatureCollector.hxx b/vcl/inc/font/FeatureCollector.hxx index 4e918c48e334..6c278ca15188 100644 --- a/vcl/inc/font/FeatureCollector.hxx +++ b/vcl/inc/font/FeatureCollector.hxx @@ -14,6 +14,7 @@ #include <vcl/font/Feature.hxx> #include <o3tl/make_unique.hxx> #include <hb.h> +#include <i18nlangtag/lang.h> namespace vcl { @@ -24,11 +25,14 @@ class FeatureCollector private: hb_face_t* m_pHbFace; std::vector<vcl::font::Feature>& m_rFontFeatures; + LanguageType m_eLanguageType; public: - FeatureCollector(hb_face_t* pHbFace, std::vector<vcl::font::Feature>& rFontFeatures) + FeatureCollector(hb_face_t* pHbFace, std::vector<vcl::font::Feature>& rFontFeatures, + LanguageType eLanguageType) : m_pHbFace(pHbFace) , m_rFontFeatures(rFontFeatures) + , m_eLanguageType(eLanguageType) { } diff --git a/vcl/qa/cppunit/FontFeatureTest.cxx b/vcl/qa/cppunit/FontFeatureTest.cxx index 879411ac5d1c..6944c7c5b6b0 100644 --- a/vcl/qa/cppunit/FontFeatureTest.cxx +++ b/vcl/qa/cppunit/FontFeatureTest.cxx @@ -102,16 +102,21 @@ void FontFeatureTest::testGetFontFeatures() CPPUNIT_ASSERT_EQUAL(vcl::font::FeatureParameterType::ENUM, rFracFeatureDefinition.getType()); - CPPUNIT_ASSERT_EQUAL(size_t(2), rFracFeatureDefinition.getEnumParameters().size()); + CPPUNIT_ASSERT_EQUAL(size_t(3), rFracFeatureDefinition.getEnumParameters().size()); vcl::font::FeatureParameter const& rParameter1 = rFracFeatureDefinition.getEnumParameters()[0]; - CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), rParameter1.getCode()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), rParameter1.getCode()); CPPUNIT_ASSERT(!rParameter1.getDescription().isEmpty()); vcl::font::FeatureParameter const& rParameter2 = rFracFeatureDefinition.getEnumParameters()[1]; - CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), rParameter2.getCode()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), rParameter2.getCode()); + CPPUNIT_ASSERT(!rParameter2.getDescription().isEmpty()); + + vcl::font::FeatureParameter const& rParameter3 + = rFracFeatureDefinition.getEnumParameters()[2]; + CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), rParameter3.getCode()); CPPUNIT_ASSERT(!rParameter2.getDescription().isEmpty()); } #endif // HAVE_MORE_FONTS diff --git a/vcl/source/font/FeatureCollector.cxx b/vcl/source/font/FeatureCollector.cxx index 8f6b8180c3e9..a8c1ff0d2548 100644 --- a/vcl/source/font/FeatureCollector.cxx +++ b/vcl/source/font/FeatureCollector.cxx @@ -26,7 +26,7 @@ bool FeatureCollector::collectGraphiteFeatureDefinition(vcl::font::Feature& rFea bool bFound = false; - gr_uint16 nUILanguage = 0x0409; + gr_uint16 nUILanguage = gr_uint16(m_eLanguageType); gr_uint16 nNumberOfFeatures = gr_face_n_fref(grFace); gr_feature_val* pFeatures = gr_face_featureval_for_lang(grFace, rFeature.m_aID.m_aLanguageCode); @@ -49,22 +49,21 @@ bool FeatureCollector::collectGraphiteFeatureDefinition(vcl::font::Feature& rFea gr_uint16 nNumberOfValues = gr_fref_n_values(pFeatureRef); for (gr_uint16 j = 0; j < nNumberOfValues; ++j) { - if (gr_fref_value(pFeatureRef, j)) - { - gr_uint32 nValueLabelLength = 0; - void* pValueLabel = gr_fref_value_label(pFeatureRef, j, &nUILanguage, - gr_utf8, &nValueLabelLength); - OUString sValueLabel( - OUString::createFromAscii(static_cast<char*>(pValueLabel))); - aParameters.emplace_back(sal_uInt32(j), sValueLabel); - gr_label_destroy(pValueLabel); - } + gr_uint32 nValueLabelLength = 0; + void* pValueLabel = gr_fref_value_label(pFeatureRef, j, &nUILanguage, gr_utf8, + &nValueLabelLength); + OUString sValueLabel( + OUString::createFromAscii(static_cast<char*>(pValueLabel))); + aParameters.emplace_back(sal_uInt32(j), sValueLabel); + gr_label_destroy(pValueLabel); } auto eFeatureParameterType = vcl::font::FeatureParameterType::ENUM; // Check if the parameters are boolean - if (aParameters.size() == 1 && aParameters[0].getDescription() == "True") + if (aParameters.size() == 2 + && (aParameters[0].getDescription() == "True" + || aParameters[0].getDescription() == "False")) { eFeatureParameterType = vcl::font::FeatureParameterType::BOOL; aParameters.clear(); @@ -99,15 +98,14 @@ void FeatureCollector::collectForLanguage(hb_tag_t aTableTag, sal_uInt32 nScript vcl::font::Feature& rFeature = m_rFontFeatures.back(); rFeature.m_aID = { aFeatureTag, aScriptTag, aLanguageTag }; - FeatureDefinition aDefinition - = OpenTypeFeatureDefinitonList::get().getDefinition(aFeatureTag); - if (aDefinition) + if (!collectGraphiteFeatureDefinition(rFeature)) { - rFeature.m_aDefinition = vcl::font::FeatureDefinition(aDefinition); - } - else - { - collectGraphiteFeatureDefinition(rFeature); + FeatureDefinition aDefinition + = OpenTypeFeatureDefinitonList::get().getDefinition(aFeatureTag); + if (aDefinition) + { + rFeature.m_aDefinition = vcl::font::FeatureDefinition(aDefinition); + } } } } diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx index 318b9ffe116a..17fd97462947 100644 --- a/vcl/source/outdev/font.cxx +++ b/vcl/source/outdev/font.cxx @@ -18,6 +18,7 @@ */ #include <i18nlangtag/mslangid.hxx> +#include <i18nlangtag/lang.h> #include <unotools/configmgr.hxx> #include <vcl/virdev.hxx> @@ -189,7 +190,9 @@ bool OutputDevice::GetFontFeatures(std::vector<vcl::font::Feature>& rFontFeature if (!pHbFace) return false; - vcl::font::FeatureCollector aFeatureCollector(pHbFace, rFontFeatures); + const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguageTag().getLanguageType(); + + vcl::font::FeatureCollector aFeatureCollector(pHbFace, rFontFeatures, eOfficeLanguage); aFeatureCollector.collectForTable(HB_OT_TAG_GSUB); // substitution aFeatureCollector.collectForTable(HB_OT_TAG_GPOS); // positioning _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits