include/vcl/filter/PDFiumLibrary.hxx | 14 ++++++++ vcl/source/pdf/PDFiumLibrary.cxx | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+)
New commits: commit 93cbaf5ad0c2a2a7463d555207a7174bbdb9b8ce Author: Caolán McNamara <[email protected]> AuthorDate: Tue Oct 28 15:17:58 2025 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Wed Oct 29 12:07:13 2025 +0100 add PDFiumClipPath Change-Id: I32a535d94b392871eb3ebe047586ecb030ee1314 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193102 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 57350f87d32e..ce222c0e44ac 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -158,6 +158,17 @@ public: virtual PDFSegmentType getType() const = 0; }; +class VCL_DLLPUBLIC PDFiumClipPath +{ +public: + virtual ~PDFiumClipPath() = default; + + virtual int getPathCount() = 0; + virtual int getPathSegmentCount(int nPathIndex) = 0; + virtual std::unique_ptr<PDFiumPathSegment> getPathSegment(int nPathIndex, int nSegmentIndex) + = 0; +}; + class VCL_DLLPUBLIC PDFiumPageObject { public: @@ -193,6 +204,9 @@ public: virtual Size getImageSize(PDFiumPage& rPage) = 0; virtual std::unique_ptr<PDFiumBitmap> getImageBitmap() = 0; virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0; + + // ClipPath + virtual std::unique_ptr<PDFiumClipPath> getClipPath() = 0; }; class VCL_DLLPUBLIC PDFiumSearchHandle diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 7490959abded..079d4a4bcd36 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -17,6 +17,7 @@ #include <fpdf_annot.h> #include <fpdf_edit.h> #include <fpdf_text.h> +#include <fpdf_transformpage.h> #include <fpdf_save.h> #include <fpdf_signature.h> #include <fpdf_formfill.h> @@ -300,6 +301,22 @@ public: PDFSegmentType getType() const override; }; +class PDFiumClipPathImpl final : public PDFiumClipPath +{ +private: + FPDF_CLIPPATH mpClipPath; + + PDFiumClipPathImpl(const PDFiumClipPathImpl&) = delete; + PDFiumClipPathImpl& operator=(const PDFiumClipPathImpl&) = delete; + +public: + PDFiumClipPathImpl(FPDF_CLIPPATH pClipPath); + + int getPathCount() override; + int getPathSegmentCount(int nPathIndex) override; + std::unique_ptr<PDFiumPathSegment> getPathSegment(int nPathIndex, int nSegmentIndex) override; +}; + class PDFiumAnnotationImpl final : public PDFiumAnnotation { private: @@ -435,6 +452,9 @@ public: Size getImageSize(PDFiumPage& rPage) override; std::unique_ptr<PDFiumBitmap> getImageBitmap() override; bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) override; + + // ClipPath + std::unique_ptr<PDFiumClipPath> getClipPath() override; }; class PDFiumFontImpl final : public PDFiumFont @@ -1375,6 +1395,17 @@ std::unique_ptr<PDFiumPathSegment> PDFiumPageObjectImpl::getPathSegment(int inde return pPDFiumPathSegment; } +std::unique_ptr<PDFiumClipPath> PDFiumPageObjectImpl::getClipPath() +{ + std::unique_ptr<PDFiumClipPath> pPDFiumClipPath; + FPDF_CLIPPATH pClipPath = FPDFPageObj_GetClipPath(mpPageObject); + if (pClipPath) + { + pPDFiumClipPath = std::make_unique<PDFiumClipPathImpl>(pClipPath); + } + return pPDFiumClipPath; +} + Size PDFiumPageObjectImpl::getImageSize(PDFiumPage& rPage) { FPDF_IMAGEOBJ_METADATA aMeta; @@ -1496,6 +1527,31 @@ PDFSegmentType PDFiumPathSegmentImpl::getType() const return static_cast<PDFSegmentType>(FPDFPathSegment_GetType(mpPathSegment)); } +PDFiumClipPathImpl::PDFiumClipPathImpl(FPDF_CLIPPATH pClipPath) + : mpClipPath(pClipPath) +{ +} + +int PDFiumClipPathImpl::getPathCount() { return FPDFClipPath_CountPaths(mpClipPath); } + +int PDFiumClipPathImpl::getPathSegmentCount(int nPathIndex) +{ + return FPDFClipPath_CountPathSegments(mpClipPath, nPathIndex); +} + +std::unique_ptr<PDFiumPathSegment> PDFiumClipPathImpl::getPathSegment(int nPathIndex, + int nSegmentIndex) +{ + std::unique_ptr<PDFiumPathSegment> pPDFiumPathSegment; + FPDF_PATHSEGMENT pPathSegment + = FPDFClipPath_GetPathSegment(mpClipPath, nPathIndex, nSegmentIndex); + if (pPathSegment) + { + pPDFiumPathSegment = std::make_unique<PDFiumPathSegmentImpl>(pPathSegment); + } + return pPDFiumPathSegment; +} + PDFiumFormHandle::PDFiumFormHandle(FPDF_FORMHANDLE pHandle) : mpHandle(pHandle) {
