Fix mobile heart and warning emoji with native font fallback (#7842)

Mobile heart and warning reactions and message text render as monochrome
symbols because bundled Inter supplies U+2764 and U+26A0. Remove only
those two character mappings from both regular and italic Inter fonts so
Flutter uses native font fallback. No production Dart or Markdown
parsing changes are needed.

The reproducible font-processing script verifies that every other
mapping and font table is unchanged, apart from the required checksum.
Glyphs, metrics, language coverage and symbols such as © ® ™ ↑ ↓ − ∕ are
preserved; the bundled Inter license is retained.

Validated on an actual iPhone 17 Pro simulator running iOS 26.5.
Reaction hearts and warnings remain centered within 0.33 logical pixels
of the pill center. Native screenshot checks cover reactions and plain,
emoji, explicit text-style, bold, italic, and enlarged emoji-only
message hearts and warnings, plus pixel-identical preserved text
samples.

**Fallback behavior:** on iOS 26.5, plain ❤ / ⚠ and explicit text-style
❤︎ / ⚠︎ also render as color emoji. Native font metrics add one logical
pixel to each of the three mixed-message lines in this fixture. Android
visual behavior has not been validated.

### Reactions

| Before | After |
| --- | --- |
| ![Monochrome hearts and warnings in
reactions](https://raw.githubusercontent.com/block/buzz/cf60b78c79fbdc4ac314ba74f3fd27b76c823755/pr-7842--before-reactions.png)
| ![Centered native color hearts and warnings in
reactions](https://raw.githubusercontent.com/block/buzz/cf60b78c79fbdc4ac314ba74f3fd27b76c823755/pr-7842--after-reactions.png)
|

### Message text

| Before | After |
| --- | --- |
| ![Monochrome message hearts and warnings with preserved
symbols](https://raw.githubusercontent.com/block/buzz/cf60b78c79fbdc4ac314ba74f3fd27b76c823755/pr-7842--before-messages.png)
| ![Native color message hearts and warnings with preserved
symbols](https://raw.githubusercontent.com/block/buzz/cf60b78c79fbdc4ac314ba74f3fd27b76c823755/pr-7842--after-messages.png)
|

Images are cropped native simulator screenshots of production widgets
with synthetic content. Before uses the original bundled fonts; after
uses the processed fonts.

Added tests: the existing mobile CI test lane now checks both bundled
fonts against the verified generated artifacts, preventing restoration
of the old mappings or unintended font changes.

Validation: the two asset tests, font-table verification, byte-identical
regeneration, native screenshot regression checks, and Flutter analysis
pass. The screenshot test fails against the original rendering. Pre-push
checks, including the full mobile suite, pass. Full repository
validation also passes. The enlarged emoji-only screenshot check passes
and rejects the old normal-sized fixture. GitHub CI, Codex review, and
the security review pass for commit 538167a788. Both prior Codex
findings are addressed and resolved.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
Tom Brow
2026-09-24 07:30:30 -07:00
committed by GitHub
parent 4544ba1713
commit 9462d8884a
7 changed files with 324 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Remove Inter's heart and warning mappings for native emoji fallback.
Requires fonttools==4.60.1. See assets/fonts/README.md for source and commands.
"""
import argparse
import hashlib
from pathlib import Path
from fontTools.ttLib import TTFont
SOURCES = {
"InterVariable.ttf": "4989b125924991b90d05b2d16e0e388c48f7d5bb8b30539bbf9c755278d0ccaf",
"InterVariable-Italic.ttf": "d6f1f6a172d9e588438db9f986fd5cfad7b30f644374080a8a9d4d91e344586f",
}
NATIVE_EMOJI = (0x2764, 0x26A0)
def verify(source: Path, output: Path) -> None:
with TTFont(source, lazy=True) as before, TTFont(output, lazy=True) as after:
if set(before.reader.keys()) != set(after.reader.keys()):
raise ValueError("Font tables changed")
for tag in before.reader.keys():
original, modified = before.reader[tag], after.reader[tag]
if tag == "cmap":
continue
if tag == "head":
# The only allowed header change is the whole-font checksum.
original = original[:8] + original[12:]
modified = modified[:8] + modified[12:]
if original != modified:
raise ValueError(f"Unexpected change to {tag}")
old_tables, new_tables = before["cmap"].tables, after["cmap"].tables
if len(old_tables) != len(new_tables):
raise ValueError("Character-map table count changed")
for old, new in zip(old_tables, new_tables, strict=True):
identity = lambda t: (t.format, t.platformID, t.platEncID, t.language)
if identity(old) != identity(new):
raise ValueError("Character-map identity changed")
expected = dict(old.cmap)
if old.isUnicode():
for codepoint in NATIVE_EMOJI:
del expected[codepoint]
if new.cmap != expected:
raise ValueError("Character mappings changed beyond U+2764 and U+26A0")
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("source_dir", type=Path)
parser.add_argument("--output-dir", type=Path, default=Path(__file__).resolve().parents[1] / "assets/fonts")
parser.add_argument("--check", action="store_true", help="Verify existing output without writing")
args = parser.parse_args()
for name, digest in SOURCES.items():
source, output = args.source_dir / name, args.output_dir / name
if source.resolve() == output.resolve():
raise ValueError("Keep pristine sources separate from generated fonts")
if hashlib.sha256(source.read_bytes()).hexdigest() != digest:
raise ValueError(f"Unexpected source font: {name}")
if not args.check:
with TTFont(source, lazy=True, recalcTimestamp=False) as font:
tables = [t for t in font["cmap"].tables if t.isUnicode()]
if not tables or any(codepoint not in t.cmap for t in tables for codepoint in NATIVE_EMOJI):
raise ValueError(f"Expected heart and warning mappings in {name}")
# FontTools shares dictionaries between equivalent subtables.
for cmap in {id(t.cmap): t.cmap for t in tables}.values():
for codepoint in NATIVE_EMOJI:
del cmap[codepoint]
args.output_dir.mkdir(parents=True, exist_ok=True)
font.save(output, reorderTables=False)
verify(source, output)
print(f"{name}: only U+2764 and U+26A0 mappings removed; other mappings and glyph data unchanged")
if __name__ == "__main__":
main()