Last active
February 9, 2022 00:35
-
-
Save connordavenport/a674c7b0c013df0a7e6438356679885d to your computer and use it in GitHub Desktop.
A start up script to simply access a glyph's script or unicode category
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
from mojo.roboFont import RGlyph | |
''' | |
A start up script to simply access a glyph's script or unicode category | |
for g in CurrentFont(): | print(CurrentGlyph().getScript()) | print(CurrentGlyph().getCat(verbose=True)) | |
print(g.getScript()) | | | |
| | | |
| | | |
>> Latin | >> Cyrillic | >> Ll : Letter (lowercase) | |
>> Latin | | | |
>> Common | | | |
>> Latin | | | |
>> Cyrillic | | | |
''' | |
catMap = {"Lu" : "Letter (uppercase)", | |
"Ll" : "Letter (lowercase)", | |
"Lt" : "Letter (titlecase)", | |
"Lm" : "Letter (modifier)", | |
"Lo" : "Letter (other)", | |
"Mn" : "Mark (nonspacing)", | |
"Mc" : "Mark (spacing combining)", | |
"Me" : "Mark (enclosing)", | |
"Nd" : "Number (decimal digit)", | |
"Nl" : "Number (letter)", | |
"No" : "Number (other)", | |
"Pc" : "Punctuation (connector)", | |
"Pd" : "Punctuation (dash)", | |
"Ps" : "Punctuation (open)", | |
"Pe" : "Punctuation (close)", | |
"Pi" : "Punctuation (initial quote)", | |
"Pf" : "Punctuation (final quote)", | |
"Po" : "Punctuation (other)", | |
"Sm" : "Symbol (math)", | |
"Sc" : "Symbol (currency)", | |
"Sk" : "Symbol (modifier)", | |
"So" : "Symbol (other)", | |
"Zs" : "Separator (space)", | |
"Zl" : "Separator (line)", | |
"Zp" : "Separator (paragraph)", | |
"Cc" : "Other (control)", | |
"Cf" : "Other (format)", | |
"Cs" : "Other (surrogate)", | |
"Co" : "Other (private use)", | |
"Cn" : "Other (not assigned)",} | |
def getScript(self): | |
naked = self.font.asDefcon() | |
return naked.unicodeData.scriptForGlyphName(self.name) | |
def getCat(self,verbose=False): | |
naked = self.font.asDefcon() | |
c = naked.unicodeData.categoryForGlyphName(self.name) | |
if verbose: | |
return f"{c} : {catMap.get(c)}" | |
else: | |
return c | |
RGlyph.getScript = getScript | |
RGlyph.getCat = getCat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment