diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2018-04-10 18:06:47 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2018-06-06 12:48:30 +0200 |
commit | fcefaa57516e30a0c7e48aafc76ac24311d1b64f (patch) | |
tree | 60af3c2fb24426f9239e6c1e9e28235854c2c026 | |
parent | be39b2f0a14e5fde96a965f32ba1b13137efe445 (diff) |
svx: support Paths in PDFs while importing
Change-Id: Idba294cf5a3a8dd00988f94786715b110039e000
(cherry picked from commit b1083c119832c32d722a4e81415ef7a02c23d4aa)
-rw-r--r-- | external/pdfium/0005-svx-support-Paths-in-PDFs-while-importing.patch.2 | 54 | ||||
-rw-r--r-- | external/pdfium/UnpackedTarball_pdfium.mk | 1 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.cxx | 91 | ||||
-rw-r--r-- | svx/source/svdraw/svdpdf.hxx | 2 |
4 files changed, 147 insertions, 1 deletions
diff --git a/external/pdfium/0005-svx-support-Paths-in-PDFs-while-importing.patch.2 b/external/pdfium/0005-svx-support-Paths-in-PDFs-while-importing.patch.2 new file mode 100644 index 000000000000..ed0e4d4af418 --- /dev/null +++ b/external/pdfium/0005-svx-support-Paths-in-PDFs-while-importing.patch.2 @@ -0,0 +1,54 @@ +From 42afb017a64ffcc89f670df5f5a0d42a6e710b20 Mon Sep 17 00:00:00 2001 +From: Ashod Nakashian <ashod.nakashian@collabora.co.uk> +Date: Tue, 5 Jun 2018 11:30:22 +0200 +Subject: [PATCH 05/14] svx: support Paths in PDFs while importing + +--- + pdfium/fpdfsdk/fpdf_editpath.cpp | 10 ++++++++++ + pdfium/public/fpdf_edit.h | 9 +++++++++ + 2 files changed, 19 insertions(+) + +diff --git a/pdfium/fpdfsdk/fpdf_editpath.cpp b/pdfium/fpdfsdk/fpdf_editpath.cpp +index aca2beb..55f9fce 100644 +--- a/pdfium/fpdfsdk/fpdf_editpath.cpp ++++ b/pdfium/fpdfsdk/fpdf_editpath.cpp +@@ -117,6 +117,16 @@ FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width) { + return true; + } + ++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV ++FPDFPath_GetStrokeWidth(FPDF_PAGEOBJECT path, float* width) { ++ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); ++ if (!pPathObj || !width) ++ return false; ++ ++ *width = pPathObj->m_GraphState.GetLineWidth(); ++ return true; ++} ++ + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, + unsigned int R, + unsigned int G, +diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h +index fa9902e..b44bc71 100644 +--- a/pdfium/public/fpdf_edit.h ++++ b/pdfium/public/fpdf_edit.h +@@ -678,6 +678,15 @@ FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width); + FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV + FPDFPageObj_SetStrokeWidth(FPDF_PAGEOBJECT page_object, float width); + ++// Get the stroke width of a path. ++// ++// path - the handle to the path object. ++// width - the width of the stroke. ++// ++// Returns TRUE on success ++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV ++FPDFPath_GetStrokeWidth(FPDF_PAGEOBJECT path, float* width); ++ + // Set the line join of |page_object|. + // + // page_object - handle to a page object. +-- +2.16.3 + diff --git a/external/pdfium/UnpackedTarball_pdfium.mk b/external/pdfium/UnpackedTarball_pdfium.mk index b7dc4d2fa5e3..b10194ef3b14 100644 --- a/external/pdfium/UnpackedTarball_pdfium.mk +++ b/external/pdfium/UnpackedTarball_pdfium.mk @@ -18,6 +18,7 @@ pdfium_patches += 0001-svx-import-PDF-text-using-PDFium.patch.2 pdfium_patches += 0002-svx-more-accurate-PDF-text-importing.patch.2 pdfium_patches += 0003-svx-import-PDF-images-as-BGRA.patch.2 pdfium_patches += 0004-svx-support-PDF-text-color.patch.2 +pdfium_patches += 0005-svx-support-Paths-in-PDFs-while-importing.patch.2 $(eval $(call gb_UnpackedTarball_UnpackedTarball,pdfium)) diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index 0c990d911e38..eb3ea0daa4a1 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -236,7 +236,7 @@ void ImpSdrPdfImport::DoLoopActions(SvdProgressInfo* pProgrInfo, sal_uInt32* pAc ImportText(pPageObject, nPageObjectIndex); break; case FPDF_PAGEOBJ_PATH: - SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex); + ImportPath(pPageObject, nPageObjectIndex); break; case FPDF_PAGEOBJ_IMAGE: ImportImage(pPageObject, nPageObjectIndex); @@ -1252,6 +1252,95 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn InsertObj(pGraf); } +void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex) +{ + SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex); + basegfx::B2DPolygon aPoly; + std::vector<basegfx::B2DPoint> aBezier; + + const int nSegments = FPDFPath_CountSegments(pPageObject); + for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex) + { + FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex); + if (pPathSegment != nullptr) + { + float x, y; + if (!FPDFPathSegment_GetPoint(pPathSegment, &x, &y)) + { + SAL_WARN("sd.filter", "Failed to get PDF path segement point"); + continue; + } + + const bool bClose = FPDFPathSegment_GetClose(pPathSegment); + SAL_WARN("sd.filter", + "Got (" << x << ", " << y << "): " << (bClose ? "CLOSE" : "OPEN")); + Point aPoint = PointsToLogic(x, y); + x = aPoint.X(); + y = aPoint.Y(); + + const int nSegmentType = FPDFPathSegment_GetType(pPathSegment); + switch (nSegmentType) + { + case FPDF_SEGMENT_LINETO: + SAL_WARN("sd.filter", "Got LineTo Segment."); + aPoly.append(basegfx::B2DPoint(x, y)); + break; + + case FPDF_SEGMENT_BEZIERTO: + SAL_WARN("sd.filter", "Got BezierTo Segment."); + aBezier.emplace_back(x, y); + if (aBezier.size() == 3) + { + aPoly.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]); + aBezier.clear(); + } + break; + + case FPDF_SEGMENT_MOVETO: + SAL_WARN("sd.filter", "Got MoveTo Segment."); + aPoly.append(basegfx::B2DPoint(x, y)); + break; + + case FPDF_SEGMENT_UNKNOWN: + default: + SAL_WARN("sd.filter", "Unknown path segment type in PDF: " << nSegmentType); + break; + } + } + } + + if (aBezier.size() == 3) + { + aPoly.appendBezierSegment(aBezier[0], aBezier[1], aBezier[2]); + aBezier.clear(); + } + + const basegfx::B2DHomMatrix aTransform( + basegfx::tools::createScaleTranslateB2DHomMatrix(mfScaleX, mfScaleY, maOfs.X(), maOfs.Y())); + aPoly.transform(aTransform); + + float fWidth = 1; + FPDFPath_GetStrokeWidth(pPageObject, &fWidth); + mnLineWidth = lcl_ToLogic(lcl_PointToPixel(fWidth)); + + unsigned int r; + unsigned int g; + unsigned int b; + unsigned int a; + FPDFPath_GetFillColor(pPageObject, &r, &g, &b, &a); + mpVD->SetFillColor(Color(r, g, b)); + + FPDFPath_GetStrokeColor(pPageObject, &r, &g, &b, &a); + mpVD->SetLineColor(Color(r, g, b)); + + // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource))) + + aPoly.setClosed(true); // TODO: Review + SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aPoly)); + SetAttributes(pPath); + InsertObj(pPath, false); +} + Point ImpSdrPdfImport::PointsToLogic(double x, double y) const { y = correctVertOrigin(y); diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx index dd4306c738bd..17b926b43619 100644 --- a/svx/source/svdraw/svdpdf.hxx +++ b/svx/source/svdraw/svdpdf.hxx @@ -103,6 +103,8 @@ class ImpSdrPdfImport final void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); void SetupPageScale(const double dPageWidth, const double dPageHeight); + void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); + void ImportText(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); void ImportText(const Point& rPos, const OUString& rStr); void SetAttributes(SdrObject* pObj, bool bForceTextAttr = false); |