diff --git a/cartocrow/renderer/geometry_widget.cpp b/cartocrow/renderer/geometry_widget.cpp index ce5afc88..e494636d 100644 --- a/cartocrow/renderer/geometry_widget.cpp +++ b/cartocrow/renderer/geometry_widget.cpp @@ -964,7 +964,11 @@ void GeometryWidget::saveToSvg() { for (const DrawnPainting& painting : m_paintings) { renderer.addPainting(painting.m_painting, painting.name); } - renderer.save(fileName.toStdString()); + auto windowSize = size(); + auto bottomLeft = inverseConvertPoint(QPoint(0, windowSize.height())); + auto topRight = inverseConvertPoint(QPoint(windowSize.width(), 0)); + + renderer.save(fileName.toStdString(), Box(bottomLeft.x(), bottomLeft.y(), topRight.x(), topRight.y())); } } // namespace cartocrow::renderer diff --git a/cartocrow/renderer/svg_renderer.cpp b/cartocrow/renderer/svg_renderer.cpp index 9bba8b37..03042a66 100644 --- a/cartocrow/renderer/svg_renderer.cpp +++ b/cartocrow/renderer/svg_renderer.cpp @@ -37,12 +37,7 @@ SvgRenderer::SvgRenderer(const std::shared_ptr& painting, cons m_paintings.push_back(DrawnPainting{painting, name}); } -void SvgRenderer::save(const std::filesystem::path& file) { - std::locale::global(std::locale("C")); - m_out.open(file); - m_out << "\n"; - m_out << "\n"; - +void SvgRenderer::savePaintings() { for (auto painting : m_paintings) { m_out << "\n"; } +} +void SvgRenderer::save(const std::filesystem::path& file) { + std::locale::global(std::locale("C")); + m_out.open(file); + m_out << "\n"; + m_out << "\n"; + savePaintings(); + m_out << "\n"; + m_out.close(); +} + +void SvgRenderer::save(const std::filesystem::path& file, Box viewBox) { + std::locale::global(std::locale("C")); + m_out.open(file); + m_out << "\n"; + m_out << "\n"; + savePaintings(); m_out << "\n"; m_out.close(); } diff --git a/cartocrow/renderer/svg_renderer.h b/cartocrow/renderer/svg_renderer.h index 0804eacf..6895655d 100644 --- a/cartocrow/renderer/svg_renderer.h +++ b/cartocrow/renderer/svg_renderer.h @@ -74,6 +74,7 @@ class SvgRenderer : public GeometryRenderer { /// Saves the painting to an SVG file with the given name. void save(const std::filesystem::path& file); + void save(const std::filesystem::path& file, Box viewBox); void draw(const Point& p) override; void draw(const Circle& c) override; @@ -136,6 +137,9 @@ class SvgRenderer : public GeometryRenderer { std::stack m_styleStack; /// Clip path index; the number of clip paths already added to the SVG. int m_clipPathId = 0; + + /// Output paintings as svg to m_out. + void savePaintings(); }; } // namespace cartocrow::renderer