Get glyph by unicode char


#1

I thought I’ve seen in a blog post that it’s possible to get a glyph by its unicode char (something like Font.glyphs[u"ก"]) but I cannot find it, nor make it work anyhow. Did I just dream that?

Another thing: I usually encode my .py files with the # -*- coding: utf-8 -*- snippet, but I cannot make use of it in the Macro Panel, where I’d love to quickly sketch especially complex unicode handlings. This for example:

#-*- coding: utf-8 -*-
print u"ä" # >>> ä

But maybe I’m confusing things here. this works for example: print u'\u2713' # >>> ✓

Edit:
Ah, almost there. I can use repr() and ask font.glyphs by unicode …

this works:

print Font.glyphs[u'\u0e01'] # --> <GSGlyph "koKai-thai" with 1 layers>

this doesn’t:

x = u"ก"
print repr(x) # --> u'\u0e01'
print Font.glyphs[repr(x)] # --> None

#2

Works for me:


#3

Ah, this didn’t work, because I had a comment before the #-*- coding: utf-8 -*-

Anyway, I try to get the unicode from a char in order to get the corresponding glyph. And I can’t make it work as described above.

Edit:

I think now I got it:

x = u"ก"
Font.glyphs[unichr(ord(x))] # --> <GSGlyph "koKai-thai" with 1 layers>

#4

You likely saw mention of this in: https://docu.glyphsapp.com/index.html#GSFont.glyphs

And you should be able to simplify that to:

#-*- coding: utf-8 -*-
x = u"ก"
Font.glyphs[x]

#5

Exactly, but weirdly enough, of course this was the very first thing I tried before opening this thread and it didn’t work. And my “solution” is stupid anyway, it just converts the char back and forth :smiley:


#6

Sometimes it might help if you look into the implementation of the wrapper. The getItem method of the GlyphsProxy should give you some ideas.


#7

Yeah, I peek in there all the time =)
I think my environment is just too messy sometimes, you know different computers in different offices, different OS and Glyphs Versions, then such things like comments before the encoding declaration in some macro panel tab … it all adds up to confusion on my side. my bad. sorry.

But speaking of Macro Tabs: I’m probably the only one (and maybe @Tosche) who got more than 20 tabs in the Macro Panel. It would be amazing if you could scroll through the tabs if you got too many.

Currently I have to resize the window with the option key to a ridiculous size way off screen in order to access tab number 21+, and recently I wanted to clean up old scraps tabs, but after any Glyphs restart they where all there again each time, so I gave up cleaning those :smiley:


#8

Also I want Glyphs to assign Macro tabs proper numbers. I’ve got lots of Macro 7’s (some of them appear before 6).


#9

the macro tab names are assigned when you first open them (and the number is the count of the existing tabs).
You can change the tab names yourself:

idx = 0
for tab in Glyphs.delegate().macroPanelController().tabBarControl().tabItems():
	tab.setTitle_("Macro %s" % chr(idx + ord("A")))
	idx += 1