qt5/src/poppler-private.cc | 37 +++++++------------------------------ qt5/tests/check_annotations.cpp | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 30 deletions(-)
New commits: commit 74abafe107d0e865919557034c7d6d9dcd19ef6c Author: Adam Reichold <[email protected]> Date: Sat Mar 30 19:31:58 2019 +0100 Implement UnicodeParsedString in terms of QString::fromUtf16 for significant simplifications. diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc index 719ccffc..5a86bafb 100644 --- a/qt5/src/poppler-private.cc +++ b/qt5/src/poppler-private.cc @@ -105,41 +105,18 @@ namespace Debug { if ( !s1 || s1->getLength() == 0 ) return QString(); - const char *cString; - int stringLength; - bool deleteCString; - bool isLE = false; - if ( s1->hasUnicodeMarker() ) + if ( s1->hasUnicodeMarker() || s1->hasUnicodeMarkerLE() ) { - cString = s1->c_str(); - stringLength = s1->getLength(); - deleteCString = false; - } - else if ( s1->hasUnicodeMarkerLE() ) - { - isLE = true; - cString = s1->c_str(); - stringLength = s1->getLength(); - deleteCString = false; + return QString::fromUtf16(reinterpret_cast<const ushort *>(s1->c_str()), s1->getLength() / 2); } else { - cString = pdfDocEncodingToUTF16(s1, &stringLength); - deleteCString = true; - } - - QString result; - result.reserve(stringLength / 2); - // i = 2 to skip the unicode marker - for ( int i = 2; i < stringLength; i += 2 ) - { - 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) + int stringLength; + const char *cString = pdfDocEncodingToUTF16(s1, &stringLength); + auto result = QString::fromUtf16(reinterpret_cast<const ushort *>(cString), stringLength / 2); delete[] cString; - return result; + return result; + } } GooString *QStringToUnicodeGooString(const QString &s) { commit b9512adc677408f74087f7865b2d7ea99b81cc4b Author: Adam Reichold <[email protected]> Date: Sat Mar 30 12:25:51 2019 +0100 Add test case for annotations containing UTF-16LE-encoded text. diff --git a/qt5/tests/check_annotations.cpp b/qt5/tests/check_annotations.cpp index 2ae3613b..95a30ac8 100644 --- a/qt5/tests/check_annotations.cpp +++ b/qt5/tests/check_annotations.cpp @@ -19,6 +19,7 @@ private slots: void checkQColorPrecision(); void checkFontSizeAndColor(); void checkHighlightFromAndToQuads(); + void checkUTF16LEAnnot(); }; /* Is .5f sufficient for 16 bit color channel roundtrip trough save and load on all architectures? */ @@ -135,6 +136,25 @@ void TestAnnotations::checkHighlightFromAndToQuads() QCOMPARE(ha->highlightQuads(), quads); } +void TestAnnotations::checkUTF16LEAnnot() +{ + std::unique_ptr<Poppler::Document> doc{ + Poppler::Document::load(TESTDATADIR "/unittestcases/utf16le-annot.pdf") + }; + QVERIFY(doc.get()); + + std::unique_ptr<Poppler::Page> page{ + doc->page(0) + }; + QVERIFY(page.get()); + + auto annots = page->annotations(); + QCOMPARE(annots.size(), 2); + + auto annot = annots[1]; + QCOMPARE(annot->contents(), QStringLiteral("Únîcödé豰")); +} + QTEST_GUILESS_MAIN(TestAnnotations) #include "check_annotations.moc" _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
