run black on colrv1_postproc.py script to fix indentation

pull/378/head
Cosimo Lupo 2022-01-26 16:09:18 +00:00
parent 831faf480d
commit 5d4f4d6b38
1 changed files with 90 additions and 93 deletions

View File

@ -17,10 +17,7 @@ from colrv1_add_soft_light_to_flags import add_soft_light_to_flags
def _is_colrv1(font): def _is_colrv1(font):
return ( return "COLR" in font and font["COLR"].version == 1
"COLR" in font
and font["COLR"].version == 1
)
def _is_cbdt(font): def _is_cbdt(font):
@ -28,10 +25,7 @@ def _is_cbdt(font):
def _is_compat_font(font): def _is_compat_font(font):
return ( return "meta" in font and "Emji" in font["meta"].data
"meta" in font
and "Emji" in font["meta"].data
)
def _copy_emojicompat_data(colr_font, cbdt_font): def _copy_emojicompat_data(colr_font, cbdt_font):
@ -49,8 +43,9 @@ def _set_name(name_table, nameID, value):
def _copy_names(colr_font, cbdt_font): def _copy_names(colr_font, cbdt_font):
colr_font["name"] = cbdt_font["name"] colr_font["name"] = cbdt_font["name"]
name_table = colr_font["name"] name_table = colr_font["name"]
assert all((n.platformID, n.platEncID, n.langID) == (3, 1, 0x409) assert all(
for n in name_table.names), "Should only have names Android uses" (n.platformID, n.platEncID, n.langID) == (3, 1, 0x409) for n in name_table.names
), "Should only have names Android uses"
# Amendments # Amendments
_set_name(name_table, 10, "Color emoji font using COLRv1.") _set_name(name_table, 10, "Color emoji font using COLRv1.")
@ -60,7 +55,11 @@ def _copy_names(colr_font, cbdt_font):
# CBDT build step: @$(VS_ADDER) -vs 2640 2642 2695 --dstdir '.' -o "$@-with-pua-varsel" "$@-with-pua" # CBDT build step: @$(VS_ADDER) -vs 2640 2642 2695 --dstdir '.' -o "$@-with-pua-varsel" "$@-with-pua"
def _add_vs_cmap(colr_font): def _add_vs_cmap(colr_font):
emoji_variants = unicode_data.get_unicode_emoji_variants() | {0x2640, 0x2642, 0x2695} emoji_variants = unicode_data.get_unicode_emoji_variants() | {
0x2640,
0x2642,
0x2695,
}
add_vs_cmap.modify_font("COLRv1 Emoji", colr_font, "emoji", emoji_variants) add_vs_cmap.modify_font("COLRv1 Emoji", colr_font, "emoji", emoji_variants)
@ -92,10 +91,7 @@ def _add_cmap_entries(colr_font, codepoint, glyph_name):
def _map_missing_flag_tag_chars_to_empty_glyphs(colr_font): def _map_missing_flag_tag_chars_to_empty_glyphs(colr_font):
# Add all tag characters used in flags # Add all tag characters used in flags
tag_cps = ( tag_cps = set(range(0xE0030, 0xE0039 + 1)) | set(range(0xE0061, 0xE007A + 1))
set(range(0xE0030, 0xE0039 + 1))
| set(range(0xE0061, 0xE007A + 1))
)
# Cancel tag # Cancel tag
tag_cps |= {0xE007F} tag_cps |= {0xE007F}
@ -133,12 +129,11 @@ def _ligaset_for_glyph(lookup_list, glyph_name):
def _Cmap(ttfont): def _Cmap(ttfont):
def _Reducer(acc, u): def _Reducer(acc, u):
acc.update(u) acc.update(u)
return acc return acc
unicode_cmaps = (t.cmap for t in ttfont['cmap'].tables if t.isUnicode()) unicode_cmaps = (t.cmap for t in ttfont["cmap"].tables if t.isUnicode())
return functools.reduce(_Reducer, unicode_cmaps, {}) return functools.reduce(_Reducer, unicode_cmaps, {})
@ -149,8 +144,8 @@ def _map_empty_flag_tag_to_black_flag(colr_font):
# if the emoji font starts using extensions this code will require revision # if the emoji font starts using extensions this code will require revision
cmap = _Cmap(colr_font) cmap = _Cmap(colr_font)
black_flag_glyph = cmap[0x1f3f4] black_flag_glyph = cmap[0x1F3F4]
cancel_tag_glyph = cmap[0xe007f] cancel_tag_glyph = cmap[0xE007F]
lookup_list = colr_font["GSUB"].table.LookupList lookup_list = colr_font["GSUB"].table.LookupList
liga_set = _ligaset_for_glyph(lookup_list, black_flag_glyph) liga_set = _ligaset_for_glyph(lookup_list, black_flag_glyph)
assert liga_set is not None, "There should be existing ligatures using black flag" assert liga_set is not None, "There should be existing ligatures using black flag"
@ -166,7 +161,9 @@ def _map_empty_flag_tag_to_black_flag(colr_font):
def main(argv): def main(argv):
if len(argv) != 3: if len(argv) != 3:
raise ValueError("Must have two args, a COLRv1 font and a CBDT emojicompat font") raise ValueError(
"Must have two args, a COLRv1 font and a CBDT emojicompat font"
)
colr_file = Path(argv[1]) colr_file = Path(argv[1])
assert colr_file.is_file() assert colr_file.is_file()
@ -197,7 +194,7 @@ def main(argv):
add_soft_light_to_flags(colr_font) add_soft_light_to_flags(colr_font)
out_file = Path('fonts/Noto-COLRv1-noflags.ttf').absolute() out_file = Path("fonts/Noto-COLRv1-noflags.ttf").absolute()
print("Writing", out_file) print("Writing", out_file)
colr_font.save(out_file) colr_font.save(out_file)