[Libreoffice-commits] core.git: 4 commits - include/basegfx offapi/com svgio/CppunitTest_svgio_read.mk svgio/inc svgio/Library_svgio.mk svgio/Module_svgio.mk svgio/qa svgio/source vcl/source vcl/uiconfig

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Mar 6 15:35:33 UTC 2019


 include/basegfx/DrawCommands.hxx              |   74 ++++++++++++++++
 offapi/com/sun/star/graphic/XSvgParser.idl    |   14 +++
 svgio/CppunitTest_svgio_read.mk               |   67 +++++++++++++++
 svgio/Library_svgio.mk                        |    1 
 svgio/Module_svgio.mk                         |    1 
 svgio/inc/svgnode.hxx                         |   12 ++
 svgio/inc/svgvisitor.hxx                      |   41 +++++++++
 svgio/qa/cppunit/SvgRead.cxx                  |  102 ++++++++++++++++++++++
 svgio/source/svgreader/svgnode.cxx            |    4 
 svgio/source/svgreader/svgvisitor.cxx         |  105 +++++++++++++++++++++++
 svgio/source/svguno/xsvgparser.cxx            |  116 +++++++++++++++++---------
 vcl/source/gdi/FileDefinitionWidgetDraw.cxx   |   21 ++++
 vcl/source/gdi/WidgetDefinitionReader.cxx     |   25 ++++-
 vcl/uiconfig/theme_definitions/definition.xml |  100 ++++++++++++++++++++++
 14 files changed, 637 insertions(+), 46 deletions(-)

New commits:
commit ddc8d51f09756f14a93b54bbb221a437f8420f8d
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat Mar 2 23:37:02 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Mar 6 16:33:58 2019 +0100

    Draw basic toolbar from the theme definition
    
    Change-Id: I4d9935973bb6e46a7c5f17f914944f91a3e10a63
    Reviewed-on: https://gerrit.libreoffice.org/68773
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index 10b4643f5de8..9b903a20cd93 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -90,8 +90,8 @@ bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType, Contr
             return true;
         case ControlType::Slider:
         case ControlType::Fixedline:
-            return true;
         case ControlType::Toolbar:
+            return true;
         case ControlType::Menubar:
         case ControlType::MenuPopup:
             return false;
@@ -379,6 +379,10 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
         }
         break;
         case ControlType::Toolbar:
+        {
+            bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
+        }
+        break;
         case ControlType::Menubar:
             break;
         case ControlType::MenuPopup:
diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index 997ba931ebf0..be0831a4f3c7 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -149,7 +149,8 @@ bool getControlTypeForXmlString(OString const& rString, ControlType& reType)
             { "tabpane", ControlType::TabPane },
             { "tabbody", ControlType::TabBody },
             { "frame", ControlType::Frame },
-            { "windowbackground", ControlType::WindowBackground } };
+            { "windowbackground", ControlType::WindowBackground },
+            { "toolbar", ControlType::Toolbar } };
 
     auto const& rIterator = aPartMap.find(rString);
     if (rIterator != aPartMap.end())
diff --git a/vcl/uiconfig/theme_definitions/definition.xml b/vcl/uiconfig/theme_definitions/definition.xml
index 36ddb0402805..bd0a899d5ec4 100644
--- a/vcl/uiconfig/theme_definitions/definition.xml
+++ b/vcl/uiconfig/theme_definitions/definition.xml
@@ -335,4 +335,49 @@
             </state>
         </part>
     </frame>
+
+    <toolbar>
+        <part value="DrawBackgroundHorz">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#FFFFFF" fill="#FFFFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+
+        <part value="DrawBackgroundVert">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#FFFFFF" fill="#FFFFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+
+        <part value="ThumbHorz">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FFFF" fill="#00FFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+
+        <part value="ThumbVert">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FFFF" fill="#00FFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+
+        <part value="SeparatorVert">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FFFF" fill="#00FFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+
+        <part value="SeparatorHorz">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FFFF" fill="#00FFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+
+        <part value="Button">
+             <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FFFF" fill="#00FFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+    </toolbar>
+
 </widgets>
commit c28104e0c2e030b52bb39276421da8da2e28f669
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat Mar 2 23:30:42 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Mar 6 16:33:38 2019 +0100

    Draw basic frame and window background from the theme definition
    
    Change-Id: I2422650a155a874855ad4d72fa3bfd27b7d0da8a
    Reviewed-on: https://gerrit.libreoffice.org/68772
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index b88ac38b5f64..10b4643f5de8 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -99,8 +99,10 @@ bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType, Contr
         case ControlType::IntroProgress:
             return true;
         case ControlType::Tooltip:
