removeGlyphs.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. for f in AllFonts():
  2. #f = CurrentFont()
  3. # copy space-separated glyph names here
  4. glyphsToRemove = "Agrave Aacute Acircumflex Atilde Adieresis Aring Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex Idieresis Ntilde Ograve Oacute Ocircumflex Otilde Odieresis Ugrave Uacute Ucircumflex Udieresis Yacute agrave aacute acircumflex atilde adieresis aring ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex idieresis ntilde ograve oacute ocircumflex otilde odieresis ugrave uacute ucircumflex udieresis yacute ydieresis Amacron amacron Abreve abreve Cacute cacute Ccircumflex ccircumflex uni010A Cdotaccent uni010B cdotaccent Ccaron ccaron Dcaron Emacron emacron Ebreve ebreve Edotaccent edotaccent Ecaron ecaron Gcircumflex gcircumflex Gbreve gbreve uni0120 Gdotaccent uni0121 gdotaccent Gcommaaccent gcommaaccent Hcircumflex hcircumflex Itilde itilde Imacron imacron Ibreve ibreve Idotaccent Jcircumflex jcircumflex Kcommaaccent kcommaaccent Lacute lacute Lcommaaccent lcommaaccent Nacute nacute Ncommaaccent ncommaaccent Ncaron ncaron Omacron omacron Obreve obreve Ohungarumlaut ohungarumlaut Racute racute Rcommaaccent rcommaaccent Rcaron rcaron Sacute sacute Scircumflex scircumflex Scedilla scedilla Scaron scaron uni0162 Tcedilla uni0163 tcedilla Tcaron Utilde utilde Umacron umacron Ubreve ubreve Uring uring Uhungarumlaut uhungarumlaut Wcircumflex wcircumflex Ycircumflex ycircumflex Ydieresis Zacute zacute Zdotaccent zdotaccent Zcaron zcaron Gcaron gcaron AEacute aeacute Oslashacute oslashacute uni0218 Scommaaccent uni0219 scommaaccent uni021A Tcommaaccent uni021B tcommaaccent Ymacron uni0232 ymacron uni0233 Wgrave wgrave Wacute wacute Wdieresis wdieresis Ygrave ygrave"
  5. # glyphsToRemove = "Cacute cacute"
  6. # clean up the rest of the data
  7. for glyphToRemove in glyphsToRemove.split(" "):
  8. # # remove from keys
  9. # if glyphToRemove in f.keys():
  10. # del f[glyphToRemove]
  11. # # remove from glyphOrder
  12. # for glyphName in f.glyphOrder:
  13. # if glyphName == glyphToRemove:
  14. # del f.glyphOrder[glyphName]
  15. # GROUPS ------------------------------------------------------------
  16. # iterate over all groups in the font
  17. for groupName in f.groups.keys():
  18. # get the group
  19. group = f.groups[groupName]
  20. groupList = list(f.groups[groupName])
  21. # if glyph is in the group, remove it
  22. if glyphToRemove in group:
  23. print('removing %s from group %s...' % (glyphToRemove, groupName))
  24. groupList.remove(glyphToRemove)
  25. f.groups[groupName] = tuple(groupList)
  26. # KERNING -----------------------------------------------------------
  27. # iterate over all kerning pairs in the font
  28. for kerningPair in f.kerning.keys():
  29. # if glyph is in the kerning pair, remove it
  30. if glyphToRemove in kerningPair:
  31. print('removing kerning pair (%s, %s)...' % kerningPair)
  32. del f.kerning[kerningPair]
  33. # COMPONENTS --------------------------------------------------------
  34. # iterate over all glyphs in the font
  35. for glyph in f:
  36. # skip glyphs which don’t have components
  37. if not glyph.components:
  38. continue
  39. # iterate over all components in glyph
  40. for component in glyph.components:
  41. # if the base glyph is the glyph to be removed
  42. if component.baseGlyph == glyphToRemove:
  43. # delete the component
  44. glyph.removeComponent(component)
  45. f.save()