Add svg conversion.
This commit is contained in:
parent
1f85954e98
commit
dfbc87cb09
33 changed files with 602 additions and 79 deletions
5
test/data/circles.svg
Normal file
5
test/data/circles.svg
Normal file
|
@ -0,0 +1,5 @@
|
|||
<svg viewBox="0 0 800 800" xmlns="http://www.w3.org/2000/svg">
|
||||
<ellipse rx="0.500000" stroke-width="0.005000" ry="0.250000" fill="none" stroke="rgb(0,0,0)" transform="translate(50.000000 50.000000) scale(100.000000 100.000000) "/>
|
||||
<circle stroke="rgb(0,0,0)" r="0.500000" fill="none" stroke-width="0.010000" transform="translate(50.000000 50.000000) scale(100.000000 100.000000) "/>
|
||||
<circle stroke="none" r="0.500000" fill="rgb(0,0,0)" transform="translate(50.000000 50.000000) scale(4.000000 4.000000) "/>
|
||||
</svg>
|
After Width: | Height: | Size: 520 B |
|
@ -34,11 +34,9 @@ TEST_CASE(TestD2dWidgetRendering, "graphics")
|
|||
auto scene = gui_app->getMainWindowScene();
|
||||
|
||||
Widget widget;
|
||||
widget.setBackgroundColor({ 0, 200, 0 });
|
||||
widget.setBounds(300, 300);
|
||||
|
||||
auto button = Button::Create();
|
||||
button->setBackgroundColor({ 200, 0, 0 });
|
||||
button->setLabel("Test Button");
|
||||
button->setMaxWidth(100);
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
set(PUBLISHING_UNIT_TEST_FILES
|
||||
publishing/TestPdfWriter.cpp
|
||||
publishing/TestDocumentConverter.cpp
|
||||
publishing/TestSvgConverter.cpp
|
||||
publishing/TestSvgConverter.cpp
|
||||
publishing/TestSvgToNodeConverter.cpp
|
||||
publishing/TestLatexConverter.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "SvgWriter.h"
|
||||
#include "SvgDocument.h"
|
||||
#include "SvgConverter.h"
|
||||
#include "SvgPainter.h"
|
||||
#include "Scene.h"
|
||||
|
||||
#include "CircleNode.h"
|
||||
|
@ -24,13 +24,10 @@ TEST_CASE(TestSvgConverter, "[publishing]")
|
|||
//rectangle.setFillColor({255, 0, 0});
|
||||
//scene.addNode(&rectangle);
|
||||
|
||||
SvgConverter converter;
|
||||
auto svg_document = converter.convert(&scene);
|
||||
SvgPainter painter;
|
||||
auto svg_document = painter.paint(&scene);
|
||||
svg_document->setViewBox(0, 0, 200, 200);
|
||||
|
||||
SvgWriter writer;
|
||||
auto content = writer.toString(svg_document.get());
|
||||
|
||||
auto outFile = std::make_unique<File>(TestUtils::getTestOutputDir(__FILE__) / "scene.svg");
|
||||
outFile->writeText(content);
|
||||
writer.toFile(TestUtils::getTestOutputDir(__FILE__) / "scene.svg", svg_document.get());
|
||||
}
|
||||
|
|
25
test/publishing/TestSvgToNodeConverter.cpp
Normal file
25
test/publishing/TestSvgToNodeConverter.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "TestFramework.h"
|
||||
#include "TestRenderUtils.h"
|
||||
#include "TestUtils.h"
|
||||
|
||||
#include "SvgReader.h"
|
||||
#include "SvgWriter.h"
|
||||
|
||||
#include "SvgNode.h"
|
||||
|
||||
TEST_CASE(TestSvgToNodeConverter, "publishing")
|
||||
{
|
||||
SvgReader svg_reader;
|
||||
auto svg_doc = svg_reader.read(TestUtils::getTestDataDir() / "circles.svg");
|
||||
|
||||
SvgWriter svg_writer;
|
||||
svg_writer.toFile(TestUtils::getTestOutputDir(__FILE__) / "TestSvgToNodeConverter.svg", svg_doc.get());
|
||||
|
||||
TestRenderer renderer;
|
||||
|
||||
auto svg_node = std::make_unique<SvgNode>(Point(0.0, 0.0));
|
||||
svg_node->setContent(std::move(svg_doc));
|
||||
renderer.getScene()->addNode(svg_node.get());
|
||||
|
||||
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "TestSvgToNodeConverter.png");
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
#include "AbstractPainter.h"
|
||||
#include "Scene.h"
|
||||
|
||||
#include "SvgConverter.h"
|
||||
#include "SvgPainter.h"
|
||||
#include "SvgWriter.h"
|
||||
#include "SvgDocument.h"
|
||||
|
||||
|
@ -25,6 +25,8 @@ public:
|
|||
mDrawingContext = std::make_unique<DrawingContext>(mSurface.get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Scene* getScene() const
|
||||
{
|
||||
return mSurface->getScene();
|
||||
|
@ -47,8 +49,8 @@ public:
|
|||
|
||||
static void writeSvg(const Path& path, Scene* scene)
|
||||
{
|
||||
SvgConverter converter;
|
||||
auto svg_document = converter.convert(scene);
|
||||
SvgPainter painter;
|
||||
auto svg_document = painter.paint(scene);
|
||||
|
||||
SvgWriter writer;
|
||||
auto svg_content = writer.toString(svg_document.get());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue