Improve font patcher

For some reason the font patcher doesn't work well unless the target
font has an em size of 2048 while the font is being patched. This patch
also improves font patching in general, due to the more correct
calculation of font metrics.

Refs #14.
This commit is contained in:
Kim Silkebækken 2012-12-18 22:05:28 +01:00
parent def9091662
commit 7c1d48a2fd
1 changed files with 6 additions and 2 deletions

View File

@ -37,6 +37,9 @@ class FontPatcher(object):
for target_font in self.target_fonts:
source_font = self.source_font
target_font_em_original = target_font.em
target_font.em = 2048
target_font.encoding = 'ISO10646'
# Rename font
@ -74,8 +77,7 @@ class FontPatcher(object):
# Find source and target midpoints for translating
x_diff = target_bb[0] - source_bb[0]
y_diff = (target_bb[3] + target_bb[1]) - (source_bb[3] + source_bb[1])
y_diff = target_bb[1] - source_bb[1]
translate = psMat.translate(x_diff, y_diff)
transform = psMat.compose(scale, translate)
@ -97,6 +99,8 @@ class FontPatcher(object):
# Transform the glyph
target_font.transform(transform)
target_font.em = target_font_em_original
# Generate patched font
target_font.generate('{0}.otf'.format(target_font.fullname))