Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cartocrow/renderer/geometry_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 20 additions & 6 deletions cartocrow/renderer/svg_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ SvgRenderer::SvgRenderer(const std::shared_ptr<GeometryPainting>& 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 << "<svg version=\"1.1\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns=\"http://www.w3.org/2000/svg\">\n";
m_out << "<defs><circle id=\"vertex\" cx=\"0\" cy=\"0\" r=\"4\"/></defs>\n";

void SvgRenderer::savePaintings() {
for (auto painting : m_paintings) {
m_out << "<g inkscape:groupmode=\"layer\"";
if (painting.name) {
Expand All @@ -54,7 +49,26 @@ void SvgRenderer::save(const std::filesystem::path& file) {
popStyle();
m_out << "</g>\n";
}
}

void SvgRenderer::save(const std::filesystem::path& file) {
std::locale::global(std::locale("C"));
m_out.open(file);
m_out << "<svg version=\"1.1\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns=\"http://www.w3.org/2000/svg\">\n";
m_out << "<defs><circle id=\"vertex\" cx=\"0\" cy=\"0\" r=\"4\"/></defs>\n";
savePaintings();
m_out << "</svg>\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 << "<svg version=\"1.1\"" << " viewBox=\"" <<
viewBox.xmin() << " " << -viewBox.ymax() << " " << viewBox.x_span() << " " << viewBox.y_span() <<
"\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns=\"http://www.w3.org/2000/svg\">\n";
m_out << "<defs><circle id=\"vertex\" cx=\"0\" cy=\"0\" r=\"4\"/></defs>\n";
savePaintings();
m_out << "</svg>\n";
m_out.close();
}
Expand Down
4 changes: 4 additions & 0 deletions cartocrow/renderer/svg_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Inexact>& p) override;
void draw(const Circle<Inexact>& c) override;
Expand Down Expand Up @@ -136,6 +137,9 @@ class SvgRenderer : public GeometryRenderer {
std::stack<SvgRendererStyle> 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
Expand Down
Loading