From 48aa43748df011ae8476a241f1d6d4297a1408f4 Mon Sep 17 00:00:00 2001 From: Rod S Date: Wed, 29 Dec 2021 19:08:03 -0800 Subject: [PATCH] Exploratory mapping of things to space to match observed shaping in CBDT --- colrv1_postproc.py | 40 ++++++++++++++++++++++++++++++++++ fonts/Noto-COLRv1-noflags.ttf | Bin 2846160 -> 2846592 bytes 2 files changed, 40 insertions(+) diff --git a/colrv1_postproc.py b/colrv1_postproc.py index 4ae28e6dd..833568f92 100644 --- a/colrv1_postproc.py +++ b/colrv1_postproc.py @@ -58,6 +58,44 @@ def _add_vs_cmap(colr_font): add_vs_cmap.modify_font("COLRv1 Emoji", colr_font, "emoji", emoji_variants) +def _is_variation_selector_cmap_table(table): + assert table.format in {4, 12, 14} + return table.format == 14 + + +def _lookup_in_cmap(colr_font, codepoint): + result = set() + for table in colr_font["cmap"].tables: + if _is_variation_selector_cmap_table(table): + continue + assert codepoint in table.cmap + result.add(table.cmap[codepoint]) + assert len(result) == 1, f"Ambiguous mapping for {codepoint}: {result}" + return next(iter(result)) + + +def _map_flag_tag_chars_to_space(colr_font): + gn_space = _lookup_in_cmap(colr_font, ord(" ")) + + # Add all tag characters used in flags + tag_cps = set(range(0xE0030, 0xE0039 + 1)) | set(range(0xE0061, 0xE007A + 1)) + + # CBDT maps these things to space based on hb-shape testing + # Android fontchain_lint is unhappy if no such mapping exists + for table in colr_font["cmap"].tables: + if _is_variation_selector_cmap_table(table): + continue + for cp in tag_cps: + if not _is_bmp(cp) and table.format == 4: + continue + table.cmap[cp] = gn_space + print(f"Map 0x{cp:04x} to space, format {table.format}") + + +def _is_bmp(cp): + return cp in range(0x0000, 0xFFFF + 1) + + def main(argv): if len(argv) != 3: raise ValueError("Must have two args, a COLRv1 font and a CBDT emojicompat font") @@ -78,6 +116,8 @@ def main(argv): _add_vs_cmap(colr_font) + _map_flag_tag_chars_to_space(colr_font) + colr_font.save('fonts/Noto-COLRv1-noflags.ttf') diff --git a/fonts/Noto-COLRv1-noflags.ttf b/fonts/Noto-COLRv1-noflags.ttf index 95995dcc9540878c8ff513aa074fadb7f0b23cde..c20bb749cdfcc862f66b6c7152df9edc55566d4e 100644 GIT binary patch delta 826 zcmXZYJ7`l;7{KxGCXLow(`ajL8~aeBMi({dDaf|MdS3F`kQ--Z9ZzjL_vaPHaoQZSak7mStWJDaA| ze||oA?b78^?VHEqU-O9!Ee(y_7%074-WLC#CnDi1S4YkS2LJxJFJg>~$lYiU@epN(X72 zR%dWVoyA#o4(HTUcuGBur`0ofMr~qKJ&R}6b9hcTV0)+Ym8v^kzzh1)B3@K4;U(J- zto4W1x=l8N}Dvo2P0qL;gL