diff options
-rw-r--r-- | drawinglayer/CppunitTest_drawinglayer_processors.mk | 1 | ||||
-rw-r--r-- | drawinglayer/Library_drawinglayer.mk | 1 | ||||
-rw-r--r-- | drawinglayer/qa/unit/SvgExportTest.cxx | 59 | ||||
-rw-r--r-- | drawinglayer/source/tools/SvgWriter.cxx | 211 | ||||
-rw-r--r-- | include/drawinglayer/tools/SvgWriter.hxx | 43 |
5 files changed, 315 insertions, 0 deletions
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 2430852d33bd..a05937a1d7cc 100644 --- a/drawinglayer/Library_drawinglayer.mk +++ b/drawinglayer/Library_drawinglayer.mk @@ -194,6 +194,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: */ |