mirror of
https://github.com/ToxicFrog/Ligaturizer.git
synced 2024-09-11 09:55:47 +03:00
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:
parent
a37419e657
commit
f98f3523bb
@ -19,7 +19,7 @@ ligatures = [
|
|||||||
## These characters are also used by the ligatures, but are likely
|
## These characters are also used by the ligatures, but are likely
|
||||||
## to look more out of place when spliced into another font.
|
## to look more out of place when spliced into another font.
|
||||||
# 'at', 'braceleft', 'braceright', 'bracketleft', 'bracketright',
|
# 'at', 'braceleft', 'braceright', 'bracketleft', 'bracketright',
|
||||||
# 'dollar', 'parenleft', 'parenright', 'underscore',
|
# 'dollar', 'parenleft', 'parenright', 'underscore', 'w'
|
||||||
],
|
],
|
||||||
'firacode_ligature_name': None,
|
'firacode_ligature_name': None,
|
||||||
},
|
},
|
||||||
|
@ -75,7 +75,7 @@ class LigatureCreator(object):
|
|||||||
|
|
||||||
# Scale firacode to correct em height.
|
# Scale firacode to correct em height.
|
||||||
self.firacode.em = self.font.em
|
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):
|
def copy_ligature_from_source(self, ligature_name):
|
||||||
try:
|
try:
|
||||||
@ -184,6 +184,12 @@ class LigatureCreator(object):
|
|||||||
self.font.addLookup(lookup_name(i), 'gsub_single', (), ())
|
self.font.addLookup(lookup_name(i), 'gsub_single', (), ())
|
||||||
self.font.addLookupSubtable(lookup_name(i), lookup_sub_name(i))
|
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:
|
if i < len(input_chars) - 1:
|
||||||
self.font.createChar(-1, cr_name(i))
|
self.font.createChar(-1, cr_name(i))
|
||||||
self.font.selection.none()
|
self.font.selection.none()
|
||||||
@ -194,7 +200,6 @@ class LigatureCreator(object):
|
|||||||
else:
|
else:
|
||||||
self.font[char].addPosSub(lookup_sub_name(i), ligature_name)
|
self.font[char].addPosSub(lookup_sub_name(i), ligature_name)
|
||||||
|
|
||||||
|
|
||||||
calt_lookup_name = 'calt.{}'.format(self._lig_counter)
|
calt_lookup_name = 'calt.{}'.format(self._lig_counter)
|
||||||
self.font.addLookup(calt_lookup_name, 'gsub_contextchain', (),
|
self.font.addLookup(calt_lookup_name, 'gsub_contextchain', (),
|
||||||
(('calt', (('DFLT', ('dflt',)),
|
(('calt', (('DFLT', ('dflt',)),
|
||||||
|
Loading…
Reference in New Issue
Block a user