Created
June 7, 2016 14:26
-
-
Save weiweihuanghuang/cfe36653a618e331898f42995fcb0b2e to your computer and use it in GitHub Desktop.
Get All Components
This file contains 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
#MenuTitle: Get All Components | |
# -*- coding: utf-8 -*- | |
"""Returns the selected text with all components available in each glyph""" | |
from AppKit import NSRange | |
Font = Glyphs.font | |
Doc = Glyphs.currentDocument | |
# Replace selected text | |
TextStoreage = Font.currentTab.graphicView().textStorage() | |
Range = TextStoreage.selectedRange() | |
editList = [] | |
for l in Font.selectedLayers: | |
editList += ["/%s" % l.parent.name] | |
if len(l.components)>0: | |
for c in l.components: | |
editList += ["/%s" % c.componentName] | |
# Remove duplicates | |
def f7(seq): | |
seen = set() | |
seen_add = seen.add | |
return [ x for x in seq if not (x in seen or seen_add(x))] | |
editList = f7(editList) | |
# Sort editList according to file order | |
# editList = ["/%s" % g.name for g in thisFont.glyphs if "/%s" % g.name in editList] | |
editString = "".join(editList) | |
# Convert text string into character string | |
charString = Font.charStringFromDisplayString_(editString) | |
TextStoreage.replaceCharactersInRange_withString_(Range, charString) | |
# Set cursor at start of TextStorage | |
TextStoreage.setSelectedRange_(NSRange(0,0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment