diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/lettering.py | 16 | ||||
| -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 | 22 | ||||
| -rw-r--r-- | lib/extensions/zip.py | 2 |
6 files changed, 58 insertions, 28 deletions
diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py index ee0dd9a0..cddf1b11 100644 --- a/lib/extensions/lettering.py +++ b/lib/extensions/lettering.py @@ -1,6 +1,7 @@ import json import os import sys +from base64 import b64decode import appdirs import inkex @@ -86,12 +87,17 @@ class LetteringFrame(wx.Frame): "scale": 100 }) - try: - if INKSTITCH_LETTERING in self.group.attrib: + if INKSTITCH_LETTERING in self.group.attrib: + try: self.settings.update(json.loads(self.group.get(INKSTITCH_LETTERING))) - return - except (TypeError, ValueError): - pass + except json.decoder.JSONDecodeError: + # legacy base64 encoded (changed in v2.0) + try: + self.settings.update(json.loads(b64decode(self.group.get(INKSTITCH_LETTERING)))) + except (TypeError, ValueError): + pass + except (TypeError, ValueError): + pass def apply_settings(self): """Make the settings in self.settings visible in the UI.""" 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 71d8339f..acd96d5b 100644 --- a/lib/extensions/params.py +++ b/lib/extensions/params.py @@ -153,7 +153,11 @@ class ParamsTab(ScrolledPanel): for name, input in self.param_inputs.items(): if input in self.changed_inputs and input != self.toggle_checkbox: - values[name] = input.GetValue() + try: + values[name] = input.GetValue() + except AttributeError: + # dropdown + values[name] = input.GetSelection() return values @@ -183,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() @@ -271,6 +278,10 @@ class ParamsTab(ScrolledPanel): input.SetValue(param.values[0]) input.Bind(wx.EVT_CHECKBOX, self.changed) + elif param.type == 'dropdown': + input = wx.Choice(self, wx.ID_ANY, choices=param.options) + input.SetSelection(int(param.values[0])) + input.Bind(wx.EVT_CHOICE, self.changed) elif len(param.values) > 1: input = wx.ComboBox(self, wx.ID_ANY, choices=sorted(str(value) for value in param.values), style=wx.CB_DROPDOWN) input.Bind(wx.EVT_COMBOBOX, self.changed) @@ -449,6 +460,13 @@ class SettingsFrame(wx.Frame): sizer_1.Add(sizer_3, 0, wx.ALIGN_RIGHT, 0) self.SetSizer(sizer_1) sizer_1.Fit(self) + + # prevent the param dialog to become smaller than 500*400 + # otherwise the scrollbar jumps to the side and produces a + # deprecation warning in wxpythons scrolledpanel.py line 225 - + # which is expecting an integer, but uses previously a division + self.SetSizeHints(500, 400) + self.Layout() # end wxGlade diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py index fedf8c65..eacf2260 100644 --- a/lib/extensions/zip.py +++ b/lib/extensions/zip.py @@ -55,7 +55,7 @@ class Zip(InkstitchExtension): svg.write(etree.tostring(document).decode('utf-8')) elif format == 'threadlist': output_file = os.path.join(path, "%s_%s.txt" % (base_file_name, _("threadlist"))) - output = open(output_file, 'w') + output = open(output_file, 'w', encoding='utf-8') output.write(self.get_threadlist(stitch_plan, base_file_name)) output.close() else: |
