svx/source/svdraw/svdpdf.cxx | 59 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-)
New commits: commit addd0d4cb95e245de4472557b094ab63879c3b0c Author: Caolán McNamara <[email protected]> AuthorDate: Mon Sep 29 20:30:18 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Tue Oct 14 20:50:50 2025 +0200 The font name can be missing in the embedded font force the PostScript FontName in the font to the name provided from the PDF object. Guess something sensible based on the PostScript FontName to use as the name for humans. Change-Id: Ida07f45c65e18513f216543112dfcc0ace50247d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191673 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> (cherry picked from commit 2c5300a2a1a97b3853d6bbe7b99f4213757e93fe) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192344 Tested-by: Caolán McNamara <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index adb527a4e496..489e3ce037de 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -189,6 +189,17 @@ bool writeFontFile(const OUString& fileUrl, const std::vector<uint8_t>& rFontDat return true; } + +OUString guessFontName(const OUString& postScriptName) +{ + OUString sFontName; + sal_Int32 lastDash = postScriptName.lastIndexOf('-'); + if (lastDash == -1) + sFontName = postScriptName; + else + sFontName = postScriptName.copy(0, lastDash); + return sFontName; +} } // Possibly there is some alternative route to query pdfium for all fonts without @@ -228,10 +239,17 @@ void ImpSdrPdfImport::CollectFonts() auto itImportedFont = maImportedFonts.find(font); if (itImportedFont == maImportedFonts.end()) { - OUString sFontName = pPageObject->getFontName(); - OUString sPostScriptName = GetPostScriptName(pPageObject->getBaseFontName()); + OUString sFontName = pPageObject->getFontName(); + if (sFontName.isEmpty()) + { + sFontName = guessFontName(sPostScriptName); + SAL_WARN("sd.filter", + "missing font name, attempt to reconstruct from postscriptname as: " + << sFontName); + } + SubSetInfo* pSubSetInfo; SAL_INFO("sd.filter", "importing font: " << font); @@ -908,6 +926,33 @@ static bool isSimpleFamilyName(std::string_view Weight) || Weight == "BoldItalic"; } +static void rewriteBrokenFontName(std::string_view brokenName, std::string_view fixedName, + const OUString& pfaCIDUrl) +{ + OUString oldCIDUrl = pfaCIDUrl + ".broken"; + if (osl::File::move(pfaCIDUrl, oldCIDUrl) != osl::File::E_None) + { + SAL_WARN("sd.filter", "unable to move file"); + return; + } + + const OString sBrokenLine = "/FontName /"_ostr + brokenName + " def"_ostr; + const OString sFixedLine = "/FontName /"_ostr + fixedName + " def"_ostr; + + SvFileStream input(oldCIDUrl, StreamMode::READ); + SvFileStream output(pfaCIDUrl, StreamMode::WRITE | StreamMode::TRUNC); + OString sLine; + while (input.ReadLine(sLine)) + { + if (sLine == sBrokenLine) + { + output.WriteLine(sFixedLine); + continue; + } + output.WriteLine(sLine); + } +} + // https://ccjktype.fonts.adobe.com/2011/12/leveraging-afdko-part-1.html // https://ccjktype.fonts.adobe.com/2012/01/leveraging-afdko-part-2.html // https://ccjktype.fonts.adobe.com/2012/01/leveraging-afdko-part-3.html @@ -942,6 +987,7 @@ static bool toPfaCID(SubSetInfo& rSubSetInfo, const OUString& fileUrl, return false; } SAL_INFO("sd.filter", "dump success"); + bool bBrokenFontName(false); SvFileStream info(infoUrl, StreamMode::READ); OStringBuffer glyphBuffer; OString sLine; @@ -961,8 +1007,10 @@ static bool toPfaCID(SubSetInfo& rSubSetInfo, const OUString& fileUrl, continue; if (extractEntry(sLine, "FontName", FontName)) { - SAL_WARN_IF(FontName != postScriptName.toUtf8(), "sd.filter", - "expected that these match"); + bBrokenFontName = FontName != postScriptName.toUtf8(); + SAL_WARN_IF(bBrokenFontName, "sd.filter", + "expected that FontName of <" << FontName << "> matches PostScriptName of <" + << postScriptName << ">"); continue; } if (sLine.startsWith("glyph[")) @@ -1072,6 +1120,9 @@ static bool toPfaCID(SubSetInfo& rSubSetInfo, const OUString& fileUrl, } } + if (bBrokenFontName) + rewriteBrokenFontName(FontName, postScriptName.toUtf8(), pfaCIDUrl); + return true; }
