include/vcl/filter/PDFiumLibrary.hxx               |    2 
 include/vcl/pdf/PDFAnnotationMarker.hxx            |    2 
 vcl/qa/cppunit/PDFiumLibraryTest.cxx               |   58 +++++++++++++++++++++
 vcl/qa/cppunit/data/Annotations_Adobe_FreeText.pdf |binary
 vcl/source/filter/ipdf/pdfread.cxx                 |   10 +++
 5 files changed, 72 insertions(+)

New commits:
commit 98775b28a2ce13b8e91536468fe22bb72bbf3be5
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Thu Jun 13 20:53:56 2024 +0900
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Jun 18 12:24:12 2024 +0200

    annot: read PDF FreeText annotation "DS" and "RC" keys
    
    DS (DefaultStyle) and RC (RichContent") contain xhtml, css3 rich
    text content for the text presented by the FreeText annotation in
    the document. This adds reading of those 2 things to the PDFium
    library, PDFium based import and the PDFAnnotationFreeTextMarker
    class.
    
    Change-Id: I32f89640611c730c8a1a8d1a2107e2e11669ec18
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168846
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Miklos Vajna <[email protected]>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx 
b/include/vcl/filter/PDFiumLibrary.hxx
index d90da7286020..e008a502be58 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -46,6 +46,8 @@ inline constexpr OString constDictionaryKeyContents = 
"Contents"_ostr;
 inline constexpr OString constDictionaryKeyPopup = "Popup"_ostr;
 inline constexpr OString constDictionaryKeyModificationDate = "M"_ostr;
 inline constexpr OString constDictionaryKeyInteriorColor = "IC"_ostr;
+inline constexpr OString constDictionaryKey_DefaultStyle = "DS"_ostr;
+inline constexpr OString constDictionaryKey_RichContent = "RC"_ostr;
 
 class PDFiumBitmap;
 class PDFiumDocument;
diff --git a/include/vcl/pdf/PDFAnnotationMarker.hxx 
b/include/vcl/pdf/PDFAnnotationMarker.hxx
index d1217c65c3af..0c559a4cedae 100644
--- a/include/vcl/pdf/PDFAnnotationMarker.hxx
+++ b/include/vcl/pdf/PDFAnnotationMarker.hxx
@@ -37,6 +37,8 @@ struct VCL_DLLPUBLIC PDFAnnotationMarkerStamp : public 
PDFAnnotationMarker
 /** Free text annotation marker - showing text of the annotation in the 
document */
 struct VCL_DLLPUBLIC PDFAnnotationMarkerFreeText : public PDFAnnotationMarker
 {
+    OUString maDefaultStyle;
+    OUString maRichContent;
 };
 
 struct VCL_DLLPUBLIC PDFAnnotationMarkerCircle : public PDFAnnotationMarker
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx 
b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
index 287ae079ef96..45c59b46d447 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -412,6 +412,64 @@ CPPUNIT_TEST_FIXTURE(PDFiumLibraryTest, 
testAnnotationsDifferentTypes)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(PDFiumLibraryTest, testAnnotationsFreeText)
+{
+    OUString aURL = getFullUrl(u"Annotations_Adobe_FreeText.pdf");
+    SvFileStream aStream(aURL, StreamMode::READ);
+
+    std::vector<vcl::PDFGraphicResult> aResults;
+    CPPUNIT_ASSERT_EQUAL(size_t(1), vcl::ImportPDFUnloaded(aURL, aResults));
+
+    vcl::PDFGraphicResult& rResult = aResults[0];
+
+    Graphic aGraphic = rResult.GetGraphic();
+    aGraphic.makeAvailable();
+
+    OUString aDefaultStyle;
+    OUString aRichContent;
+
+    {
+        auto pVectorGraphicData = aGraphic.getVectorGraphicData();
+        CPPUNIT_ASSERT(pVectorGraphicData);
+        CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf, 
pVectorGraphicData->getType());
+
+        auto& rDataContainer = pVectorGraphicData->getBinaryDataContainer();
+
+        auto pPdfium = vcl::pdf::PDFiumLibrary::get();
+        auto pDocument
+            = pPdfium->openDocument(rDataContainer.getData(), 
rDataContainer.getSize(), OString());
+        CPPUNIT_ASSERT(pDocument);
+
+        CPPUNIT_ASSERT_EQUAL(1, pDocument->getPageCount());
+
+        auto pPage = pDocument->openPage(0);
+        CPPUNIT_ASSERT(pPage);
+
+        CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
+
+        auto pAnnotation = pPage->getAnnotation(0);
+        CPPUNIT_ASSERT(pAnnotation);
+        CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::FreeText, 
pAnnotation->getSubType());
+
+        aDefaultStyle = 
pAnnotation->getString(vcl::pdf::constDictionaryKey_DefaultStyle);
+        CPPUNIT_ASSERT_EQUAL(false, aDefaultStyle.isEmpty());
+
+        aRichContent = 
pAnnotation->getString(vcl::pdf::constDictionaryKey_RichContent);
+        CPPUNIT_ASSERT_EQUAL(false, aRichContent.isEmpty());
+    }
+
+    auto const& rAnnotations = rResult.GetAnnotations();
+    CPPUNIT_ASSERT_EQUAL(size_t(1), rAnnotations.size());
+
+    CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::FreeText, 
rAnnotations[0].meSubType);
+
+    auto* pMarker
+        = 
static_cast<vcl::pdf::PDFAnnotationMarkerFreeText*>(rAnnotations[0].mpMarker.get());
+
+    CPPUNIT_ASSERT_EQUAL(aDefaultStyle, pMarker->maDefaultStyle);
+    CPPUNIT_ASSERT_EQUAL(aRichContent, pMarker->maRichContent);
+}
+
 CPPUNIT_TEST_FIXTURE(PDFiumLibraryTest, testTools)
 {
     OUString sConverted = 
vcl::pdf::convertPdfDateToISO8601(u"D:20200612201322+02'00");
diff --git a/vcl/qa/cppunit/data/Annotations_Adobe_FreeText.pdf 
b/vcl/qa/cppunit/data/Annotations_Adobe_FreeText.pdf
new file mode 100755
index 000000000000..32cb3a6cbc31
Binary files /dev/null and b/vcl/qa/cppunit/data/Annotations_Adobe_FreeText.pdf 
differ
diff --git a/vcl/source/filter/ipdf/pdfread.cxx 
b/vcl/source/filter/ipdf/pdfread.cxx
index b2e97a519ed5..9145bdce3657 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -330,6 +330,16 @@ findAnnotations(const 
std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
                 {
                     auto pMarker = 
std::make_shared<vcl::pdf::PDFAnnotationMarkerFreeText>();
                     rPDFGraphicAnnotation.mpMarker = pMarker;
+                    if 
(pAnnotation->hasKey(vcl::pdf::constDictionaryKey_DefaultStyle))
+                    {
+                        pMarker->maDefaultStyle
+                            = 
pAnnotation->getString(vcl::pdf::constDictionaryKey_DefaultStyle);
+                    }
+                    if 
(pAnnotation->hasKey(vcl::pdf::constDictionaryKey_RichContent))
+                    {
+                        pMarker->maRichContent
+                            = 
pAnnotation->getString(vcl::pdf::constDictionaryKey_RichContent);
+                    }
                 }
                 else if (eSubtype == vcl::pdf::PDFAnnotationSubType::Stamp)
                 {

Reply via email to