#include #include "PDFDoc.h" #include "GlobalParams.h" #include "Outline.h" #include "poppler-private.h" class TestUtf8Document : public QObject { Q_OBJECT public: explicit TestUtf8Document(QObject *parent = nullptr) : QObject(parent) { } private Q_SLOTS: void checkStrings(); }; inline QString outlineItemTitle(OutlineItem *item) { if (!item) { return {}; } const std::vector &title = item->getTitle(); return QString::fromUcs4(reinterpret_cast(title.data()), title.size()); } void TestUtf8Document::checkStrings() { globalParams = std::make_unique(); auto doc = std::make_unique(std::make_unique(TESTDATADIR "/unittestcases/pdf20-utf8-test.pdf")); QVERIFY(doc); QVERIFY(doc->isOk()); QVERIFY(doc->getOptContentConfig() && doc->getOptContentConfig()->hasOCGs()); QCOMPARE(Poppler::UnicodeParsedString(doc->getDocInfoTitle().get()), QString::fromUtf8("表ポあA鷗ŒéB逍Üߪąñ丂㐀𠀀")); // clazy:exclude=qstring-allocations QSet expectedNames { QString::fromUtf8("گچپژ"), QString::fromUtf8("Layer 1") }; // clazy:exclude=qstring-allocations QSet foundNames; for (auto &[ref, group] : doc->getOptContentConfig()->getOCGs()) { foundNames.insert(Poppler::UnicodeParsedString(group->getName())); } QCOMPARE(expectedNames, foundNames); auto outlineItems = doc->getOutline()->getItems(); QVERIFY(outlineItems); QCOMPARE(outlineItems->size(), 3); QCOMPARE(outlineItemTitle(outlineItems->at(0)), QString::fromUtf8("PDF 2.0 with UTF-8 test file")); // clazy:exclude=qstring-allocations QCOMPARE(outlineItemTitle(outlineItems->at(1)), QString::fromUtf8("\u202A\u202Atest\u202A")); // clazy:exclude=qstring-allocations QCOMPARE(outlineItemTitle(outlineItems->at(2)), QString::fromUtf8("🌈️\n" /*emoji rainbow flag*/)); // clazy:exclude=qstring-allocations } QTEST_GUILESS_MAIN(TestUtf8Document) #include "check_utf8document.moc"