+            return false;
         case ControlType::WindowBackground:
         case ControlType::Frame:
+            return true;
         case ControlType::ListNode:
         case ControlType::ListNet:
         case ControlType::ListHeader:
@@ -391,6 +393,10 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
             break;
         case ControlType::WindowBackground:
         case ControlType::Frame:
+        {
+            bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
+        }
+        break;
         case ControlType::ListNode:
         case ControlType::ListNet:
         case ControlType::ListHeader:
diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index 84740bced4a2..997ba931ebf0 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -133,14 +133,23 @@ ControlPart xmlStringToControlPart(OString const& sPart)
 bool getControlTypeForXmlString(OString const& rString, ControlType& reType)
 {
     static std::unordered_map<OString, ControlType> aPartMap
-        = { { "pushbutton", ControlType::Pushbutton }, { "radiobutton", ControlType::Radiobutton },
-            { "checkbox", ControlType::Checkbox },     { "combobox", ControlType::Combobox },
-            { "editbox", ControlType::Editbox },       { "listbox", ControlType::Listbox },
-            { "scrollbar", ControlType::Scrollbar },   { "spinbox", ControlType::Spinbox },
-            { "slider", ControlType::Slider },         { "fixedline", ControlType::Fixedline },
-            { "progress", ControlType::Progress },     { "tabitem", ControlType::TabItem },
-            { "tabheader", ControlType::TabHeader },   { "tabpane", ControlType::TabPane },
-            { "tabbody", ControlType::TabBody } };
+        = { { "pushbutton", ControlType::Pushbutton },
+            { "radiobutton", ControlType::Radiobutton },
+            { "checkbox", ControlType::Checkbox },
+            { "combobox", ControlType::Combobox },
+            { "editbox", ControlType::Editbox },
+            { "listbox", ControlType::Listbox },
+            { "scrollbar", ControlType::Scrollbar },
+            { "spinbox", ControlType::Spinbox },
+            { "slider", ControlType::Slider },
+            { "fixedline", ControlType::Fixedline },
+            { "progress", ControlType::Progress },
+            { "tabitem", ControlType::TabItem },
+            { "tabheader", ControlType::TabHeader },
+            { "tabpane", ControlType::TabPane },
+            { "tabbody", ControlType::TabBody },
+            { "frame", ControlType::Frame },
+            { "windowbackground", ControlType::WindowBackground } };
 
     auto const& rIterator = aPartMap.find(rString);
     if (rIterator != aPartMap.end())
diff --git a/vcl/uiconfig/theme_definitions/definition.xml b/vcl/uiconfig/theme_definitions/definition.xml
index c9cdfd63605c..36ddb0402805 100644
--- a/vcl/uiconfig/theme_definitions/definition.xml
+++ b/vcl/uiconfig/theme_definitions/definition.xml
@@ -310,4 +310,29 @@
         </part>
     </tabbody>
 
+    <windowbackground>
+        <part value="BackgroundWindow">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#FF0000" fill="#FF0000" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+        <part value="BackgroundDialog">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#0000FF" fill="#FFFFFF" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+    </windowbackground>
+
+    <frame>
+        <part value="Entire">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FF00" fill="#00FF00" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+        <part value="Border">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#00FF00" fill="#00FF00" stroke-width="1" rx="1" ry="1"/>
+            </state>
+        </part>
+    </frame>
 </widgets>
commit 734a5cc1eba1bbfafcd93f09177ff07b52fa95f8
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sat Mar 2 23:24:13 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Mar 6 16:33:22 2019 +0100

    Draw basic listbox from the theme definition
    
    Change-Id: Id3dd5aaa8b5537e5f740752cec292d6f4a44044e
    Reviewed-on: https://gerrit.libreoffice.org/68771
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index d0743208f6fc..b88ac38b5f64 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -69,7 +69,9 @@ bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType, Contr
         case ControlType::MultilineEditbox:
             return true;
         case ControlType::Listbox:
-            return false;
+            if (ePart == ControlPart::HasBackgroundTexture)
+                return false;
+            return true;
         case ControlType::Spinbox:
             if (ePart == ControlPart::AllButtons)
                 return false;
@@ -290,7 +292,10 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
         }
         break;
         case ControlType::Listbox:
