Correctly handle glyph widths when patching fonts

This commit is contained in:
Kim Silkebækken 2012-12-18 22:28:27 +01:00
parent 7c1d48a2fd
commit e5f5df8a12
1 changed files with 7 additions and 0 deletions

View File

@ -52,6 +52,7 @@ class FontPatcher(object):
source_bb = source_font['block'].boundingBox()
target_bb = [0, 0, 0, 0]
target_font_width = 0
# Find the biggest char width and height in the Latin-1 extended range and the box drawing range
# This isn't ideal, but it works fairly well - some fonts may need tuning after patching
@ -61,6 +62,9 @@ class FontPatcher(object):
except TypeError:
continue
if not target_font_width:
target_font_width = target_font[cp].width
if bbox[0] < target_bb[0]:
target_bb[0] = bbox[0]
if bbox[1] < target_bb[1]:
@ -99,6 +103,9 @@ class FontPatcher(object):
# Transform the glyph
target_font.transform(transform)
# Reset the font's glyph width so it's still considered monospaced
target_font[source_glyph.unicode].width = target_font_width
target_font.em = target_font_em_original
# Generate patched font