mirror of
https://github.com/googlefonts/noto-emoji.git
synced 2025-06-07 15:27:59 +00:00
Merge pull request #15 from googlefonts/catchup
Catch up with downstream
This commit is contained in:
commit
83d60b6b75
9 changed files with 131 additions and 0 deletions
37
about_fonts.py
Normal file
37
about_fonts.py
Normal 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()
|
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
|
48
drop_flags.py
Normal file
48
drop_flags.py
Normal 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)
|
36
fix_colr_font_revision.py
Normal file
36
fix_colr_font_revision.py
Normal 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()
|
BIN
fonts/Noto-COLRv1-emojicompat.ttf
Normal file
BIN
fonts/Noto-COLRv1-emojicompat.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
fonts/NotoColorEmoji-emojicompat.ttf
Normal file
BIN
fonts/NotoColorEmoji-emojicompat.ttf
Normal file
Binary file not shown.
BIN
fonts/NotoColorEmoji-noflags.ttf
Normal file
BIN
fonts/NotoColorEmoji-noflags.ttf
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue