Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 432b738

Browse files
committed
Ensure that ligatures are also kerened consistently
1 parent 03b9724 commit 432b738

7 files changed

Lines changed: 35 additions & 19 deletions

File tree

xkcd-script/font/xkcd-script.otf

1.32 KB
Binary file not shown.

xkcd-script/font/xkcd-script.sfd

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xkcd-script/font/xkcd-script.ttf

1.32 KB
Binary file not shown.

xkcd-script/font/xkcd-script.woff

796 Bytes
Binary file not shown.

xkcd-script/generator/pt4_svg_to_font.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,23 @@ def autokern(font):
247247
font.addLookupSubtable('kerning', 'kern')
248248

249249
def kern(sep, left, right, **kwargs):
250-
"""Wraps font.autoKern: binds the subtable and expands accented variants."""
251-
font.autoKern('kern', sep,
252-
_expand_with_variants(font, left),
253-
_expand_with_variants(font, right),
254-
**kwargs)
250+
"""Wraps font.autoKern: expands accented variants and leading/trailing ligatures."""
251+
def expand(chars, left_side):
252+
expanded = _expand_with_variants(font, chars)
253+
seen = set(expanded)
254+
for glyph in font.glyphs():
255+
name = glyph.glyphname
256+
if '_' not in name:
257+
continue
258+
parts = name.split('_')
259+
# Left side: ligature's right edge (last component) determines spacing.
260+
# Right side: ligature's left edge (first component) determines spacing.
261+
anchor = parts[-1] if left_side else parts[0]
262+
if anchor in seen and name not in seen:
263+
expanded.append(name)
264+
seen.add(name)
265+
return expanded
266+
font.autoKern('kern', sep, expand(left, left_side=True), expand(right, left_side=False), **kwargs)
255267

256268
kern(150, ['/', '\\'], ['/', '\\'])
257269

@@ -274,10 +286,13 @@ def kern(sep, left, right, **kwargs):
274286
kern(220, all_chars, ['j'], minKern=35)
275287
# F/E are separated from T/J so they can use a tighter target gap.
276288
kern(130, ['F'], all_chars)
289+
kern(140, ['E'], ['V', 'W', 'Y'])
277290
kern(100, ['E'], all_chars)
278-
kern(150, ['T', 'J', 'T_T', 'T_O'], all_chars)
291+
kern(120, ['T', 'J'], ['R'])
292+
kern(150, ['T', 'J'], all_chars)
279293
# C: loosen from the default (was too tight for Ct/Cf/Cj).
280294
kern(65, ['C'], all_chars)
295+
kern(60, ['O'], all_chars)
281296

282297

283298
font = basic_font()
-21 Bytes
Loading

xkcd-script/samples/kerning.png

-65 Bytes
Loading

0 commit comments

Comments
 (0)