summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-10 18:06:47 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-04 12:36:28 -0400
commit677dd7a54eb11feb98c7cf7f9d53a5fa932e22d6 (patch)
treec33fcf347e62fdcc861d62658fc318602951f967 /svx
parentc4eadb1dd5ff7159b9b9414a553424fd8685074e (diff)
svx: support Paths in PDFs while importing
Change-Id: Idba294cf5a3a8dd00988f94786715b110039e000 (cherry picked from commit b1083c119832c32d722a4e81415ef7a02c23d4aa)
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdpdf.cxx91
-rw-r--r--svx/source/svdraw/svdpdf.hxx2
2 files changed, 92 insertions, 1 deletions
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index a8ddfd80fef9..eec592f7886e 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -238,7 +238,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);
@@ -1254,6 +1254,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 92e1e1d6e740..f8f9f0d0a17f 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -102,6 +102,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);