diff options
author | jaseg <git@jaseg.de> | 2022-01-09 23:37:27 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-01-09 23:37:27 +0100 |
commit | 2ce0ff81ae50053022cc091b9db2d44f5b3ddc63 (patch) | |
tree | c1b4a444564c9799905aebb3556038a2ffe005c0 /gerbonara/gerber/tests | |
parent | 4d77937f01e4a7561f412a07e1e2c5a5dba0fc49 (diff) | |
download | gerbonara-2ce0ff81ae50053022cc091b9db2d44f5b3ddc63.tar.gz gerbonara-2ce0ff81ae50053022cc091b9db2d44f5b3ddc63.tar.bz2 gerbonara-2ce0ff81ae50053022cc091b9db2d44f5b3ddc63.zip |
Fix remaining svg rendering/gerber compositing bugs
Diffstat (limited to 'gerbonara/gerber/tests')
-rw-r--r-- | gerbonara/gerber/tests/image_support.py | 3 | ||||
-rw-r--r-- | gerbonara/gerber/tests/test_rs274x.py | 13 |
2 files changed, 10 insertions, 6 deletions
diff --git a/gerbonara/gerber/tests/image_support.py b/gerbonara/gerber/tests/image_support.py index ee84203..ba28561 100644 --- a/gerbonara/gerber/tests/image_support.py +++ b/gerbonara/gerber/tests/image_support.py @@ -63,13 +63,14 @@ def run_cargo_cmd(cmd, args, **kwargs): def svg_to_png(in_svg, out_png, dpi=100, bg='black'): run_cargo_cmd('resvg', ['--background', bg, '--dpi', str(dpi), in_svg, out_png], check=True, stdout=subprocess.DEVNULL) -def gerbv_export(in_gbr, out_svg, format='svg', origin=(0, 0), size=(6, 6), fg='#ffffff'): +def gerbv_export(in_gbr, out_svg, format='svg', origin=(0, 0), size=(6, 6), fg='#ffffff', bg='#000000'): x, y = origin w, h = size cmd = ['gerbv', '-x', format, '--border=0', f'--origin={x:.6f}x{y:.6f}', f'--window_inch={w:.6f}x{h:.6f}', f'--foreground={fg}', + f'--background={bg}', '-o', str(out_svg), str(in_gbr)] subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) diff --git a/gerbonara/gerber/tests/test_rs274x.py b/gerbonara/gerber/tests/test_rs274x.py index 5be0af5..7382997 100644 --- a/gerbonara/gerber/tests/test_rs274x.py +++ b/gerbonara/gerber/tests/test_rs274x.py @@ -46,7 +46,7 @@ def print_on_error(request): if request.node.rep_call.failed: for msg in messages: - print(msg) + print(msg, end='') @pytest.fixture def tmpfile(request): @@ -322,8 +322,14 @@ def test_svg_export(reference, tmpfile): with open(out_svg, 'w') as f: f.write(str(grb.to_svg(force_bounds=bounds, arg_unit='inch', color='white'))) + # NOTE: Instead of having gerbv directly export a PNG, we ask gerbv to output SVG which we then rasterize using + # resvg. We have to do this since gerbv's built-in cairo-based PNG export has severe aliasing issues. In contrast, + # using resvg for both allows an apples-to-apples comparison of both results. + ref_svg = tmpfile('Reference export', '.svg') ref_png = tmpfile('Reference render', '.png') - gerbv_export(reference, ref_png, origin=bounds[0], size=bounds[1], format='png', fg='#000000') + gerbv_export(reference, ref_svg, origin=bounds[0], size=bounds[1]) + svg_to_png(ref_svg, ref_png, dpi=72) # make dpi match Cairo's default + out_png = tmpfile('Output render', '.png') svg_to_png(out_svg, out_png, dpi=72) # make dpi match Cairo's default @@ -363,11 +369,8 @@ def test_bounding_box(reference, tmpfile): assert (img > 0).any() # there must be some content, none of the test gerbers are completely empty. cols = img.sum(axis=1) rows = img.sum(axis=0) - print('shape:', img.shape) col_prefix, col_suffix = np.argmax(cols > 0), np.argmax(cols[::-1] > 0) row_prefix, row_suffix = np.argmax(rows > 0), np.argmax(rows[::-1] > 0) - print('cols', 'prefix:', row_prefix, 'suffix:', row_suffix) - print('rows', 'prefix:', row_prefix, 'suffix:', row_suffix) # Check that all margins are completely black and that the content touches the margins. Allow for some tolerance to # allow for antialiasing artifacts. |