| 1 |
from fontTools import ttLib |
| 2 |
from pathlib import Path |
| 3 |
import pytest |
| 4 |
import re |
| 5 |
|
| 6 |
|
| 7 |
NAME_ID_FAMILY = 1 |
| 8 |
NAME_ID_UNIQUE_ID = 3 |
| 9 |
NAME_ID_FULLNAME = 4 |
| 10 |
NAME_ID_POSTSCRIPT_NAME = 6 |
| 11 |
|
| 12 |
|
| 13 |
def test_consistent_version(): |
| 14 |
fonts_dir = Path("fonts") |
| 15 |
assert fonts_dir.is_dir() |
| 16 |
|
| 17 |
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$") |
| 18 |
|
| 19 |
debug_versions = [] |
| 20 |
versions = set() |
| 21 |
for font_file in fonts_dir.rglob("*.ttf"): |
| 22 |
font = ttLib.TTFont(font_file) |
| 23 |
head_ver = f"{font['head'].fontRevision:.03f}" |
| 24 |
versions.add(head_ver) |
| 25 |
debug_versions.append(f"{font_file.name} head {head_ver}") |
| 26 |
for name in font["name"].names: |
| 27 |
# name 5 is version |
| 28 |
if name.nameID != 5: |
| 29 |
continue |
| 30 |
if not name.isUnicode(): |
| 31 |
continue |
| 32 |
match = name5_re.match(name.toUnicode()) |
| 33 |
assert match is not None, f"{name.toUnicode()} is malformed" |
| 34 |
versions.add(match.group(1)) |
| 35 |
debug_versions.append(f"{font_file.name} name {match.group(1)}") |
| 36 |
debug_versions = "\n".join(debug_versions) |
| 37 |
assert ( |
| 38 |
len(versions) == 1 |
| 39 |
), f"Should have a consistent version, found\n{debug_versions}" |
| 40 |
|
| 41 |
|
| 42 |
def test_consistent_fstype(): |
| 43 |
fonts_dir = Path("fonts") |
| 44 |
assert fonts_dir.is_dir() |
| 45 |
|
| 46 |
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$") |
| 47 |
|
| 48 |
debug_fstypes = [] |
| 49 |
fstypes = set() |
| 50 |
for font_file in fonts_dir.rglob("*.ttf"): |
| 51 |
font = ttLib.TTFont(font_file) |
| 52 |
fstype = font["OS/2"].fsType |
| 53 |
fstypes.add(fstype) |
| 54 |
debug_fstypes.append(f"{font_file.name} fsType {fstype}") |
| 55 |
debug_fstypes = "\n".join(debug_fstypes) |
| 56 |
assert fstypes == {0}, f"All fsType's should be 0, found\n{debug_fstypes}" |
| 57 |
|
| 58 |
|
| 59 |
def test_has_emojicompat(): |
| 60 |
fonts_dir = Path("fonts") |
| 61 |
assert fonts_dir.is_dir() |
| 62 |
|
| 63 |
ec_fonts = set(fonts_dir.rglob("*-emojicompat.ttf")) |
| 64 |
assert {f.name for f in ec_fonts} == { |
| 65 |
"Noto-COLRv1-emojicompat.ttf", |
| 66 |
"NotoColorEmoji-emojicompat.ttf", |
| 67 |
} |
| 68 |
|
| 69 |
for font_file in ec_fonts: |
| 70 |
font = ttLib.TTFont(font_file) |
| 71 |
assert "meta" in font, f"{font_file.name} should have a meta table" |
| 72 |
assert ( |
| 73 |
"Emji" in font["meta"].data |
| 74 |
), f"{font_file.name} should have emojicompat data" |
| 75 |
|
| 76 |
|
| 77 |
def name(font, name_id): |
| 78 |
values = set() |
| 79 |
for name in font["name"].names: |
| 80 |
if name.nameID == name_id: |
| 81 |
values.add(name.toUnicode()) |
| 82 |
assert len(values) == 1, f"{name_id} has multiple definitions: {values}" |
| 83 |
return next(iter(values)) |
| 84 |
|
| 85 |
|
| 86 |
def test_flagsonly_name(): |
| 87 |
fonts_dir = Path("fonts") |
| 88 |
assert fonts_dir.is_dir() |
| 89 |
font_file = fonts_dir / "NotoColorEmoji-flagsonly.ttf" |
| 90 |
font = ttLib.TTFont(font_file) |
| 91 |
assert [ |
| 92 |
"Noto Color Emoji Flags", |
| 93 |
"Noto Color Emoji Flags", |
| 94 |
"Noto Color Emoji Flags", |
| 95 |
"NotoColorEmojiFlags", |
| 96 |
] == [ |
| 97 |
name(font, NAME_ID_FAMILY), |
| 98 |
name(font, NAME_ID_FULLNAME), |
| 99 |
name(font, NAME_ID_UNIQUE_ID), |
| 100 |
name(font, NAME_ID_POSTSCRIPT_NAME), |
| 101 |
] |