drawinglayer/source/tools/emfpcustomlinecap.cxx |    8 --
 drawinglayer/source/tools/emfphelperdata.cxx    |   91 ++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 7 deletions(-)

New commits:
commit 26c6e23155b151c3f05f3cfdde2bd842aef05306
Author:     Bartosz Kosiorek <gan...@poczta.onet.pl>
AuthorDate: Wed Nov 13 07:39:46 2019 +0100
Commit:     Xisco FaulĂ­ <xiscofa...@libreoffice.org>
CommitDate: Wed Nov 20 23:15:58 2019 +0100

    tdf#42112 Add support for Custom Line Cap
    
    original patch updated by Chris Sherlock
    
    Change-Id: Ie68c3cc40d2c7263a0f786a973da77b00e4cbeb8
    Reviewed-on: https://gerrit.libreoffice.org/82564
    Tested-by: Jenkins
    Reviewed-by: Bartosz Kosiorek <gan...@poczta.onet.pl>
    (cherry picked from commit d15518584a3197e4b8318d0176352a0584f42167)
    Reviewed-on: https://gerrit.libreoffice.org/83298
    Reviewed-by: Chris Sherlock <chris.sherloc...@gmail.com>
    Reviewed-by: Xisco FaulĂ­ <xiscofa...@libreoffice.org>

diff --git a/drawinglayer/source/tools/emfpcustomlinecap.cxx 
b/drawinglayer/source/tools/emfpcustomlinecap.cxx
index 82e8f94e0e37..98af0f5241c7 100644
--- a/drawinglayer/source/tools/emfpcustomlinecap.cxx
+++ b/drawinglayer/source/tools/emfpcustomlinecap.cxx
@@ -67,13 +67,7 @@ namespace emfplushelper
         path.Read(s, pathFlags);
         polygon = path.GetPolygon(rR, false);
         mbIsFilled = bFill;
-
-        // transformation to convert the path to what LibreOffice
-        // expects
-        B2DHomMatrix aMatrix;
-        aMatrix.scale(1.0, -1.0);
-        polygon.transform(aMatrix);
-    };
+    }
 
     void EMFPCustomLineCap::Read(SvStream& s, EmfPlusHelperData const & rR)
     {
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx 
b/drawinglayer/source/tools/emfphelperdata.cxx
index 58cb38dc21c9..a9ac0e9f8e30 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include "emfpcustomlinecap.hxx"
 #include "emfphelperdata.hxx"
 #include "emfpbrush.hxx"
 #include "emfppen.hxx"
@@ -476,6 +477,96 @@ namespace emfplushelper
                                 pen->GetColor().GetTransparency() / 255.0));
             }
 
+            if ((pen->penDataFlags & 0x00000800) && 
(pen->customStartCap->polygon.begin()->count() > 1))
+            {
+                SAL_WARN("drawinglayer", "EMF+\tCustom Start Line Cap");
+                ::basegfx::B2DPolyPolygon 
startCapPolygon(pen->customStartCap->polygon);
+
+                // get the gradient of the first line in the polypolygon
+                double x1 = polygon.begin()->getB2DPoint(0).getX();
+                double y1 = polygon.begin()->getB2DPoint(0).getY();
+                double x2 = polygon.begin()->getB2DPoint(1).getX();
+                double y2 = polygon.begin()->getB2DPoint(1).getY();
+
+                if ((x2 - x1) != 0)
+                {
+                    double gradient = (y2 - y1) / (x2 - x1);
+
+                    // now we get the angle that we need to rotate the arrow by
+                    double angle = (M_PI / 2) - atan(gradient);
+
+                    // rotate the arrow
+                    
startCapPolygon.transform(basegfx::utils::createRotateB2DHomMatrix(angle));
+                }
+
+                startCapPolygon.transform(maMapTransform);
+
+                basegfx::B2DHomMatrix tran(pen->penWidth, 0.0, 
polygon.begin()->getB2DPoint(0).getX(),
+                                           0.0, pen->penWidth, 
polygon.begin()->getB2DPoint(0).getY());
+                startCapPolygon.transform(tran);
+
+                if (pen->customStartCap->mbIsFilled)
+                {
+                    mrTargetHolders.Current().append(
+                                
std::make_unique<drawinglayer::primitive2d::PolyPolygonColorPrimitive2D>(
+                                    startCapPolygon,
+                                    pen->GetColor().getBColor()));
+                }
+                else
+                {
+                    mrTargetHolders.Current().append(
+                                
std::make_unique<drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D>(
+                                    startCapPolygon,
+                                    lineAttribute,
+                                    aStrokeAttribute));
+                }
+            }
+
+            if ((pen->penDataFlags & 0x00001000) && 
(pen->customEndCap->polygon.begin()->count() > 1))
+            {
+                SAL_WARN("drawinglayer", "EMF+\tCustom End Line Cap");
+
+                ::basegfx::B2DPolyPolygon 
endCapPolygon(pen->customEndCap->polygon);
+
+                // get the gradient of the first line in the polypolygon
+                double x1 = 
polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getX();
+                double y1 = 
polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getY();
+                double x2 = 
polygon.begin()->getB2DPoint(polygon.begin()->count() - 2).getX();
+                double y2 = 
polygon.begin()->getB2DPoint(polygon.begin()->count() - 2).getY();
+
+                if ((x2 - x1) != 0)
+                {
+                    double gradient = (y2 - y1) / (x2 - x1);
+
+                    // now we get the angle that we need to rotate the arrow by
+                    double angle = (M_PI / 2) - atan(gradient);
+
+                    // rotate the arrow
+                    
endCapPolygon.transform(basegfx::utils::createRotateB2DHomMatrix(angle));
+                }
+
+                endCapPolygon.transform(maMapTransform);
+                basegfx::B2DHomMatrix tran(pen->penWidth, 0.0, 
polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getX(),
+                                           0.0, pen->penWidth, 
polygon.begin()->getB2DPoint(polygon.begin()->count() - 1).getY());
+                endCapPolygon.transform(tran);
+
+                if (pen->customEndCap->mbIsFilled)
+                {
+                    mrTargetHolders.Current().append(
+                                
std::make_unique<drawinglayer::primitive2d::PolyPolygonColorPrimitive2D>(
+                                    endCapPolygon,
+                                    pen->GetColor().getBColor()));
+                }
+                else
+                {
+                    mrTargetHolders.Current().append(
+                                
std::make_unique<drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D>(
+                                    endCapPolygon,
+                                    lineAttribute,
+                                    aStrokeAttribute));
+                }
+            }
+
             
mrPropertyHolders.Current().setLineColor(pen->GetColor().getBColor());
             mrPropertyHolders.Current().setLineColorActive(true);
             mrPropertyHolders.Current().setFillColorActive(false);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to