-            break;
+        {
+            bOK = resolveDefinition(eType, ePart, eState, rValue, nX, nY, nWidth, nHeight);
+        }
+        break;
         case ControlType::Spinbox:
         {
             if (rValue.getType() == ControlType::SpinButtons)
diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index 351d0fcdc9ef..84740bced4a2 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -135,11 +135,12 @@ bool getControlTypeForXmlString(OString const& rString, ControlType& reType)
     static std::unordered_map<OString, ControlType> aPartMap
         = { { "pushbutton", ControlType::Pushbutton }, { "radiobutton", ControlType::Radiobutton },
             { "checkbox", ControlType::Checkbox },     { "combobox", ControlType::Combobox },
-            { "editbox", ControlType::Editbox },       { "scrollbar", ControlType::Scrollbar },
-            { "spinbox", ControlType::Spinbox },       { "slider", ControlType::Slider },
-            { "fixedline", ControlType::Fixedline },   { "progress", ControlType::Progress },
-            { "tabitem", ControlType::TabItem },       { "tabheader", ControlType::TabHeader },
-            { "tabpane", ControlType::TabPane },       { "tabbody", ControlType::TabBody } };
+            { "editbox", ControlType::Editbox },       { "listbox", ControlType::Listbox },
+            { "scrollbar", ControlType::Scrollbar },   { "spinbox", ControlType::Spinbox },
+            { "slider", ControlType::Slider },         { "fixedline", ControlType::Fixedline },
+            { "progress", ControlType::Progress },     { "tabitem", ControlType::TabItem },
+            { "tabheader", ControlType::TabHeader },   { "tabpane", ControlType::TabPane },
+            { "tabbody", ControlType::TabBody } };
 
     auto const& rIterator = aPartMap.find(rString);
     if (rIterator != aPartMap.end())
diff --git a/vcl/uiconfig/theme_definitions/definition.xml b/vcl/uiconfig/theme_definitions/definition.xml
index 308bec61f614..c9cdfd63605c 100644
--- a/vcl/uiconfig/theme_definitions/definition.xml
+++ b/vcl/uiconfig/theme_definitions/definition.xml
@@ -140,6 +140,36 @@
         </part>
     </editbox>
 
+    <listbox>
+        <part value="Entire">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="1" ry="1" />
+            </state>
+        </part>
+        <part value="ListboxWindow">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="1" ry="1" />
+            </state>
+        </part>
+        <part value="Focus">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="1" ry="1" />
+            </state>
+        </part>
+        <part value="ButtonUp">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <line stroke="#007AFF" stroke-width="4" x1="0.2" y1="0.6" x2="0.5" y2="0.4"/>
+                <line stroke="#007AFF" stroke-width="4" x1="0.5" y1="0.4" x2="0.8" y2="0.6"/>
+            </state>
+        </part>
+        <part value="ButtonDown">
+            <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
+                <line stroke="#007AFF" stroke-width="4" x1="0.2" y1="0.4" x2="0.5" y2="0.6"/>
+                <line stroke="#007AFF" stroke-width="4" x1="0.5" y1="0.6" x2="0.8" y2="0.4"/>
+            </state>
+        </part>
+    </listbox>
+
     <spinbox>
         <part value="Entire">
             <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
