# Which fonts have a glyph for each emoji code point. Usage: python3 cmap-check.py fontdir [fontdir ...]
# Part 1: fontconfig (what libass asks when the chosen font lacks a glyph). Part 2: the cmap table of every font file in the given folders.
import subprocess, sys, glob, os
from fontTools.ttLib import TTFont
cps = [(0x1F389, "party popper"), (0x2764, "red heart"), (0xFE0F, "variation selector-16"), (0x2705, "check mark button"), (0x1F525, "fire"),
       (0x1F44D, "thumbs up"), (0x1F3FD, "medium skin tone"), (0x1F468, "man"), (0x200D, "zero width joiner"), (0x61, "letter a (control)")]
print("fontconfig on this machine, fonts that cover each code point (family names):")
for cp, name in cps:
    r = subprocess.run(["fc-list", ":charset=%x" % cp, "family"], capture_output=True, text=True).stdout.split("\n")
    fams = sorted({x.split(",")[0].strip() for x in r if x.strip()})
    shown = fams if len(fams) <= 4 else fams[:3] + ["... %d families in all" % len(fams)]
    print("U+%04X %-22s | %d families | %s" % (cp, name, len(fams), "; ".join(shown) if fams else "NONE"))
print("\ncmap of the font files given:")
for d in sys.argv[1:]:
    for f in sorted(glob.glob(os.path.join(d, "*.ttf"))):
        cmap = TTFont(f, fontNumber=0).getBestCmap()
        print(os.path.basename(f), "|", " ".join("%X:%s" % (cp, "yes" if cp in cmap else "no") for cp, _ in cps))
