diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-07-06 14:08:23 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-07-08 20:55:01 +0200 |
commit | bc8016b81c2c609711c26af1f85da327cf30a4ff (patch) | |
tree | 40155b9e9cc116af7fcabbd5996aac756f96384e /svx/source/svdraw | |
parent | 243b96653e0f5d1113521129baecb4e1c278cc83 (diff) |
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@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source/svdraw')
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 44 |
1 files changed, 18 insertions, 26 deletions
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 |