commit 7894fd2b442eff45ecf14088ebd17ee9f8678752
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Feb 24 18:08:38 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Mar 6 16:33:06 2019 +0100

    svgio visitor, add draw commands and create the from svg
    
    Adds a visitor for svgio for visiting svg nodes and create something
    useful from them.
    
    Basic draw commands - a tree of draw commands (with sub-pixel
    precision support) just to store a simple definition for drawing.
    
    Adds a svg draw visitor and create draw commands from the svg
    structure and expose the commands through UNO API.
    
    Change-Id: I073e891a2cffdd76d4e3b838590e3a19c998e9bf
    Reviewed-on: https://gerrit.libreoffice.org/68770
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/basegfx/DrawCommands.hxx b/include/basegfx/DrawCommands.hxx
new file mode 100644
index 000000000000..23afbecb9273
--- /dev/null
+++ b/include/basegfx/DrawCommands.hxx
@@ -0,0 +1,74 @@
+/* -*- 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/.
+ */
+
+class DrawBase;
+
+class DrawCommand
+{
+public:
+    std::vector<std::shared_ptr<DrawBase>> maChildren;
+};
+
+enum class DrawCommandType
+{
+    Root,
+    Rectangle,
+    Path
+};
+
+class DrawBase : public DrawCommand
+{
+private:
+    DrawCommandType meType;
+
+public:
+    DrawBase(DrawCommandType eType)
+        : meType(eType)
+    {
+    }
+
+    DrawCommandType getType() { return meType; }
+};
+
+class DrawRoot : public DrawBase
+{
+public:
+    basegfx::B2DRange maRectangle;
+
+    DrawRoot()
+        : DrawBase(DrawCommandType::Root)
+    {
+    }
+};
+
+class DrawRectangle : public DrawBase
+{
+public:
+    basegfx::B2DRange maRectangle;
+
+    DrawRectangle(basegfx::B2DRange const& rRectangle)
+        : DrawBase(DrawCommandType::Rectangle)
+        , maRectangle(rRectangle)
+    {
+    }
+};
+
+class DrawPath : public DrawBase
+{
+public:
+    basegfx::B2DPolyPolygon maPolyPolygon;
+
+    DrawPath(basegfx::B2DPolyPolygon const& rPolyPolygon)
+        : DrawBase(DrawCommandType::Path)
+        , maPolyPolygon(rPolyPolygon)
+    {
+    }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/graphic/XSvgParser.idl b/offapi/com/sun/star/graphic/XSvgParser.idl
index 742fce4bcd3e..7410a9d7947f 100644
--- a/offapi/com/sun/star/graphic/XSvgParser.idl
+++ b/offapi/com/sun/star/graphic/XSvgParser.idl
@@ -45,6 +45,20 @@ interface XSvgParser : ::com::sun::star::uno::XInterface
     sequence< XPrimitive2D > getDecomposition(
         [in] io::XInputStream xSvgStream,
         [in] string aAbsolutePath);
+
+    /** Get the "draw command" graph that is created from the SVG content
+
+        @param xSvgStream
+        The file containing the SVG XML data
+
+        @param aAbsolutePath
+        The path containing the SVG XML data
+
+        @since LibreOffice 6.3
+     */
+    any getDrawCommands(
+        [in] io::XInputStream xSvgStream,
+        [in] string aAbsolutePath);
 };
 
 }; }; }; };
diff --git a/svgio/CppunitTest_svgio_read.mk b/svgio/CppunitTest_svgio_read.mk
new file mode 100644
index 000000000000..20ebc0eee176
--- /dev/null
+++ b/svgio/CppunitTest_svgio_read.mk
@@ -0,0 +1,67 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,svgio_read))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svgio_read,\
+    svgio/qa/cppunit/SvgRead \
+))
+
+$(eval $(call gb_CppunitTest_set_include,svgio_read,\
+    $$(INCLUDE) \
+    -I$(SRCDIR)/svgio/inc \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,svgio_read,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_use_library_objects,svgio_read,\
+    svgio \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,svgio_read, \
+	basegfx \
+	comphelper \
+	cppu \
+	cppuhelper \
+	drawinglayer \
+	editeng \
+	i18nlangtag \
+	sal \
+	salhelper \
+	sax \
+	sot \
+	svl \
+	svt \
+	svx \
+	svxcore \
+	test \
+	tl \
+	tk \
+	ucbhelper \
+	unotest \
+	utl \
+	vcl \
+	xo \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,svgio_read))
+$(eval $(call gb_CppunitTest_use_ure,svgio_read))
+$(eval $(call gb_CppunitTest_use_vcl,svgio_read))
+$(eval $(call gb_CppunitTest_use_rdb,svgio_read,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,svgio_read,\
+        officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,svgio_read))
+
+# vim: set noet sw=4 ts=4:
diff --git a/svgio/Library_svgio.mk b/svgio/Library_svgio.mk
index 44d8ef9c05b5..94f78b91e5ce 100644
--- a/svgio/Library_svgio.mk
+++ b/svgio/Library_svgio.mk
@@ -77,6 +77,7 @@ $(eval $(call gb_Library_add_exception_objects,svgio,\
     svgio/source/svgreader/svgtextpathnode \
     svgio/source/svgreader/svgtspannode \
     svgio/source/svgreader/svgusenode \
+    svgio/source/svgreader/svgvisitor \
     svgio/source/svguno/svguno \
     svgio/source/svguno/xsvgparser \
 ))
