aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-03-29 22:21:15 +0200
committerjaseg <git@jaseg.de>2023-03-29 22:21:15 +0200
commit25628f1d24a6902e7f7d18befeb751b0a7305fd5 (patch)
tree08b0f8cb0c13b5fa0a2f6acb2709e959130b92fe
parent65a426c64500cee6f7e85864abdaee064221c7df (diff)
downloadgerbolyze-25628f1d24a6902e7f7d18befeb751b0a7305fd5.tar.gz
gerbolyze-25628f1d24a6902e7f7d18befeb751b0a7305fd5.tar.bz2
gerbolyze-25628f1d24a6902e7f7d18befeb751b0a7305fd5.zip
svg-flatten: Add stroked SVG output
-rw-r--r--svg-flatten/include/gerbolyze.hpp3
-rw-r--r--svg-flatten/src/out_svg.cpp26
-rw-r--r--svg-flatten/testdata/svg/xform_uniformity_threshold.svg8
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 << "<path fill=\"" << m_current_color << "\" d=\"";
+ if (std::isnan(m_stroke_width)) {
+ m_out << "<path fill=\"" << m_current_color << "\" d=\"";
+ } else {
+ m_out << "<path stroke=\"" << m_current_color << "\" stroke-width=\"" << m_stroke_width << "\" stroke-linejoin=\"round\" stroke-linecap=\"round\" d=\"";
+ }
+
m_out << "M " << setprecision(m_digits_frac) << (poly[0][0] + m_offset[0])
<< " " << setprecision(m_digits_frac) << (poly[0][1] + m_offset[1]);
+
for (size_t i=1; i<poly.size(); i++) {
m_out << " L " << setprecision(m_digits_frac) << (poly[i][0] + m_offset[0])
<< " " << setprecision(m_digits_frac) << (poly[i][1] + m_offset[1]);
}
- m_out << " Z";
+
+ if (std::isnan(m_stroke_width)) {
+ m_out << " Z";
+ }
+
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 @@
<svg
width="80mm"
- height="160mm"
- viewBox="0 0 80 160"
+ height="100mm"
+ viewBox="0 0 80 100"
version="1.1"
id="svg5"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
@@ -25,7 +25,7 @@
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.5760525"
- inkscape:cx="161.79664"
+ inkscape:cx="162.74839"
inkscape:cy="175.75557"
inkscape:window-width="1920"
inkscape:window-height="1011"
@@ -39,7 +39,7 @@
x="31.361818"
y="59.900364"
width="249.94496"
- height="98.71728"
+ height="98.717278"
id="rect256" />
</defs>
<g