Skip to content

Commit

Permalink
Merge pull request #15 from googlefonts/catchup
Browse files Browse the repository at this point in the history
Catch up with downstream
  • Loading branch information
rsheeter authored Nov 17, 2023
2 parents f826707 + 934a570 commit 83d60b6
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 0 deletions.
37 changes: 37 additions & 0 deletions about_fonts.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 10 additions & 0 deletions colrv1_postproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ def _add_fallback_subs_for_unknown_flags(colr_font):
font_data.delete_from_cmap(colr_font, [UNKNOWN_FLAG_PUA])


def _set_no_font_embedding_restrictions(colr_font):
# The CBDT/CBLC NotoColorEmoji has OS/2.fsType = 0 (i.e. no embedding restrictions)
# so the COLRv1 variant must also have no such restrictions.
# https://github.com/notofonts/noto-fonts/issues/2408
# https://github.com/google/fonts/issues/5729
colr_font["OS/2"].fsType = 0


def _font(path, check_fn, check_fail_str):
assert path.is_file(), path
font = ttLib.TTFont(path)
Expand Down Expand Up @@ -314,6 +322,8 @@ def main(_):

_add_fallback_subs_for_unknown_flags(colr_font)

_set_no_font_embedding_restrictions(colr_font)

print("Writing", colr_file)
colr_font.save(colr_file)

Expand Down
48 changes: 48 additions & 0 deletions drop_flags.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions fix_colr_font_revision.py
Original file line number Diff line number Diff line change
@@ -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 added fonts/Noto-COLRv1-emojicompat.ttf
Binary file not shown.
Binary file modified fonts/Noto-COLRv1-noflags.ttf
Binary file not shown.
Binary file modified fonts/Noto-COLRv1.ttf
Binary file not shown.
Binary file added fonts/NotoColorEmoji-emojicompat.ttf
Binary file not shown.
Binary file added fonts/NotoColorEmoji-noflags.ttf
Binary file not shown.

0 comments on commit 83d60b6

Please sign in to comment.