svx/source/svdraw/svdpdf.cxx |   42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

New commits:
commit 41e56894e646e9bb46659dc4866781abbc6b24db
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Oct 15 19:36:28 2025 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Oct 17 14:05:32 2025 +0200

    provide fallback toUnicode using name key via Adobe Standard
    
    Change-Id: I0ad9fd6b868bf00d3e98c41ff63589648db579e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192462
    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 709eb9a452e1..b9a836f286c1 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1271,6 +1271,7 @@ struct ToUnicodeData
     std::vector<OString> bfcharlines;
     std::vector<OString> bfcharranges;
 
+    // For the pdf provided mapping from the font to unicode
     ToUnicodeData(const std::vector<uint8_t>& toUnicodeData)
     {
         SvMemoryStream aInCMap(const_cast<uint8_t*>(toUnicodeData.data()), 
toUnicodeData.size(),
@@ -1299,20 +1300,41 @@ struct ToUnicodeData
             }
         }
     }
+
+    // For name keyed fonts without toUnicode data where we
+    // can assume the font encoding is Adobe Standard and
+    // reverse map from the name indexes so we can forward
+    // map to unicode
+    ToUnicodeData(std::map<int, int>& nameIndexToGlyph)
+    {
+        for (const auto & [ adobe, glyphid ] : nameIndexToGlyph)
+        {
+            if (glyphid == 0)
+                continue;
+
+            const char cChar(adobe);
+            OUString sUni(&cChar, 1, RTL_TEXTENCODING_ADOBE_STANDARD);
+            sal_Unicode mappedChar = sUni.toChar();
+
+            OStringBuffer aBuffer("<");
+            appendFourByteHex(aBuffer, adobe);
+            aBuffer.append("> <");
+            appendFourByteHex(aBuffer, mappedChar);
+            aBuffer.append(">");
+            bfcharlines.push_back(aBuffer.toString());
+        }
+    }
 };
 }
 
 static void buildCMapAndFeatures(const OUString& CMapUrl, SvFileStream& 
Features,
-                                 std::string_view FontName,
-                                 const std::vector<uint8_t>& toUnicodeData, 
bool bNameKeyed,
+                                 std::string_view FontName, ToUnicodeData& 
tud, bool bNameKeyed,
                                  std::map<int, int>& nameIndexToGlyph, 
SubSetInfo& rSubSetInfo)
 {
     SvFileStream CMap(CMapUrl, StreamMode::READWRITE | StreamMode::TRUNC);
 
     CMap.WriteBytes(cmapprefix, std::size(cmapprefix) - 1);
 
-    ToUnicodeData tud(toUnicodeData);
-
     sal_Int32 mergeOffset = 1; //Leave space for notdef
     for (const auto& count : rSubSetInfo.aComponents)
         mergeOffset += count.nGlyphCount;
@@ -1688,8 +1710,16 @@ EmbeddedFontInfo 
ImpSdrPdfImport::convertToOTF(SubSetInfo& rSubSetInfo, const OU
     bool bCMap = true;
     if (!toUnicodeData.empty())
     {
-        buildCMapAndFeatures(CMapUrl, Features, FontName, toUnicodeData, 
bNameKeyed,
-                             nameIndexToGlyph, rSubSetInfo);
+        ToUnicodeData tud(toUnicodeData);
+        buildCMapAndFeatures(CMapUrl, Features, FontName, tud, bNameKeyed, 
nameIndexToGlyph,
+                             rSubSetInfo);
+    }
+    else if (bNameKeyed)
+    {
+        SAL_INFO("sd.filter", "There is no CMap, assuming Adobe Standard 
encoding.");
+        ToUnicodeData tud(nameIndexToGlyph);
+        buildCMapAndFeatures(CMapUrl, Features, FontName, tud, bNameKeyed, 
nameIndexToGlyph,
+                             rSubSetInfo);
     }
     else
     {

Reply via email to