[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore2' - 2 commits - drawinglayer/CppunitTest_drawinglayer_processors.mk drawinglayer/Library_drawinglayer.mk drawinglayer/qa drawinglayer/source include/drawinginterface include/drawinglayer
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 24 02:03:57 UTC 2021
drawinglayer/CppunitTest_drawinglayer_processors.mk | 1
drawinglayer/Library_drawinglayer.mk | 1
drawinglayer/qa/unit/SvgExportTest.cxx | 59 ++
drawinglayer/source/tools/SvgWriter.cxx | 211 ++++++++++
include/drawinginterface/BasicPrimitive2D.hxx | 26 +
include/drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx | 5
include/drawinglayer/tools/SvgWriter.hxx | 43 ++
7 files changed, 345 insertions(+), 1 deletion(-)
New commits:
commit 686c9c149b4aa3a23918d047b8b2f84aa690b142
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Aug 24 11:02:40 2021 +0900
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Tue Aug 24 11:02:40 2021 +0900
SVG export for drawinglayer primitives
Change-Id: I34e17eeb9695c9a8b23178611c149f89a28a210c
diff --git a/drawinglayer/CppunitTest_drawinglayer_processors.mk b/drawinglayer/CppunitTest_drawinglayer_processors.mk
index b17a5107dc2d..fd0eb0b365c1 100644
--- a/drawinglayer/CppunitTest_drawinglayer_processors.mk
+++ b/drawinglayer/CppunitTest_drawinglayer_processors.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_CppunitTest_use_externals,drawinglayer_processors,\
$(eval $(call gb_CppunitTest_add_exception_objects,drawinglayer_processors, \
drawinglayer/qa/unit/vclmetafileprocessor2d \
drawinglayer/qa/unit/vclpixelprocessor2d \
+ drawinglayer/qa/unit/SvgExportTest \
))
$(eval $(call gb_CppunitTest_use_ure,drawinglayer_processors))
diff --git a/drawinglayer/Library_drawinglayer.mk b/drawinglayer/Library_drawinglayer.mk
index 6cee84ede118..8f2c99f1c12f 100644
--- a/drawinglayer/Library_drawinglayer.mk
+++ b/drawinglayer/Library_drawinglayer.mk
@@ -189,6 +189,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\
drawinglayer/source/texture/texture \
drawinglayer/source/dumper/XShapeDumper \
drawinglayer/source/dumper/EnhancedShapeDumper \
+ drawinglayer/source/tools/SvgWriter \
))
# vim: set noet sw=4 ts=4:
diff --git a/drawinglayer/qa/unit/SvgExportTest.cxx b/drawinglayer/qa/unit/SvgExportTest.cxx
new file mode 100644
index 000000000000..98198c2306e9
--- /dev/null
+++ b/drawinglayer/qa/unit/SvgExportTest.cxx
@@ -0,0 +1,59 @@
+/* -*- 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 <test/bootstrapfixture.hxx>
+
+#include <drawinglayer/tools/SvgWriter.hxx>
+
+#include <basegfx/range/b2drectangle.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+
+#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
+
+using namespace drawinglayer;
+
+class SvgExportTest : public test::BootstrapFixture
+{
+public:
+ SvgExportTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+
+ CPPUNIT_TEST_SUITE(SvgExportTest);
+ CPPUNIT_TEST(test);
+ CPPUNIT_TEST_SUITE_END();
+
+ void test()
+ {
+ SvFileStream aStream("~/test.svg", StreamMode::WRITE | StreamMode::TRUNC);
+
+ primitive2d::Primitive2DContainer aPrimitives;
+
+ basegfx::BColor aBColor(1.0, 0.0, 0.0);
+
+ auto aPolygon
+ = basegfx::utils::createPolygonFromRect(basegfx::B2DRectangle(10.0, 10.0, 50.0, 60.0));
+ basegfx::B2DPolyPolygon aPolyPolygon(aPolygon);
+
+ auto pStrokePrimitive(
+ new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(aPolyPolygon, aBColor));
+
+ aPrimitives.push_back(drawinglayer::primitive2d::Primitive2DReference(pStrokePrimitive));
+
+ svg::SvgWriter aWriter(aStream, svg::SvgVersion::v1_1);
+ aWriter.write(aPrimitives);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SvgExportTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/drawinglayer/source/tools/SvgWriter.cxx b/drawinglayer/source/tools/SvgWriter.cxx
new file mode 100644
index 000000000000..c0435d19a001
--- /dev/null
+++ b/drawinglayer/source/tools/SvgWriter.cxx
@@ -0,0 +1,211 @@
+/* -*- 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 <memory>
+#include <sal/log.hxx>
+
+#include <drawinglayer/tools/SvgWriter.hxx>
+
+#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
+
+#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
+#include <drawinglayer/primitive2d/pointarrayprimitive2d.hxx>
+#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
+#include <drawinglayer/primitive2d/Tools.hxx>
+#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
+#include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx>
+#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
+#include <drawinglayer/primitive2d/hiddengeometryprimitive2d.hxx>
+#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
+#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
+#include <drawinglayer/primitive2d/textprimitive2d.hxx>
+#include <drawinglayer/primitive2d/maskprimitive2d.hxx>
+#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
+#include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
+#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
+#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
+#include <drawinglayer/geometry/viewinformation2d.hxx>
+#include <drawinglayer/attribute/lineattribute.hxx>
+#include <drawinglayer/attribute/fontattribute.hxx>
+
+#include <primitive2d/textlineprimitive2d.hxx>
+
+#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <basegfx/polygon/b2dpolygontools.hxx>
+
+namespace svg
+{
+SvgWriter::SvgWriter(SvStream& rStream, SvgVersion eSvgVersion)
+ : mrStream(rStream)
+ , maWriter(&mrStream)
+ , meSvgVersion(eSvgVersion)
+{
+}
+
+bool SvgWriter::write(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence)
+{
+ maWriter.startDocument();
+ maWriter.startElement("svg");
+ OString aVersion = meSvgVersion == SvgVersion::v1_1 ? "1.1" : "2";
+ maWriter.attribute("version", aVersion);
+ maWriter.attribute("xmlns", "http://www.w3.org/2000/svg");
+
+ drawinglayer::primitive2d::VisitorParameters aParameters; // default
+
+ auto aRange = rPrimitive2DSequence.getB2DRange(aParameters);
+
+ maWriter.attribute("width", aRange.getWidth());
+ maWriter.attribute("height", aRange.getHeight());
+
+ decomposeAndWrite(rPrimitive2DSequence);
+
+ maWriter.endElement();
+ maWriter.endDocument();
+
+ return true;
+}
+
+void SvgWriter::decomposeAndWrite(
+ const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence)
+{
+ drawinglayer::primitive2d::VisitorParameters aVisitorParameters;
+
+ for (size_t i = 0; i < rPrimitive2DSequence.size(); i++)
+ {
+ auto xPrimitive2DReference = rPrimitive2DSequence[i];
+
+ const auto* pBasePrimitive
+ = dynamic_cast<const drawinglayer::primitive2d::BasePrimitive2D*>(
+ xPrimitive2DReference.get());
+
+ if (!pBasePrimitive)
+ continue;
+
+ sal_uInt32 nId = pBasePrimitive->getPrimitive2DID();
+
+ switch (nId)
+ {
+ case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D:
+ {
+ }
+ break;
+ case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D:
+ {
+ ;
+ }
+ break;
+ case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D:
+ {
+ }
+ break;
+ case PRIMITIVE2D_ID_POLYGONSTROKEPRIMITIVE2D:
+ {
+ }
+ break;
+ case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_GROUPPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_MASKPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_SVGRADIALGRADIENTPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_SVGLINEARGRADIENTPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TEXTHIERARCHYBLOCKPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TEXTHIERARCHYPARAGRAPHPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_TEXTHIERARCHYLINEPRIMITIVE2D:
+ {
+ }
+ break;
+
+ case PRIMITIVE2D_ID_SHADOWPRIMITIVE2D:
+ {
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+ }
+}
+
+} // end namespace drawinglayer
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/drawinglayer/tools/SvgWriter.hxx b/include/drawinglayer/tools/SvgWriter.hxx
new file mode 100644
index 000000000000..f4b23dde8e92
--- /dev/null
+++ b/include/drawinglayer/tools/SvgWriter.hxx
@@ -0,0 +1,43 @@
+/* -*- 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/.
+ *
+ */
+
+#pragma once
+
+#include <sal/config.h>
+#include <tools/stream.hxx>
+#include <tools/XmlWriter.hxx>
+
+#include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
+
+namespace svg
+{
+enum class SvgVersion
+{
+ v1_1,
+ v2
+};
+
+class DRAWINGLAYER_DLLPUBLIC SvgWriter
+{
+private:
+ SvStream& mrStream;
+ tools::XmlWriter maWriter;
+ SvgVersion meSvgVersion;
+
+ void
+ decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence);
+
+public:
+ SvgWriter(SvStream& rStream, SvgVersion eSvgVersion = SvgVersion::v1_1);
+ bool write(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence);
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d6f3282e017267953f01cbe772b73c448ab49145
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Aug 24 10:59:19 2021 +0900
Commit: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
CommitDate: Tue Aug 24 10:59:19 2021 +0900
Introduce BasicPrimitive2D interface
Change-Id: I75e125e717038f10210ece291c94f46ac7e0ce89
diff --git a/include/drawinginterface/BasicPrimitive2D.hxx b/include/drawinginterface/BasicPrimitive2D.hxx
new file mode 100644
index 000000000000..b7ef8da101b8
--- /dev/null
+++ b/include/drawinginterface/BasicPrimitive2D.hxx
@@ -0,0 +1,26 @@
+/* -*- 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/.
+ *
+ */
+
+#pragma once
+
+namespace drawinginterface
+{
+class BasicPrimitive2D
+{
+public:
+};
+
+class PolyPolygonBasicPrimitive : public BasicPrimitive2D
+{
+public:
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx b/include/drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx
index 55b9bfc87434..09bd5e6e39d4 100644
--- a/include/drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx
+++ b/include/drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx
@@ -21,6 +21,7 @@
#include <drawinglayer/drawinglayerdllapi.h>
+#include <drawinginterface/BasicPrimitive2D.hxx>
#include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/color/bcolor.hxx>
@@ -33,7 +34,9 @@ namespace drawinglayer::primitive2d
This is one of the non-decomposable primitives, so a renderer
should process it.
*/
-class DRAWINGLAYER_DLLPUBLIC PolyPolygonColorPrimitive2D final : public BasePrimitive2D
+class DRAWINGLAYER_DLLPUBLIC PolyPolygonColorPrimitive2D final
+ : public BasePrimitive2D,
+ public drawinginterface::PolyPolygonBasicPrimitive
{
private:
/// the tools::PolyPolygon geometry
More information about the Libreoffice-commits
mailing list