diff options
Diffstat (limited to 'lib/extensions/lettering_generate_json.py')
| -rw-r--r-- | lib/extensions/lettering_generate_json.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/extensions/lettering_generate_json.py b/lib/extensions/lettering_generate_json.py index 85c918b2..a884ccac 100644 --- a/lib/extensions/lettering_generate_json.py +++ b/lib/extensions/lettering_generate_json.py @@ -10,7 +10,8 @@ import sys from inkex import Boolean from ..i18n import _ -from ..lettering.kerning import FontKerning +from ..lettering.categories import FONT_CATEGORIES +from ..lettering.font_info import FontFileInfo from .base import InkstitchExtension @@ -20,6 +21,11 @@ class LetteringGenerateJson(InkstitchExtension): ''' def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("--options") + self.arg_parser.add_argument("--general") + self.arg_parser.add_argument("--settings") + self.arg_parser.add_argument("--kerning") + self.arg_parser.add_argument("-n", "--font-name", type=str, default="Font", dest="font_name") self.arg_parser.add_argument("-d", "--font-description", type=str, default="Description", dest="font_description") self.arg_parser.add_argument("-s", "--auto-satin", type=Boolean, default="true", dest="auto_satin") @@ -35,6 +41,9 @@ class LetteringGenerateJson(InkstitchExtension): self.arg_parser.add_argument("-w", "--word-spacing", type=int, default=26, dest="word_spacing") self.arg_parser.add_argument("-p", "--font-file", type=str, default="", dest="path") + for category in FONT_CATEGORIES: + self.arg_parser.add_argument(f"--{category.id}", type=Boolean, default="false", dest=category.id) + def effect(self): # file paths path = self.options.path @@ -43,20 +52,20 @@ class LetteringGenerateJson(InkstitchExtension): return output_path = os.path.join(os.path.dirname(path), 'font.json') - # kerning - kerning = FontKerning(path) + # font info (kerning, glyphs) + font_info = FontFileInfo(path) - horiz_adv_x = kerning.horiz_adv_x() - hkern = kerning.hkern() + horiz_adv_x = font_info.horiz_adv_x() + hkern = font_info.hkern() custom_leading = self.options.use_custom_leading custom_spacing = self.options.use_custom_spacing - word_spacing = kerning.word_spacing() + word_spacing = font_info.word_spacing() # use user input in case that the default word spacing is not defined # in the svg file or the user forces custom values if custom_spacing or not word_spacing: word_spacing = self.options.word_spacing - letter_spacing = kerning.letter_spacing() - units_per_em = kerning.units_per_em() or self.options.leading + letter_spacing = font_info.letter_spacing() + units_per_em = font_info.units_per_em() or self.options.leading # use units_per_em for leading (line height) if defined in the font file, # unless the user wishes to overwrite the value if units_per_em and not custom_leading: @@ -64,9 +73,17 @@ class LetteringGenerateJson(InkstitchExtension): else: leading = self.options.leading + glyphs = font_info.glyph_list() + + keywords = [] + for category in FONT_CATEGORIES: + if getattr(self.options, category.id): + keywords.append(category.id) + # collect data data = {'name': self.options.font_name, 'description': self.options.font_description, + 'keywords': keywords, 'leading': leading, 'auto_satin': self.options.auto_satin, 'reversible': self.options.reversible, @@ -79,7 +96,8 @@ class LetteringGenerateJson(InkstitchExtension): 'horiz_adv_x_space': word_spacing, 'units_per_em': units_per_em, 'horiz_adv_x': horiz_adv_x, - 'kerning_pairs': hkern + 'kerning_pairs': hkern, + 'glyphs': glyphs } # write data to font.json into the same directory as the font file |
