[poppler] qt5/src qt5/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Mar 28 11:53:33 UTC 2019


 qt5/src/poppler-private.cc  |   15 ++++++++++++---
 qt5/tests/check_strings.cpp |    2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)

New commits:
commit 623d073030259042921d34034cdcf701dae7c96b
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Mar 28 12:47:22 2019 +0100

    qt: UnicodeParsedString support UTF16-LE strings
    
    They are not part of the standard but Adobe seems to support them and
    there's files out there like that so better to support them than not

diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index 5f673973..b284a744 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -1,6 +1,6 @@
 /* poppler-private.cc: qt interface to poppler
  * Copyright (C) 2005, Net Integration Technologies, Inc.
- * Copyright (C) 2006, 2011, 2015, 2017, 2018 by Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006, 2011, 2015, 2017-2019 by Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2008, 2010, 2011, 2014 by Pino Toscano <pino at kde.org>
  * Copyright (C) 2013 by Thomas Freitag <Thomas.Freitag at alfa.de>
  * Copyright (C) 2013 Adrian Johnson <ajohnson at redneon.com>
@@ -108,12 +108,20 @@ namespace Debug {
         const char *cString;
         int stringLength;
         bool deleteCString;
-        if ( ( s1->getChar(0) & 0xff ) == 0xfe && ( s1->getLength() > 1 && ( s1->getChar(1) & 0xff ) == 0xff ) )
+        bool isLE = false;
+        if ( s1->hasUnicodeMarker() )
         {
             cString = s1->c_str();
             stringLength = s1->getLength();
             deleteCString = false;
         }
+        else if ( s1->hasUnicodeMarkerLE() )
+        {
+            isLE = true;
+            cString = s1->c_str();
+            stringLength = s1->getLength();
+            deleteCString = false;
+        }
         else
         {
             cString = pdfDocEncodingToUTF16(s1, &stringLength);
@@ -124,7 +132,8 @@ namespace Debug {
         // i = 2 to skip the unicode marker
         for ( int i = 2; i < stringLength; i += 2 )
         {
-            const Unicode u = ( ( cString[i] & 0xff ) << 8 ) | ( cString[i+1] & 0xff );
+            const Unicode u = isLE ? ( ( cString[i+1] & 0xff ) << 8 ) | ( cString[i] & 0xff )
+                                   : ( ( cString[i] & 0xff ) << 8 ) | ( cString[i+1] & 0xff );
             result += QChar( u );
         }
         if (deleteCString)
diff --git a/qt5/tests/check_strings.cpp b/qt5/tests/check_strings.cpp
index 583617aa..e7b3f990 100644
--- a/qt5/tests/check_strings.cpp
+++ b/qt5/tests/check_strings.cpp
@@ -163,6 +163,8 @@ void TestStrings::check_UnicodeParsedString_data()
                                 << QStringLiteral("ša");
     QTest::newRow("test string") << newGooString("\xFE\xFF\0t\0e\0s\0t\0 \0s\0t\0r\0i\0n\0g", 24)
                                  << QStringLiteral("test string");
+    QTest::newRow("UTF16-LE") << newGooString("\xFF\xFE\xDA\x00\x6E\x00\xEE\x00\x63\x00\xF6\x00\x64\x00\xE9\x00\x51\x75", 18)
+                                 << QStringLiteral("Únîcödé畑");
 }
 
 void TestStrings::check_UnicodeParsedString()


More information about the poppler mailing list