Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions Google Fonts/decompose-transformed-components.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
#MenuTitle: Decompose Transformed Components
#MenuTitle: Decompose Transformed Components (Including Brace/Bracket Layers)
"""TTFautohint doesn't like components which have been flipped"""

def find_transformed_component_glyphs(font):
found = set()
for idx, master in enumerate(font.masters):
for glyph in font.glyphs:
components = glyph.layers[idx].components
for comp in components:
if sum(comp.scale) != 2.0:
found.add(glyph.name)
if comp.rotation != 0.0:
found.add(glyph.name)
return found

bad_components = []
bad_components_ls = []

def check_for_only_one_comp(glyph):
for thisLayer in glyph.layers:
for thisComponent in thisLayer.components:
if sum(thisComponent.scale) != 2.0:
print glyph
bad_components.append(glyph)
bad_components_ls.append(glyph.name)
return
elif thisComponent.rotation != 0.0:
print glyph
bad_components.append(glyph)
bad_components_ls.append(glyph.name)
return

def find_transformed_component_glyphs(font):
for thisGlyph in font.glyphs:
check_for_only_one_comp(thisGlyph)

def main():
font = Glyphs.font
bad_components = find_transformed_component_glyphs(font)
find_transformed_component_glyphs(font)
if not bad_components:
print "Skipping. No transformed components"
return
tabString = "/"+"/".join(bad_components_ls)
font.newTab(tabString)

for idx, master in enumerate(font.masters):
for name in bad_components:

for thisGlyph in bad_components:
for thisLayer in thisGlyph.layers:
print thisLayer
print "Decomposing transformed %s in %s" % (
name, master.name
thisGlyph, thisLayer
)
font.glyphs[name].layers[idx].decomposeComponents()
thisLayer.decomposeComponents()
thisLayer.correctPathDirection()


if __name__ == "__main__":
main()