Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #MenuTitle: Lowercase
- # -*- coding: utf-8 -*-
- """Converts the selected text to lowercase."""
- 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 LowercaseString(String):
- LowerString = ""
- 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:]
- UpperGlyph = Font.glyphForName_(baseName)
- UpperString = u"%c" % int(UpperGlyph.unicode, 16)
- LowerUnicode = "%0.4X" % ord(UpperString.lower()[0])
- LowerGlyph = Font.glyphForUnicode_(LowerUnicode)
- if suffix is not None:
- LowerName = LowerGlyph.name + suffix
- LowerGlyph = Font.glyphForName_(LowerName)
- Char = unichr(Font.characterForGlyph_(LowerGlyph))
- except:
- pass
- LowerString += Char
- return LowerString
- LowerString = LowercaseString(String)
- TextStoreage.replaceCharactersInRange_withString_(Range, LowerString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement