From 55505369496c0986e54fe5722e7e8ddce0a9294e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 25 Mar 2019 19:40:37 -0400 Subject: implement font chooser --- lib/lettering/font.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/lettering/font.py') diff --git a/lib/lettering/font.py b/lib/lettering/font.py index 28807cd6..6f749d28 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -7,6 +7,7 @@ import os import inkex from ..elements import nodes_to_elements +from ..exceptions import InkstitchException from ..i18n import _ from ..stitches.auto_satin import auto_satin from ..svg import PIXELS_PER_MM @@ -15,6 +16,10 @@ from ..utils import Point from .font_variant import FontVariant +class FontError(InkstitchException): + pass + + def font_metadata(name, default=None, multiplier=None): def getter(self): value = self.metadata.get(name, default) @@ -47,6 +52,9 @@ class Font(object): self._load_license() self._load_variants() + if self.variants.get(self.default_variant) is None: + raise FontError("font not found or has no default variant") + def _load_metadata(self): try: with open(os.path.join(self.path, "font.json")) as metadata_file: @@ -81,6 +89,10 @@ class Font(object): kerning_pairs = font_metadata('kerning_pairs', {}) auto_satin = font_metadata('auto_satin', True) + @property + def id(self): + return os.path.basename(self.path) + def render_text(self, text, destination_group, variant=None, back_and_forth=True, trim=False): """Render text into an SVG group element.""" -- cgit v1.2.3