Merge pull request #409 from googlefonts/ec

Add noflags and emojicompat variants
pull/412/head
Rod 2022-12-02 09:14:16 -08:00 committed by GitHub
commit 412b9edf8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 0 deletions

37
about_fonts.py 100644
View File

@ -0,0 +1,37 @@
"""Prints info about emoji fonts."""
from fontTools import ttLib
from pathlib import Path
import sys
NAME_ID_VERSION = 5
def name(font, name_id):
return ",".join(n.toUnicode() for n in font["name"].names if n.isUnicode() and n.nameID == name_id)
def main():
font_files = sorted(p for p in (Path(__file__).parent / "fonts").iterdir() if p.suffix == ".ttf")
max_name_len = max(len(p.name) for p in font_files)
for font_file in font_files:
font = ttLib.TTFont(font_file)
font_type = []
if "CBDT" in font:
font_type.append("CBDT")
if "COLR" in font:
font_type.append("COLR")
if "meta" in font and "Emji" in font["meta"].data:
font_type.append("EmojiCompat")
font_type.append(f"fontRevision:{font['head'].fontRevision:.3f}")
font_type.append(name(font, NAME_ID_VERSION))
font_type = ", ".join(font_type)
print(f"{font_file.name:{max_name_len + 1}} {font_type}")
if __name__ == '__main__':
main()

48
drop_flags.py 100644
View File

@ -0,0 +1,48 @@
"""Removes regional indicators from a font."""
from fontTools import subset
from fontTools import ttLib
import functools
from pathlib import Path
import sys
from typing import Set
def codepoints(font: ttLib.TTFont) -> Set[int]:
unicode_cmaps = (t.cmap.keys() for t in font['cmap'].tables if t.isUnicode())
return functools.reduce(lambda acc, u: acc | u, unicode_cmaps, set())
def is_regional_indicator(cp: int) -> bool:
return 0x1F1E6 <= cp <= 0x1F1FF
def main(argv):
for font_file in sorted(argv[1:]):
font_file = Path(font_file)
assert font_file.is_file(), font_file
noflags_file = font_file.with_stem(font_file.stem + "-noflags")
if noflags_file.is_file():
print(font_file, "already has", noflags_file, "; nop")
continue
font = ttLib.TTFont(font_file)
cps = codepoints(font)
cps_without_flags = {cp for cp in cps if not is_regional_indicator(cp)}
if cps == cps_without_flags:
print(font_file, "has no regional indicators")
continue
subsetter = subset.Subsetter()
subsetter.populate(unicodes=cps_without_flags)
subsetter.subset(font)
font.save(noflags_file)
print(font_file, "=>" , noflags_file)
if __name__ == '__main__':
main(sys.argv)

View File

@ -0,0 +1,36 @@
"""Set COLRv1 fontRevision from CBDT.
Used for bugfix, should fix to set properly on build instead.
"""
from fontTools import ttLib
from pathlib import Path
import sys
NAME_ID_VERSION = 5
def name(font, name_id):
return ",".join(n.toUnicode() for n in font["name"].names if n.isUnicode() and n.nameID == name_id)
def main():
colr_font_files = sorted(p for p in (Path(__file__).parent / "fonts").iterdir() if p.name.startswith("Noto-COLRv1"))
for colr_font_file in colr_font_files:
cbdt_font_file = colr_font_file.with_stem(colr_font_file.stem.replace("Noto-COLRv1", "NotoColorEmoji"))
colr_font = ttLib.TTFont(colr_font_file)
cbdt_font = ttLib.TTFont(cbdt_font_file)
assert "CBDT" in cbdt_font
assert "COLR" in colr_font
colr_font["head"].fontRevision = cbdt_font["head"].fontRevision
colr_font.save(colr_font_file)
if __name__ == '__main__':
main()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.