[Libreoffice-commits] core.git: external/pdfium include/vcl vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 15 13:42:21 UTC 2020


 external/pdfium/AnnotationBorderProperties.patch.1 |   60 +++++++++++++++++++++
 external/pdfium/UnpackedTarball_pdfium.mk          |    1 
 include/vcl/filter/PDFiumLibrary.hxx               |    2 
 vcl/qa/cppunit/PDFiumLibraryTest.cxx               |    2 
 vcl/source/pdf/PDFiumLibrary.cxx                   |   43 +++++++++++++++
 5 files changed, 108 insertions(+)

New commits:
commit 342e427d33af0d4bfa694248e7a47fdf1f7f270d
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Oct 14 22:54:38 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Oct 15 15:41:22 2020 +0200

    pdfium: add support for border property of PDF annotations
    
    This extends PDFium with readon of "Border" property from the
    PDF annotations and adds the API to PDFium wrapper.
    
    Border is mostly used for border (line) width and the radius of
    rounding of the border (for drawing a rounded rectangle for
    example).
    
    Change-Id: I03f189eee03155ec699b2f56ceed23e6839a3f03
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104361
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/external/pdfium/AnnotationBorderProperties.patch.1 b/external/pdfium/AnnotationBorderProperties.patch.1
new file mode 100644
index 000000000000..87f8f48beed9
--- /dev/null
+++ b/external/pdfium/AnnotationBorderProperties.patch.1
@@ -0,0 +1,60 @@
+diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
+index c1471220b..229651d82 100644
+--- a/fpdfsdk/fpdf_annot.cpp
++++ b/fpdfsdk/fpdf_annot.cpp
+@@ -756,6 +756,35 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetColor(FPDF_ANNOTATION annot,
+   return true;
+ }
+
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetBorder(FPDF_ANNOTATION annot,
++                                                        float* hor_radius,
++                                                        float* vert_radius,
++                                                        float* width) {
++  CPDF_Dictionary* pAnnotDict = GetAnnotDictFromFPDFAnnotation(annot);
++  if (!pAnnotDict || !hor_radius || !vert_radius || !width)
++    return false;
++
++  // If BA entry exists, then Border is ignored
++  if (pAnnotDict->KeyExist("BA"))
++    return false;
++
++  CPDF_Array* pBorderArray = pAnnotDict->GetArrayFor("Border");
++  if (!pBorderArray) {
++    *hor_radius = 0.0f;
++    *vert_radius = 0.0f;
++    *width = 1.0f;
++    return true;
++  }
++  if (pBorderArray->size() < 3)
++    return false;
++
++  *hor_radius = pBorderArray->GetNumberAt(0);
++  *vert_radius = pBorderArray->GetNumberAt(1);
++  *width = pBorderArray->GetNumberAt(2);
++
++  return true;
++}
++
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+ FPDFAnnot_HasAttachmentPoints(FPDF_ANNOTATION annot) {
+   if (!annot)
+diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h
+index 2176450c8..ce033cde3 100644
+--- a/public/fpdf_annot.h
++++ b/public/fpdf_annot.h
+@@ -313,6 +313,12 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetColor(FPDF_ANNOTATION annot,
+                                                        unsigned int* A);
+
+ // Experimental API.
++// TODO
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFAnnot_GetBorder(FPDF_ANNOTATION annot,
++                                                        float* hor_radius,
++                                                        float* vert_radius,
++                                                        float* width);
++// Experimental API.
+ // Check if the annotation is of a type that has attachment points
+ // (i.e. quadpoints). Quadpoints are the vertices of the rectangle that
+ // encompasses the texts affected by the annotation. They provide the
+--
+2.26.2
+
diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk
index b5cbb6dc23df..5eccb92001eb 100644
--- a/external/pdfium/UnpackedTarball_pdfium.mk
+++ b/external/pdfium/UnpackedTarball_pdfium.mk
@@ -15,6 +15,7 @@ pdfium_patches += build.patch.1
 pdfium_patches += windows7.patch.1
 pdfium_patches += c++20-comparison.patch
 pdfium_patches += AnnotationInkAndVertices.patch.1
+pdfium_patches += AnnotationBorderProperties.patch.1
 
 # Work around <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94141> "c++20 rewritten operator==
 # recursive call mixing friend and external operators for template class" in GCC with
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 22602558d0d2..8e8cba1782e6 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -96,6 +96,8 @@ public:
     std::vector<basegfx::B2DPoint> getVertices();
     Color getColor();
     Color getInteriorColor();
+    float getBorderWidth();
+    basegfx::B2DSize getBorderCornerRadius();
 };
 
 class PDFiumPage;
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
index 3fc4ba86a6c3..bf4876770f2c 100644
--- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx
+++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx
@@ -338,6 +338,7 @@ void PDFiumLibraryTest::testAnnotationsDifferentTypes()
         auto const& aInkStrokes = pAnnotation->getInkStrokes();
         auto const& aPoints = aInkStrokes[0];
         CPPUNIT_ASSERT_EQUAL(size_t(74), aPoints.size());
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0f, pAnnotation->getBorderWidth(), 1E-2);
     }
 
     {
@@ -359,6 +360,7 @@ void PDFiumLibraryTest::testAnnotationsDifferentTypes()
         CPPUNIT_ASSERT_EQUAL(OUString("Polygon Text"), aContentsString);
         auto const& aVertices = pAnnotation->getVertices();
         CPPUNIT_ASSERT_EQUAL(size_t(3), aVertices.size());
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0f, pAnnotation->getBorderWidth(), 1E-2);
     }
 
     {
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index c5d27316944f..91bb70051552 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -487,6 +487,49 @@ Color PDFiumAnnotation::getInteriorColor()
     return aColor;
 }
 
+namespace
+{
+bool getBorderProperties(FPDF_ANNOTATION mpAnnotation, float& rHorizontalCornerRadius,
+                         float& rVerticalCornerRadius, float& rBorderWidth)
+{
+    float fHoriRadius = 0.0f;
+    float fVertRadius = 0.0f;
+    float fWidth = 0.0f;
+
+    if (!FPDFAnnot_GetBorder(mpAnnotation, &fHoriRadius, &fVertRadius, &fWidth))
+        return false;
+
+    rHorizontalCornerRadius = fHoriRadius;
+    rVerticalCornerRadius = fVertRadius;
+    rBorderWidth = fWidth;
+    return true;
+}
+}
+
+float PDFiumAnnotation::getBorderWidth()
+{
+    float fHorizontalCornerRadius;
+    float fVerticalCornerRadius;
+    float fBorderWidth;
+
+    if (!getBorderProperties(mpAnnotation, fHorizontalCornerRadius, fVerticalCornerRadius,
+                             fBorderWidth))
+        return 0.0f;
+    return fBorderWidth;
+}
+
+basegfx::B2DSize PDFiumAnnotation::getBorderCornerRadius()
+{
+    float fHorizontalCornerRadius;
+    float fVerticalCornerRadius;
+    float fBorderWidth;
+
+    if (!getBorderProperties(mpAnnotation, fHorizontalCornerRadius, fVerticalCornerRadius,
+                             fBorderWidth))
+        return basegfx::B2DSize(0.0, 0.0);
+    return basegfx::B2DSize(fHorizontalCornerRadius, fVerticalCornerRadius);
+}
+
 bool PDFiumAnnotation::hasKey(OString const& rKey)
 {
     return FPDFAnnot_HasKey(mpAnnotation, rKey.getStr());


More information about the Libreoffice-commits mailing list