diff --git a/svgio/Module_svgio.mk b/svgio/Module_svgio.mk
index 29ef97d7087b..26b659f59991 100644
--- a/svgio/Module_svgio.mk
+++ b/svgio/Module_svgio.mk
@@ -24,6 +24,7 @@ $(eval $(call gb_Module_add_targets,svgio,\
 
 $(eval $(call gb_Module_add_check_targets,svgio,\
     CppunitTest_svgio \
+    CppunitTest_svgio_read \
 ))
 
 # vim: set noet ts=4 sw=4:
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index 22df883b22b3..c10179bf236a 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -80,6 +80,8 @@ namespace svgio
         // which members should be initialized
         Display getDisplayFromContent(const OUString& aContent);
 
+      class Visitor;
+
         class SvgNode : public InfoProvider
         {
         private:
@@ -137,6 +139,8 @@ namespace svgio
             SvgNode(const SvgNode&) = delete;
             SvgNode& operator=(const SvgNode&) = delete;
 
+            void accept(Visitor& rVisitor);
+
             /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
             void readLocalCssStyle(const OUString& aContent);
 
@@ -182,6 +186,14 @@ namespace svgio
             /// alternative parent
             void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; }
         };
+
+      class Visitor
+      {
+      public:
+            virtual ~Visitor() = default;
+            virtual void visit(SvgNode const & pNode) = 0;
+      };
+
     } // end of namespace svgreader
 } // end of namespace svgio
 
diff --git a/svgio/inc/svgvisitor.hxx b/svgio/inc/svgvisitor.hxx
new file mode 100644
index 000000000000..ea56e4cd189a
--- /dev/null
+++ b/svgio/inc/svgvisitor.hxx
@@ -0,0 +1,41 @@
+/* -*- 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/.
+ *
+ */
+
+#ifndef INCLUDED_SVGIO_INC_SVGVISITOR_HXX
+#define INCLUDED_SVGIO_INC_SVGVISITOR_HXX
+
+#include <basegfx/DrawCommands.hxx>
+#include <memory>
+#include "svgnode.hxx"
+
+namespace svgio
+{
+namespace svgreader
+{
+class SvgDrawVisitor : public Visitor
+{
+private:
+    std::shared_ptr<DrawRoot> mpDrawRoot;
+    std::shared_ptr<DrawBase> mpCurrent;
+
+public:
+    SvgDrawVisitor();
+
+    void visit(svgio::svgreader::SvgNode const& rNode) override;
+    void goToChildren(svgio::svgreader::SvgNode const& rNode);
+
+    std::shared_ptr<DrawRoot> const& getDrawRoot() { return mpDrawRoot; }
+};
+}
+}
+
+#endif // INCLUDED_SVGIO_INC_SVGVISITOR_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svgio/qa/cppunit/SvgRead.cxx b/svgio/qa/cppunit/SvgRead.cxx
new file mode 100644
index 000000000000..9077f92db7b6
--- /dev/null
+++ b/svgio/qa/cppunit/SvgRead.cxx
@@ -0,0 +1,102 @@
+/* -*- 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/.
+ */
+
+#include <sal/config.h>
+
+#include <test/bootstrapfixture.hxx>
+
+#include <memory>
+
+#include <comphelper/seqstream.hxx>
+#include <comphelper/sequence.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/stream.hxx>
+
+#include <com/sun/star/graphic/SvgTools.hpp>
+#include <com/sun/star/graphic/Primitive2DTools.hpp>
+#include <com/sun/star/graphic/XPrimitive2D.hpp>
+
+#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
+
+#include <com/sun/star/graphic/XSvgParser.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/xml/sax/Parser.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <comphelper/sequence.hxx>
+
+#include <svgdocumenthandler.hxx>
+#include <svgrectnode.hxx>
+#include <svgsvgnode.hxx>
+#include <svggnode.hxx>
+
+#include <basegfx/DrawCommands.hxx>
+
+namespace
+{
+using namespace css;
+
+class Test : public test::BootstrapFixture
+{
+    void test();
+    uno::Reference<io::XInputStream> parseSvg(const OUString& aSource);
+
+public:
+    CPPUNIT_TEST_SUITE(Test);
+    CPPUNIT_TEST(test);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+uno::Reference<io::XInputStream> Test::parseSvg(const OUString& aSource)
+{
+    SvFileStream aFileStream(aSource, StreamMode::READ);
+    std::size_t nSize = aFileStream.remainingSize();
+    std::unique_ptr<sal_Int8[]> pBuffer(new sal_Int8[nSize + 1]);
+    aFileStream.ReadBytes(pBuffer.get(), nSize);
+    pBuffer[nSize] = 0;
+
+    uno::Sequence<sal_Int8> aData(pBuffer.get(), nSize + 1);
+    uno::Reference<io::XInputStream> aInputStream(new comphelper::SequenceInputStream(aData));
+
+    return aInputStream;
+}
+
+void Test::test()
+{
+    OUString aSvgFile = "/svgio/qa/cppunit/data/Rect.svg";
+    OUString aUrl = m_directories.getURLFromSrc(aSvgFile);
+    OUString aPath = m_directories.getPathFromSrc(aSvgFile);
+
+    uno::Reference<io::XInputStream> xStream = parseSvg(aUrl);
+    CPPUNIT_ASSERT(xStream.is());
+
+    uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
+    const uno::Reference<graphic::XSvgParser> xSvgParser = graphic::SvgTools::create(xContext);
+
+    uno::Any aAny = xSvgParser->getDrawCommands(xStream, aPath);
+    CPPUNIT_ASSERT(aAny.has<sal_uInt64>());
+    DrawRoot* pDrawRoot = reinterpret_cast<DrawRoot*>(aAny.get<sal_uInt64>());
+
+    CPPUNIT_ASSERT_EQUAL(size_t(1), pDrawRoot->maChildren.size());
+    CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(0, 0, 120, 120), pDrawRoot->maRectangle);
+
+    CPPUNIT_ASSERT_EQUAL(DrawCommandType::Rectangle, pDrawRoot->maChildren[0]->getType());
+    CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(10, 10, 110, 110),
+                         static_cast<DrawRectangle*>(pDrawRoot->maChildren[0].get())->maRectangle);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 88b9a72ec196..cb30c3111131 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -673,6 +673,10 @@ namespace svgio
             return XmlSpace_default;
         }
 
