diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-06-15 14:44:19 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-29 20:36:45 +0200 |
commit | 1709ebc984e41073ade18a4428be7387ab581c17 (patch) | |
tree | 6c0906a24e644b5c2a9e593ad009dc7daad125ea /vcl/qa | |
parent | 1aa683fb0c54dd409bb3d0a779ca0fd3e9ae8e56 (diff) |
vcl: Add annotation reading to PDFiumLibrary c++ wrapper
Also add tests readin annotations from Evince and Acrobat modified
PDF files.
Change-Id: I4565c6b621774fc8485a6c33bc18708664917b73
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96756
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 7e4dc3b1eabcb1993d4143c046a2f32fedc852ed)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97438
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/PDFiumLibraryTest.cxx | 135 | ||||
-rw-r--r-- | vcl/qa/cppunit/data/PangramAcrobatAnnotations.pdf | bin | 0 -> 21709 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/data/PangramWithAnnotations.pdf | bin | 0 -> 17785 bytes |
3 files changed, 135 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx index 422325aa9b1d..c786b6edc211 100644 --- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx +++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx @@ -32,10 +32,14 @@ class PDFiumLibraryTest : public test::BootstrapFixtureBase void testDocument(); void testPages(); + void testAnnotationsMadeInEvince(); + void testAnnotationsMadeInAcrobat(); CPPUNIT_TEST_SUITE(PDFiumLibraryTest); CPPUNIT_TEST(testDocument); CPPUNIT_TEST(testPages); + CPPUNIT_TEST(testAnnotationsMadeInEvince); + CPPUNIT_TEST(testAnnotationsMadeInAcrobat); CPPUNIT_TEST_SUITE_END(); }; @@ -96,6 +100,137 @@ void PDFiumLibraryTest::testPages() CPPUNIT_ASSERT(pPage); } +void PDFiumLibraryTest::testAnnotationsMadeInEvince() +{ + OUString aURL = getFullUrl("PangramWithAnnotations.pdf"); + SvFileStream aStream(aURL, StreamMode::READ); + GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); + Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream); + aGraphic.makeAvailable(); + + auto pVectorGraphicData = aGraphic.getVectorGraphicData(); + CPPUNIT_ASSERT(pVectorGraphicData); + CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, + pVectorGraphicData->getVectorGraphicDataType()); + + const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); + int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); + auto pDocument = pPdfium->openDocument(pData, nLength); + CPPUNIT_ASSERT(pDocument); + + CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); + + auto pPage = pDocument->openPage(0); + CPPUNIT_ASSERT(pPage); + + CPPUNIT_ASSERT_EQUAL(2, pPage->getAnnotationCount()); + + { + auto pAnnotation = pPage->getAnnotation(0); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(1, pAnnotation->getSubType()); // FPDF_ANNOT_TEXT + + OUString aPopupString = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); + CPPUNIT_ASSERT_EQUAL(OUString("quikee"), aPopupString); + + OUString aContentsString = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); + CPPUNIT_ASSERT_EQUAL(OUString("Annotation test"), aContentsString); + + CPPUNIT_ASSERT_EQUAL(true, pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)); + auto pPopupAnnotation = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); + CPPUNIT_ASSERT(pPopupAnnotation); + + CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationIndex(pPopupAnnotation)); + CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + } + + { + auto pAnnotation = pPage->getAnnotation(1); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(16, pAnnotation->getSubType()); // FPDF_ANNOT_POPUP + } +} + +void PDFiumLibraryTest::testAnnotationsMadeInAcrobat() +{ + OUString aURL = getFullUrl("PangramAcrobatAnnotations.pdf"); + SvFileStream aStream(aURL, StreamMode::READ); + GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); + Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream); + aGraphic.makeAvailable(); + + auto pVectorGraphicData = aGraphic.getVectorGraphicData(); + CPPUNIT_ASSERT(pVectorGraphicData); + CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, + pVectorGraphicData->getVectorGraphicDataType()); + + const void* pData = pVectorGraphicData->getVectorGraphicDataArray().getConstArray(); + int nLength = pVectorGraphicData->getVectorGraphicDataArrayLength(); + + auto pPdfium = vcl::pdf::PDFiumLibrary::get(); + auto pDocument = pPdfium->openDocument(pData, nLength); + CPPUNIT_ASSERT(pDocument); + + CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount()); + + auto pPage = pDocument->openPage(0); + CPPUNIT_ASSERT(pPage); + + CPPUNIT_ASSERT_EQUAL(4, pPage->getAnnotationCount()); + + { + auto pAnnotation = pPage->getAnnotation(0); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(1, pAnnotation->getSubType()); // FPDF_ANNOT_TEXT + + OUString aPopupString = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); + CPPUNIT_ASSERT_EQUAL(OUString("quikee"), aPopupString); + + OUString aContentsString = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); + CPPUNIT_ASSERT_EQUAL(OUString("YEEEY"), aContentsString); + + CPPUNIT_ASSERT_EQUAL(true, pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)); + auto pPopupAnnotation = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); + CPPUNIT_ASSERT(pPopupAnnotation); + + CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationIndex(pPopupAnnotation)); + CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + } + + { + auto pAnnotation = pPage->getAnnotation(1); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(16, pAnnotation->getSubType()); // FPDF_ANNOT_POPUP + } + + { + auto pAnnotation = pPage->getAnnotation(2); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(1, pAnnotation->getSubType()); // FPDF_ANNOT_TEXT + + OUString aPopupString = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); + CPPUNIT_ASSERT_EQUAL(OUString("quikee"), aPopupString); + + OUString aContentsString = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); + CPPUNIT_ASSERT_EQUAL(OUString("Note"), aContentsString); + + CPPUNIT_ASSERT_EQUAL(true, pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)); + auto pPopupAnnotation = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); + CPPUNIT_ASSERT(pPopupAnnotation); + + CPPUNIT_ASSERT_EQUAL(3, pPage->getAnnotationIndex(pPopupAnnotation)); + CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + } + + { + auto pAnnotation = pPage->getAnnotation(3); + CPPUNIT_ASSERT(pAnnotation); + CPPUNIT_ASSERT_EQUAL(16, pAnnotation->getSubType()); // FPDF_ANNOT_POPUP + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(PDFiumLibraryTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/vcl/qa/cppunit/data/PangramAcrobatAnnotations.pdf b/vcl/qa/cppunit/data/PangramAcrobatAnnotations.pdf Binary files differnew file mode 100644 index 000000000000..f97003a7f397 --- /dev/null +++ b/vcl/qa/cppunit/data/PangramAcrobatAnnotations.pdf diff --git a/vcl/qa/cppunit/data/PangramWithAnnotations.pdf b/vcl/qa/cppunit/data/PangramWithAnnotations.pdf Binary files differnew file mode 100644 index 000000000000..f69ddd987060 --- /dev/null +++ b/vcl/qa/cppunit/data/PangramWithAnnotations.pdf |