From 962f1bb95fc38cafe56ea2ba134ce19392102601 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 31 Aug 2020 07:53:55 +0200 Subject: store annotation subtype in PDFGraphicAnnotation, enum for subtype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib804f497a6c8f609e4899f9ebcef4c1096f44ce0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102090 Tested-by: Tomaž Vajngerl Reviewed-by: Tomaž Vajngerl --- include/vcl/filter/PDFiumLibrary.hxx | 3 +- include/vcl/pdf/PDFAnnotationSubType.hxx | 49 +++++++++++++++++++++++++ include/vcl/pdfread.hxx | 8 +++-- sd/qa/unit/SdrPdfImportTest.cxx | 12 ++++--- vcl/qa/cppunit/PDFiumLibraryTest.cxx | 18 +++++----- vcl/source/filter/ipdf/pdfread.cxx | 61 ++++++++++++++++++-------------- vcl/source/pdf/PDFiumLibrary.cxx | 5 ++- 7 files changed, 112 insertions(+), 44 deletions(-) create mode 100644 include/vcl/pdf/PDFAnnotationSubType.hxx diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index aee470cfd852..6386441b6f39 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -65,7 +66,7 @@ public: ~PDFiumAnnotation(); FPDF_ANNOTATION getPointer() { return mpAnnotation; } - int getSubType(); + PDFAnnotationSubType getSubType(); basegfx::B2DRectangle getRectangle(); bool hasKey(OString const& rKey); OUString getString(OString const& rKey); diff --git a/include/vcl/pdf/PDFAnnotationSubType.hxx b/include/vcl/pdf/PDFAnnotationSubType.hxx new file mode 100644 index 000000000000..bee1d82cd399 --- /dev/null +++ b/include/vcl/pdf/PDFAnnotationSubType.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +namespace vcl::pdf +{ +enum class PDFAnnotationSubType +{ + Unknown = 0, + Text = 1, + Link = 2, + FreeText = 3, + Line = 4, + Square = 5, + Circle = 6, + Polygon = 7, + Polyline = 8, + Highlight = 9, + Underline = 10, + Squiggly = 11, + Strikeout = 12, + Stamp = 13, + Caret = 14, + Ink = 15, + Popup = 16, + FileAttachment = 17, + Sound = 18, + Movie = 19, + Widget = 20, + Screen = 21, + Printermark = 22, + Trapnet = 23, + Watermark = 24, + Threed = 25, + Richmedia = 26, + XFAWidget = 27 +}; + +} // namespace vcl::pdf + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx index 4b76d9360f2b..f60ae8ef243f 100644 --- a/include/vcl/pdfread.hxx +++ b/include/vcl/pdfread.hxx @@ -17,6 +17,8 @@ #include #include +#include + namespace com::sun::star::uno { template class Sequence; @@ -37,9 +39,11 @@ struct PDFGraphicAnnotation { OUString maAuthor; OUString maText; - // In HMM - basegfx::B2DRectangle maRectangle; + + basegfx::B2DRectangle maRectangle; // In HMM css::util::DateTime maDateTime; + + pdf::PDFAnnotationSubType meSubType; }; class PDFGraphicResult diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx index 07f90ba26e24..50e7d233877d 100644 --- a/sd/qa/unit/SdrPdfImportTest.cxx +++ b/sd/qa/unit/SdrPdfImportTest.cxx @@ -209,10 +209,12 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport) CPPUNIT_ASSERT_EQUAL(2, pPDFPage->getAnnotationCount()); auto pPDFAnnotation1 = pPDFPage->getAnnotation(0); - CPPUNIT_ASSERT_EQUAL(1, pPDFAnnotation1->getSubType()); // Text annotation + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Text, + pPDFAnnotation1->getSubType()); // Text annotation auto pPDFAnnotation2 = pPDFPage->getAnnotation(1); - CPPUNIT_ASSERT_EQUAL(16, pPDFAnnotation2->getSubType()); // Pop-up annotation + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, + pPDFAnnotation2->getSubType()); // Pop-up annotation } { // save as PDF and check annotations @@ -243,10 +245,12 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport) CPPUNIT_ASSERT_EQUAL(2, pPDFPage->getAnnotationCount()); auto pPDFAnnotation1 = pPDFPage->getAnnotation(0); - CPPUNIT_ASSERT_EQUAL(1, pPDFAnnotation1->getSubType()); // Text annotation + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Text, + pPDFAnnotation1->getSubType()); // Text annotation auto pPDFAnnotation2 = pPDFPage->getAnnotation(1); - CPPUNIT_ASSERT_EQUAL(16, pPDFAnnotation2->getSubType()); // Pop-up annotation + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, + pPDFAnnotation2->getSubType()); // Pop-up annotation // Load document again mxComponent = loadFromDesktop(aTempFile.GetURL()); diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx index 43d6b92bae27..7e60ab92ec2a 100644 --- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx +++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx @@ -184,7 +184,7 @@ void PDFiumLibraryTest::testAnnotationsMadeInEvince() { auto pAnnotation = pPage->getAnnotation(0); CPPUNIT_ASSERT(pAnnotation); - CPPUNIT_ASSERT_EQUAL(1, pAnnotation->getSubType()); // FPDF_ANNOT_TEXT + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Text, pAnnotation->getSubType()); OUString aPopupString = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); CPPUNIT_ASSERT_EQUAL(OUString("quikee"), aPopupString); @@ -197,7 +197,7 @@ void PDFiumLibraryTest::testAnnotationsMadeInEvince() CPPUNIT_ASSERT(pPopupAnnotation); CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationIndex(pPopupAnnotation)); - CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pPopupAnnotation->getSubType()); OUString sDateTimeString = pAnnotation->getString(vcl::pdf::constDictionaryKeyModificationDate); @@ -207,7 +207,7 @@ void PDFiumLibraryTest::testAnnotationsMadeInEvince() { auto pAnnotation = pPage->getAnnotation(1); CPPUNIT_ASSERT(pAnnotation); - CPPUNIT_ASSERT_EQUAL(16, pAnnotation->getSubType()); // FPDF_ANNOT_POPUP + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pAnnotation->getSubType()); } } @@ -241,7 +241,7 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat() { auto pAnnotation = pPage->getAnnotation(0); CPPUNIT_ASSERT(pAnnotation); - CPPUNIT_ASSERT_EQUAL(1, pAnnotation->getSubType()); // FPDF_ANNOT_TEXT + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Text, pAnnotation->getSubType()); OUString aPopupString = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); CPPUNIT_ASSERT_EQUAL(OUString("quikee"), aPopupString); @@ -254,19 +254,19 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat() CPPUNIT_ASSERT(pPopupAnnotation); CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationIndex(pPopupAnnotation)); - CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pPopupAnnotation->getSubType()); } { auto pAnnotation = pPage->getAnnotation(1); CPPUNIT_ASSERT(pAnnotation); - CPPUNIT_ASSERT_EQUAL(16, pAnnotation->getSubType()); // FPDF_ANNOT_POPUP + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pAnnotation->getSubType()); } { auto pAnnotation = pPage->getAnnotation(2); CPPUNIT_ASSERT(pAnnotation); - CPPUNIT_ASSERT_EQUAL(1, pAnnotation->getSubType()); // FPDF_ANNOT_TEXT + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Text, pAnnotation->getSubType()); OUString aPopupString = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); CPPUNIT_ASSERT_EQUAL(OUString("quikee"), aPopupString); @@ -279,13 +279,13 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat() CPPUNIT_ASSERT(pPopupAnnotation); CPPUNIT_ASSERT_EQUAL(3, pPage->getAnnotationIndex(pPopupAnnotation)); - CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pPopupAnnotation->getSubType()); } { auto pAnnotation = pPage->getAnnotation(3); CPPUNIT_ASSERT(pAnnotation); - CPPUNIT_ASSERT_EQUAL(16, pAnnotation->getSubType()); // FPDF_ANNOT_POPUP + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Popup, pAnnotation->getSubType()); } } diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 5282a012d423..01ab6d3625cd 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -286,36 +286,43 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector& rG for (int nAnnotation = 0; nAnnotation < pPage->getAnnotationCount(); nAnnotation++) { auto pAnnotation = pPage->getAnnotation(nAnnotation); - if (pAnnotation && pAnnotation->getSubType() == 1 /*FPDF_ANNOT_TEXT*/ - && pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)) + if (pAnnotation) { - OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); - OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); - auto pPopupAnnotation = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); - - basegfx::B2DRectangle rRectangle = pAnnotation->getRectangle(); - basegfx::B2DRectangle rRectangleHMM( - convertPointToMm100(rRectangle.getMinX()), - convertPointToMm100(aPageSize.getY() - rRectangle.getMinY()), - convertPointToMm100(rRectangle.getMaxX()), - convertPointToMm100(aPageSize.getY() - rRectangle.getMaxY())); - - OUString sDateTimeString - = pAnnotation->getString(vcl::pdf::constDictionaryKeyModificationDate); - OUString sISO8601String = vcl::pdf::convertPdfDateToISO8601(sDateTimeString); - - css::util::DateTime aDateTime; - if (!sISO8601String.isEmpty()) + auto eSubtype = pAnnotation->getSubType(); + + if (eSubtype == vcl::pdf::PDFAnnotationSubType::Text + && pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)) { - utl::ISO8601parseDateTime(sISO8601String, aDateTime); + OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); + OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); + auto pPopupAnnotation + = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); + + basegfx::B2DRectangle rRectangle = pAnnotation->getRectangle(); + basegfx::B2DRectangle rRectangleHMM( + convertPointToMm100(rRectangle.getMinX()), + convertPointToMm100(aPageSize.getY() - rRectangle.getMinY()), + convertPointToMm100(rRectangle.getMaxX()), + convertPointToMm100(aPageSize.getY() - rRectangle.getMaxY())); + + OUString sDateTimeString + = pAnnotation->getString(vcl::pdf::constDictionaryKeyModificationDate); + OUString sISO8601String = vcl::pdf::convertPdfDateToISO8601(sDateTimeString); + + css::util::DateTime aDateTime; + if (!sISO8601String.isEmpty()) + { + utl::ISO8601parseDateTime(sISO8601String, aDateTime); + } + + PDFGraphicAnnotation aPDFGraphicAnnotation; + aPDFGraphicAnnotation.maRectangle = rRectangleHMM; + aPDFGraphicAnnotation.maAuthor = sAuthor; + aPDFGraphicAnnotation.maText = sText; + aPDFGraphicAnnotation.maDateTime = aDateTime; + aPDFGraphicAnnotation.meSubType = eSubtype; + aPDFGraphicAnnotations.push_back(aPDFGraphicAnnotation); } - - PDFGraphicAnnotation aPDFGraphicAnnotation; - aPDFGraphicAnnotation.maRectangle = rRectangleHMM; - aPDFGraphicAnnotation.maAuthor = sAuthor; - aPDFGraphicAnnotation.maText = sText; - aPDFGraphicAnnotation.maDateTime = aDateTime; - aPDFGraphicAnnotations.push_back(aPDFGraphicAnnotation); } } diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index bacb45097c1b..f8d5b79c8f6f 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -391,7 +391,10 @@ PDFiumAnnotation::~PDFiumAnnotation() FPDFPage_CloseAnnot(mpAnnotation); } -int PDFiumAnnotation::getSubType() { return FPDFAnnot_GetSubtype(mpAnnotation); } +PDFAnnotationSubType PDFiumAnnotation::getSubType() +{ + return PDFAnnotationSubType(FPDFAnnot_GetSubtype(mpAnnotation)); +} basegfx::B2DRectangle PDFiumAnnotation::getRectangle() { -- cgit