+        void SvgNode::accept(Visitor & rVisitor)
+        {
+            rVisitor.visit(*this);
+        }
     } // end of namespace svgreader
 } // end of namespace svgio
 
diff --git a/svgio/source/svgreader/svgvisitor.cxx b/svgio/source/svgreader/svgvisitor.cxx
new file mode 100644
index 000000000000..841a1cb7022e
--- /dev/null
+++ b/svgio/source/svgreader/svgvisitor.cxx
@@ -0,0 +1,105 @@
+/* -*- 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/.
+ *
+ */
+
+#include <sal/config.h>
+#include <sal/log.hxx>
+
+#include <svgdocumenthandler.hxx>
+#include <svgrectnode.hxx>
+#include <svgsvgnode.hxx>
+#include <svggnode.hxx>
+#include <svgpathnode.hxx>
+
+#include <svgvisitor.hxx>
+
+namespace svgio
+{
+namespace svgreader
+{
+SvgDrawVisitor::SvgDrawVisitor()
+    : mpDrawRoot(std::make_shared<DrawRoot>())
+    , mpCurrent(mpDrawRoot)
+{
+}
+
+void SvgDrawVisitor::visit(svgio::svgreader::SvgNode const& rNode)
+{
+    switch (rNode.getType())
+    {
+        case svgio::svgreader::SVGTokenSvg:
+        {
+            auto const& rSvgNode = static_cast<svgio::svgreader::SvgSvgNode const&>(rNode);
+
+            double x = rSvgNode.getX().getNumber();
+            double y = rSvgNode.getY().getNumber();
+            double w = rSvgNode.getWidth().getNumber();
+            double h = rSvgNode.getHeight().getNumber();
+
+            static_cast<DrawRoot*>(mpCurrent.get())->maRectangle
+                = basegfx::B2DRange(x, y, x + w, y + h);
+        }
+        break;
+        case svgio::svgreader::SVGTokenG:
+        {
+            auto const& rGNode = static_cast<svgio::svgreader::SvgGNode const&>(rNode);
+
+            if (rGNode.getTransform() != nullptr)
+            {
+                basegfx::B2DHomMatrix rMatrix = *rGNode.getTransform();
+
+                printf("G [%f %f %f - %f %f %f - %f %f %f]\n", rMatrix.get(0, 0), rMatrix.get(0, 1),
+                       rMatrix.get(0, 2), rMatrix.get(1, 0), rMatrix.get(1, 1), rMatrix.get(1, 2),
+                       rMatrix.get(2, 0), rMatrix.get(2, 1), rMatrix.get(2, 2));
+            }
+        }
+        break;
+        case svgio::svgreader::SVGTokenRect:
+        {
+            auto const& rRectNode = static_cast<svgio::svgreader::SvgRectNode const&>(rNode);
+
+            double x = rRectNode.getX().getNumber();
+            double y = rRectNode.getY().getNumber();
+            double w = rRectNode.getWidth().getNumber();
+            double h = rRectNode.getHeight().getNumber();
+
+            auto pRectangle
+                = std::make_shared<DrawRectangle>(basegfx::B2DRange(x, y, x + w, y + h));
+            mpCurrent->maChildren.push_back(pRectangle);
+        }
+        break;
+        case svgio::svgreader::SVGTokenPath:
+        {
+            auto const& rPathNode = static_cast<svgio::svgreader::SvgPathNode const&>(rNode);
+            auto pPath = rPathNode.getPath();
+            if (pPath)
+            {
+                auto pDrawPath = std::make_shared<DrawPath>(*pPath);
+                mpCurrent->maChildren.push_back(pDrawPath);
+            }
+        }
+        break;
+
+        default:
+            break;
+    }
+    goToChildren(rNode);
+}
+
+void SvgDrawVisitor::goToChildren(svgio::svgreader::SvgNode const& rNode)
+{
+    for (auto& rChild : rNode.getChildren())
+    {
+        rChild->accept(*this);
+    }
+}
+}
+} // end of namespace svgio::svgreader
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svgio/source/svguno/xsvgparser.cxx b/svgio/source/svguno/xsvgparser.cxx
index 2f2a51c5c318..3ed675763f72 100644
--- a/svgio/source/svguno/xsvgparser.cxx
+++ b/svgio/source/svguno/xsvgparser.cxx
@@ -32,6 +32,8 @@
 #include <drawinglayer/geometry/viewinformation2d.hxx>
 #include <svgdocumenthandler.hxx>
 
