Lookup letter glyphs by codepoint rather than name

Fonts usually let you look up the glyphs by name, but not always; all
they are *required* to support is lookup by codepoint. This fixes em
lookup and the www ligature on fonts that don't have nametables for
letter glyphs.

Fixes #16 and #21.
This commit is contained in:
Ben Kelly 2018-03-06 18:08:02 -05:00 committed by Ben Kelly
parent a37419e657
commit f98f3523bb
2 changed files with 8 additions and 3 deletions

View File

@ -19,7 +19,7 @@ ligatures = [
## These characters are also used by the ligatures, but are likely
## to look more out of place when spliced into another font.
# 'at', 'braceleft', 'braceright', 'bracketleft', 'bracketright',
# 'dollar', 'parenleft', 'parenright', 'underscore',
# 'dollar', 'parenleft', 'parenright', 'underscore', 'w'
],
'firacode_ligature_name': None,
},

View File

@ -75,7 +75,7 @@ class LigatureCreator(object):
# Scale firacode to correct em height.
self.firacode.em = self.font.em
self.emwidth = self.font['m'].width
self.emwidth = self.font[ord('m')].width
def copy_ligature_from_source(self, ligature_name):
try:
@ -184,6 +184,12 @@ class LigatureCreator(object):
self.font.addLookup(lookup_name(i), 'gsub_single', (), ())
self.font.addLookupSubtable(lookup_name(i), lookup_sub_name(i))
if char not in self.font:
# We assume here that this is because char is a single letter
# (e.g. 'w') rather than a character name, and the font we're
# editing doesn't have glyphnames for letters.
self.font[ord(char)].glyphname = char
if i < len(input_chars) - 1:
self.font.createChar(-1, cr_name(i))
self.font.selection.none()
@ -194,7 +200,6 @@ class LigatureCreator(object):
else:
self.font[char].addPosSub(lookup_sub_name(i), ligature_name)
calt_lookup_name = 'calt.{}'.format(self._lig_counter)
self.font.addLookup(calt_lookup_name, 'gsub_contextchain', (),
(('calt', (('DFLT', ('dflt',)),