Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #MenuTitle: Lowercase
  2. # -*- coding: utf-8 -*-
  3. """Converts the selected text to lowercase."""
  4.  
  5. Doc = Glyphs.currentDocument
  6. Font = Glyphs.font
  7. Doc = Glyphs.currentDocument
  8. TextStoreage = Doc.windowController().activeEditViewController().graphicView().textStorage()
  9. String = TextStoreage.text().string()
  10. Range = TextStoreage.selectedRange()
  11. if Range.length == 0:
  12. Range.length = 1
  13.  
  14. # or if you pefer to replace the hole sting if nothing is selected:
  15. if Range.length == 0:
  16. Range.location = 0
  17. Range.length = len(String)
  18.  
  19. String = String.substringWithRange_(Range)
  20.  
  21. def LowercaseString(String):
  22. LowerString = ""
  23. for Char in String:
  24. g = Font.glyphForCharacter_(ord(Char))
  25. try:
  26. if ord(Char) > ord(' '):
  27. name = g.name
  28. baseName = name
  29. suffix = None
  30. periodPos = baseName.find(".")
  31. if periodPos > 0:
  32. baseName = name[:periodPos]
  33. suffix = name[periodPos:]
  34. UpperGlyph = Font.glyphForName_(baseName)
  35. UpperString = u"%c" % int(UpperGlyph.unicode, 16)
  36. LowerUnicode = "%0.4X" % ord(UpperString.lower()[0])
  37. LowerGlyph = Font.glyphForUnicode_(LowerUnicode)
  38. if suffix is not None:
  39. LowerName = LowerGlyph.name + suffix
  40. LowerGlyph = Font.glyphForName_(LowerName)
  41. Char = unichr(Font.characterForGlyph_(LowerGlyph))
  42. except:
  43. pass
  44. LowerString += Char
  45. return LowerString
  46.  
  47. LowerString = LowercaseString(String)
  48. TextStoreage.replaceCharactersInRange_withString_(Range, LowerString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement