Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified xkcd-script/font/xkcd-script.otf
Binary file not shown.
2,427 changes: 1,327 additions & 1,100 deletions xkcd-script/font/xkcd-script.sfd

Large diffs are not rendered by default.

Binary file modified xkcd-script/font/xkcd-script.ttf
Binary file not shown.
Binary file modified xkcd-script/font/xkcd-script.woff
Binary file not shown.
12 changes: 12 additions & 0 deletions xkcd-script/generator/pt2_character_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ def merge(img1, img1_bbox, img2, img2_bbox):



_LIGATURE_SOURCES = [
(5, 4, 5, 'TH'), # UNAUTHORITATIVENESS: T + H
(5, 31, 32, 'TR'), # INTRACOLIC: T + R
(6, 24, 25, 'TI'), # ALBERTITE: T + I
]
for line_no, left_no, right_no, lig in _LIGATURE_SOURCES:
_, left_bbox, left_img = characters_by_line[line_no][left_no]
_, right_bbox, right_img = characters_by_line[line_no][right_no]
lig_img, lig_bbox = merge(left_img, left_bbox, right_img, right_bbox)
characters_by_line[line_no].append([lig, lig_bbox, lig_img])


import skimage.io

if not os.path.isdir('../generated/characters'):
Expand Down
62 changes: 62 additions & 0 deletions xkcd-script/samples/gen_ligatures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""Validate expected ligatures against the built OTF and emit preview text."""
import os
import sys

from fontTools.ttLib import TTFont

HERE = os.path.dirname(os.path.abspath(__file__))
OTF = os.path.join(HERE, '../font/xkcd-script.otf')

# (display_text, input_glyph_sequence)
EXPECTED = [
('co', ('c', 'o')),
('oo', ('o', 'o')),
('EA', ('E', 'A')),
('CO', ('C', 'O')),
('CR', ('C', 'R')),
('OCH', ('O', 'C', 'H')),
('TH', ('T', 'H')),
('TR', ('T', 'R')),
('TI', ('T', 'I')),
('EE', ('E', 'E')),
('TT', ('T', 'T')),
('LB', ('L', 'B')),
('ER', ('E', 'R')),
('RR', ('R', 'R')),
('LA', ('L', 'A')),
('LL', ('L', 'L')),
('ON', ('O', 'N')),
('CA', ('C', 'A')),
('PS', ('P', 'S')),
('TO', ('T', 'O')),
('|>', ('bar', 'greater')),
('<|', ('less', 'bar')),
('I-pronoun', ('I', 'hyphen', 'p', 'r', 'o', 'n', 'o', 'u', 'n')),
]

tt = TTFont(OTF)
gsub = tt['GSUB'].table

ligatures = set()
for record in gsub.FeatureList.FeatureRecord:
if record.FeatureTag != 'liga':
continue
for idx in record.Feature.LookupListIndex:
lookup = gsub.LookupList.Lookup[idx]
if lookup.LookupType != 4:
continue
for sub in lookup.SubTable:
for first, ligset in sub.ligatures.items():
for lig in ligset:
ligatures.add((first,) + tuple(lig.Component))

expected_seqs = {seq for _, seq in EXPECTED}
uncovered = sorted(str(seq) for seq in ligatures if seq not in expected_seqs)
if uncovered:
sys.exit('ERROR: font ligatures not in EXPECTED — add to gen_ligatures.py:\n' + '\n'.join(uncovered))

cols = 6
tokens = [display for display, _ in EXPECTED]
rows = [tokens[i:i + cols] for i in range(0, len(tokens), cols)]
print('Ligatures:\n' + '\n'.join(' ' + ' '.join(row) for row in rows))
Binary file modified xkcd-script/samples/handwriting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added xkcd-script/samples/ligatures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions xkcd-script/samples/preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ ${RUN_CTXT} convert -strip ${NAME}.pgm ${NAME}.png
${RUN_CTXT} rm ${NAME}.pgm


NAME=ligatures
CONTENT=$(${RUN_CTXT} python3 gen_ligatures.py) || exit 1
${SIMPLE_CTXT} -o ${NAME}.pgm --text "${CONTENT}"
${RUN_CTXT} convert -strip ${NAME}.pgm ${NAME}.png
${RUN_CTXT} rm ${NAME}.pgm


if [ "$?" == "141" ] ; then
# Unexplained exit code from the handwriting sample.
exit 0
Expand Down
Loading