[Libreoffice-commits] core.git: 2 commits - include/vcl sd/source vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sun Oct 18 19:21:54 UTC 2020


 include/vcl/pdf/PDFAnnotationMarker.hxx |   13 +++++++++
 sd/source/filter/pdf/sdpdffilter.cxx    |   34 ++++++++++++++++++++++++
 vcl/source/filter/ipdf/pdfread.cxx      |   45 +++++++++++++++++++++++++++++++-
 3 files changed, 91 insertions(+), 1 deletion(-)

New commits:
commit 560d3b95840221fe9661d46682af7c4ce897193b
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Oct 15 11:22:07 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Oct 18 21:21:18 2020 +0200

    sd: support ink PDF annot. as custom marker
    
    Ink PDF annotation is similar to a set of polylines (or freehand
    drawing), so we can again just reuse the polygon code paths. The
    difference to the polygon is that the polygon is closed.
    
    Change-Id: I99641dccc0b2f9f2d3ebf2c71d3e20f8b1d0a485
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104367
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/pdf/PDFAnnotationMarker.hxx b/include/vcl/pdf/PDFAnnotationMarker.hxx
index 4cf088dc1b8e..f2841b09db6c 100644
--- a/include/vcl/pdf/PDFAnnotationMarker.hxx
+++ b/include/vcl/pdf/PDFAnnotationMarker.hxx
@@ -35,6 +35,11 @@ struct VCL_DLLPUBLIC PDFAnnotationMarkerSquare : public PDFAnnotationMarker
 {
 };
 
+struct VCL_DLLPUBLIC PDFAnnotationMarkerInk : public PDFAnnotationMarker
+{
+    std::vector<basegfx::B2DPolygon> maStrokes;
+};
+
 struct VCL_DLLPUBLIC PDFAnnotationMarkerPolygon : public PDFAnnotationMarker
 {
     basegfx::B2DPolygon maPolygon;
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 28cf7b6902dd..b2866dd1701d 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -145,6 +145,15 @@ bool SdPdfFilter::Import()
                     rCustomAnnotationMarker.maFillColor = pMarker->maFillColor;
                     rCustomAnnotationMarker.maPolygons.push_back(aPoly);
                 }
+                else if (rPDFAnnotation.meSubType == vcl::pdf::PDFAnnotationSubType::Ink)
+                {
+                    auto* pMarker = static_cast<vcl::pdf::PDFAnnotationMarkerInk*>(
+                        rPDFAnnotation.mpMarker.get());
+                    for (auto const& rPolygon : pMarker->maStrokes)
+                        rCustomAnnotationMarker.maPolygons.push_back(rPolygon);
+                    rCustomAnnotationMarker.mnLineWidth = pMarker->mnWidth;
+                    rCustomAnnotationMarker.maFillColor = pMarker->maFillColor;
+                }
             }
         }
     }
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 001303194259..a0e9b51e28a8 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -257,7 +257,8 @@ findAnnotations(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
             if (eSubtype == vcl::pdf::PDFAnnotationSubType::Text
                 || eSubtype == vcl::pdf::PDFAnnotationSubType::Polygon
                 || eSubtype == vcl::pdf::PDFAnnotationSubType::Circle
-                || eSubtype == vcl::pdf::PDFAnnotationSubType::Square)
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Square
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Ink)
             {
                 OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle);
                 OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents);
@@ -326,6 +327,30 @@ findAnnotations(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
                     if (pAnnotation->hasKey(vcl::pdf::constDictionaryKeyInteriorColor))
                         pMarker->maFillColor = pAnnotation->getInteriorColor();
                 }
+                else if (eSubtype == vcl::pdf::PDFAnnotationSubType::Ink)
+                {
+                    auto const& rStrokesList = pAnnotation->getInkStrokes();
+                    if (!rStrokesList.empty())
+                    {
+                        auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerInk>();
+                        rPDFGraphicAnnotation.mpMarker = pMarker;
+                        for (auto const& rStrokes : rStrokesList)
+                        {
+                            basegfx::B2DPolygon aPolygon;
+                            for (auto const& rVertex : rStrokes)
+                            {
+                                double x = convertPointToMm100(rVertex.getX());
+                                double y = convertPointToMm100(aPageSize.getY() - rVertex.getY());
+                                aPolygon.append({ x, y });
+                            }
+                            pMarker->maStrokes.push_back(aPolygon);
+                        }
+                        float fWidth = pAnnotation->getBorderWidth();
+                        pMarker->mnWidth = convertPointToMm100(fWidth);
+                        if (pAnnotation->hasKey(vcl::pdf::constDictionaryKeyInteriorColor))
+                            pMarker->maFillColor = pAnnotation->getInteriorColor();
+                    }
+                }
             }
         }
     }
