From c20fa884cf20959dbd65814274e450e1f49cf45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Sun, 29 Mar 2020 23:05:25 +0200 Subject: [PATCH] replace usage of Matrix for B2DHomMatrix in ImpSdrPdfImport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I366ee435ddf217c7c078d58f882610df12bec276 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91341 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- svx/source/svdraw/svdpdf.cxx | 40 ++++++++++++++++++++---------------- svx/source/svdraw/svdpdf.hxx | 4 ++-- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index a86be9aa5bc0..c0eb4941d446 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -757,11 +757,12 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex int /*nPageObjectIndex*/) { // Get the form matrix to perform correct translation/scaling of the form sub-objects. - const Matrix aOldMatrix = mCurMatrix; + const basegfx::B2DHomMatrix aOldMatrix = maCurrentMatrix; FS_MATRIX matrix; FPDFFormObj_GetMatrix(pPageObject, &matrix); - mCurMatrix = Matrix(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f); + maCurrentMatrix + = basegfx::B2DHomMatrix::abcdef(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f); const int nCount = FPDFFormObj_CountObjects(pPageObject); for (int nIndex = 0; nIndex < nCount; ++nIndex) @@ -771,7 +772,7 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex } // Restore the old one. - mCurMatrix = aOldMatrix; + maCurrentMatrix = aOldMatrix; } void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTextPage, @@ -791,10 +792,11 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex FS_MATRIX matrix; FPDFTextObj_GetMatrix(pPageObject, &matrix); - Matrix aTextMatrix(mCurMatrix); - - aTextMatrix.Transform(left, right, top, bottom); - const tools::Rectangle aRect = PointsToLogic(left, right, top, bottom); + basegfx::B2DHomMatrix aTextMatrix(maCurrentMatrix); + basegfx::B2DRange aTextRect(left, top, right, bottom); + aTextRect *= aTextMatrix; + const tools::Rectangle aRect = PointsToLogic(aTextRect.getMinX(), aTextRect.getMaxX(), + aTextRect.getMinY(), aTextRect.getMaxY()); const int nChars = FPDFTextObj_GetText(pPageObject, pTextPage, nullptr, 0); std::unique_ptr pText(new sal_Unicode[nChars]); @@ -1027,8 +1029,10 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI { FS_MATRIX matrix; FPDFPath_GetMatrix(pPageObject, &matrix); - Matrix aPathMatrix(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f); - aPathMatrix.Concatinate(mCurMatrix); + + 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; @@ -1047,26 +1051,26 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI continue; } - double x = fx; - double y = fy; - aPathMatrix.Transform(x, y); + basegfx::B2DPoint aB2DPoint(fx, fy); + aB2DPoint *= aPathMatrix; + const bool bClose = FPDFPathSegment_GetClose(pPathSegment); if (bClose) aPoly.setClosed(bClose); // TODO: Review - Point aPoint = PointsToLogic(x, y); - x = aPoint.X(); - y = aPoint.Y(); + Point aPoint = PointsToLogic(aB2DPoint.getX(), aB2DPoint.getY()); + aB2DPoint.setX(aPoint.X()); + aB2DPoint.setY(aPoint.Y()); const int nSegmentType = FPDFPathSegment_GetType(pPathSegment); switch (nSegmentType) { case FPDF_SEGMENT_LINETO: - aPoly.append(basegfx::B2DPoint(x, y)); + aPoly.append(aB2DPoint); break; case FPDF_SEGMENT_BEZIERTO: - aBezier.emplace_back(x, y); + aBezier.emplace_back(aB2DPoint.getX(), aB2DPoint.getY()); if (aBezier.size() == 3) { aPoly.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]); @@ -1082,7 +1086,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI aPoly.clear(); } - aPoly.append(basegfx::B2DPoint(x, y)); + aPoly.append(aB2DPoint); break; case FPDF_SEGMENT_UNKNOWN: diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx index 46e63a7783ba..32de912b3b63 100644 --- a/svx/source/svdraw/svdpdf.hxx +++ b/svx/source/svdraw/svdpdf.hxx @@ -34,7 +34,7 @@ #include #include -#include +#include // Prevent workdir/UnpackedTarball/pdfium/public/fpdfview.h from including windows.h in a way that // it will define e.g. Yield as a macro: @@ -92,7 +92,7 @@ class ImpSdrPdfImport final double mdPageWidthPts; double mdPageHeightPts; /// The current transformation matrix, typically used with Form objects. - Matrix mCurMatrix; + basegfx::B2DHomMatrix maCurrentMatrix; /// Correct the vertical coordinate to start at the top. /// PDF coordinate system has origin at the bottom right.