mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-12 09:41:47 +02:00
font-patcher: Use list comprehension in refcheck
[why] List comprehension helps with readability. Also add comments that describe expected data structures of altuni and references. Also bump up the patcher version number. [how] Use list comprehension. Add comments. Change the version number.
This commit is contained in:
parent
46e2fcf00d
commit
e514906a9f
1 changed files with 15 additions and 8 deletions
23
font-patcher
23
font-patcher
|
@ -6,7 +6,7 @@
|
|||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Change the script version when you edit this script:
|
||||
script_version = "3.5.0"
|
||||
script_version = "3.5.1"
|
||||
|
||||
version = "2.3.0"
|
||||
projectName = "Nerd Fonts"
|
||||
|
@ -915,17 +915,24 @@ class font_patcher:
|
|||
def add_glyphrefs_to_essential(self, unicode):
|
||||
self.essential.add(unicode)
|
||||
# According to fontforge spec, altuni is either None or a tuple of tuples
|
||||
if self.sourceFont[unicode].altuni is not None:
|
||||
for r in self.sourceFont[unicode].altuni:
|
||||
# Those tuples contained in altuni are of the following "format":
|
||||
# (unicode-value, variation-selector, reserved-field)
|
||||
altuni = self.sourceFont[unicode].altuni
|
||||
if altuni is not None:
|
||||
for altcode in [ v for v, s, r in altuni if v >= 0 ]:
|
||||
# If alternate unicode already exists in self.essential,
|
||||
# that means it has gone through this function before.
|
||||
# Therefore we skip it to avoid infinite loop.
|
||||
# A unicode value of -1 basically means unused and is also worth skipping.
|
||||
if r[0] not in self.essential and r[0] >= 0:
|
||||
self.add_glyphrefs_to_essential(r[0])
|
||||
for r in self.sourceFont[unicode].references:
|
||||
if self.sourceFont[r[0]].unicode not in self.essential and self.sourceFont[r[0]].unicode >= 0:
|
||||
self.add_glyphrefs_to_essential(self.sourceFont[r[0]].unicode)
|
||||
if altcode not in self.essential:
|
||||
self.add_glyphrefs_to_essential(altcode)
|
||||
# From fontforge documentation:
|
||||
# glyph.references return a tuple of tuples containing, for each reference in foreground,
|
||||
# a glyph name, a transformation matrix, and whether the reference is currently selected.
|
||||
references = self.sourceFont[unicode].references
|
||||
for refcode in [ self.sourceFont[n].unicode for n, m, s in references ]:
|
||||
if refcode not in self.essential and refcode >= 0:
|
||||
self.add_glyphrefs_to_essential(refcode)
|
||||
|
||||
def get_essential_references(self):
|
||||
"""Find glyphs that are needed for the basic glyphs"""
|
||||
|
|
Loading…
Reference in a new issue