summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-05-14 19:57:15 -0400
committerJan Holesovsky <kendy@collabora.com>2018-05-22 12:17:19 +0200
commit02d15d96fe42f7c5e1857f52ab6c0620017ac06f (patch)
treeb6c20da66f56cbeb22ca83c906fb898c8ef619f3 /svx
parent1ae9a1396e09f9715afea0feabe66b6bfc923bed (diff)
svx: transform PDF text rectangles while importing
Change-Id: I7675a183bfb691a8783950f33dc34826f91cb768
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdpdf.cxx26
-rw-r--r--svx/source/svdraw/svdpdf.hxx54
2 files changed, 69 insertions, 11 deletions
diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index 8fe06e2bc18c..4059a8d8a83d 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -1067,17 +1067,23 @@ void ImpSdrPdfImport::ImportText(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
return;
}
- const Rectangle aRect = PointsToLogic(left, right, top, bottom);
-
double a, b, c, d, e, f;
FPDFTextObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
- Matrix aTextMatrix(a, b, c, d, e, f);
- aTextMatrix.Concatinate(mCurMatrix);
- SAL_WARN("sd.filter", "Got font scale matrix (" << a << ", " << b << ", " << c << ", " << d
- << ", " << e << ", " << f << ')');
- Point aPos = PointsToLogic(e, f);
+ // Matrix aTextMatrix(a, b, c, d, e, f);
+ Matrix aTextMatrix(mCurMatrix);
+ SAL_WARN("sd.filter", "Got text matrix " << aTextMatrix.toString());
+ SAL_WARN("sd.filter", "Context matrix " << mCurMatrix.toString());
+ // aTextMatrix.Concatinate(mCurMatrix);
+ // SAL_WARN("sd.filter", "Got text matrix concat " << aTextMatrix.toString());
+
+ Point aPos = PointsToLogic(aTextMatrix.e(), aTextMatrix.f());
SAL_WARN("sd.filter", "Got TEXT origin: " << aPos);
- SAL_WARN("sd.filter", "Got TEXT Bounds: " << aRect);
+
+ const Rectangle aRect2 = PointsToLogic(left, right, top, bottom);
+ SAL_WARN("sd.filter", "Untransformed TEXT Bounds: " << aRect2);
+ aTextMatrix.Transform(left, right, top, bottom);
+ const Rectangle aRect = PointsToLogic(left, right, top, bottom);
+ SAL_WARN("sd.filter", "Transformed TEXT Bounds: " << aRect);
const int nChars = FPDFTextObj_CountChars(pPageObject) * 2;
std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nChars + 1]); // + terminating null
@@ -1413,9 +1419,9 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
float fWidth = 1;
FPDFPath_GetStrokeWidth(pPageObject, &fWidth);
- const double dWidth = 0.5 * fabs(sqrt2(mCurMatrix.a(), mCurMatrix.c()) * fWidth);
+ const double dWidth = 0.5 * fabs(sqrt2(aPathMatrix.a(), aPathMatrix.c()) * fWidth);
mnLineWidth = lcl_ToLogic(lcl_PointToPixel(dWidth));
- mnLineWidth /= 2;
+ // mnLineWidth /= 2;
SAL_WARN("sd.filter", "Path Stroke Width: " << fWidth << ", scaled: " << dWidth
<< ", Logical: " << mnLineWidth);
diff --git a/svx/source/svdraw/svdpdf.hxx b/svx/source/svdraw/svdpdf.hxx
index bb8dfb159b30..09d0d680cd7d 100644
--- a/svx/source/svdraw/svdpdf.hxx
+++ b/svx/source/svdraw/svdpdf.hxx
@@ -87,6 +87,7 @@ class ImpSdrPdfImport final
double d() const { return md; }
double e() const { return me; }
double f() const { return mf; }
+
/// Mutliply this * other.
void Concatinate(const Matrix& other)
{
@@ -99,12 +100,63 @@ class ImpSdrPdfImport final
}
/// Transform the point (x, y) by this Matrix.
- void Transform(double& x, double& y)
+ template <typename T> void Transform(T& x, T& y)
{
x = ma * x + mc * y + me;
y = mb * x + md * y + mf;
}
+ /// Transform the rectangle (left, right, top, bottom) by this Matrix.
+ template <typename T> void Transform(T& left, T& right, T& top, T& bottom)
+ {
+ SAL_WARN("sd.filter",
+ "Transforming: " << left << ", " << right << ", " << top << ", " << bottom);
+ T leftTopX = left;
+ T leftTopY = top;
+ Transform(leftTopX, leftTopY);
+ SAL_WARN("sd.filter", "Left-Top: " << leftTopX << ", " << leftTopY);
+
+ T leftBottomX = left;
+ T leftBottomY = bottom;
+ Transform(leftBottomX, leftBottomY);
+ SAL_WARN("sd.filter", "Left-Bottom: " << leftBottomX << ", " << leftBottomY);
+
+ T rightTopX = right;
+ T rightTopY = top;
+ Transform(rightTopX, rightTopY);
+ SAL_WARN("sd.filter", "Right-Top: " << rightTopX << ", " << rightTopY);
+
+ T rightBottomX = right;
+ T rightBottomY = bottom;
+ Transform(rightBottomX, rightBottomY);
+ SAL_WARN("sd.filter", "Right-Bottom: " << rightBottomX << ", " << rightBottomY);
+
+ left = std::min(leftTopX, leftBottomX);
+ SAL_WARN("sd.filter", "left: " << left);
+ right = std::max(rightTopX, rightBottomX);
+ SAL_WARN("sd.filter", "right: " << right);
+
+ if (top > bottom)
+ top = std::max(leftTopY, rightTopY);
+ else
+ top = std::min(leftTopY, rightTopY);
+ SAL_WARN("sd.filter", "top: " << top);
+
+ if (top > bottom)
+ bottom = std::max(leftBottomY, rightBottomY);
+ else
+ bottom = std::max(leftBottomY, rightBottomY);
+ SAL_WARN("sd.filter", "bottom: " << bottom);
+ }
+
+ std::string toString() const
+ {
+ std::ostringstream oss;
+ oss << '(' << ma << ", " << mb << ", " << mc << ", " << md << ", " << me << ", " << mf
+ << ')';
+ return oss.str();
+ }
+
private:
double ma, mb, mc, md, me, mf;
};