commit fb3965470a79d5b45bd211e9f95775c75e793cc8
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Oct 15 11:01:29 2020 +0200
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Oct 18 21:21:00 2020 +0200

    sd: support square and circle PDF annot. as custom marker
    
    Use the existing polygon code paths, but convert a ellipse or
    the rectangle to the polygon, and add that as a custom marker
    for the annotation.
    
    Change-Id: I8f8657b868f2c410a3f604dcc1e609f4c6a12638
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104366
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/pdf/PDFAnnotationMarker.hxx b/include/vcl/pdf/PDFAnnotationMarker.hxx
index 2cfbeaa31111..4cf088dc1b8e 100644
--- a/include/vcl/pdf/PDFAnnotationMarker.hxx
+++ b/include/vcl/pdf/PDFAnnotationMarker.hxx
@@ -27,6 +27,14 @@ struct VCL_DLLPUBLIC PDFAnnotationMarker
     Color maFillColor;
 };
 
+struct VCL_DLLPUBLIC PDFAnnotationMarkerCircle : public PDFAnnotationMarker
+{
+};
+
+struct VCL_DLLPUBLIC PDFAnnotationMarkerSquare : public PDFAnnotationMarker
+{
+};
+
 struct VCL_DLLPUBLIC PDFAnnotationMarkerPolygon : public PDFAnnotationMarker
 {
     basegfx::B2DPolygon maPolygon;
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index a1f6100cfd19..28cf7b6902dd 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -120,6 +120,31 @@ bool SdPdfFilter::Import()
                     rCustomAnnotationMarker.maFillColor = pMarker->maFillColor;
                     rCustomAnnotationMarker.maPolygons.push_back(pMarker->maPolygon);
                 }
+                else if (rPDFAnnotation.meSubType == vcl::pdf::PDFAnnotationSubType::Square)
+                {
+                    auto* pMarker = static_cast<vcl::pdf::PDFAnnotationMarkerSquare*>(
+                        rPDFAnnotation.mpMarker.get());
+                    basegfx::B2DPolygon aPoly
+                        = basegfx::utils::createPolygonFromRect(rPDFAnnotation.maRectangle);
+                    rCustomAnnotationMarker.mnLineWidth = pMarker->mnWidth;
+                    rCustomAnnotationMarker.maFillColor = pMarker->maFillColor;
+                    rCustomAnnotationMarker.maPolygons.push_back(aPoly);
+                }
+                else if (rPDFAnnotation.meSubType == vcl::pdf::PDFAnnotationSubType::Circle)
+                {
+                    auto* pMarker = static_cast<vcl::pdf::PDFAnnotationMarkerCircle*>(
+                        rPDFAnnotation.mpMarker.get());
+
+                    basegfx::B2DPoint rCenter = rPDFAnnotation.maRectangle.getCenter();
+                    double fRadiusX = rPDFAnnotation.maRectangle.getWidth() / 2;
+                    double fRadiusY = rPDFAnnotation.maRectangle.getHeight() / 2;
+
+                    basegfx::B2DPolygon aPoly
+                        = basegfx::utils::createPolygonFromEllipse(rCenter, fRadiusX, fRadiusY);
+                    rCustomAnnotationMarker.mnLineWidth = pMarker->mnWidth;
+                    rCustomAnnotationMarker.maFillColor = pMarker->maFillColor;
+                    rCustomAnnotationMarker.maPolygons.push_back(aPoly);
+                }
             }
         }
     }
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index 856cc7864d77..001303194259 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -255,7 +255,9 @@ findAnnotations(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
             auto eSubtype = pAnnotation->getSubType();
 
             if (eSubtype == vcl::pdf::PDFAnnotationSubType::Text
-                || eSubtype == vcl::pdf::PDFAnnotationSubType::Polygon)
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Polygon
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Circle
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Square)
             {
                 OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle);
                 OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents);
@@ -308,6 +310,22 @@ findAnnotations(const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
                             pMarker->maFillColor = pAnnotation->getInteriorColor();
                     }
                 }
+                else if (eSubtype == vcl::pdf::PDFAnnotationSubType::Square)
+                {
+                    auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerSquare>();
+                    rPDFGraphicAnnotation.mpMarker = pMarker;
+                    pMarker->mnWidth = convertPointToMm100(pAnnotation->getBorderWidth());
+                    if (pAnnotation->hasKey(vcl::pdf::constDictionaryKeyInteriorColor))
+                        pMarker->maFillColor = pAnnotation->getInteriorColor();
+                }
+                else if (eSubtype == vcl::pdf::PDFAnnotationSubType::Circle)
+                {
+                    auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerCircle>();
+                    rPDFGraphicAnnotation.mpMarker = pMarker;
+                    pMarker->mnWidth = convertPointToMm100(pAnnotation->getBorderWidth());
+                    if (pAnnotation->hasKey(vcl::pdf::constDictionaryKeyInteriorColor))
+                        pMarker->maFillColor = pAnnotation->getInteriorColor();
+                }
             }
         }
     }


More information about the Libreoffice-commits mailing list