svx/source/svdraw/svdpdf.cxx | 50 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-)
New commits: commit 3bdd2a95dd57a6d4a0ce5664499bafa3617ed073 Author: Caolán McNamara <[email protected]> AuthorDate: Tue Oct 14 21:27:52 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 17 09:23:30 2025 +0200 retain original FSType This ends up as the OS/2 fsType field, retain the original font FSType here. what matter is: - [makeotf] The OS/2 table 'fsType' field is now set to the feature file override. If not supplied, then the value of the environment variable FDK_FSTYPE. If not set then 4 (Preview & Print embedding). so always put this in the features file on generating the otf, but while we're at it retain the FSType in cidfontinfo description as well for consistency. This retains the original embedding permissions without defaulting to bogus 'cannot edit' messages if the original fonts allowed editing. Change-Id: I1c40a62ac9c0371543f7f599bee2069439293d8a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192449 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index ec0442cec989..2b5a5f7eef0b 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -995,9 +995,11 @@ static void rewriteBrokenFontName(std::string_view brokenName, std::string_view // https://ccjktype.fonts.adobe.com/2012/01/leveraging-afdko-part-3.html static bool toPfaCID(SubSetInfo& rSubSetInfo, const OUString& fileUrl, const OUString& postScriptName, bool& bNameKeyed, - std::map<int, int>& nameIndexToGlyph, OString& FontName, OString& Weight) + std::map<int, int>& nameIndexToGlyph, OString& FontName, OString& Weight, + OString& FSType) { bNameKeyed = false; + FSType = "0"_ostr; OUString infoUrl = fileUrl + u".1"; OUString cidFontInfoUrl = fileUrl + u".cidfontinfo"; @@ -1041,6 +1043,8 @@ static bool toPfaCID(SubSetInfo& rSubSetInfo, const OUString& fileUrl, continue; if (extractEntry(sLine, "FamilyName", FamilyName)) continue; + if (extractEntry(sLine, "FSType", FSType)) + continue; if (extractEntry(sLine, "Weight", Weight)) continue; if (extractEntry(sLine, "sup.srcFontType", srcFontType)) @@ -1147,7 +1151,7 @@ static bool toPfaCID(SubSetInfo& rSubSetInfo, const OUString& fileUrl, cidFontInfo.WriteLine("Ordering (Identity)"); cidFontInfo.WriteLine("Supplement 0"); cidFontInfo.WriteLine("XUID [1 11 9273828]"); - cidFontInfo.WriteLine("FSType 4"); + cidFontInfo.WriteLine(Concat2View("FSType " + FSType)); cidFontInfo.WriteLine(Concat2View("AdobeCopyright (" + AdobeCopyright + ")")); cidFontInfo.WriteLine(Concat2View("Trademark (" + Trademark + ")")); cidFontInfo.Close(); @@ -1259,14 +1263,11 @@ const char cmapsuffix[] = "endcmap " "end " "end "; -static void buildCMapAndFeatures(const OUString& CMapUrl, const OUString& FeaturesUrl, +static void buildCMapAndFeatures(const OUString& CMapUrl, SvFileStream& Features, std::string_view FontName, const std::vector<uint8_t>& toUnicodeData, bool bNameKeyed, - std::map<int, int>& nameIndexToGlyph, bool& bFeatures, - SubSetInfo& rSubSetInfo) + std::map<int, int>& nameIndexToGlyph, SubSetInfo& rSubSetInfo) { - bFeatures = false; - SvFileStream CMap(CMapUrl, StreamMode::READWRITE | StreamMode::TRUNC); CMap.WriteBytes(cmapprefix, std::size(cmapprefix) - 1); @@ -1409,7 +1410,6 @@ static void buildCMapAndFeatures(const OUString& CMapUrl, const OUString& Featur { std::map<OString, sal_Int32>& charsToGlyph = rSubSetInfo.aComponents.back().charsToGlyph; - SvFileStream Features(FeaturesUrl, StreamMode::READWRITE | StreamMode::TRUNC); Features.WriteLine("languagesystem DFLT dflt;"); Features.WriteLine("feature liga {"); for (const auto& ligature : ligatureGlyphToChars) @@ -1427,9 +1427,6 @@ static void buildCMapAndFeatures(const OUString& CMapUrl, const OUString& Featur Features.WriteLine(ligatureLine); } Features.WriteLine("} liga;"); - Features.Close(); - - bFeatures = true; } } @@ -1630,23 +1627,25 @@ EmbeddedFontInfo ImpSdrPdfImport::convertToOTF(SubSetInfo& rSubSetInfo, const OU // Convert to Type 1 CID keyed std::map<int, int> nameIndexToGlyph; bool bNameKeyed = false; - OString FontName, Weight; + OString FontName, Weight, FSType; if (!toPfaCID(rSubSetInfo, fileUrl, postScriptName, bNameKeyed, nameIndexToGlyph, FontName, - Weight)) + Weight, FSType)) { return EmbeddedFontInfo(); } + OUString FeaturesUrl = fileUrl + u".Features"; + SvFileStream Features(FeaturesUrl, StreamMode::READWRITE | StreamMode::TRUNC); + const OUString& pfaCIDUrl = rSubSetInfo.aComponents.back().pfaCIDUrl; // Build CMap from pdfium toUnicodeData, etc. OUString CMapUrl = fileUrl + u".CMap"; - OUString FeaturesUrl = fileUrl + u".Features"; - bool bFeatures = false, bCMap = true; + bool bCMap = true; if (!toUnicodeData.empty()) { - buildCMapAndFeatures(CMapUrl, FeaturesUrl, FontName, toUnicodeData, bNameKeyed, - nameIndexToGlyph, bFeatures, rSubSetInfo); + buildCMapAndFeatures(CMapUrl, Features, FontName, toUnicodeData, bNameKeyed, + nameIndexToGlyph, rSubSetInfo); } else { @@ -1654,6 +1653,12 @@ EmbeddedFontInfo ImpSdrPdfImport::convertToOTF(SubSetInfo& rSubSetInfo, const OU bCMap = false; } + Features.WriteLine("table OS/2 {"); + Features.WriteLine(Concat2View(" FSType " + FSType + ";")); + Features.WriteLine("} OS/2;"); + + Features.Close(); + // Create FontMenuName OUString FontMenuNameDBUrl = fileUrl + u".FontMenuNameDBUrl"; OUString longFontName = buildFontMenuName(FontMenuNameDBUrl, postScriptName, fontName, Weight); @@ -1669,9 +1674,8 @@ EmbeddedFontInfo ImpSdrPdfImport::convertToOTF(SubSetInfo& rSubSetInfo, const OU // Otherwise not merged font, just a single subset OUString otfUrl = EmbeddedFontsManager::getFileUrlForTemporaryFont(fontFileName, u".otf"); - OUString features = bFeatures ? FeaturesUrl : OUString(); OUString cmap = bCMap ? CMapUrl : OUString(); - if (EmbeddedFontsManager::makeotf(pfaCIDUrl, otfUrl, FontMenuNameDBUrl, cmap, features)) + if (EmbeddedFontsManager::makeotf(pfaCIDUrl, otfUrl, FontMenuNameDBUrl, cmap, FeaturesUrl)) return { longFontName, otfUrl, toOfficeWeight(Weight) }; SAL_WARN("sd.filter", "conversion failed"); return EmbeddedFontInfo(); commit 15878a828b921b1dc04856b89d40cbd8960d98d3 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Oct 15 10:55:15 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 17 09:23:22 2025 +0200 cid#451711189 Integer-overflow Change-Id: Ib83e3f108a49eccb0c12d75485fbc6e900446b70 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192429 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 9943ae8254b2..ec0442cec989 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -1689,6 +1689,14 @@ void ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> con basegfx::B2DHomMatrix aTextMatrix(maCurrentMatrix); aTextRect *= aTextMatrix; + + if (!std::isfinite(aTextRect.getMinX()) || !std::isfinite(aTextRect.getMaxX()) + || !std::isfinite(aTextRect.getMinY()) || !std::isfinite(aTextRect.getMaxY())) + { + SAL_WARN("sd.filter", "unusable text rectangle: " << aTextRect); + return; + } + const tools::Rectangle aRect = PointsToLogic(aTextRect.getMinX(), aTextRect.getMaxX(), aTextRect.getMinY(), aTextRect.getMaxY());
