Skip to content
Merged
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.
3,212 changes: 1,630 additions & 1,582 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.
4 changes: 2 additions & 2 deletions xkcd-script/generator/pt2_character_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
U N A U T H O R I T A T I V E N E S S L EA T H E R B A R K I N T R A CO L I C M I CR OCH E L I A
O F F S I D ER G LA S S W EE D R O TT O L O A LB E R T I T E H ER M A T O RR H A C H I S
O R G A N O M E T A LL I C S E G R E G A T I ON I S T U N E V A N G E L I C CA M PS TO O L
+ - x * ! ? # @ $ % ¦ & ^ _ — – - ( ) [ ] { } / \ < > ÷ ± √ Σ
+ - × * ! ? # @ $ % ¦ & ^ _ — – - ( ) [ ] { } / \ < > ÷ ± √ Σ
1 2 3 4 5 6 7 8 9 0 ∫ = ≈ ≠ ~ ≤ ≥ |> <| 🎂 . , ; : “ H I ” ’ ‘ C A N ' T ' "
É Ò Å Ü ≪ ≫ ‽ Ē Ő “ ”
""".strip()
Expand All @@ -74,7 +74,7 @@ def merge(img1, img1_bbox, img2, img2_bbox):
shape = bbox[3] - bbox[1], bbox[2] - bbox[0], 3
img1_slice = [slice(img1_bbox[1] - bbox[1], img1_bbox[3] - bbox[1]),
slice(img1_bbox[0] - bbox[0], img1_bbox[2] - bbox[0])]

img2_slice = [slice(img2_bbox[1] - bbox[1], img2_bbox[3] - bbox[1]),
slice(img2_bbox[0] - bbox[0], img2_bbox[2] - bbox[0])]

Expand Down
55 changes: 40 additions & 15 deletions xkcd-script/generator/pt5_svg_to_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def create_char(font, chars, fname):

baseline_chars = ['a', 'e', 'm', 'A', 'E', 'M', '&', '@', '.', u'≪', u'É']
caps_chars = ['S', 'T', 'J', 'k', 't', 'l', 'b', 'd', '1', '2', u'3', u'≪', '?', '!']
exheight_chars = ['a', 'e', 'm']

line_stats = {}
for line, position, bbox, fname, chars in characters:
Expand All @@ -126,6 +127,8 @@ def create_char(font, chars, fname):
this_line.setdefault('baseline', []).append(bbox[3])
if char in caps_chars:
this_line.setdefault('cap-height', []).append(bbox[1])
if char in exheight_chars:
this_line.setdefault('x-height', []).append(bbox[1])


import numpy as np
Expand All @@ -137,9 +140,31 @@ def create_char(font, chars, fname):
_spans = {line: np.mean(s['baseline']) - np.mean(s['cap-height'])
for line, s in line_stats.items()
if 'baseline' in s and 'cap-height' in s}
_baselines = {line: np.mean(s['baseline'])
for line, s in line_stats.items()
if 'baseline' in s and 'cap-height' in s}
_top_ratio = 600 / (600 + 256)
_full_glyph_sizes = {line: span / _top_ratio for line, span in _spans.items()}
_median_full_glyph_size = np.median(list(_full_glyph_sizes.values()))
print(_spans)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the prints.

print({line: np.mean(s['baseline']) - np.mean(s['x-height'])
for line, s in line_stats.items()
if 'baseline' in s and 'x-height' in s})
print(_baselines)

# Adjust to be consistent with the subsequent per-line weight adjustment.
# changeWeight() seems to enlarge the stroke to the right and downward.
for line in line_stats.keys():
_line_fgs = _full_glyph_sizes.get(line)
if _line_fgs:
if _line_fgs > _median_full_glyph_size * 1.10:
_scale_correction = _line_fgs / _median_full_glyph_size
_estimated_stroke = 0.12 * 600
_delta = int(round(_estimated_stroke * (_scale_correction - 1)))
_delta *= _median_full_glyph_size / (600 + 256)
_spans[line] += _delta
_baselines[line] += _delta
# not yet for < 0.90 (pending)


def scale_glyph(char, char_bbox, baseline, cap_height):
Expand Down Expand Up @@ -206,11 +231,12 @@ def translate_glyph(c, char_bbox, cap_height, baseline):
t = psMat.translate(-glyph_bbox[0], -glyph_bbox[1] + ((baseline - char_bbox[3]) * c.font.em / full_glyph_size))
c.transform(t)

def pad_glyph(c):
# Put horizontal padding around the glyph. I choose a number here that looks reasonable,
# there are far more sophisticated means of doing this (like looking at the original image,
# and calculating how much space there should be).
space = 20
scaled_width = glyph_bbox[2] - glyph_bbox[0]
scaled_width = c.boundingBox()[2]
c.width = int(round(scaled_width + 2 * space))
t = psMat.translate(space, 0)
c.transform(t)
Expand Down Expand Up @@ -240,9 +266,9 @@ def charname(char):

# Per-character size scaling applied after changeWeight, to fine-tune individual glyphs
# that end up slightly too large despite correct stroke weight.
_per_char_size = {
('q',): 0.92,
('x',): 0.83,
_per_char_operation = {
('q',): psMat.compose(psMat.scale(0.92), psMat.translate(0, 20)),
('x',): psMat.translate(0, 20),
}

# Pick out particular glyphs that are more pleasant than their latter alternatives.
Expand All @@ -263,18 +289,15 @@ def charname(char):

c = create_char(font, chars, fname)

# Get the linestats for this character.
line_features = line_stats[line]

scale_glyph(
c, bbox,
baseline=np.mean(line_features['baseline']),
cap_height=np.mean(line_features['cap-height']))
baseline=_baselines[line],
cap_height=_baselines[line] - _spans[line])

translate_glyph(
c, bbox,
baseline=np.mean(line_features['baseline']),
cap_height=np.mean(line_features['cap-height']))
baseline=_baselines[line],
cap_height=_baselines[line] - _spans[line])

# Correct for lines written at a significantly different scale than the median.
# - Too large (fgs high): chars scaled down → thin strokes → fatten with changeWeight.
Expand Down Expand Up @@ -305,10 +328,12 @@ def charname(char):

# Per-character size adjustments: scale about the baseline (origin) to reduce
# overall size while preserving stroke weight gained from changeWeight above.
_size_scale = _per_char_size.get(chars)
if _size_scale is not None:
c.transform(psMat.scale(_size_scale))
c.width = int(round(c.width * _size_scale))
_operation_matrix = _per_char_operation.get(chars)
if _operation_matrix is not None:
c.transform(_operation_matrix)

# Apply padding afterward so that it is not affected by scaling.
pad_glyph(c)

# Simplify, then put the vertices on rounded coordinate positions.
c.simplify()
Expand Down
Binary file modified xkcd-script/samples/charmap_basic_latin.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 modified xkcd-script/samples/charmap_general_punctuation.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 modified xkcd-script/samples/charmap_greek_and_coptic.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 modified xkcd-script/samples/charmap_latin_1_supplement.png
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - multiplication was on my list (FYI I'm currently looking at all math symbols)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified xkcd-script/samples/charmap_latin_extended_a.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 modified xkcd-script/samples/charmap_latin_extended_additional.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 modified xkcd-script/samples/charmap_latin_extended_b.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 modified xkcd-script/samples/charmap_mathematical_operators.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 modified xkcd-script/samples/handwriting.png
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you should update handwriting.txt to have the multiplication symbol rather than the x.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified xkcd-script/samples/ipsum.png
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xe is still a bit close (or ex is too far appart)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified xkcd-script/samples/kerning.png
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good 👍

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading