diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2021-10-09 18:25:29 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-09 18:25:29 +0200 |
| commit | 5a1ad7e4e8bebb31a679674ed8b4ca526138695c (patch) | |
| tree | 254f906a6524abd3cb9a685975e563f09790bbaa /lib/lettering/font_variant.py | |
| parent | 0224794a0815f22a719d2880e175077b77214513 (diff) | |
Letters to font extension (#1312)
Diffstat (limited to 'lib/lettering/font_variant.py')
| -rw-r--r-- | lib/lettering/font_variant.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/lettering/font_variant.py b/lib/lettering/font_variant.py index d9d8ed44..a7f353fe 100644 --- a/lib/lettering/font_variant.py +++ b/lib/lettering/font_variant.py @@ -7,7 +7,8 @@ import os import inkex -from ..svg.tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL +from ..svg.tags import (INKSCAPE_GROUPMODE, INKSCAPE_LABEL, SVG_GROUP_TAG, + SVG_PATH_TAG, SVG_USE_TAG) from .glyph import Glyph @@ -60,7 +61,8 @@ class FontVariant(object): def _load_glyphs(self): svg_path = os.path.join(self.path, "%s.svg" % self.variant) - svg = inkex.load_svg(svg_path) + svg = inkex.load_svg(svg_path).getroot() + svg = self._apply_transforms(svg) glyph_layers = svg.xpath(".//svg:g[starts-with(@inkscape:label, 'GlyphLayer-')]", namespaces=inkex.NSS) for layer in glyph_layers: @@ -79,6 +81,29 @@ class FontVariant(object): group.style.pop('display', None) group.attrib.pop('display', None) + def _apply_transforms(self, svg): + # apply transforms to paths and use tags + for element in svg.iterdescendants((SVG_PATH_TAG, SVG_USE_TAG)): + transform = element.composed_transform() + if element.tag == SVG_PATH_TAG: + path = element.path.transform(transform) + element.set_path(path) + element.attrib.pop("transform", None) + + if element.tag == SVG_USE_TAG: + oldx = element.get('x', 0) + oldy = element.get('y', 0) + newx, newy = transform.apply_to_point((oldx, oldy)) + element.set('x', newx) + element.set('y', newy) + element.attrib.pop("transform", None) + + # remove transforms after they have been applied + for group in svg.iterdescendants(SVG_GROUP_TAG): + group.attrib.pop('transform', None) + + return svg + def __getitem__(self, character): if character in self.glyphs: return self.glyphs[character] |
