diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-01-25 16:41:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-25 16:41:30 +0100 |
| commit | be93c858a4b7bdd771521502c3c1195a01b32fbf (patch) | |
| tree | 889aab3a266eb12a22847dcb4fff0cd728e2e921 /lib/marker.py | |
| parent | 6ca29b066817af3d666aeb48c6e9713f8a34dc60 (diff) | |
markers and lettering (#1559)
Diffstat (limited to 'lib/marker.py')
| -rw-r--r-- | lib/marker.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/marker.py b/lib/marker.py new file mode 100644 index 00000000..4f262abe --- /dev/null +++ b/lib/marker.py @@ -0,0 +1,37 @@ +# Authors: see git history +# +# Copyright (c) 2022 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from copy import deepcopy +from os import path + +import inkex + +from .utils import cache, get_bundled_dir + +MARKER = ['pattern'] + + +def ensure_marker(svg, marker): + marker_path = ".//*[@id='inkstitch-%s-marker']" % marker + if svg.defs.find(marker_path) is None: + svg.defs.append(deepcopy(_marker_svg().defs.find(marker_path))) + + +@cache +def _marker_svg(): + marker_path = path.join(get_bundled_dir("symbols"), "marker.svg") + with open(marker_path) as marker_file: + return inkex.load_svg(marker_file).getroot() + + +def set_marker(node, position, marker): + ensure_marker(node.getroottree().getroot(), marker) + + # attach marker to node + style = node.get('style') or '' + style = style.split(";") + style = [i for i in style if not i.startswith('marker-%s' % position)] + style.append('marker-%s:url(#inkstitch-pattern-marker)' % position) + node.set('style', ";".join(style)) |
