Update postproc script and instructions
parent
9aca844e1b
commit
58e371b3d4
|
@ -23,11 +23,14 @@ contains emojicompat metadata.
|
||||||
cp build/NotoColorEmoji-noflags.ttf ../fonts/Noto-COLRv1-noflags.ttf
|
cp build/NotoColorEmoji-noflags.ttf ../fonts/Noto-COLRv1-noflags.ttf
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Post-process COLRv1 font for Android
|
1. Post-process COLRv1 fonts
|
||||||
|
* Adds some additional sequences, fixes up `name`, etc
|
||||||
* At time of writing only the noflags version is for Android
|
* At time of writing only the noflags version is for Android
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Assumed to be in a python3 environment with requirements.txt fulfilled
|
# Assumed to be in a python3 environment with requirements.txt fulfilled
|
||||||
python colrv1_postproc.py colrv1/build/NotoColorEmoji-noflags.ttf \
|
python colrv1_postproc.py
|
||||||
PATH_TO/NotoColorEmojiCompat.ttf
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
1. Add emojicompat metadata to the Android font and pass to the Android team
|
||||||
|
* TODO write detailed instructions
|
|
@ -1,5 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Post-nanoemoji processing of the Noto COLRv1 Emoji file.
|
Post-nanoemoji processing of the Noto COLRv1 Emoji files.
|
||||||
|
|
||||||
|
Adds additional sequences to properly support Safari, corrects 'name', etc.
|
||||||
|
|
||||||
For now substantially based on copying from a correct bitmap build.
|
For now substantially based on copying from a correct bitmap build.
|
||||||
"""
|
"""
|
||||||
|
@ -18,9 +20,10 @@ from pathlib import Path
|
||||||
from colrv1_add_soft_light_to_flags import add_soft_light_to_flags
|
from colrv1_add_soft_light_to_flags import add_soft_light_to_flags
|
||||||
|
|
||||||
|
|
||||||
_OUTPUT_FILE = {
|
_CBDT_FILE = Path("fonts/NotoColorEmoji.ttf")
|
||||||
"NotoColorEmoji-noflags.ttf": "fonts/Noto-COLRv1-noflags.ttf",
|
_COLR_FILES = {
|
||||||
"NotoColorEmoji.ttf": "fonts/Noto-COLRv1.ttf",
|
Path("fonts/Noto-COLRv1-noflags.ttf"),
|
||||||
|
Path("fonts/Noto-COLRv1.ttf"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,14 +35,6 @@ def _is_cbdt(font):
|
||||||
return "CBDT" in font
|
return "CBDT" in font
|
||||||
|
|
||||||
|
|
||||||
def _is_compat_font(font):
|
|
||||||
return "meta" in font and "Emji" in font["meta"].data
|
|
||||||
|
|
||||||
|
|
||||||
def _copy_emojicompat_data(colr_font, cbdt_font):
|
|
||||||
colr_font["meta"] = cbdt_font["meta"]
|
|
||||||
|
|
||||||
|
|
||||||
def _set_name(name_table, nameID):
|
def _set_name(name_table, nameID):
|
||||||
name_table.getName(value, nameID, 3, 1, 0x409)
|
name_table.getName(value, nameID, 3, 1, 0x409)
|
||||||
|
|
||||||
|
@ -94,7 +89,7 @@ def _add_cmap_entries(colr_font, codepoint, glyph_name):
|
||||||
if not _is_bmp(codepoint) and table.format == 4:
|
if not _is_bmp(codepoint) and table.format == 4:
|
||||||
continue
|
continue
|
||||||
table.cmap[codepoint] = glyph_name
|
table.cmap[codepoint] = glyph_name
|
||||||
print(f"Map 0x{codepoint:04x} to {glyph_name}, format {table.format}")
|
#print(f"Map 0x{codepoint:04x} to {glyph_name}, format {table.format}")
|
||||||
|
|
||||||
|
|
||||||
FLAG_TAGS = set(range(0xE0030, 0xE0039 + 1)) | set(range(0xE0061, 0xE007A + 1))
|
FLAG_TAGS = set(range(0xE0030, 0xE0039 + 1)) | set(range(0xE0061, 0xE007A + 1))
|
||||||
|
@ -113,7 +108,7 @@ def _map_missing_flag_tag_chars_to_empty_glyphs(colr_font):
|
||||||
hmtx_table = colr_font["hmtx"]
|
hmtx_table = colr_font["hmtx"]
|
||||||
glyph_order_size = len(glyf_table.glyphOrder)
|
glyph_order_size = len(glyf_table.glyphOrder)
|
||||||
for cp in tag_cps:
|
for cp in tag_cps:
|
||||||
print(f"Map 0x{cp:04x} to a blank glyf")
|
#print(f"Map 0x{cp:04x} to a blank glyf")
|
||||||
glyph_name = f"u{cp:04X}"
|
glyph_name = f"u{cp:04X}"
|
||||||
assert glyph_name not in glyf_table, f"{glyph_name} already in glyf"
|
assert glyph_name not in glyf_table, f"{glyph_name} already in glyf"
|
||||||
assert glyph_name not in hmtx_table.metrics, f"{glyph_name} already in hmtx"
|
assert glyph_name not in hmtx_table.metrics, f"{glyph_name} already in hmtx"
|
||||||
|
@ -288,29 +283,22 @@ def _add_fallback_subs_for_unknown_flags(colr_font):
|
||||||
font_data.delete_from_cmap(colr_font, [UNKNOWN_FLAG_PUA])
|
font_data.delete_from_cmap(colr_font, [UNKNOWN_FLAG_PUA])
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def _font(path, check_fn, check_fail_str):
|
||||||
if len(argv) != 3:
|
assert path.is_file(), path
|
||||||
raise ValueError(
|
font = ttLib.TTFont(path)
|
||||||
"Must have two args, a COLRv1 font and a CBDT emojicompat font"
|
if not check_fn(font):
|
||||||
)
|
raise ValueError(path + check_fail_str)
|
||||||
|
return font
|
||||||
|
|
||||||
colr_file = Path(argv[1])
|
|
||||||
assert colr_file.is_file()
|
|
||||||
assert colr_file.name in _OUTPUT_FILE
|
|
||||||
colr_font = ttLib.TTFont(colr_file)
|
|
||||||
if not _is_colrv1(colr_font):
|
|
||||||
raise ValueError("First arg must be a COLRv1 font")
|
|
||||||
|
|
||||||
cbdt_file = Path(argv[2])
|
def main(_):
|
||||||
assert cbdt_file.is_file()
|
cbdt_font = _font(_CBDT_FILE, _is_cbdt, " must be a CBDT font")
|
||||||
cbdt_font = ttLib.TTFont(cbdt_file)
|
|
||||||
if not _is_cbdt(cbdt_font) or not _is_compat_font(cbdt_font):
|
|
||||||
raise ValueError("Second arg must be a CBDT emojicompat font")
|
|
||||||
|
|
||||||
print(f"COLR {colr_file.absolute()}")
|
for colr_file in _COLR_FILES:
|
||||||
print(f"CBDT {cbdt_file.absolute()}")
|
colr_font = _font(colr_file, _is_colrv1, " must be a COLRv1 font")
|
||||||
|
|
||||||
|
print(f"Updating {colr_file} from {_CBDT_FILE}")
|
||||||
|
|
||||||
_copy_emojicompat_data(colr_font, cbdt_font)
|
|
||||||
_copy_names(colr_font, cbdt_font)
|
_copy_names(colr_font, cbdt_font)
|
||||||
|
|
||||||
# CBDT build step: @$(PYTHON) $(PUA_ADDER) "$@" "$@-with-pua"
|
# CBDT build step: @$(PYTHON) $(PUA_ADDER) "$@" "$@-with-pua"
|
||||||
|
@ -326,9 +314,8 @@ def main(argv):
|
||||||
|
|
||||||
_add_fallback_subs_for_unknown_flags(colr_font)
|
_add_fallback_subs_for_unknown_flags(colr_font)
|
||||||
|
|
||||||
out_file = Path(_OUTPUT_FILE[colr_file.name]).absolute()
|
print("Writing", colr_file)
|
||||||
print("Writing", out_file)
|
colr_font.save(colr_file)
|
||||||
colr_font.save(out_file)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue