From 25628f1d24a6902e7f7d18befeb751b0a7305fd5 Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 29 Mar 2023 22:21:15 +0200 Subject: svg-flatten: Add stroked SVG output --- svg-flatten/include/gerbolyze.hpp | 3 +++ svg-flatten/src/out_svg.cpp | 26 +++++++++++++++++----- .../testdata/svg/xform_uniformity_threshold.svg | 8 +++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/svg-flatten/include/gerbolyze.hpp b/svg-flatten/include/gerbolyze.hpp index 7c54337..2fb7605 100644 --- a/svg-flatten/include/gerbolyze.hpp +++ b/svg-flatten/include/gerbolyze.hpp @@ -355,7 +355,9 @@ namespace gerbolyze { virtual ~SimpleSVGOutput() {} virtual SimpleSVGOutput &operator<<(const Polygon &poly); virtual SimpleSVGOutput &operator<<(GerberPolarityToken pol); + virtual SimpleSVGOutput &operator<<(const ApertureToken &ap); virtual SimpleSVGOutput &operator<<(const FlashToken &tok); + virtual bool can_do_apertures() { return true; } virtual void header_impl(d2p origin, d2p size); virtual void footer_impl(); @@ -364,6 +366,7 @@ namespace gerbolyze { std::string m_dark_color; std::string m_clear_color; std::string m_current_color; + double m_stroke_width; d2p m_offset; }; diff --git a/svg-flatten/src/out_svg.cpp b/svg-flatten/src/out_svg.cpp index 80a5bdd..5ec061c 100644 --- a/svg-flatten/src/out_svg.cpp +++ b/svg-flatten/src/out_svg.cpp @@ -32,7 +32,8 @@ SimpleSVGOutput::SimpleSVGOutput(ostream &out, bool only_polys, int digits_frac, m_digits_frac(digits_frac), m_dark_color(dark_color), m_clear_color(clear_color), - m_current_color(dark_color) + m_current_color(dark_color), + m_stroke_width(std::nan("0")) { } @@ -57,21 +58,36 @@ SimpleSVGOutput &SimpleSVGOutput::operator<<(GerberPolarityToken pol) { return *this; } +SimpleSVGOutput &SimpleSVGOutput::operator<<(const ApertureToken &ap) { + m_stroke_width = ap.m_has_aperture ? ap.m_size : std::nan("0"); + return *this; +} + SimpleSVGOutput &SimpleSVGOutput::operator<<(const Polygon &poly) { //cerr << "svg: got poly of size " << poly.size() << endl; - if (poly.size() < 3) { - cerr << "Warning: " << poly.size() << "-element polygon passed to SimpleGerberOutput" << endl; + if (std::isnan(m_stroke_width) && poly.size() < 3) { + cerr << "Warning: " << poly.size() << "-element polygon passed to SimpleSVGOutput in fill mode" << endl; return *this; } - m_out << "" << endl; return *this; diff --git a/svg-flatten/testdata/svg/xform_uniformity_threshold.svg b/svg-flatten/testdata/svg/xform_uniformity_threshold.svg index 4198241..90fb3c8 100644 --- a/svg-flatten/testdata/svg/xform_uniformity_threshold.svg +++ b/svg-flatten/testdata/svg/xform_uniformity_threshold.svg @@ -3,8 +3,8 @@