diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/lettering_custom_font_dir.py | 2 | ||||
| -rw-r--r-- | lib/extensions/lettering_generate_json.py | 32 | ||||
| -rw-r--r-- | lib/extensions/lettering_remove_kerning.py | 12 | ||||
| -rw-r--r-- | lib/extensions/params.py | 5 |
4 files changed, 30 insertions, 21 deletions
diff --git a/lib/extensions/lettering_custom_font_dir.py b/lib/extensions/lettering_custom_font_dir.py index 0103c7d6..a8284d38 100644 --- a/lib/extensions/lettering_custom_font_dir.py +++ b/lib/extensions/lettering_custom_font_dir.py @@ -28,6 +28,8 @@ class LetteringCustomFontDir(InkstitchExtension): config_path = appdirs.user_config_dir('inkstitch') except ImportError: config_path = os.path.expanduser('~/.inkstitch') + if not os.path.exists(config_path): + os.makedirs(config_path) config_path = os.path.join(config_path, 'custom_dirs.json') with open(config_path, 'w', encoding="utf8") as font_data: diff --git a/lib/extensions/lettering_generate_json.py b/lib/extensions/lettering_generate_json.py index 9b44c367..446c4ce8 100644 --- a/lib/extensions/lettering_generate_json.py +++ b/lib/extensions/lettering_generate_json.py @@ -20,9 +20,12 @@ class LetteringGenerateJson(InkstitchExtension): self.arg_parser.add_argument("-s", "--auto-satin", type=Boolean, default="true", dest="auto_satin") self.arg_parser.add_argument("-r", "--reversible", type=Boolean, default="true", dest="reversible") self.arg_parser.add_argument("-g", "--default-glyph", type=str, default="", dest="default_glyph") - self.arg_parser.add_argument("-i", "--min-scale", type=float, default=1, dest="min_scale") - self.arg_parser.add_argument("-a", "--max-scale", type=float, default=1, dest="max_scale") + self.arg_parser.add_argument("-i", "--min-scale", type=float, default=1.0, dest="min_scale") + self.arg_parser.add_argument("-a", "--max-scale", type=float, default=1.0, dest="max_scale") + self.arg_parser.add_argument("-c", "--use-custom-leading", type=Boolean, default="false", dest="use_custom_leading") + self.arg_parser.add_argument("-b", "--use-custom-spacing", type=Boolean, default="false", dest="use_custom_spacing") self.arg_parser.add_argument("-l", "--leading", type=int, default=0, dest="leading") + 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") def effect(self): @@ -38,19 +41,18 @@ class LetteringGenerateJson(InkstitchExtension): horiz_adv_x = kerning.horiz_adv_x() hkern = kerning.hkern() + custom_leading = self.options.use_custom_leading + custom_spacing = self.options.use_custom_spacing word_spacing = kerning.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() - # missing_glyph_spacing = kerning.missing_glyph_spacing() - - # if letter spacing returns 0, it hasn't been specified in the font file - # Ink/Stitch will calculate the width of each letter automatically - if letter_spacing == 0: - letter_spacing = None - - # if leading (line height) is set to 0, the font author wants Ink/Stitch to use units_per_em - # if units_per_em is not defined in the font file a default value will be returned - if self.options.leading == 0: + units_per_em = kerning.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: leading = units_per_em else: leading = self.options.leading @@ -62,8 +64,8 @@ class LetteringGenerateJson(InkstitchExtension): 'auto_satin': self.options.auto_satin, 'reversible': self.options.reversible, 'default_glyph': self.options.default_glyph, - 'min_scale': self.options.min_scale, - 'max_scale': self.options.max_scale, + 'min_scale': round(self.options.min_scale, 1), + 'max_scale': round(self.options.max_scale, 1), 'horiz_adv_x_default': letter_spacing, 'horiz_adv_x_space': word_spacing, 'units_per_em': units_per_em, diff --git a/lib/extensions/lettering_remove_kerning.py b/lib/extensions/lettering_remove_kerning.py index aec8717e..b58e4fb2 100644 --- a/lib/extensions/lettering_remove_kerning.py +++ b/lib/extensions/lettering_remove_kerning.py @@ -23,8 +23,10 @@ class LetteringRemoveKerning(InkstitchExtension): with open(path, 'r+', encoding="utf-8") as fontfile: svg = etree.parse(fontfile) xpath = ".//svg:font[1]" - kerning = svg.xpath(xpath, namespaces=NSS)[0] - kerning.getparent().remove(kerning) - fontfile.seek(0) - fontfile.write(etree.tostring(svg).decode('utf-8')) - fontfile.truncate() + kerning = svg.xpath(xpath, namespaces=NSS) + if kerning: + kerning = kerning[0] + kerning.getparent().remove(kerning) + fontfile.seek(0) + fontfile.write(etree.tostring(svg).decode('utf-8')) + fontfile.truncate() diff --git a/lib/extensions/params.py b/lib/extensions/params.py index b03ea973..2501f157 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -187,7 +187,10 @@ class ParamsTab(ScrolledPanel): for name, value in preset_data.items(): if name in self.param_inputs: - self.param_inputs[name].SetValue(value) + try: + self.param_inputs[name].SetValue(value) + except AttributeError: + self.param_inputs[name].SetSelection(int(value)) self.changed_inputs.add(self.param_inputs[name]) self.update_toggle_state() |
