aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-05-24 21:11:21 +0200
committerjaseg <git@jaseg.de>2021-05-24 21:11:46 +0200
commite06bbdbe9b359fb168278b44f039b6d1108e5a2d (patch)
tree4b800c2ece05559dd1e9e69c3970c438ef684d8a
parentd23d1486608f59d9c0729a8514dd0220be703d23 (diff)
downloadgerbolyze-e06bbdbe9b359fb168278b44f039b6d1108e5a2d.tar.gz
gerbolyze-e06bbdbe9b359fb168278b44f039b6d1108e5a2d.tar.bz2
gerbolyze-e06bbdbe9b359fb168278b44f039b6d1108e5a2d.zip
Make templates default to silk layer when opened in inkscape
-rwxr-xr-xgerbolyze/gerbolyze.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/gerbolyze/gerbolyze.py b/gerbolyze/gerbolyze.py
index f77e047..d4b4ab5 100755
--- a/gerbolyze/gerbolyze.py
+++ b/gerbolyze/gerbolyze.py
@@ -504,7 +504,7 @@ DEFAULT_EXTRA_LAYERS = [ layer for layer in LAYER_RENDER_ORDER if layer != "dril
def template_layer(name):
return f'<g id="g-{slugify(name)}" inkscape:label="{name}" inkscape:groupmode="layer"></g>'
-def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS):
+def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS, current_layer='silk'):
(x1, x2), (y1, y2) = bounds
w_mm, h_mm = (x2 - x1), (y2 - y1)
@@ -519,6 +519,7 @@ def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS):
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
width="{w_mm}mm" height="{h_mm}mm" viewBox="0 0 {w_mm} {h_mm}" >
<defs/>
+ <sodipodi:namedview inkscape:current-layer="g-{slugify(current_layer)}" />
<g inkscape:label="Preview" inkscape:groupmode="layer" id="g-preview" sodipodi:insensitive="true" style="opacity:0.5">
<image x="0" y="0" width="{w_mm}" height="{h_mm}"
xlink:href="data:image/jpeg;base64,{base64.b64encode(png_data).decode()}" />
@@ -538,7 +539,7 @@ def svg_pt_to_mm(pt_len, dpi=CAIRO_SVG_HARDCODED_DPI):
return f'{float(pt_len) / dpi * MM_PER_INCH}mm'
-def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS):
+def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS, current_layer='silk'):
svg = etree.fromstring(svg_data)
# add inkscape namespaces
@@ -555,6 +556,11 @@ def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS
svg.set('width', svg_pt_to_mm(svg.get('width')))
svg.set('height', svg_pt_to_mm(svg.get('height')))
+ # add inkscape <namedview> elem to set currently selected layer
+ namedview_elem = etree.SubElement(svg, SODIPODI_NS+'namedview')
+ namedview_elem.set('id', "namedview23")
+ namedview_elem.set(INKSCAPE_NS+'current-layer', f'g-{current_layer}')
+
# make original group an inkscape layer
orig_g = svg.find(SVG_NS+'g')
orig_g.set('id', 'g-preview')