Created
July 26, 2018 11:23
-
-
Save anthrotype/2a1f6984c9cc873f8a84c7a664653d54 to your computer and use it in GitHub Desktop.
Sort glyphs in UFO by increasing Unicode codepoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Sort glyphs in UFO by increasing Unicode codepoint to try shrinking the | |
| size of the cmap table. | |
| """ | |
| import sys | |
| from defcon import Font | |
| try: | |
| font = Font(sys.argv[1]) | |
| except IndexError: | |
| sys.exit("usage: optimize_glyph_order.py FONT.ufo") | |
| # sort glyphs by increasing unicode codepoint; put unencoded glyphs last | |
| new_order = sorted( | |
| font.glyphOrder, | |
| key=lambda gn: font.unicodeData.unicodeForGlyphName(gn) or sys.maxsize, | |
| ) | |
| # ensure .notdef is first glyph, if present | |
| try: | |
| new_order.insert(0, new_order.pop(new_order.index(".notdef"))) | |
| except ValueError: | |
| pass | |
| font.glyphOrder = new_order | |
| font.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment