summaryrefslogtreecommitdiff
path: root/lib/extensions/lettering_generate_json.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2025-10-10 10:25:49 +0200
committerGitHub <noreply@github.com>2025-10-10 10:25:49 +0200
commit2c295ace644a27b7d1523c047e168aac2ead03dc (patch)
tree436f73eb6b788c3ac68fdda3b1e15fac27a8eef0 /lib/extensions/lettering_generate_json.py
parent31cebe4228be707a1fe0a8727044fbc7271dd4b3 (diff)
Edit json: allow 0 values for horiz_adv_x_default (#3965)
* edit json: allow 0 values for horiz_adv_x_default and enable None for using the glyph width * enable None value in generate json too
Diffstat (limited to 'lib/extensions/lettering_generate_json.py')
-rw-r--r--lib/extensions/lettering_generate_json.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/extensions/lettering_generate_json.py b/lib/extensions/lettering_generate_json.py
index f4a01ddb..bfdd1055 100644
--- a/lib/extensions/lettering_generate_json.py
+++ b/lib/extensions/lettering_generate_json.py
@@ -38,6 +38,7 @@ class LetteringGenerateJson(InkstitchExtension):
self.arg_parser.add_argument("--use-custom-leading", type=Boolean, default="false", dest="use_custom_leading")
self.arg_parser.add_argument("--use-custom-spacing", type=Boolean, default="false", dest="use_custom_spacing")
self.arg_parser.add_argument("--use-custom-letter-spacing", type=Boolean, default="false", dest="use_custom_letter_spacing")
+ self.arg_parser.add_argument("--use-glyph-width", type=Boolean, default="false", dest="use_glyph_width")
self.arg_parser.add_argument("-l", "--leading", type=int, default=100, dest="leading")
self.arg_parser.add_argument("-w", "--word-spacing", type=int, default=20, dest="word_spacing")
self.arg_parser.add_argument("-b", "--letter-spacing", type=int, default=100, dest="letter_spacing")
@@ -61,17 +62,14 @@ class LetteringGenerateJson(InkstitchExtension):
hkern = font_info.hkern()
custom_leading = self.options.use_custom_leading
custom_spacing = self.options.use_custom_spacing
- custom_letter_spacing = self.options.use_custom_letter_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 = font_info.letter_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_letter_spacing or not letter_spacing:
- letter_spacing = self.options.letter_spacing
+
+ letter_spacing = self._get_letter_spacing(font_info)
+
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
@@ -127,3 +125,13 @@ class LetteringGenerateJson(InkstitchExtension):
# write data to font.json into the same directory as the font file
with open(output_path, 'w', encoding="utf8") as font_data:
json.dump(data, font_data, indent=4, ensure_ascii=False)
+
+ def _get_letter_spacing(self, font_info):
+ letter_spacing = font_info.letter_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 self.options.use_custom_letter_spacing or not letter_spacing:
+ letter_spacing = self.options.letter_spacing
+ if self.options.use_glyph_width:
+ letter_spacing = None
+ return letter_spacing