googlefonts / glyphsLib

A bridge from Glyphs source files (.glyphs) to UFOs
Apache License 2.0
178 stars 51 forks source link

Getting script of glyph #936

Closed georgeyjm closed 10 months ago

georgeyjm commented 10 months ago

I am trying to get the script by a glyph's unicode value. It seems like this is not yet supported, and accessing the property GSGlyph.script always returns None. But I'm not completely sure if this is indeed the case. If so, I will try to fill this part in.

anthrotype commented 10 months ago

a GSGlyph.script is None by default, it's purpose is to allow one to override the default script definition for a specific glyph (via the CTRL+OPTION+I panel). The default script for a given glyph name is stored in the GlyphData.xml, and accessible from glyphsLib by looking up the glyph name with e.g. data = glyphsLib.glyphdata.get_glyph("A"); assert data.script == "latin"

anthrotype commented 10 months ago

get the script by a glyph's unicode value

you can try to query the glyph database directly using the unicode value (as hexadecimal string), e.g.:

>>> from glyphsLib.glyphdata import GLYPHDATA
>>> GLYPHDATA.unicodes.get("0061")
{'unicode': '0061',
 'name': 'a',
 'category': 'Letter',
 'subCategory': 'Lowercase',
 'script': 'latin',
 'description': 'LATIN SMALL LETTER A'}
>>> GLYPHDATA.unicodes.get("0061")["script"]
'latin'
>>> GLYPHDATA.unicodes.get("104A3")["script"]
'osmanya'
georgeyjm commented 10 months ago

a GSGlyph.script is None by default, it's purpose is to allow one to override the default script definition for a specific glyph (via the CTRL+OPTION+I panel). The default script for a given glyph name is stored in the GlyphData.xml, and accessible from glyphsLib by looking up the glyph name with e.g. data = glyphsLib.glyphdata.get_glyph("A"); assert data.script == "latin"

Thanks a lot! I thought GSGlyph.script being defaulted to None meant it was not implemented yet. This is super helpful!