[poppler] poppler/PDFDoc.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Mar 21 14:32:50 UTC 2022


 poppler/PDFDoc.cc |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

New commits:
commit 48c6eee27a7a6439507dc28df983f1d55efa6a9a
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Mar 17 17:50:55 2022 +0100

    Write unicode strings using PDF hexadecimal strings
    
    As far as I can see our old way of doing it was correct but when saving
    contents like
    我不会复印
    ( i'm sure this is going to break, so check it on https://bugs.kde.org/show_bug.cgi?id=378186 )
    
    Adobe Reader would not read the string back correctly.
    mupdf works both with the old and the new code

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 6580fc1f..20bb191f 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -70,7 +70,9 @@
 #include <cstddef>
 #include <cstring>
 #include <ctime>
+#include <iomanip>
 #include <regex>
+#include <sstream>
 #include <sys/stat.h>
 #include "goo/glibc.h"
 #include "goo/gstrtod.h"
@@ -1277,16 +1279,14 @@ void PDFDoc::writeString(const GooString *s, OutStream *outStr, const unsigned c
     if (s->hasUnicodeMarker()) {
         // unicode string don't necessary end with \0
         const char *c = s->c_str();
-        outStr->printf("(");
+        std::stringstream stream;
+        stream << std::setfill('0') << std::hex;
         for (int i = 0; i < s->getLength(); i++) {
-            char unescaped = *(c + i) & 0x000000ff;
-            // escape if needed
-            if (unescaped == '(' || unescaped == ')' || unescaped == '\\') {
-                outStr->printf("%c", '\\');
-            }
-            outStr->printf("%c", unescaped);
+            stream << std::setw(2) << (0xff & (unsigned int)*(c + i));
         }
-        outStr->printf(") ");
+        outStr->printf("<");
+        outStr->printf("%s", stream.str().c_str());
+        outStr->printf("> ");
     } else {
         const char *c = s->c_str();
         outStr->printf("(");


More information about the poppler mailing list