mirror of
https://github.com/googlefonts/noto-emoji.git
synced 2025-06-07 15:27:59 +00:00
Flags-only name values
This commit is contained in:
parent
797dbcf1ff
commit
8eb7491de6
4 changed files with 87 additions and 7 deletions
1
BUILD.md
1
BUILD.md
|
@ -62,4 +62,5 @@ $ emojicompat --op check --font Noto-COLRv1-emojicompat.ttf
|
||||||
$ hb-subset --unicodes-file=flags-only-unicodes.txt \
|
$ hb-subset --unicodes-file=flags-only-unicodes.txt \
|
||||||
--output-file=fonts/NotoColorEmoji-flagsonly.ttf \
|
--output-file=fonts/NotoColorEmoji-flagsonly.ttf \
|
||||||
fonts/NotoColorEmoji.ttf
|
fonts/NotoColorEmoji.ttf
|
||||||
|
$ python update_flag_name.py
|
||||||
```
|
```
|
Binary file not shown.
|
@ -3,11 +3,18 @@ from pathlib import Path
|
||||||
import pytest
|
import pytest
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
NAME_ID_FAMILY = 1
|
||||||
|
NAME_ID_UNIQUE_ID = 3
|
||||||
|
NAME_ID_FULLNAME = 4
|
||||||
|
NAME_ID_POSTSCRIPT_NAME = 6
|
||||||
|
|
||||||
|
|
||||||
def test_consistent_version():
|
def test_consistent_version():
|
||||||
fonts_dir = Path("fonts")
|
fonts_dir = Path("fonts")
|
||||||
assert fonts_dir.is_dir()
|
assert fonts_dir.is_dir()
|
||||||
|
|
||||||
name5_re = re.compile(r'^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$')
|
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$")
|
||||||
|
|
||||||
debug_versions = []
|
debug_versions = []
|
||||||
versions = set()
|
versions = set()
|
||||||
|
@ -16,7 +23,7 @@ def test_consistent_version():
|
||||||
head_ver = f"{font['head'].fontRevision:.03f}"
|
head_ver = f"{font['head'].fontRevision:.03f}"
|
||||||
versions.add(head_ver)
|
versions.add(head_ver)
|
||||||
debug_versions.append(f"{font_file.name} head {head_ver}")
|
debug_versions.append(f"{font_file.name} head {head_ver}")
|
||||||
for name in font['name'].names:
|
for name in font["name"].names:
|
||||||
# name 5 is version
|
# name 5 is version
|
||||||
if name.nameID != 5:
|
if name.nameID != 5:
|
||||||
continue
|
continue
|
||||||
|
@ -27,32 +34,68 @@ def test_consistent_version():
|
||||||
versions.add(match.group(1))
|
versions.add(match.group(1))
|
||||||
debug_versions.append(f"{font_file.name} name {match.group(1)}")
|
debug_versions.append(f"{font_file.name} name {match.group(1)}")
|
||||||
debug_versions = "\n".join(debug_versions)
|
debug_versions = "\n".join(debug_versions)
|
||||||
assert len(versions) == 1, f"Should have a consistent version, found\n{debug_versions}"
|
assert (
|
||||||
|
len(versions) == 1
|
||||||
|
), f"Should have a consistent version, found\n{debug_versions}"
|
||||||
|
|
||||||
|
|
||||||
def test_consistent_fstype():
|
def test_consistent_fstype():
|
||||||
fonts_dir = Path("fonts")
|
fonts_dir = Path("fonts")
|
||||||
assert fonts_dir.is_dir()
|
assert fonts_dir.is_dir()
|
||||||
|
|
||||||
name5_re = re.compile(r'^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$')
|
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$")
|
||||||
|
|
||||||
debug_fstypes = []
|
debug_fstypes = []
|
||||||
fstypes = set()
|
fstypes = set()
|
||||||
for font_file in fonts_dir.rglob("*.ttf"):
|
for font_file in fonts_dir.rglob("*.ttf"):
|
||||||
font = ttLib.TTFont(font_file)
|
font = ttLib.TTFont(font_file)
|
||||||
fstype = font['OS/2'].fsType
|
fstype = font["OS/2"].fsType
|
||||||
fstypes.add(fstype)
|
fstypes.add(fstype)
|
||||||
debug_fstypes.append(f"{font_file.name} fsType {fstype}")
|
debug_fstypes.append(f"{font_file.name} fsType {fstype}")
|
||||||
debug_fstypes = "\n".join(debug_fstypes)
|
debug_fstypes = "\n".join(debug_fstypes)
|
||||||
assert fstypes == {0}, f"All fsType's should be 0, found\n{debug_fstypes}"
|
assert fstypes == {0}, f"All fsType's should be 0, found\n{debug_fstypes}"
|
||||||
|
|
||||||
|
|
||||||
def test_has_emojicompat():
|
def test_has_emojicompat():
|
||||||
fonts_dir = Path("fonts")
|
fonts_dir = Path("fonts")
|
||||||
assert fonts_dir.is_dir()
|
assert fonts_dir.is_dir()
|
||||||
|
|
||||||
ec_fonts = set(fonts_dir.rglob("*-emojicompat.ttf"))
|
ec_fonts = set(fonts_dir.rglob("*-emojicompat.ttf"))
|
||||||
assert {f.name for f in ec_fonts} == {"Noto-COLRv1-emojicompat.ttf", "NotoColorEmoji-emojicompat.ttf"}
|
assert {f.name for f in ec_fonts} == {
|
||||||
|
"Noto-COLRv1-emojicompat.ttf",
|
||||||
|
"NotoColorEmoji-emojicompat.ttf",
|
||||||
|
}
|
||||||
|
|
||||||
for font_file in ec_fonts:
|
for font_file in ec_fonts:
|
||||||
font = ttLib.TTFont(font_file)
|
font = ttLib.TTFont(font_file)
|
||||||
assert "meta" in font, f"{font_file.name} should have a meta table"
|
assert "meta" in font, f"{font_file.name} should have a meta table"
|
||||||
assert "Emji" in font["meta"].data, f"{font_file.name} should have emojicompat data"
|
assert (
|
||||||
|
"Emji" in font["meta"].data
|
||||||
|
), f"{font_file.name} should have emojicompat data"
|
||||||
|
|
||||||
|
|
||||||
|
def name(font, name_id):
|
||||||
|
values = set()
|
||||||
|
for name in font["name"].names:
|
||||||
|
if name.nameID == name_id:
|
||||||
|
values.add(name.toUnicode())
|
||||||
|
assert len(values) == 1, f"{name_id} has multiple definitions: {values}"
|
||||||
|
return next(iter(values))
|
||||||
|
|
||||||
|
|
||||||
|
def test_flagsonly_name():
|
||||||
|
fonts_dir = Path("fonts")
|
||||||
|
assert fonts_dir.is_dir()
|
||||||
|
font_file = fonts_dir / "NotoColorEmoji-flagsonly.ttf"
|
||||||
|
font = ttLib.TTFont(font_file)
|
||||||
|
assert [
|
||||||
|
"Noto Color Emoji Flags",
|
||||||
|
"Noto Color Emoji Flags",
|
||||||
|
"Noto Color Emoji Flags",
|
||||||
|
"NotoColorEmojiFlags",
|
||||||
|
] == [
|
||||||
|
name(font, NAME_ID_FAMILY),
|
||||||
|
name(font, NAME_ID_FULLNAME),
|
||||||
|
name(font, NAME_ID_UNIQUE_ID),
|
||||||
|
name(font, NAME_ID_POSTSCRIPT_NAME),
|
||||||
|
]
|
||||||
|
|
36
update_flag_name.py
Normal file
36
update_flag_name.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
"""Updates the name table for the CBDT flagsonly font."""
|
||||||
|
|
||||||
|
from fontTools import subset
|
||||||
|
from fontTools import ttLib
|
||||||
|
import functools
|
||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
from typing import Set
|
||||||
|
|
||||||
|
|
||||||
|
NAME_ID_FAMILY = 1
|
||||||
|
NAME_ID_UNIQUE_ID = 3
|
||||||
|
NAME_ID_FULLNAME = 4
|
||||||
|
NAME_ID_POSTSCRIPT_NAME = 6
|
||||||
|
|
||||||
|
|
||||||
|
_NAME_VALUES = [
|
||||||
|
(NAME_ID_FAMILY, "Noto Color Emoji Flags"),
|
||||||
|
(NAME_ID_UNIQUE_ID, "Noto Color Emoji Flags"),
|
||||||
|
(NAME_ID_FULLNAME, "Noto Color Emoji Flags"),
|
||||||
|
(NAME_ID_POSTSCRIPT_NAME, "NotoColorEmojiFlags"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
font_file = "fonts/NotoColorEmoji-flagsonly.ttf"
|
||||||
|
font = ttLib.TTFont(font_file)
|
||||||
|
name_table = font["name"]
|
||||||
|
for (name_id, value) in _NAME_VALUES:
|
||||||
|
name = name_table.getName(name_id, 3, 1, 0x409)
|
||||||
|
name.string = value
|
||||||
|
font.save(font_file)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
Loading…
Add table
Reference in a new issue