Skip to content

Instantly share code, notes, and snippets.

@frankrolf
Last active November 8, 2020 17:22
Show Gist options
  • Save frankrolf/766f80456d546b77e3ffb149871025d3 to your computer and use it in GitHub Desktop.
Save frankrolf/766f80456d546b77e3ffb149871025d3 to your computer and use it in GitHub Desktop.
Robofont script to validate segment structure across fonts
'''
Print out segment structure for current glyph in all open fonts.
If the structure matches, only one line will be printed:
a 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️ ✔
If it does not, the structure of all open fonts will be printed for comparison:
Caption 0 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Caption 1 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Caption 2 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Display 0 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Display 1 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Display 2 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Text 0 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Text 1 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
Text 2 0 ⤴️📈📈⤴️⤴️⤴️⤴️📈⤴️⤴️⤴️ 1 ⤴️📈⤴️⤴️📈⤴️⤴️⤴️⤴️📈📈⤴️⤴️📈📈⤴️
'''
def segment_structure(g):
'''
simple segment structure string for comparison
'''
structure = ''
for c_index, contour in enumerate(g.contours):
structure += f' {str(c_index)} '
for segment in contour.segments:
if len(segment) == 3:
structure += '⤴️'
else:
structure += '📈'
return structure.strip()
cg = CurrentGlyph()
a = AllFonts(sortOptions=['familyName', 'styleName'])
structure_set = []
style_names = []
for f in a:
g = f[cg.name]
structure_set.append(segment_structure(g))
style_names.append((len(f.info.styleName), f.info.styleName))
if len(set(structure_set)) > 1:
max_name = max(style_names)[0]
for f in a:
g = f[cg.name]
print(f.info.styleName.rjust(max_name), segment_structure(g))
else:
print(cg.name, structure_set[0], '✔')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment