diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-11-14 20:23:06 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-14 20:23:06 -0500 |
| commit | f5c85183d9c874fca806917e50992daea4101496 (patch) | |
| tree | a2450e2e37a7d94625a917240e78eadc939fd65b /lib/extensions/lettering.py | |
| parent | 238ad843dd658de6c7afd5b8697c0e080b1cf965 (diff) | |
basic lettering (#344)
Can handle multiple lines of text and routes the stitching in alternating directions on each line.
Diffstat (limited to 'lib/extensions/lettering.py')
| -rw-r--r-- | lib/extensions/lettering.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py new file mode 100644 index 00000000..0d6629f8 --- /dev/null +++ b/lib/extensions/lettering.py @@ -0,0 +1,39 @@ +import os + +from ..i18n import _ +from ..lettering import Font +from ..svg.tags import SVG_PATH_TAG, SVG_GROUP_TAG, INKSCAPE_LABEL +from ..utils import get_bundled_dir +from .commands import CommandsExtension + + +class Lettering(CommandsExtension): + COMMANDS = ["trim"] + + def __init__(self, *args, **kwargs): + CommandsExtension.__init__(self, *args, **kwargs) + + self.OptionParser.add_option("-t", "--text") + + def effect(self): + font_path = os.path.join(get_bundled_dir("fonts"), "small_font") + font = Font(font_path) + self.ensure_current_layer() + + lines = font.render_text(self.options.text.decode('utf-8')) + self.set_labels(lines) + self.current_layer.append(lines) + + def set_labels(self, lines): + path = 1 + for node in lines.iterdescendants(): + if node.tag == SVG_PATH_TAG: + node.set("id", self.uniqueId("lettering")) + + # L10N Label for an object created by the Lettering extension + node.set(INKSCAPE_LABEL, _("Lettering %d") % path) + path += 1 + elif node.tag == SVG_GROUP_TAG: + node.set("id", self.uniqueId("letteringline")) + + # lettering extension already set the label |
