basegfx/CppunitTest_basegfx.mk                 |    3 
 basegfx/test/minimalCreateAreaGeometryTest.cxx |   87 ++++++++++++++++++
 canvas/source/opengl/ogl_canvashelper.cxx      |  118 +++++++++++++++++++++++--
 3 files changed, 202 insertions(+), 6 deletions(-)

New commits:
commit f70e408c975c22403bb1d6eb72e02162dcdd262c
Author: Michael Jaumann <meta_...@yahoo.com>
Date:   Thu Dec 11 12:15:23 2014 +0000

    testcase for createAreaGeometry
    
    Change-Id: Ie9b6dcad91549feba738e0b3e010982a54cd327d

diff --git a/basegfx/CppunitTest_basegfx.mk b/basegfx/CppunitTest_basegfx.mk
index 8f34f3b..86ebf8cd5 100644
--- a/basegfx/CppunitTest_basegfx.mk
+++ b/basegfx/CppunitTest_basegfx.mk
@@ -25,6 +25,8 @@ $(eval $(call gb_CppunitTest_use_libraries,basegfx,\
        $(gb_UWINAPI) \
 ))
 
+
+
 $(eval $(call gb_CppunitTest_add_exception_objects,basegfx,\
     basegfx/test/basegfx1d \
     basegfx/test/basegfx2d \
@@ -33,6 +35,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basegfx,\
     basegfx/test/basegfxtools \
     basegfx/test/clipstate \
     basegfx/test/genericclipper \
+       basegfx/test/minimalCreateAreaGeometryTest \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/basegfx/test/minimalCreateAreaGeometryTest.cxx 
b/basegfx/test/minimalCreateAreaGeometryTest.cxx
new file mode 100644
index 0000000..11e91a9
--- /dev/null
+++ b/basegfx/test/minimalCreateAreaGeometryTest.cxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/types.h>
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <basegfx/tools/tools.hxx>
+#include <com/sun/star/rendering/PathCapType.hpp>
+#include <com/sun/star/rendering/PathJoinType.hpp>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dlinegeometry.hxx>
+
+
+using namespace ::basegfx;
+
+namespace basegfxtools
+{
+
+class createAreaGeometryTest : public CppUnit::TestFixture
+{
+    B2DPolygon mPoly;
+    const float mStrokeWidth;
+    static B2DPolygon getTestVector()
+    {
+        B2DPolygon aTestPoly;
+        aTestPoly.reserve(6);
+        aTestPoly.append(B2DPoint(2.26965,2.33533));
+        aTestPoly.append(B2DPoint(523.855,2.33533));
+        aTestPoly.append(B2DPoint(523.855,312.263));
+        aTestPoly.append(B2DPoint(2.26965,2.33533));
+        aTestPoly.append(B2DPoint(523.855,2.33533));
+        aTestPoly.append(B2DPoint(523.855,312.263));
+        return aTestPoly;
+    }
+
+public:
+    createAreaGeometryTest():
+    mPoly(getTestVector()),
+    mStrokeWidth(2.3*0.5)
+    {}
+    void setUp() SAL_OVERRIDE
+    {}
+
+    void tearDown() SAL_OVERRIDE
+    {}
+
+    void test()
+    {
+         ::basegfx::B2DPolyPolygon aStrokedPolyPoly;
+         aStrokedPolyPoly.append(basegfx::tools::createAreaGeometry(
+                                 mPoly,
+                                 mStrokeWidth,
+                                 basegfx::B2DLINEJOIN_NONE,
+                                 com::sun::star::drawing::LineCap_SQUARE));
+    }
+
+    // Change the following lines only, if you add, remove or rename
+    // member functions of the current class,
+    // because these macros are need by auto register mechanism.
+
+    CPPUNIT_TEST_SUITE(createAreaGeometryTest);
+    CPPUNIT_TEST(test);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfxtools::createAreaGeometryTest);
+} // namespace basegfxtools
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 851bef411081e2d922d5bd781d7e549bb4b7d3af
Author: Michael Jaumann <meta_...@yahoo.com>
Date:   Thu Dec 11 10:38:10 2014 +0000

    draw stroke polygons
    
    Change-Id: I55e35eabc59ce45b9cd271f8bc8596c0082a8fde

diff --git a/canvas/source/opengl/ogl_canvashelper.cxx 
b/canvas/source/opengl/ogl_canvashelper.cxx
index ec08cf8..992fe87 100644
--- a/canvas/source/opengl/ogl_canvashelper.cxx
+++ b/canvas/source/opengl/ogl_canvashelper.cxx
@@ -17,6 +17,8 @@
 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 
+ #include <basegfx/polygon/b2dpolygontools.hxx>
+
 #include <com/sun/star/rendering/TexturingMode.hpp>
 #include <com/sun/star/rendering/CompositeOperation.hpp>
 #include <com/sun/star/rendering/RepaintResult.hpp>
@@ -27,6 +29,8 @@
 #include <vcl/metric.hxx>
 #include <vcl/font.hxx>
 
+#include <basegfx/polygon/b2dlinegeometry.hxx>
+
 #include "ogl_canvasfont.hxx"
 #include "ogl_canvastools.hxx"
 #include "ogl_canvasbitmap.hxx"
@@ -36,6 +40,7 @@
 
 #include <GL/glew.h>
 #include <glm/gtc/type_ptr.hpp>
+#include <vcl/opengl/GLMHelper.hxx>
 
 #include <boost/scoped_array.hpp>
 
@@ -94,6 +99,53 @@ namespace oglcanvas
 
     namespace
     {
+
+
+       basegfx::B2DLineJoin b2DJoineFromJoin( sal_Int8 nJoinType )
+       {
+           switch( nJoinType )
+           {
+               case rendering::PathJoinType::NONE:
+                   return basegfx::B2DLINEJOIN_NONE;
+
+               case rendering::PathJoinType::MITER:
+                   return basegfx::B2DLINEJOIN_MITER;
+
+               case rendering::PathJoinType::ROUND:
+                   return basegfx::B2DLINEJOIN_ROUND;
+
+               case rendering::PathJoinType::BEVEL:
+                   return basegfx::B2DLINEJOIN_BEVEL;
+
+               default:
+                   ENSURE_OR_THROW( false,
+                                     "b2DJoineFromJoin(): Unexpected join 
type" );
+           }
+
+           return basegfx::B2DLINEJOIN_NONE;
+       }
+
+       drawing::LineCap unoCapeFromCap( sal_Int8 nCapType)
+       {
+           switch ( nCapType)
+           {
+               case rendering::PathCapType::BUTT:
+                   return drawing::LineCap_BUTT;
+
+               case rendering::PathCapType::ROUND:
+                   return drawing::LineCap_ROUND;
+
+               case rendering::PathCapType::SQUARE:
+                   return drawing::LineCap_SQUARE;
+
+               default:
+                   ENSURE_OR_THROW( false,
+                                     "unoCapeFromCap(): Unexpected cap type" );
+           }
+           return drawing::LineCap_BUTT;
+       }
+
+
         bool lcl_drawPoint( const CanvasHelper&              rHelper,
                             const ::basegfx::B2DHomMatrix&   rTransform,
                             GLenum                           eSrcBlend,
@@ -531,7 +583,7 @@ namespace oglcanvas
                                                                                
    const uno::Reference< rendering::XPolyPolygon2D >&   xPolyPolygon,
                                                                                
    const rendering::ViewState&                          viewState,
                                                                                
    const rendering::RenderState&                        renderState,
-                                                                               
    const rendering::StrokeAttributes&                   /*strokeAttributes*/ )
+                                                                               
    const rendering::StrokeAttributes&                   strokeAttributes )
     {
         ENSURE_OR_THROW( xPolyPolygon.is(),
                           "CanvasHelper::strokePolyPolygon: polygon is NULL");
@@ -542,12 +594,66 @@ namespace oglcanvas
             Action& rAct=mpRecordedActions->back();
 
             setupGraphicsState( rAct, viewState, renderState );
-            rAct.maPolyPolys.push_back(
-                
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(xPolyPolygon));
-            rAct.maPolyPolys.back().makeUnique(); // own copy, for thread 
safety
+            ::basegfx::B2DSize aLinePixelSize(strokeAttributes.StrokeWidth,
+                                              strokeAttributes.StrokeWidth);
+            ::basegfx::B2DPolyPolygon aPolyPoly(
+                     
::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(xPolyPolygon) );
 
-            // TODO(F3): fallback to drawPolyPolygon currently
-            rAct.maFunction = &lcl_drawPolyPolygon;
+
+            if( strokeAttributes.DashArray.getLength() )
+            {
+                const ::std::vector<double>& aDashArray(
+                    ::comphelper::sequenceToContainer< ::std::vector<double> 
>(strokeAttributes.DashArray) );
+
+                ::basegfx::B2DPolyPolygon aDashedPolyPoly;
+
+                for( sal_uInt32 i=0; i<aPolyPoly.count(); ++i )
+                {
+                    // AW: new interface; You may also get gaps in the same 
run now
+                    
basegfx::tools::applyLineDashing(aPolyPoly.getB2DPolygon(i),
+                                                     aDashArray,
+                                                     &aDashedPolyPoly);
+                }
+
+                aPolyPoly = aDashedPolyPoly;
+            }
+
+            if( aLinePixelSize.getLength() < 1.42 )
+            {
+                // line width < 1.0 in device pixel, thus, output as a
+                // simple hairline poly-polygon
+                rAct.maPolyPolys.push_back(aPolyPoly);
+                rAct.maPolyPolys.back().makeUnique(); // own copy, for thread 
safety
+
+                rAct.maFunction = &lcl_drawPolyPolygon;
+            }
+            else
+            {
+                // render as a 'thick' line
+                ::basegfx::B2DPolyPolygon aStrokedPolyPoly;
+                for( sal_uInt32 i=0; i<aPolyPoly.count(); ++i )
+                {
+                    // TODO(F2): Use MiterLimit from StrokeAttributes,
+                    // need to convert it here to angle.
+
+                    // TODO(F2): Also use Cap settings from
+                    // StrokeAttributes, the
+                    // createAreaGeometryForLineStartEnd() method does not
+                    // seem to fit very well here
+
+                    // AW: New interface, will create bezier polygons now
+                    aStrokedPolyPoly.append(basegfx::tools::createAreaGeometry(
+                        aPolyPoly.getB2DPolygon(i),
+                        strokeAttributes.StrokeWidth*0.5,
+                        b2DJoineFromJoin(strokeAttributes.JoinType),
+                        unoCapeFromCap(strokeAttributes.StartCapType)
+                        ));
+                }
+                rAct.maPolyPolys.push_back(aStrokedPolyPoly);
+                rAct.maPolyPolys.back().makeUnique(); // own copy, for thread 
safety
+
+                rAct.maFunction = &lcl_fillPolyPolygon;
+            }
         }
 
         // TODO(P1): Provide caching here.
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to