mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-19 09:51:48 +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
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
|
||||||
# Change the script version when you edit this script:
|
# Change the script version when you edit this script:
|
||||||
script_version = "3.5.0"
|
script_version = "3.5.1"
|
||||||
|
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
projectName = "Nerd Fonts"
|
projectName = "Nerd Fonts"
|
||||||
|
@ -915,17 +915,24 @@ class font_patcher:
|
||||||
def add_glyphrefs_to_essential(self, unicode):
|
def add_glyphrefs_to_essential(self, unicode):
|
||||||
self.essential.add(unicode)
|
self.essential.add(unicode)
|
||||||
# According to fontforge spec, altuni is either None or a tuple of tuples
|
# According to fontforge spec, altuni is either None or a tuple of tuples
|
||||||
if self.sourceFont[unicode].altuni is not None:
|
# Those tuples contained in altuni are of the following "format":
|
||||||
for r in self.sourceFont[unicode].altuni:
|
# (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,
|
# If alternate unicode already exists in self.essential,
|
||||||
# that means it has gone through this function before.
|
# that means it has gone through this function before.
|
||||||
# Therefore we skip it to avoid infinite loop.
|
# Therefore we skip it to avoid infinite loop.
|
||||||
# A unicode value of -1 basically means unused and is also worth skipping.
|
# A unicode value of -1 basically means unused and is also worth skipping.
|
||||||
if r[0] not in self.essential and r[0] >= 0:
|
if altcode not in self.essential:
|
||||||
self.add_glyphrefs_to_essential(r[0])
|
self.add_glyphrefs_to_essential(altcode)
|
||||||
for r in self.sourceFont[unicode].references:
|
# From fontforge documentation:
|
||||||
if self.sourceFont[r[0]].unicode not in self.essential and self.sourceFont[r[0]].unicode >= 0:
|
# glyph.references return a tuple of tuples containing, for each reference in foreground,
|
||||||
self.add_glyphrefs_to_essential(self.sourceFont[r[0]].unicode)
|
# 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):
|
def get_essential_references(self):
|
||||||
"""Find glyphs that are needed for the basic glyphs"""
|
"""Find glyphs that are needed for the basic glyphs"""
|
||||||
|
|
Loading…
Reference in a new issue