summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-10 18:06:47 -0400
committerJan Holesovsky <kendy@collabora.com>2018-05-22 12:17:14 +0200
commitb1083c119832c32d722a4e81415ef7a02c23d4aa (patch)
tree086ba24a073a2624d59087b67516c2ed31da35d1
parent3c02b52fdad9c5a34d4bfb7623e04c4e85875a89 (diff)
svx: support Paths in PDFs while importing
Change-Id: Idba294cf5a3a8dd00988f94786715b110039e000
-rw-r--r--external/pdfium/edit.patch.141
-rw-r--r--svx/source/svdraw/svdpdf.cxx91
-rw-r--r--svx/source/svdraw/svdpdf.hxx2
3 files changed, 131 insertions, 3 deletions
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index 9099a4024b3e..03b4ab221730 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -208,6 +208,27 @@ index ca2cf3f..8073a18 100644
+ (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
+ return true;
+}
+diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
+index a291987..d3b0bc1 100644
+--- a/fpdfsdk/fpdfeditpath.cpp
++++ b/fpdfsdk/fpdfeditpath.cpp
+@@ -101,6 +101,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/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 68bf4f8..e073b20 100644
--- a/fpdfsdk/fpdftext.cpp
@@ -279,10 +300,26 @@ index 77c2315..db3e734 100644
CPDF_PageObject* CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
-index 54735a3..15292f5 100644
+index 54735a3..282bcdb 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
-@@ -761,6 +761,73 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+@@ -520,6 +520,15 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path,
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+ FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, 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.
+@@ -761,6 +770,73 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
FPDF_FONT font,
float font_size);
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 9b57adf737bc..cd10f7738f9e 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -233,7 +233,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);
@@ -1247,6 +1247,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 f78b427671f6..8bce23449a06 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);