include/vcl/filter/PDFiumLibrary.hxx | 2 ++ vcl/source/pdf/PDFiumLibrary.cxx | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-)
New commits: commit 3ed3e2987671cf90f430fd5e719a6f3f07f0a2cd Author: Caolán McNamara <[email protected]> AuthorDate: Mon Aug 18 17:30:41 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 10 12:00:52 2025 +0200 extract the font data as a separate thing Change-Id: Ie03950a80fa5f7ebc4500276e9326604d1904893 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191040 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192156 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 5eb567928a47..ee6041f6783c 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -53,6 +53,7 @@ inline constexpr OString constDictionaryKey_RichContent = "RC"_ostr; class PDFiumBitmap; class PDFiumDocument; class PDFiumPageObject; +typedef void* PFDiumFont; class VCL_DLLPUBLIC PDFium { @@ -156,6 +157,7 @@ public: virtual double getFontSize() = 0; virtual OUString getFontName() = 0; virtual int getFontAngle() = 0; + virtual bool getFontData(std::vector<uint8_t>& rData) = 0; virtual bool getFontProperties(FontWeight& weight) = 0; virtual PDFTextRenderMode getTextRenderMode() = 0; virtual Color getFillColor() = 0; diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index e6c8eaf9d50b..150a83bd4b7d 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -417,6 +417,7 @@ public: double getFontSize() override; OUString getFontName() override; int getFontAngle() override; + bool getFontData(std::vector<uint8_t>& rData) override; bool getFontProperties(FontWeight& weight) override; PDFTextRenderMode getTextRenderMode() override; Color getFillColor() override; @@ -1162,15 +1163,8 @@ int PDFiumPageObjectImpl::getFontAngle() return nFontAngle; } -bool PDFiumPageObjectImpl::getFontProperties(FontWeight& weight) +bool PDFiumPageObjectImpl::getFontData(std::vector<uint8_t>& rData) { - // FPDFFont_GetWeight turns out not to be that useful. It seems to just - // reports what explicit "FontWeight" feature is mentioned in the PDF font, - // which is an optional property. - // So pull the font data and analyze it directly. Though the font might not - // have an OS/2 table so we may end up eventually inferring the weight from - // the style name. - FPDF_FONT pFontObject = FPDFTextObj_GetFont(mpPageObject); size_t buflen(0); bool bOk = FPDFFont_GetFontData(pFontObject, nullptr, 0, &buflen); @@ -1179,11 +1173,24 @@ bool PDFiumPageObjectImpl::getFontProperties(FontWeight& weight) SAL_WARN("vcl.filter", "PDFiumImpl: failed to get font data"); return false; } - std::vector<uint8_t> aData(buflen); - bOk = FPDFFont_GetFontData(pFontObject, aData.data(), aData.size(), &buflen); - assert(bOk && aData.size() == buflen); - bOk = EmbeddedFontsManager::analyzeTTF(aData.data(), aData.size(), weight); - if (!bOk) + rData.resize(buflen); + bOk = FPDFFont_GetFontData(pFontObject, rData.data(), rData.size(), &buflen); + assert(bOk && rData.size() == buflen); + return bOk; +} + +bool PDFiumPageObjectImpl::getFontProperties(FontWeight& weight) +{ + // FPDFFont_GetWeight turns out not to be that useful. It seems to just + // reports what explicit "FontWeight" feature is mentioned in the PDF font, + // which is an optional property. + // So pull the font data and analyze it directly. Though the font might not + // have an OS/2 table so we may end up eventually inferring the weight from + // the style name. + std::vector<uint8_t> aData; + if (!getFontData(aData)) + return false; + if (!EmbeddedFontsManager::analyzeTTF(aData.data(), aData.size(), weight)) { SAL_WARN("vcl.filter", "PDFiumImpl: failed to analyzeTTF"); return false;
