[Libreoffice-commits] core.git: include/vcl svx/source vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 8 18:55:47 UTC 2020
include/vcl/filter/PDFiumLibrary.hxx | 21 ++++++++++++++++
svx/source/inc/svdpdf.hxx | 6 +++-
svx/source/svdraw/svdpdf.cxx | 44 ++++++++++++++---------------------
vcl/source/pdf/PDFiumLibrary.cxx | 33 ++++++++++++++++++++++++++
4 files changed, 76 insertions(+), 28 deletions(-)
New commits:
commit bc8016b81c2c609711c26af1f85da327cf30a4ff
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Jul 6 14:08:23 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Jul 8 20:55:01 2020 +0200
pdf: add PDFiumPathSegment to the wrapper & use in ImpSdrPdfImport
A PageObject of type FPDF_PAGEOBJ_PATH can have a path segment,
that is common in vector graphic objects. The path segment is
wrapped into PDFiumPathSegment which can be used to handle the
path and path properties.
Change-Id: I990d51ba90fa356a6eca137eb4b71947858289aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98210
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index f7dcc4b2c99e..43176f584420 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -73,6 +73,24 @@ public:
class PDFiumTextPage;
+class VCL_DLLPUBLIC PDFiumPathSegment final
+{
+private:
+ FPDF_PATHSEGMENT mpPathSegment;
+
+ PDFiumPathSegment(const PDFiumPathSegment&) = delete;
+ PDFiumPathSegment& operator=(const PDFiumPathSegment&) = delete;
+
+public:
+ PDFiumPathSegment(FPDF_PATHSEGMENT pPathSegment);
+ ~PDFiumPathSegment();
+
+ FPDF_PATHSEGMENT getPointer() { return mpPathSegment; }
+ basegfx::B2DPoint getPoint();
+ bool isClosed();
+ int getType();
+};
+
class VCL_DLLPUBLIC PDFiumPageObject final
{
private:
@@ -100,6 +118,9 @@ public:
int getTextRenderMode();
Color getFillColor();
Color getStrokeColor();
+ // Path
+ int getPathSegmentCount();
+ std::unique_ptr<PDFiumPathSegment> getPathSegment(int index);
};
class VCL_DLLPUBLIC PDFiumTextPage final
diff --git a/svx/source/inc/svdpdf.hxx b/svx/source/inc/svdpdf.hxx
index 60a90619e6a8..08a05a50f156 100644
--- a/svx/source/inc/svdpdf.hxx
+++ b/svx/source/inc/svdpdf.hxx
@@ -113,8 +113,10 @@ class ImpSdrPdfImport final
void ImportForm(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
int nPageObjectIndex);
- void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
- void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex);
+ void ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ int nPageObjectIndex);
+ void ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ int nPageObjectIndex);
void ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage,
int nPageObjectIndex);
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 30413fa1a30f..85911156159b 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -680,10 +680,10 @@ void ImpSdrPdfImport::ImportPdfObject(
ImportText(pPageObject, pTextPage, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_PATH:
- ImportPath(pPageObject->getPointer(), nPageObjectIndex);
+ ImportPath(pPageObject, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_IMAGE:
- ImportImage(pPageObject->getPointer(), nPageObjectIndex);
+ ImportImage(pPageObject, nPageObjectIndex);
break;
case FPDF_PAGEOBJ_SHADING:
SAL_WARN("sd.filter", "Got page object SHADING: " << nPageObjectIndex);
@@ -878,10 +878,11 @@ void ImpSdrPdfImport::MapScaling()
mnMapScalingOfs = nCount;
}
-void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/)
+void ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ int /*nPageObjectIndex*/)
{
std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter> bitmap(
- FPDFImageObj_GetBitmap(pPageObject));
+ FPDFImageObj_GetBitmap(pPageObject->getPointer()));
if (!bitmap)
{
SAL_WARN("sd.filter", "Failed to get IMAGE");
@@ -924,7 +925,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObject
float bottom;
float right;
float top;
- if (!FPDFPageObj_GetBounds(pPageObject, &left, &bottom, &right, &top))
+ if (!FPDFPageObj_GetBounds(pPageObject->getPointer(), &left, &bottom, &right, &top))
{
SAL_WARN("sd.filter", "FAILED to get image bounds");
}
@@ -941,36 +942,27 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObject
InsertObj(pGraf);
}
-void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/)
+void ImpSdrPdfImport::ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject,
+ int /*nPageObjectIndex*/)
{
- FS_MATRIX matrix;
- FPDFPath_GetMatrix(pPageObject, &matrix);
+ auto aPathMatrix = pPageObject->getMatrix();
- auto aPathMatrix
- = basegfx::B2DHomMatrix::abcdef(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
aPathMatrix *= maCurrentMatrix;
basegfx::B2DPolyPolygon aPolyPoly;
basegfx::B2DPolygon aPoly;
std::vector<basegfx::B2DPoint> aBezier;
- const int nSegments = FPDFPath_CountSegments(pPageObject);
+ const int nSegments = pPageObject->getPathSegmentCount();
for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex)
{
- FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex);
+ auto pPathSegment = pPageObject->getPathSegment(nSegmentIndex);
if (pPathSegment != nullptr)
{
- float fx, fy;
- if (!FPDFPathSegment_GetPoint(pPathSegment, &fx, &fy))
- {
- SAL_WARN("sd.filter", "Failed to get PDF path segment point");
- continue;
- }
-
- basegfx::B2DPoint aB2DPoint(fx, fy);
+ basegfx::B2DPoint aB2DPoint = pPathSegment->getPoint();
aB2DPoint *= aPathMatrix;
- const bool bClose = FPDFPathSegment_GetClose(pPathSegment);
+ const bool bClose = pPathSegment->isClosed();
if (bClose)
aPoly.setClosed(bClose); // TODO: Review
@@ -978,7 +970,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
aB2DPoint.setX(aPoint.X());
aB2DPoint.setY(aPoint.Y());
- const int nSegmentType = FPDFPathSegment_GetType(pPathSegment);
+ const int nSegmentType = pPathSegment->getType();
switch (nSegmentType)
{
case FPDF_SEGMENT_LINETO:
@@ -1030,13 +1022,13 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
aPolyPoly.transform(aTransform);
float fWidth = 1;
- FPDFPageObj_GetStrokeWidth(pPageObject, &fWidth);
+ FPDFPageObj_GetStrokeWidth(pPageObject->getPointer(), &fWidth);
const double dWidth = 0.5 * fabs(sqrt2(aPathMatrix.a(), aPathMatrix.c()) * fWidth);
mnLineWidth = convertPointToMm100(dWidth);
int nFillMode = FPDF_FILLMODE_ALTERNATE;
FPDF_BOOL bStroke = 1; // Assume we have to draw, unless told otherwise.
- if (FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke))
+ if (FPDFPath_GetDrawMode(pPageObject->getPointer(), &nFillMode, &bStroke))
{
if (nFillMode == FPDF_FILLMODE_ALTERNATE)
mpVD->SetDrawMode(DrawModeFlags::Default);
@@ -1050,12 +1042,12 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI
unsigned int nG;
unsigned int nB;
unsigned int nA;
- FPDFPageObj_GetFillColor(pPageObject, &nR, &nG, &nB, &nA);
+ FPDFPageObj_GetFillColor(pPageObject->getPointer(), &nR, &nG, &nB, &nA);
mpVD->SetFillColor(Color(nR, nG, nB));
if (bStroke)
{
- FPDFPageObj_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA);
+ FPDFPageObj_GetStrokeColor(pPageObject->getPointer(), &nR, &nG, &nB, &nA);
mpVD->SetLineColor(Color(nR, nG, nB));
}
else
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index b58878e7881e..d77a2f8da663 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -315,6 +315,39 @@ Color PDFiumPageObject::getStrokeColor()
return aColor;
}
+int PDFiumPageObject::getPathSegmentCount() { return FPDFPath_CountSegments(mpPageObject); }
+
+std::unique_ptr<PDFiumPathSegment> PDFiumPageObject::getPathSegment(int index)
+{
+ std::unique_ptr<PDFiumPathSegment> pPDFiumPathSegment;
+ FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(mpPageObject, index);
+ if (pPathSegment)
+ {
+ pPDFiumPathSegment = std::make_unique<PDFiumPathSegment>(pPathSegment);
+ }
+ return pPDFiumPathSegment;
+}
+
+PDFiumPathSegment::PDFiumPathSegment(FPDF_PATHSEGMENT pPathSegment)
+ : mpPathSegment(pPathSegment)
+{
+}
+
+PDFiumPathSegment::~PDFiumPathSegment() {}
+
+basegfx::B2DPoint PDFiumPathSegment::getPoint()
+{
+ basegfx::B2DPoint aPoint;
+ float fx, fy;
+ if (FPDFPathSegment_GetPoint(mpPathSegment, &fx, &fy))
+ aPoint = basegfx::B2DPoint(fx, fy);
+ return aPoint;
+}
+
+bool PDFiumPathSegment::isClosed() { return FPDFPathSegment_GetClose(mpPathSegment); }
+
+int PDFiumPathSegment::getType() { return FPDFPathSegment_GetType(mpPathSegment); }
+
PDFiumAnnotation::PDFiumAnnotation(FPDF_ANNOTATION pAnnotation)
: mpAnnotation(pAnnotation)
{
More information about the Libreoffice-commits
mailing list