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

New commits:
commit 7ea49126e7a247ac60ad45ab420106fe4be574ea
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Oct 15 12:23:08 2020 +0200
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Oct 18 21:22:03 2020 +0200

    sd: support text annotation PDF annot. as custom marker
    
    This one is special as it annotates text. Normally the annotation
    would be present behind the text, but this is not possible in
    this case, so the best alternative is to use a transparent
    rectangle over the text.
    
    Change-Id: Ib115efa4a5994e17dcf9d7b02591ccae26800928
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104369
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/vcl/pdf/PDFAnnotationMarker.hxx 
b/include/vcl/pdf/PDFAnnotationMarker.hxx
index f2841b09db6c..2c525f85cbd5 100644
--- a/include/vcl/pdf/PDFAnnotationMarker.hxx
+++ b/include/vcl/pdf/PDFAnnotationMarker.hxx
@@ -45,6 +45,25 @@ struct VCL_DLLPUBLIC PDFAnnotationMarkerPolygon : public 
PDFAnnotationMarker
     basegfx::B2DPolygon maPolygon;
 };
 
+enum class PDFTextMarkerType
+{
+    Highlight,
+    Underline,
+    Squiggly,
+    StrikeOut
+};
+
+struct VCL_DLLPUBLIC PDFAnnotationMarkerHighlight : public PDFAnnotationMarker
+{
+    std::vector<basegfx::B2DPolygon> maQuads;
+    PDFTextMarkerType meTextMarkerType;
+
+    PDFAnnotationMarkerHighlight(PDFTextMarkerType eTextMarkerType)
+        : meTextMarkerType(eTextMarkerType)
+    {
+    }
+};
+
 } // namespace vcl::pdf
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx 
b/sd/source/filter/pdf/sdpdffilter.cxx
index b2866dd1701d..5e190f8a0117 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -154,6 +154,19 @@ bool SdPdfFilter::Import()
                     rCustomAnnotationMarker.mnLineWidth = pMarker->mnWidth;
                     rCustomAnnotationMarker.maFillColor = pMarker->maFillColor;
                 }
+                else if (rPDFAnnotation.meSubType == 
vcl::pdf::PDFAnnotationSubType::Highlight)
+                {
+                    if (rCustomAnnotationMarker.maLineColor.GetTransparency() 
== 0)
+                        
rCustomAnnotationMarker.maLineColor.SetTransparency(0x90);
+                    auto* pMarker = 
static_cast<vcl::pdf::PDFAnnotationMarkerHighlight*>(
+                        rPDFAnnotation.mpMarker.get());
+                    for (auto const& rPolygon : pMarker->maQuads)
+                        rCustomAnnotationMarker.maPolygons.push_back(rPolygon);
+                    rCustomAnnotationMarker.mnLineWidth = 1;
+                    rCustomAnnotationMarker.maFillColor = 
rPDFAnnotation.maColor;
+                    if (rCustomAnnotationMarker.maFillColor.GetTransparency() 
== 0)
+                        
rCustomAnnotationMarker.maFillColor.SetTransparency(0x90);
+                }
             }
         }
     }
diff --git a/vcl/source/filter/ipdf/pdfread.cxx 
b/vcl/source/filter/ipdf/pdfread.cxx
index a0e9b51e28a8..9be28fcf0c9b 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -258,7 +258,8 @@ findAnnotations(const 
std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
                 || eSubtype == vcl::pdf::PDFAnnotationSubType::Polygon
                 || eSubtype == vcl::pdf::PDFAnnotationSubType::Circle
                 || eSubtype == vcl::pdf::PDFAnnotationSubType::Square
-                || eSubtype == vcl::pdf::PDFAnnotationSubType::Ink)
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Ink
+                || eSubtype == vcl::pdf::PDFAnnotationSubType::Highlight)
             {
                 OUString sAuthor = 
pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle);
                 OUString sText = 
pAnnotation->getString(vcl::pdf::constDictionaryKeyContents);
@@ -351,6 +352,48 @@ findAnnotations(const 
std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, basegfx::B2D
                             pMarker->maFillColor = 
pAnnotation->getInteriorColor();
                     }
                 }
+                else if (eSubtype == vcl::pdf::PDFAnnotationSubType::Highlight)
+                {
+                    size_t nCount = pAnnotation->getAttachmentPointsCount();
+                    if (nCount > 0)
+                    {
+                        auto pMarker = 
std::make_shared<vcl::pdf::PDFAnnotationMarkerHighlight>(
+                            vcl::pdf::PDFTextMarkerType::Highlight);
+                        rPDFGraphicAnnotation.mpMarker = pMarker;
+                        for (size_t i = 0; i < nCount; ++i)
+                        {
+                            auto aAttachmentPoints = 
pAnnotation->getAttachmentPoints(i);
+                            if (!aAttachmentPoints.empty())
+                            {
+                                double x, y;
+                                basegfx::B2DPolygon aPolygon;
+                                aPolygon.setClosed(true);
+
+                                x = 
convertPointToMm100(aAttachmentPoints[0].getX());
+                                y = convertPointToMm100(aPageSize.getY()
+                                                        - 
aAttachmentPoints[0].getY());
+                                aPolygon.append({ x, y });
+
+                                x = 
convertPointToMm100(aAttachmentPoints[1].getX());
+                                y = convertPointToMm100(aPageSize.getY()
+                                                        - 
aAttachmentPoints[1].getY());
+                                aPolygon.append({ x, y });
+
+                                x = 
convertPointToMm100(aAttachmentPoints[3].getX());
+                                y = convertPointToMm100(aPageSize.getY()
+                                                        - 
aAttachmentPoints[3].getY());
+                                aPolygon.append({ x, y });
+
+                                x = 
convertPointToMm100(aAttachmentPoints[2].getX());
+                                y = convertPointToMm100(aPageSize.getY()
+                                                        - 
aAttachmentPoints[2].getY());
+                                aPolygon.append({ x, y });
+
+                                pMarker->maQuads.push_back(aPolygon);
+                            }
+                        }
+                    }
+                }
             }
         }
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to