svx/source/svdraw/svdpdf.cxx | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-)
New commits: commit 3724a1f30a318d3814467d4be5c8524f88f175be Author: Caolán McNamara <[email protected]> AuthorDate: Tue Oct 14 21:27:52 2025 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Wed Oct 15 16:52:20 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/+/192434 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index cb53cdfb8c4a..5ce09123dc83 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -992,9 +992,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"; @@ -1038,6 +1040,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)) @@ -1144,7 +1148,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(); @@ -1256,14 +1260,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); @@ -1406,7 +1407,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) @@ -1424,9 +1424,6 @@ static void buildCMapAndFeatures(const OUString& CMapUrl, const OUString& Featur Features.WriteLine(ligatureLine); } Features.WriteLine("} liga;"); - Features.Close(); - - bFeatures = true; } } @@ -1627,23 +1624,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 { @@ -1651,6 +1650,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); @@ -1666,9 +1671,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();