+#include <svgvisitor.hxx>
+
 #include "xsvgparser.hxx"
 
 using namespace ::com::sun::star;
@@ -43,9 +45,11 @@ namespace svgio
         class XSvgParser : public ::cppu::WeakAggImplHelper2< graphic::XSvgParser, lang::XServiceInfo >
         {
         private:
-            uno::Reference< uno::XComponentContext > context_;
+            std::shared_ptr<SvgDrawVisitor> mpVisitor;
 
-        protected:
+            uno::Reference< uno::XComponentContext > context_;
+            bool parseSvgXML(uno::Reference<io::XInputStream> const & xSVGStream,
+                             uno::Reference<xml::sax::XDocumentHandler> const & xSvgDocHdl);
         public:
             explicit XSvgParser(
                 uno::Reference< uno::XComponentContext > const & context);
@@ -57,6 +61,10 @@ namespace svgio
                 const uno::Reference< ::io::XInputStream >& xSVGStream,
                 const OUString& aAbsolutePath) override;
 
+            virtual uno::Any SAL_CALL getDrawCommands(
+                uno::Reference<io::XInputStream> const & xSvgStream,
+                const OUString& aAbsolutePath) override;
+
             // XServiceInfo
             virtual OUString SAL_CALL getImplementationName() override;
             virtual sal_Bool SAL_CALL supportsService(const OUString&) override;
@@ -97,6 +105,45 @@ namespace svgio
         {
         }
 
+        bool XSvgParser::parseSvgXML(uno::Reference<io::XInputStream> const & xSVGStream, uno::Reference<xml::sax::XDocumentHandler> const & xSvgDocHdl)
+        {
+            try
+            {
+                // prepare ParserInputSrouce
+                xml::sax::InputSource myInputSource;
+                myInputSource.aInputStream = xSVGStream;
+
+                // get parser
+                uno::Reference< xml::sax::XParser > xParser(
+                    xml::sax::Parser::create(context_));
+                // fdo#60471 need to enable internal entities because
+                // certain ... popular proprietary products write SVG files
+                // that use entities to define XML namespaces.
+                uno::Reference<lang::XInitialization> const xInit(xParser,
+                        uno::UNO_QUERY_THROW);
+                uno::Sequence<uno::Any> args(1);
+                args[0] <<= OUString("DoSmeplease");
+                xInit->initialize(args);
+
+                // connect parser and filter
+                xParser->setDocumentHandler(xSvgDocHdl);
+
+                // finally, parse the stream to a hierarchy of
+                // SVGGraphicPrimitive2D which will be embedded to the
+                // primitive sequence. Their decompositions will in the
+                // end create local low-level primitives, thus SVG will
+                // be processable from all our processors
+                xParser->parseStream(myInputSource);
+            }
+            catch(const uno::Exception& e)
+            {
+                SAL_WARN( "svg", "Parse error! : " << e);
+                return false;
+            }
+
+            return true;
+        }
+
         uno::Sequence< uno::Reference< ::graphic::XPrimitive2D > > XSvgParser::getDecomposition(
             const uno::Reference< ::io::XInputStream >& xSVGStream,
             const OUString& aAbsolutePath )
