aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-09-26 15:45:09 +0200
committerjaseg <git@jaseg.de>2021-09-29 16:38:13 +0200
commit8a64621e8c8610a45884df82b46859bc3297d3e3 (patch)
tree4b6265bb01377e16e66dddeee8259f40ea86d562 /svg-flatten/src
parent7eb0b9d7e42a20b85bd7afbfe3d33d9dd5fa5794 (diff)
downloadgerbolyze-8a64621e8c8610a45884df82b46859bc3297d3e3.tar.gz
gerbolyze-8a64621e8c8610a45884df82b46859bc3297d3e3.tar.bz2
gerbolyze-8a64621e8c8610a45884df82b46859bc3297d3e3.zip
CI/svg-flatten: add wasm builds
Diffstat (limited to 'svg-flatten/src')
-rw-r--r--svg-flatten/src/out_svg.cpp4
-rw-r--r--svg-flatten/src/svg_color.cpp1
-rw-r--r--svg-flatten/src/svg_doc.cpp1
-rw-r--r--svg-flatten/src/test/svg_tests.py18
4 files changed, 19 insertions, 5 deletions
diff --git a/svg-flatten/src/out_svg.cpp b/svg-flatten/src/out_svg.cpp
index 159bf13..e778d6b 100644
--- a/svg-flatten/src/out_svg.cpp
+++ b/svg-flatten/src/out_svg.cpp
@@ -37,6 +37,7 @@ SimpleSVGOutput::SimpleSVGOutput(ostream &out, bool only_polys, int digits_frac,
}
void SimpleSVGOutput::header_impl(d2p origin, d2p size) {
+ cerr << "svg: header" << endl;
m_offset[0] = origin[0];
m_offset[1] = origin[1];
m_out << "<svg width=\"" << size[0] << "mm\" height=\"" << size[1] << "mm\" viewBox=\"0 0 "
@@ -44,6 +45,7 @@ void SimpleSVGOutput::header_impl(d2p origin, d2p size) {
}
SimpleSVGOutput &SimpleSVGOutput::operator<<(GerberPolarityToken pol) {
+ cerr << "svg: got polarity " << pol << endl;
if (pol == GRB_POL_DARK) {
m_current_color = m_dark_color;
} else if (pol == GRB_POL_CLEAR) {
@@ -56,6 +58,7 @@ SimpleSVGOutput &SimpleSVGOutput::operator<<(GerberPolarityToken pol) {
}
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;
return *this;
@@ -75,6 +78,7 @@ SimpleSVGOutput &SimpleSVGOutput::operator<<(const Polygon &poly) {
}
void SimpleSVGOutput::footer_impl() {
+ cerr << "svg: footer" << endl;
m_out << "</svg>" << endl;
}
diff --git a/svg-flatten/src/svg_color.cpp b/svg-flatten/src/svg_color.cpp
index 76938e8..62b11bf 100644
--- a/svg-flatten/src/svg_color.cpp
+++ b/svg-flatten/src/svg_color.cpp
@@ -31,6 +31,7 @@ using namespace std;
* them.
*/
enum gerber_color gerbolyze::svg_color_to_gerber(string color, string opacity, enum gerber_color default_val, const RenderSettings &rset) {
+ cerr << "resolving svg color spec color=\"" << color << "\", opacity=\"" << opacity << "\", default=" << default_val << endl;
float alpha = 1.0;
if (!opacity.empty() && opacity[0] != '\0') {
char *endptr = nullptr;
diff --git a/svg-flatten/src/svg_doc.cpp b/svg-flatten/src/svg_doc.cpp
index 5a27163..a3186ec 100644
--- a/svg-flatten/src/svg_doc.cpp
+++ b/svg-flatten/src/svg_doc.cpp
@@ -227,6 +227,7 @@ void gerbolyze::SVGDocument::export_svg_group(RenderContext &ctx, const pugi::xm
void gerbolyze::SVGDocument::export_svg_path(RenderContext &ctx, const pugi::xml_node &node) {
enum gerber_color fill_color = gerber_fill_color(node, ctx.settings());
enum gerber_color stroke_color = gerber_stroke_color(node, ctx.settings());
+ cerr << "path: resolved colors, stroke=" << stroke_color << ", fill=" << fill_color << endl;
double stroke_width = usvg_double_attr(node, "stroke-width", /* default */ 1.0);
assert(stroke_width > 0.0);
diff --git a/svg-flatten/src/test/svg_tests.py b/svg-flatten/src/test/svg_tests.py
index 3784c59..0fc8dd6 100644
--- a/svg-flatten/src/test/svg_tests.py
+++ b/svg-flatten/src/test/svg_tests.py
@@ -7,6 +7,7 @@ from pathlib import Path
import subprocess
import itertools
import os
+import sys
from PIL import Image
import numpy as np
@@ -14,6 +15,9 @@ import numpy as np
def run_svg_flatten(input_file, output_file, *args, **kwargs):
if 'SVG_FLATTEN' in os.environ:
svg_flatten = os.environ.get('SVG_FLATTEN')
+ if not hasattr(run_svg_flatten, 'custom_svg_flatten_warned'):
+ print(f'Using svg-flatten from SVG_FLATTEN environment variable: "{svg_flatten}"', file=sys.stderr)
+ run_svg_flatten.custom_svg_flatten_warned = True
elif (Path(__file__) / '../../build/svg-flatten').is_file():
svg_flatten = '../../build/svg-flatten'
elif Path('./build/svg-flatten').is_file():
@@ -34,11 +38,12 @@ def run_svg_flatten(input_file, output_file, *args, **kwargs):
try:
proc = subprocess.run(args, capture_output=True, check=True)
except:
+ raise
+ finally:
print('Subprocess stdout:')
- print(proc.stdout)
+ print(proc.stdout.decode())
print('Subprocess stderr:')
- print(proc.stderr)
- raise
+ print(proc.stderr.decode())
def run_cargo_cmd(cmd, args, **kwargs):
if cmd.upper() in os.environ:
@@ -84,7 +89,8 @@ class SVGRoundTripTests(unittest.TestCase):
}
def compare_images(self, reference, output, test_name, mean=test_mean_default, vectorizer_test=False, rsvg_workaround=False):
- ref, out = Image.open(reference), Image.open(output)
+ ref = Image.open(reference)
+ out =Image.open(output)
if vectorizer_test:
target_size = (100, 100)
@@ -184,6 +190,8 @@ class SVGRoundTripTests(unittest.TestCase):
else:
run_svg_flatten(test_in_svg, tmp_out_svg.name, format='svg')
+ shutil.copyfile(tmp_out_svg.name, f'/tmp/gerbolyze-intermediate-{test_in_svg.stem}-out.svg')
+
if not use_rsvg: # default!
run_cargo_cmd('resvg', [tmp_out_svg.name, tmp_out_png.name], check=True, stdout=subprocess.DEVNULL)
run_cargo_cmd('resvg', [test_in_svg, tmp_in_png.name], check=True, stdout=subprocess.DEVNULL)
@@ -193,7 +201,7 @@ class SVGRoundTripTests(unittest.TestCase):
subprocess.run(['rsvg-convert', test_in_svg, '-f', 'png', '-o', tmp_in_png.name], check=True, stdout=subprocess.DEVNULL)
try:
- self.compare_images(tmp_in_png, tmp_out_png, test_in_svg.stem,
+ self.compare_images(tmp_in_png.name, tmp_out_png.name, test_in_svg.stem,
SVGRoundTripTests.test_mean_overrides.get(test_in_svg.stem, SVGRoundTripTests.test_mean_default),
vectorizer_test, rsvg_workaround=use_rsvg)