summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-04-13 18:59:56 -0400
committerAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-05 21:02:05 -0400
commitb7a90bcdc16f32a8ef5009c93f09d54a7a7d5f61 (patch)
tree6ddd82404f34c92a8ae54fbdbc71e30d0c029b55
parent2daad356108363a0132cc99993fd3869473a0074 (diff)
svx: improve path importing from PDF
Change-Id: I8e63b2a35d841e065ef32fea95c0a5f22ca6f049
-rw-r--r--external/pdfium/edit.patch.1100
-rw-r--r--svx/source/svdraw/svdpdf.cxx39
2 files changed, 125 insertions, 14 deletions
diff --git a/external/pdfium/edit.patch.1 b/external/pdfium/edit.patch.1
index 03b4ab221730..86cda347f262 100644
--- a/external/pdfium/edit.patch.1
+++ b/external/pdfium/edit.patch.1
@@ -209,7 +209,7 @@ index ca2cf3f..8073a18 100644
+ return true;
+}
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
-index a291987..d3b0bc1 100644
+index a291987..1ac8257 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -101,6 +101,16 @@ FPDFPath_SetStrokeWidth(FPDF_PAGEOBJECT path, float width) {
@@ -229,6 +229,63 @@ index a291987..d3b0bc1 100644
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetFillColor(FPDF_PAGEOBJECT path,
unsigned int R,
unsigned int G,
+@@ -217,6 +227,25 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path,
+ return true;
+ }
+
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetDrawMode(FPDF_PAGEOBJECT path,
++ int* fillmode,
++ FPDF_BOOL* stroke)
++{
++ auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path);
++ if (!pPathObj || !fillmode || !stroke)
++ return false;
++
++ if (pPathObj->m_FillType == FXFILL_ALTERNATE)
++ *fillmode = FPDF_FILLMODE_ALTERNATE;
++ else if (pPathObj->m_FillType == FXFILL_WINDING)
++ *fillmode = FPDF_FILLMODE_WINDING;
++ else
++ *fillmode = 0; // no fill
++
++ *stroke = pPathObj->m_bStroke;
++ return true;
++}
++
+ FPDF_EXPORT void FPDF_CALLCONV FPDFPath_SetLineJoin(FPDF_PAGEOBJECT path,
+ int line_join) {
+ if (!path)
+@@ -250,6 +279,30 @@ FPDF_EXPORT void FPDF_CALLCONV FPDFPath_SetLineCap(FPDF_PAGEOBJECT path,
+ }
+
+ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
++FPDFPath_GetMatrix(FPDF_PAGEOBJECT path_object,
++ double* a,
++ double* b,
++ double* c,
++ double* d,
++ double* e,
++ double* f)
++{
++ if (!path_object || !a || !b || !c || !d || !e || !f)
++ return false;
++
++ auto* pPathObj = CPDFPageObjectFromFPDFPageObject(path_object);
++ CFX_Matrix* pMatrix = pPathObj->m_GeneralState.GetMutableMatrix();
++ *a = pMatrix->a;
++ *b = pMatrix->b;
++ *c = pMatrix->c;
++ *d = pMatrix->d;
++ *e = pMatrix->e;
++ *f = pMatrix->f;
++
++ return true;
++}
++
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+ FPDFPathSegment_GetPoint(FPDF_PATHSEGMENT segment, float* x, float* y) {
+ auto* pPathPoint = FXPathPointFromFPDFPathSegment(segment);
+ if (!pPathPoint || !x || !y)
diff --git a/fpdfsdk/fpdftext.cpp b/fpdfsdk/fpdftext.cpp
index 68bf4f8..e073b20 100644
--- a/fpdfsdk/fpdftext.cpp
@@ -300,7 +357,7 @@ 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..282bcdb 100644
+index 54735a3..a415c98 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -520,6 +520,15 @@ FPDFPath_GetStrokeColor(FPDF_PAGEOBJECT path,
@@ -319,7 +376,44 @@ index 54735a3..282bcdb 100644
// Set the line join of |page_object|.
//
// page_object - handle to a page object.
-@@ -761,6 +770,73 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
+@@ -688,6 +697,36 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path,
+ int fillmode,
+ FPDF_BOOL stroke);
+
++// Get the drawing mode of a path.
++//
++// path - the handle to the path object.
++// fillmode - the filling mode to be set: 0 for no fill, 1 for alternate, 2 for
++// winding.
++// stroke - a boolean specifying if the path should be stroked or not.
++//
++// Returns TRUE on success
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetDrawMode(FPDF_PAGEOBJECT path,
++ int* fillmode,
++ FPDF_BOOL* stroke);
++
++// Get the matrix of a particular text object.
++//
++// path_object - Handle of path object returned by FPDFPath_NewPathObj
++// a - Pointer to a double value receiving coefficient "a" of the matrix.
++// b - Pointer to a double value receiving coefficient "b" of the matrix.
++// c - Pointer to a double value receiving coefficient "c" of the matrix.
++// d - Pointer to a double value receiving coefficient "d" of the matrix.
++// e - Pointer to a double value receiving coefficient "e" of the matrix.
++// f - Pointer to a double value receiving coefficient "f" of the matrix.
++FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
++FPDFPath_GetMatrix(FPDF_PAGEOBJECT path_object,
++ double* a,
++ double* b,
++ double* c,
++ double* d,
++ double* e,
++ double* f);
++
+ // Create a new text object using one of the standard PDF fonts.
+ //
+ // document - handle to the document.
+@@ -761,6 +800,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 f69d43b6c16d..f89f8b3f38dd 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -568,7 +568,7 @@ void ImpSdrPdfImport::SetAttributes(SdrObject* pObj, bool bForceTextAttr)
if (mpVD->IsLineColor())
{
- mpLineAttr->Put(XLineStyleItem(drawing::LineStyle_SOLID));
+ mpLineAttr->Put(XLineStyleItem(drawing::LineStyle_SOLID)); //TODO support dashed lines.
mpLineAttr->Put(XLineColorItem(OUString(), mpVD->GetLineColor()));
}
else
@@ -1254,6 +1254,10 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex)
{
SAL_WARN("sd.filter", "Got page object PATH: " << nPageObjectIndex);
+
+ double a, b, c, d, e, f;
+ FPDFPath_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
+
basegfx::B2DPolygon aPoly;
std::vector<basegfx::B2DPoint> aBezier;
@@ -1270,9 +1274,14 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
continue;
}
+ SAL_WARN("sd.filter", "Got point (" << x << ", " << y << ")");
+
+ x = a * x + c * y + e;
+ y = b * x + d * y + f;
+
const bool bClose = FPDFPathSegment_GetClose(pPathSegment);
SAL_WARN("sd.filter",
- "Got (" << x << ", " << y << "): " << (bClose ? "CLOSE" : "OPEN"));
+ "Point corrected (" << x << ", " << y << "): " << (bClose ? "CLOSE" : "OPEN"));
Point aPoint = PointsToLogic(x, y);
x = aPoint.X();
y = aPoint.Y();
@@ -1322,15 +1331,23 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
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));
+ unsigned int nR;
+ unsigned int nG;
+ unsigned int nB;
+ unsigned int nA;
+ FPDFPath_GetFillColor(pPageObject, &nR, &nG, &nB, &nA);
+ SAL_WARN("sd.filter", "Got PATH fill color: " << nR << ", " << nG << ", " << nB << ", " << nA);
+ mpVD->SetFillColor(Color(nR, nG, nB));
+
+ FPDFPath_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA);
+ SAL_WARN("sd.filter",
+ "Got PATH stroke color: " << nR << ", " << nG << ", " << nB << ", " << nA);
+ mpVD->SetLineColor(Color(nR, nG, nB));
+
+ // int nFillMode = 0; // No fill.
+ // bool bStroke = false;
+ // FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke);
+ // mpVD->Setstroke(Color(r, g, b));
// if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))