diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-02-24 18:08:38 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-03-06 16:33:06 +0100 |
commit | 7894fd2b442eff45ecf14088ebd17ee9f8678752 (patch) | |
tree | cf1525a0c7118b6c84a0abd555a36277f8d8e91b /svgio/qa | |
parent | de5dc664fc923b9704860f51267c438cad28cbe4 (diff) |
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@gmail.com>
Diffstat (limited to 'svgio/qa')
-rw-r--r-- | svgio/qa/cppunit/SvgRead.cxx | 102 |
1 files changed, 102 insertions, 0 deletions
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: */ |