Skip to content

Instantly share code, notes, and snippets.

@schriftgestalt
Created October 13, 2014 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save schriftgestalt/2f5134d955229f63402a to your computer and use it in GitHub Desktop.
Save schriftgestalt/2f5134d955229f63402a to your computer and use it in GitHub Desktop.
Covert text to Uppercase for Glyphs App
#MenuTitle: Uppercase
# -*- coding: utf-8 -*-
"""Converts the selected text to upppercase."""
Doc = Glyphs.currentDocument
Font = Glyphs.font
Doc = Glyphs.currentDocument
TextStoreage = Doc.windowController().activeEditViewController().graphicView().textStorage()
String = TextStoreage.text().string()
Range = TextStoreage.selectedRange()
if Range.length == 0:
Range.length = 1
# or if you pefer to replace the hole sting if nothing is selected:
#if Range.length == 0:
# Range.location = 0
# Range.length = len(String)
String = String.substringWithRange_(Range)
def UppercaseString(String):
UpperString = ""
for Char in String:
g = Font.glyphForCharacter_(ord(Char))
try:
if ord(Char) > ord(' '):
name = g.name
baseName = name
suffix = None
periodPos = baseName.find(".")
if periodPos > 0:
baseName = name[:periodPos]
suffix = name[periodPos:]
LowerGlyph = Font.glyphForName_(baseName)
LowerString = u"%c" % int(LowerGlyph.unicode, 16)
UpperUnicode = "%0.4X" % ord(LowerString.upper()[0])
UpperGlyph = Font.glyphForUnicode_(UpperUnicode)
if suffix is not None:
UpperName = UpperGlyph.name + suffix
UpperGlyph = Font.glyphForName_(UpperName)
Char = unichr(Font.characterForGlyph_(UpperGlyph))
except:
pass
UpperString += Char
return UpperString
UpperString = UppercaseString(String)
TextStoreage.replaceCharactersInRange_withString_(Range, UpperString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment