vcl/qa/cppunit/pdfexport/data/variable-font-psname-1.odt |binary vcl/qa/cppunit/pdfexport/data/variable-font-psname-2.odt |binary vcl/qa/cppunit/pdfexport/pdfexport.cxx | 98 ++++++++++++++- 3 files changed, 97 insertions(+), 1 deletion(-)
New commits: commit 079d72659a6218c156bd048a54d59dae21391f0c Author: Khaled Hosny <[email protected]> AuthorDate: Fri Feb 20 15:06:34 2026 +0200 Commit: Khaled Hosny <[email protected]> CommitDate: Sat Feb 21 07:43:18 2026 +0100 Add tests for generating PostScript names of variable fonts Change-Id: I936ebe92bbbce17ce053baf8e1ba33a4866eda72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199865 Tested-by: Jenkins Reviewed-by: Khaled Hosny <[email protected]> diff --git a/vcl/qa/cppunit/pdfexport/data/variable-font-psname-1.odt b/vcl/qa/cppunit/pdfexport/data/variable-font-psname-1.odt new file mode 100644 index 000000000000..c1896f0bf852 Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/variable-font-psname-1.odt differ diff --git a/vcl/qa/cppunit/pdfexport/data/variable-font-psname-2.odt b/vcl/qa/cppunit/pdfexport/data/variable-font-psname-2.odt new file mode 100644 index 000000000000..c319125625aa Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/variable-font-psname-2.odt differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index c41988e4d28f..ad1e4fc7949c 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -18,7 +18,6 @@ #include <comphelper/propertysequence.hxx> #include <comphelper/sequenceashashmap.hxx> -#include <test/unoapi_test.hxx> #include <unotools/tempfile.hxx> #include <vcl/filter/pdfdocument.hxx> #include <tools/color.hxx> @@ -32,8 +31,30 @@ #include <vcl/pdf/PDFSegmentType.hxx> #include <vcl/pdf/PDFTextRenderMode.hxx> +#if defined MACOSX || defined _WIN32 +#include <set> +static std::ostream& operator<<(std::ostream& rStream, const std::set<rtl::OString>& rSet); +#endif + +#include <test/unoapi_test.hxx> + using namespace ::com::sun::star; +#if defined MACOSX || defined _WIN32 +static std::ostream& operator<<(std::ostream& rStream, const std::set<OString>& rSet) +{ + rStream << "{ "; + for (auto it = rSet.begin(); it != rSet.end(); ++it) + { + if (it != rSet.begin()) + rStream << ", "; + rStream << *it; + } + rStream << " }"; + return rStream; +} +#endif + namespace { /// Tests the PDF export filter. @@ -2068,6 +2089,81 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf105954) CPPUNIT_ASSERT_LESS(static_cast<tools::Long>(250), aMeta.getWidth()); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testVariableFontPSName1) +{ +// Embedding variable fonts does not work on Linux, only the default instance is enumerated +// https://bugs.documentfoundation.org/show_bug.cgi?id=155853 +#if defined MACOSX || defined _WIN32 + loadFromFile(u"variable-font-psname-1.odt"); + save(TestFilter::PDF_WRITER); + + vcl::filter::PDFDocument aDocument; + SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + std::set<OString> aFontNames; + for (const auto& aElement : aDocument.GetElements()) + { + auto pObject = dynamic_cast<vcl::filter::PDFObjectElement*>(aElement.get()); + if (!pObject) + continue; + auto pType = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("Type"_ostr)); + if (pType && pType->GetValue() == "Font") + { + auto pName + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("BaseFont"_ostr)); + aFontNames.insert(pName->GetValue().copy(7)); // skip the subset id + } + } + + std::set<OString> aExpected{ "STIXTwoText"_ostr, + "STIXTwoTextRoman-Bold"_ostr, + "STIXTwoText-Italic"_ostr, + "STIXTwoTextItalic-BoldItalic"_ostr, + "STIXTwoTextRoman-SemiBold"_ostr, + "STIXTwoTextItalic-SemiBoldItalic"_ostr }; + + CPPUNIT_ASSERT_EQUAL(aExpected, aFontNames); +#endif +} + +CPPUNIT_TEST_FIXTURE(PdfExportTest, testVariableFontPSName2) +{ +// Embedding variable fonts does not work on Linux, only the default instance is enumerated +// https://bugs.documentfoundation.org/show_bug.cgi?id=155853 +#if defined MACOSX || defined _WIN32 + loadFromFile(u"variable-font-psname-2.odt"); + save(TestFilter::PDF_WRITER); + + vcl::filter::PDFDocument aDocument; + SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + std::set<OString> aFontNames; + for (const auto& aElement : aDocument.GetElements()) + { + auto pObject = dynamic_cast<vcl::filter::PDFObjectElement*>(aElement.get()); + if (!pObject) + continue; + auto pType = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("Type"_ostr)); + if (pType && pType->GetValue() == "Font") + { + auto pName + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("BaseFont"_ostr)); + aFontNames.insert(pName->GetValue().copy(7)); // skip the subset id + } + } + + std::set<OString> aExpected{ + "SourceCodePro-Regular"_ostr, "SourceCodePro-Bold"_ostr, + "SourceCodePro-Italic"_ostr, "SourceCodePro-BoldItalic"_ostr, + "SourceCodePro-SemiBold"_ostr, "SourceCodePro-SemiBoldItalic"_ostr + }; + + CPPUNIT_ASSERT_EQUAL(aExpected, aFontNames); +#endif +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf157679) { // Import the bugdoc and export as PDF.
