svg-flatten: Add stroked SVG output

wip
jaseg 2023-03-29 22:21:15 +02:00
rodzic 65a426c645
commit 25628f1d24
3 zmienionych plików z 28 dodań i 9 usunięć

Wyświetl plik

@ -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;
};

Wyświetl plik

@ -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;

Wyświetl plik

@ -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

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 21 KiB

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 21 KiB