diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-06-18 13:50:15 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-21 21:02:38 +0200 |
commit | 4e3196ceedc2b79d58bb57dba86f2f0158d32998 (patch) | |
tree | e403030503ba791ed80fc9ecea3049ab632e62c9 | |
parent | a641e68077b8c91db8f7520f817da9f7949d0e6d (diff) |
support date and time for PDFium and use it for annotations
PDF annotations have the modification date and time accessible in
the PDF specific format. With PDFium we read the annotation date
and time and convert that to css::utils::DateTime (by converting
to ISO8601 compatible string first).
Add support for modification date and tme for annotations into
ImportPDFUnloaded and when the annotations are inserted into the
document as comments (in Draw document).
Change-Id: I24aacde84b7530365d67ed335b1eefbaee706eca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96759
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/vcl/filter/PDFiumLibrary.hxx | 6 | ||||
-rw-r--r-- | include/vcl/pdfread.hxx | 2 | ||||
-rw-r--r-- | sd/source/filter/pdf/sdpdffilter.cxx | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/PDFiumLibraryTest.cxx | 25 | ||||
-rw-r--r-- | vcl/source/filter/ipdf/pdfread.cxx | 12 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 57 |
6 files changed, 102 insertions, 1 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 9deff47e0ab9..2a70c3f89bce 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -29,7 +29,7 @@ namespace vcl::pdf constexpr char constDictionaryKeyTitle[] = "T"; constexpr char constDictionaryKeyContents[] = "Contents"; constexpr char constDictionaryKeyPopup[] = "Popup"; - +constexpr char constDictionaryKeyModificationDate[] = "M"; class PDFiumDocument; class VCL_DLLPUBLIC PDFium final @@ -121,6 +121,10 @@ struct PDFiumLibrary final : public rtl::StaticWithInit<std::shared_ptr<PDFium>, std::shared_ptr<PDFium> operator()() { return std::make_shared<PDFium>(); } }; +// Tools + +VCL_DLLPUBLIC OUString convertPdfDateToISO8601(OUString const& rInput); + } // namespace vcl::pdf #endif // HAVE_FEATURE_PDFIUM diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx index d79115f40249..f1534c326ee6 100644 --- a/include/vcl/pdfread.hxx +++ b/include/vcl/pdfread.hxx @@ -15,6 +15,7 @@ #include <tools/stream.hxx> #include <vcl/graph.hxx> #include <basegfx/range/b2drectangle.hxx> +#include <com/sun/star/util/DateTime.hpp> namespace com::sun::star::uno { @@ -38,6 +39,7 @@ struct PDFGraphicAnnotation OUString maText; // In HMM basegfx::B2DRectangle maRectangle; + css::util::DateTime maDateTime; }; struct PDFGraphicResult diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index da989974bc87..9a53dde90cdf 100644 --- a/sd/source/filter/pdf/sdpdffilter.cxx +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -91,6 +91,7 @@ bool SdPdfFilter::Import() rPDFAnnotation.maRectangle.getHeight() / 100.00); xAnnotation->setPosition(aUnoPosition); xAnnotation->setSize(aUnoSize); + xAnnotation->setDateTime(rPDFAnnotation.maDateTime); } } diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx index c786b6edc211..61b3981731f6 100644 --- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx +++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx @@ -16,6 +16,9 @@ #include <unotest/bootstrapfixturebase.hxx> #include <unotest/directories.hxx> +#include <unotools/datetime.hxx> + +#include <com/sun/star/util/DateTime.hpp> #include <vcl/graph.hxx> #include <vcl/graphicfilter.hxx> @@ -34,12 +37,14 @@ class PDFiumLibraryTest : public test::BootstrapFixtureBase void testPages(); void testAnnotationsMadeInEvince(); void testAnnotationsMadeInAcrobat(); + void testTools(); CPPUNIT_TEST_SUITE(PDFiumLibraryTest); CPPUNIT_TEST(testDocument); CPPUNIT_TEST(testPages); CPPUNIT_TEST(testAnnotationsMadeInEvince); CPPUNIT_TEST(testAnnotationsMadeInAcrobat); + CPPUNIT_TEST(testTools); CPPUNIT_TEST_SUITE_END(); }; @@ -144,6 +149,10 @@ void PDFiumLibraryTest::testAnnotationsMadeInEvince() CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationIndex(pPopupAnnotation)); CPPUNIT_ASSERT_EQUAL(16, pPopupAnnotation->getSubType()); + + OUString sDateTimeString + = pAnnotation->getString(vcl::pdf::constDictionaryKeyModificationDate); + CPPUNIT_ASSERT_EQUAL(OUString("D:20200612201322+02'00"), sDateTimeString); } { @@ -231,6 +240,22 @@ void PDFiumLibraryTest::testAnnotationsMadeInAcrobat() } } +void PDFiumLibraryTest::testTools() +{ + OUString sConverted = vcl::pdf::convertPdfDateToISO8601("D:20200612201322+02'00"); + + css::util::DateTime aDateTime; + CPPUNIT_ASSERT(utl::ISO8601parseDateTime(sConverted, aDateTime)); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2020), aDateTime.Year); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(6), aDateTime.Month); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(12), aDateTime.Day); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(20), aDateTime.Hours); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(13), aDateTime.Minutes); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(22), aDateTime.Seconds); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), aDateTime.NanoSeconds); + CPPUNIT_ASSERT_EQUAL(false, bool(aDateTime.IsUTC)); +} + CPPUNIT_TEST_SUITE_REGISTRATION(PDFiumLibraryTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index b5e63937bf00..ccb12f4a4cc7 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -20,6 +20,7 @@ #include <vcl/graph.hxx> #include <bitmapwriteaccess.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <unotools/datetime.hxx> #include <vcl/filter/PDFiumLibrary.hxx> @@ -298,10 +299,21 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG 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; aPDFGraphicAnnotations.push_back(aPDFGraphicAnnotation); } } diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index faf59c24a5a3..7e723c56bf88 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -18,6 +18,63 @@ namespace vcl::pdf { +OUString convertPdfDateToISO8601(OUString const& rInput) +{ + if (rInput.getLength() < 6) + return OUString(); + + OUString prefix = rInput.copy(0, 2); + if (prefix != "D:") + return OUString(); + + OUString sYear = rInput.copy(2, 4); + + OUString sMonth("01"); + if (rInput.getLength() >= 8) + sMonth = rInput.copy(6, 2); + + OUString sDay("01"); + if (rInput.getLength() >= 10) + sDay = rInput.copy(8, 2); + + OUString sHours("00"); + if (rInput.getLength() >= 12) + sHours = rInput.copy(10, 2); + + OUString sMinutes("00"); + if (rInput.getLength() >= 14) + sMinutes = rInput.copy(12, 2); + + OUString sSeconds("00"); + if (rInput.getLength() >= 16) + sSeconds = rInput.copy(14, 2); + + OUString sTimeZoneMark("Z"); + if (rInput.getLength() >= 17) + sTimeZoneMark = rInput.copy(16, 1); + + OUString sTimeZoneHours("00"); + OUString sTimeZoneMinutes("00"); + if ((sTimeZoneMark == "+" || sTimeZoneMark == "-") && rInput.getLength() >= 22) + { + OUString sTimeZoneSeparator = rInput.copy(19, 1); + if (sTimeZoneSeparator == "'") + { + sTimeZoneHours = rInput.copy(17, 2); + sTimeZoneMinutes = rInput.copy(20, 2); + } + } + + OUString sTimeZoneString; + if (sTimeZoneMark == "+" || sTimeZoneString == "-") + sTimeZoneString = sTimeZoneMark + sTimeZoneHours + ":" + sTimeZoneMinutes; + else if (sTimeZoneMark == "Z") + sTimeZoneString = sTimeZoneMark; + + return sYear + "-" + sMonth + "-" + sDay + "T" + sHours + ":" + sMinutes + ":" + sSeconds + + sTimeZoneString; +} + PDFium::PDFium() { FPDF_LIBRARY_CONFIG aConfig; |