include/vcl/filter/PDFiumLibrary.hxx | 1 svx/source/svdraw/svdpdf.cxx | 45 ++++++++++++++++++++++++----------- vcl/source/pdf/PDFiumLibrary.cxx | 7 +++++ 3 files changed, 39 insertions(+), 14 deletions(-)
New commits: commit 26413eb0fc488760602fb30bca6e083ad88ee132 Author: Caolán McNamara <[email protected]> AuthorDate: Tue Sep 30 10:51:49 2025 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Wed Oct 1 16:31:02 2025 +0200 Don't attempt to import non-embedded fonts Where the font data appears to be that of the font pdfium substitues the embedded font with. Change-Id: I436c5a1644cde0961adfe34d8539d571f9460edb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191678 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index bc759288efbd..be1f4866ec7f 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -161,6 +161,7 @@ public: virtual PDFiumFont getFont() = 0; virtual bool getFontData(PDFiumFont font, std::vector<uint8_t>& rData) = 0; virtual bool getFontToUnicode(PDFiumFont font, std::vector<uint8_t>& rData) = 0; + virtual bool getIsEmbedded(PDFiumFont font) = 0; virtual bool getFontProperties(FontWeight& weight) = 0; virtual PDFTextRenderMode getTextRenderMode() = 0; virtual Color getFillColor() = 0; diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index f0715718bb72..83a4e83d8c1c 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -190,14 +190,31 @@ bool writeFontFile(const OUString& fileUrl, const std::vector<uint8_t>& rFontDat return true; } -OUString guessFontName(const OUString& postScriptName) +FontWeight toOfficeWeight(std::string_view style) +{ + if (o3tl::equalsIgnoreAsciiCase(style, "Regular")) + return WEIGHT_NORMAL; + else if (o3tl::equalsIgnoreAsciiCase(style, "Bold")) + return WEIGHT_BOLD; + else if (o3tl::equalsIgnoreAsciiCase(style, "BoldItalic")) + return WEIGHT_BOLD; + return WEIGHT_DONTKNOW; +} + +OUString stripPostScriptStyle(const OUString& postScriptName, FontWeight& eWeight) { OUString sFontName; sal_Int32 lastDash = postScriptName.lastIndexOf('-'); if (lastDash == -1) + { sFontName = postScriptName; + eWeight = WEIGHT_NORMAL; + } else + { sFontName = postScriptName.copy(0, lastDash); + eWeight = toOfficeWeight(postScriptName.copy(lastDash + 1).toUtf8()); + } return sFontName; } } @@ -243,14 +260,26 @@ void ImpSdrPdfImport::CollectFonts() OUString sFontName = pPageObject->getFontName(); + FontWeight eFontWeight(WEIGHT_DONTKNOW); + OUString sPostScriptFontFamily = stripPostScriptStyle(sPostScriptName, eFontWeight); + if (sFontName.isEmpty()) { - sFontName = guessFontName(sPostScriptName); + sFontName = sPostScriptFontFamily; SAL_WARN("sd.filter", "missing font name, attempt to reconstruct from postscriptname as: " << sFontName); } + if (!pPageObject->getIsEmbedded(font)) + { + SAL_WARN("sd.filter", "skipping not embedded font, map: " + << sFontName << " to " << sPostScriptFontFamily); + maImportedFonts.emplace(font, + OfficeFontInfo{ sPostScriptFontFamily, eFontWeight }); + continue; + } + SubSetInfo* pSubSetInfo; SAL_INFO("sd.filter", "importing font: " << font); @@ -274,7 +303,6 @@ void ImpSdrPdfImport::CollectFonts() std::vector<uint8_t> aFontData; if (!pPageObject->getFontData(font, aFontData)) SAL_WARN("sd.filter", "that's worrying"); - FontWeight eFontWeight(WEIGHT_DONTKNOW); bool bTTF = EmbeddedFontsManager::analyzeTTF(aFontData.data(), aFontData.size(), eFontWeight); SAL_INFO_IF(!bTTF, "sd.filter", "not ttf/otf, converting"); @@ -1333,17 +1361,6 @@ static OUString buildFontMenuName(const OUString& FontMenuNameDBUrl, return longFontName; } -static FontWeight toOfficeWeight(std::string_view style) -{ - if (o3tl::equalsIgnoreAsciiCase(style, "Regular")) - return WEIGHT_NORMAL; - else if (o3tl::equalsIgnoreAsciiCase(style, "Bold")) - return WEIGHT_BOLD; - else if (o3tl::equalsIgnoreAsciiCase(style, "BoldItalic")) - return WEIGHT_BOLD; - return WEIGHT_DONTKNOW; -} - // https://adobe-type-tools.github.io/font-tech-notes/pdfs/5900.RFMFAH_Tutorial.pdf static EmbeddedFontInfo mergeFontSubsets(const OUString& mergedFontUrl, const OUString& FontMenuNameDBUrl, diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index c4bfb80984ee..17265501be58 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -422,6 +422,7 @@ public: PDFiumFont getFont() override; bool getFontData(PDFiumFont font, std::vector<uint8_t>& rData) override; bool getFontToUnicode(PDFiumFont font, std::vector<uint8_t>& rData) override; + bool getIsEmbedded(PDFiumFont font) override; bool getFontProperties(FontWeight& weight) override; PDFTextRenderMode getTextRenderMode() override; Color getFillColor() override; @@ -1203,6 +1204,12 @@ bool PDFiumPageObjectImpl::getFontToUnicode(PDFiumFont font, std::vector<uint8_t return bOk; } +bool PDFiumPageObjectImpl::getIsEmbedded(PDFiumFont font) +{ + FPDF_FONT pFontObject = static_cast<FPDF_FONT>(font); + return FPDFFont_GetIsEmbedded(pFontObject) == 1; +} + bool PDFiumPageObjectImpl::getFontProperties(FontWeight& weight) { // FPDFFont_GetWeight turns out not to be that useful. It seems to just
