summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/PDFiumLibraryTest.cxx25
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx12
-rw-r--r--vcl/source/pdf/PDFiumLibrary.cxx57
3 files changed, 94 insertions, 0 deletions
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 d3eb243bcbd4..5574f4a67778 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>
@@ -294,10 +295,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 344fac51aa76..cad2296eeea9 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;