[Libreoffice-commits] core.git: Branch 'private/Ashod/cd-5.3.3.2' - 2 commits - svx/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed May 16 14:48:29 UTC 2018


 svx/source/svdraw/svdpdf.cxx |   30 +++++++++++++++--------
 svx/source/svdraw/svdpdf.hxx |   54 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 73 insertions(+), 11 deletions(-)

New commits:
commit d5eed4392b546349b3058dc4a462fd22436a4710
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 14 19:57:15 2018 -0400

    svx: transform PDF text rectangles while importing
    
    Change-Id: I7675a183bfb691a8783950f33dc34826f91cb768

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;
     };
commit 6494b909e3281765e15fc150d1b67ae5de6d9aef
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 14 19:01:44 2018 -0400

    svx: set the Model explicitly before using SDR objects
    
    Change-Id: I176d1c1c7f759904ab36796a47e879e45ce4a5af

diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx
index bb241986a199..8fe06e2bc18c 100644
--- a/svx/source/svdraw/svdpdf.cxx
+++ b/svx/source/svdraw/svdpdf.cxx
@@ -771,6 +771,7 @@ void ImpSdrPdfImport::InsertObj(SdrObject* pObj, bool bScale)
                 if (!aNewRange.isEmpty())
                 {
                     pObj = new SdrPathObj(aNewPoly.isClosed() ? OBJ_POLY : OBJ_PLIN, aNewPoly);
+                    pObj->SetModel(mpModel);
 
                     pObj->SetLayer(aOldLayer);
                     pObj->SetMergedItemSet(aOldItemSet);
@@ -1157,6 +1158,7 @@ void ImpSdrPdfImport::ImportText(const Point& rPos, const Size& rSize, const OUS
     Rectangle aTextRect(aPos, bSize);
     // SAL_WARN("sd.filter", "Text Rect: " << aTextRect);
     SdrRectObj* pText = new SdrRectObj(OBJ_TEXT, aTextRect);
+    pText->SetModel(mpModel);
 
     pText->SetMergedItem(makeSdrTextUpperDistItem(0));
     pText->SetMergedItem(makeSdrTextLowerDistItem(0));
@@ -1304,6 +1306,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIn
     SAL_WARN("sd.filter", "IMAGE Logical Rect FINAL: " << aRect);
 
     SdrGrafObj* pGraf = new SdrGrafObj(Graphic(aBitmap), aRect);
+    pGraf->SetModel(mpModel);
 
     // This action is not creating line and fill, set directly, do not use SetAttributes(..)
     pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1450,6 +1453,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectInd
     // if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(basegfx::B2DPolyPolygon(aSource)))
 
     SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aPolyPoly);
+    pPath->SetModel(mpModel);
     SetAttributes(pPath);
     InsertObj(pPath, false);
 }


More information about the Libreoffice-commits mailing list