@@ -107,40 +154,8 @@ namespace svgio
             {
                 // local document handler
                 SvgDocHdl* pSvgDocHdl = new SvgDocHdl(aAbsolutePath);
-                uno::Reference< xml::sax::XDocumentHandler > xSvgDocHdl(pSvgDocHdl);
-
-                try
-                {
-                    // prepare ParserInputSrouce
-                    xml::sax::InputSource myInputSource;
-                    myInputSource.aInputStream = xSVGStream;
-
-                    // get parser
-                    uno::Reference< xml::sax::XParser > xParser(
-                        xml::sax::Parser::create(context_));
-                    // fdo#60471 need to enable internal entities because
-                    // certain ... popular proprietary products write SVG files
-                    // that use entities to define XML namespaces.
-                    uno::Reference<lang::XInitialization> const xInit(xParser,
-                            uno::UNO_QUERY_THROW);
-                    uno::Sequence<uno::Any> args(1);
-                    args[0] <<= OUString("DoSmeplease");
-                    xInit->initialize(args);
-
-                    // connect parser and filter
-                    xParser->setDocumentHandler(xSvgDocHdl);
-
-                    // finally, parse the stream to a hierarchy of
-                    // SVGGraphicPrimitive2D which will be embedded to the
-                    // primitive sequence. Their decompositions will in the
-                    // end create local low-level primitives, thus SVG will
-                    // be processable from all our processors
-                    xParser->parseStream(myInputSource);
-                }
-                catch(const uno::Exception& e)
-                {
-                    SAL_WARN( "svg", "Parse error! : " << e);
-                }
+                uno::Reference<xml::sax::XDocumentHandler> xSvgDocHdl(pSvgDocHdl);
+                parseSvgXML(xSVGStream, xSvgDocHdl);
 
                 // decompose to primitives
                 for(std::unique_ptr<SvgNode> const & pCandidate : pSvgDocHdl->getSvgDocument().getSvgNodeVector())
@@ -159,6 +174,35 @@ namespace svgio
             return comphelper::containerToSequence(aRetval);
         }
 
+        uno::Any SAL_CALL XSvgParser::getDrawCommands(
+                uno::Reference<io::XInputStream> const & xSvgStream,
+                const OUString& aAbsolutePath)
+        {
+            uno::Any aAnyResult;
+
+            if (!xSvgStream.is())
+                return aAnyResult;
+
+            SvgDocHdl* pSvgDocHdl = new SvgDocHdl(aAbsolutePath);
+            uno::Reference<xml::sax::XDocumentHandler> xSvgDocHdl(pSvgDocHdl);
+            parseSvgXML(xSvgStream, xSvgDocHdl);
+
+            // decompose to primitives
+            for (std::unique_ptr<SvgNode> const & pCandidate : pSvgDocHdl->getSvgDocument().getSvgNodeVector())
+            {
+                if (Display_none != pCandidate->getDisplay())
+                {
+                    mpVisitor = std::make_shared<SvgDrawVisitor>();
+                    pCandidate->accept(*mpVisitor);
+                    std::shared_ptr<DrawRoot> pDrawRoot(mpVisitor->getDrawRoot());
+                    sal_uInt64 nPointer = reinterpret_cast<sal_uInt64>(pDrawRoot.get());
+                    aAnyResult <<= sal_uInt64(nPointer);
+                }
+            }
+
+            return aAnyResult;
+        }
+
         OUString SAL_CALL XSvgParser::getImplementationName()
         {
             return XSvgParser_getImplementationName();


More information about the Libreoffice-commits mailing list