diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2022-06-18 23:52:22 +0200 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2022-06-18 23:52:22 +0200 |
commit | dfaf23b71803bdaf331e8353b93e3862838da042 (patch) | |
tree | 393a219e9a0be338f1b6e8d8f555d0f67feae8a3 /gerbonara/utils.py | |
parent | 4b38d0905e766e19e19103b86af1a6352c8e1bf9 (diff) | |
download | gerbonara-dfaf23b71803bdaf331e8353b93e3862838da042.tar.gz gerbonara-dfaf23b71803bdaf331e8353b93e3862838da042.tar.bz2 gerbonara-dfaf23b71803bdaf331e8353b93e3862838da042.zip |
Add selectable inkscape SVG export
Diffstat (limited to 'gerbonara/utils.py')
-rw-r--r-- | gerbonara/utils.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/gerbonara/utils.py b/gerbonara/utils.py index 290a44a..04d1e54 100644 --- a/gerbonara/utils.py +++ b/gerbonara/utils.py @@ -432,7 +432,7 @@ def svg_arc(old, new, center, clockwise): def svg_rotation(angle_rad, cx=0, cy=0): return f'rotate({float(math.degrees(angle_rad)):.4} {float(cx):.6} {float(cy):.6})' -def setup_svg(tags, bounds, margin=0, arg_unit=MM, svg_unit=MM, pagecolor='white', tag=Tag): +def setup_svg(tags, bounds, margin=0, arg_unit=MM, svg_unit=MM, pagecolor='white', tag=Tag, inkscape=False): (min_x, min_y), (max_x, max_y) = bounds if margin: @@ -446,17 +446,25 @@ def setup_svg(tags, bounds, margin=0, arg_unit=MM, svg_unit=MM, pagecolor='white w = 1.0 if math.isclose(w, 0.0) else w h = 1.0 if math.isclose(h, 0.0) else h - view = tag('sodipodi:namedview', [], id='namedview1', pagecolor=pagecolor, - inkscape__document_units=svg_unit.shorthand) + if inkscape: + tags.insert(0, tag('sodipodi:namedview', [], id='namedview1', pagecolor=pagecolor, + inkscape__document_units=svg_unit.shorthand)) + namespaces = dict( + xmlns="http://www.w3.org/2000/svg", + xmlns__xlink="http://www.w3.org/1999/xlink", + xmlns__sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd', + xmlns__inkscape='http://www.inkscape.org/namespaces/inkscape') + + else: + namespaces = dict( + xmlns="http://www.w3.org/2000/svg", + xmlns__xlink="http://www.w3.org/1999/xlink") svg_unit = 'in' if svg_unit == 'inch' else 'mm' # TODO export apertures as <uses> where reasonable. - return tag('svg', [view, *tags], + return tag('svg', tags, width=f'{w}{svg_unit}', height=f'{h}{svg_unit}', viewBox=f'{min_x} {min_y} {w} {h}', - xmlns="http://www.w3.org/2000/svg", - xmlns__xlink="http://www.w3.org/1999/xlink", - xmlns__sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd', - xmlns__inkscape='http://www.inkscape.org/namespaces/inkscape', + **namespaces, root=True) |