Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ctrlcctrlv/94d0f69358aa1b8dd4e1939697b66703 to your computer and use it in GitHub Desktop.

Select an option

Save ctrlcctrlv/94d0f69358aa1b8dd4e1939697b66703 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# If you have a font that you've already added A-Z smallcaps to, and it has a bunch of precombined characters (e.g. İ, Ĵ, Ṡ, Ẅ), this script will select candidates for automatic building of precombined small caps via «Element→Style→Add Small Capitals…» in FontForge.
import fontforge
import unicodedata
import sys
import string
f = fontforge.activeFont()
f.selection.none()
def decompose(udd):
if any(["<" in c for c in udd]):
return []
r = [chr(int(c, 16)) for c in udd.split()]
return r
to_select = list()
for g in f.glyphs():
try:
u = chr(g.unicode)
except ValueError:
continue
c = unicodedata.category(u)
d = decompose(unicodedata.decomposition(u))
if not c.startswith("L"):
continue
if u.upper() == u and len(d) > 0 and d[0] in string.ascii_uppercase:
to_select.append(g)
f.selection.select(*to_select, ("more",))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment