Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a33e5347 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update fontchain_linter for non-compat font"

parents 6e14ebc0 e7e383e0
Loading
Loading
Loading
Loading
+4 −52
Original line number Diff line number Diff line
@@ -381,62 +381,14 @@ def hex_strs(sequence):
        return tuple(f"{s:X}" for s in sequence)
    return hex(sequence)

def check_plausible_compat_pua(coverage, all_emoji, equivalent_emoji):
    # A PUA should point to every RGI emoji and that PUA should be unique to the
    # set of equivalent sequences for the emoji.
    problems = []
    for seq in all_emoji:
        # We're looking to match not-PUA with PUA so filter out existing PUA
        if contains_pua(seq):
            continue

        # Filter out non-RGI things that end up in all_emoji
        if only_tags(seq) or seq in {ZWJ, COMBINING_KEYCAP, EMPTY_FLAG_SEQUENCE}:
            continue

        equivalents = [seq]
        if seq in equivalent_emoji:
            equivalents.append(equivalent_emoji[seq])

        # If there are problems the hex code is much more useful
        log_equivalents = [hex_strs(s) for s in equivalents]

        # The system compat font should NOT include regional indicators as these have been split out
        if contains_regional_indicator(seq):
            assert not any(s in coverage for s in equivalents), f"Regional indicators not expected in compat font, found {log_equivalents}"
            continue

        glyph = {coverage[e] for e in equivalents}
        if len(glyph) != 1:
            problems.append(f"{log_equivalents} should all point to the same glyph")
            continue
        glyph = next(iter(glyph))

        pua = {s for s, g in coverage.items() if contains_pua(s) and g == glyph}
        if not pua:
            problems.append(f"Expected PUA for {log_equivalents} but none exist")
            continue

    assert not problems, "\n".join(sorted(problems)) + f"\n{len(problems)} PUA problems"

def check_emoji_compat(all_emoji, equivalent_emoji):
def check_emoji_not_compat(all_emoji, equivalent_emoji):
    compat_psnames = set()
    for emoji_font in get_emoji_fonts():
        ttf = open_font(emoji_font)
        psname = get_psname(ttf)

        is_compat_font = "meta" in ttf and 'Emji' in ttf["meta"].data
        if not is_compat_font:
            continue
        compat_psnames.add(psname)

        # If the font has compat metadata it should have PUAs for emoji sequences
        coverage = get_emoji_map(emoji_font)
        check_plausible_compat_pua(coverage, all_emoji, equivalent_emoji)


    # NotoColorEmoji must be a Compat font.
    assert 'NotoColorEmoji' in compat_psnames, 'NotoColorEmoji MUST be a compat font'
        if "meta" in ttf:
            assert 'Emji' not in ttf["meta"].data, 'NotoColorEmoji MUST be a compat font'


def check_emoji_font_coverage(emoji_fonts, all_emoji, equivalent_emoji):
@@ -847,7 +799,7 @@ def main():
        ucd_path = sys.argv[3]
        parse_ucd(ucd_path)
        all_emoji, default_emoji, equivalent_emoji = compute_expected_emoji()
        check_emoji_compat(all_emoji, equivalent_emoji)
        check_emoji_not_compat(all_emoji, equivalent_emoji)
        check_emoji_coverage(all_emoji, equivalent_emoji)
        check_emoji_defaults(default_emoji)