Skip to content

Commit 965d702

Browse files
committed
Use native heart fallback by narrowing bundled Inter coverage
Signed-off-by: Tom Brow <[email protected]>
1 parent d9a5bdd commit 965d702

8 files changed

Lines changed: 210 additions & 27 deletions

File tree

-20 Bytes
Binary file not shown.
-20 Bytes
Binary file not shown.

‎mobile/assets/fonts/README.md‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Inter heart fallback
2+
3+
The two Inter 4.001 variable fonts are derived from the previously bundled
4+
fonts by removing only U+2764 from their Unicode character maps. Flutter can
5+
then choose a native font for heart characters, including emoji presentation
6+
in reactions and message text. No glyphs, language coverage, other symbols,
7+
font metrics, or variation tables are removed. The license remains in
8+
`Inter-LICENSE.txt`.
9+
10+
To reproduce from the repository root:
11+
12+
```sh
13+
mkdir -p /tmp/buzz-inter-source
14+
for font in InterVariable.ttf InterVariable-Italic.ttf; do
15+
git show ec7ea38f62ea917f15e85a678bc94f3bbee5bb64:mobile/assets/fonts/$font > /tmp/buzz-inter-source/$font
16+
done
17+
python3 -m venv /tmp/buzz-inter-tools
18+
/tmp/buzz-inter-tools/bin/pip install fonttools==4.60.1
19+
/tmp/buzz-inter-tools/bin/python mobile/scripts/prepare-inter.py /tmp/buzz-inter-source
20+
/tmp/buzz-inter-tools/bin/python mobile/scripts/prepare-inter.py /tmp/buzz-inter-source --check
21+
```
22+
23+
The script checks pristine source hashes and verifies every character mapping
24+
and every other font table. Only the `cmap` table and the font checksum may
25+
change. Repeated generation from the same sources produces identical bytes.
26+
Warning signs, ©, ®, ™, arrows, math symbols, accents, and supported languages
27+
keep their original Inter mappings.
28+
29+
Use `test/visual/heart_sim_app.dart` on an actual iOS simulator to compare
30+
reactions, plain/emoji/text-presentation hearts, bold/italic message text,
31+
warning signs, and preserved symbols. Font fallback for plain and explicit
32+
text-presentation hearts is platform-dependent; do not infer their appearance
33+
from a macOS widget-test renderer. On iOS 26.5, all three heart presentations
34+
fall back to the color emoji, including explicit VS15. Message line metrics
35+
can change with the fallback font.
36+
37+
The native screenshot regression check (requires Pillow) covers both reaction
38+
states, each message-heart presentation, bold/italic text, and unchanged warning
39+
signs and symbols:
40+
41+
```sh
42+
python3 mobile/test/visual/verify_heart_screenshots.py before.png after.png
43+
```
44+
45+
Use original 1206×2622 captures from the documented simulator and fixture for
46+
this check. PR images may be cropped afterward for readability.

‎mobile/lib/shared/emoji/native_emoji_glyph.dart‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ class NativeEmojiGlyph extends StatelessWidget {
3131
maxLines: 1,
3232
softWrap: false,
3333
textScaler: TextScaler.noScaling,
34-
// Inter contains a monochrome heart, so emoji fonts must take priority.
35-
style: TextStyle(
36-
fontFamily: 'Apple Color Emoji',
37-
fontFamilyFallback: const ['Noto Color Emoji', 'Segoe UI Emoji'],
38-
fontSize: size,
39-
height: 1,
40-
),
34+
style: TextStyle(fontSize: size, height: 1),
4135
);
4236
if (defaultTargetPlatform == TargetPlatform.iOS) {
4337
glyph = Transform.translate(offset: const Offset(0, -1), child: glyph);

‎mobile/scripts/prepare-inter.py‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
"""Remove only Inter's U+2764 mapping so hearts use native font fallback.
3+
4+
Requires fonttools==4.60.1. See assets/fonts/README.md for source and commands.
5+
"""
6+
7+
import argparse
8+
import hashlib
9+
from pathlib import Path
10+
11+
from fontTools.ttLib import TTFont
12+
13+
14+
SOURCES = {
15+
"InterVariable.ttf": "4989b125924991b90d05b2d16e0e388c48f7d5bb8b30539bbf9c755278d0ccaf",
16+
"InterVariable-Italic.ttf": "d6f1f6a172d9e588438db9f986fd5cfad7b30f644374080a8a9d4d91e344586f",
17+
}
18+
HEART = 0x2764
19+
20+
21+
def verify(source: Path, output: Path) -> None:
22+
with TTFont(source, lazy=True) as before, TTFont(output, lazy=True) as after:
23+
if set(before.reader.keys()) != set(after.reader.keys()):
24+
raise ValueError("Font tables changed")
25+
for tag in before.reader.keys():
26+
original, modified = before.reader[tag], after.reader[tag]
27+
if tag == "cmap":
28+
continue
29+
if tag == "head":
30+
# The only allowed header change is the whole-font checksum.
31+
original = original[:8] + original[12:]
32+
modified = modified[:8] + modified[12:]
33+
if original != modified:
34+
raise ValueError(f"Unexpected change to {tag}")
35+
old_tables, new_tables = before["cmap"].tables, after["cmap"].tables
36+
if len(old_tables) != len(new_tables):
37+
raise ValueError("Character-map table count changed")
38+
for old, new in zip(old_tables, new_tables, strict=True):
39+
identity = lambda t: (t.format, t.platformID, t.platEncID, t.language)
40+
if identity(old) != identity(new):
41+
raise ValueError("Character-map identity changed")
42+
expected = dict(old.cmap)
43+
if old.isUnicode():
44+
del expected[HEART]
45+
if new.cmap != expected:
46+
raise ValueError("Character mappings changed beyond U+2764")
47+
48+
49+
def main() -> None:
50+
parser = argparse.ArgumentParser(description=__doc__)
51+
parser.add_argument("source_dir", type=Path)
52+
parser.add_argument("--output-dir", type=Path, default=Path(__file__).resolve().parents[1] / "assets/fonts")
53+
parser.add_argument("--check", action="store_true", help="Verify existing output without writing")
54+
args = parser.parse_args()
55+
for name, digest in SOURCES.items():
56+
source, output = args.source_dir / name, args.output_dir / name
57+
if source.resolve() == output.resolve():
58+
raise ValueError("Keep pristine sources separate from generated fonts")
59+
if hashlib.sha256(source.read_bytes()).hexdigest() != digest:
60+
raise ValueError(f"Unexpected source font: {name}")
61+
if not args.check:
62+
with TTFont(source, lazy=True, recalcTimestamp=False) as font:
63+
tables = [t for t in font["cmap"].tables if t.isUnicode()]
64+
if not tables or any(HEART not in t.cmap for t in tables):
65+
raise ValueError(f"Expected heart mapping in {name}")
66+
# FontTools shares dictionaries between equivalent subtables.
67+
for cmap in {id(t.cmap): t.cmap for t in tables}.values():
68+
del cmap[HEART]
69+
args.output_dir.mkdir(parents=True, exist_ok=True)
70+
font.save(output, reorderTables=False)
71+
verify(source, output)
72+
print(f"{name}: only U+2764 mapping removed; other mappings and glyph data unchanged")
73+
74+
75+
if __name__ == "__main__":
76+
main()

‎mobile/test/features/channels/reaction_row_test.dart‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,6 @@ class _FakeUserCacheNotifier extends UserCacheNotifier {
9595

9696
void main() {
9797
group('ReactionRow', () {
98-
testWidgets(
99-
'heart reactions prefer a color font without recoloring counts',
100-
(tester) async {
101-
await _pumpRow(tester, reactions: [_reaction(emoji: '❤️', count: 5)]);
102-
final heart = tester.widget<Text>(find.text('❤️'));
103-
final count = tester.widget<Text>(find.text('5'));
104-
expect(heart.style?.fontFamily, 'Apple Color Emoji');
105-
expect(heart.style?.fontFamilyFallback, [
106-
'Noto Color Emoji',
107-
'Segoe UI Emoji',
108-
]);
109-
expect(count.style?.fontFamily, 'Inter');
110-
expect(
111-
tester.getSize(find.byKey(const ValueKey('reaction-pill-❤️'))).height,
112-
28,
113-
);
114-
},
115-
);
116-
11798
testWidgets('shows the count even at one, matching desktop', (
11899
tester,
119100
) async {

‎mobile/test/visual/heart_sim_app.dart‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:buzz/features/channels/message_content.dart';
2+
import 'package:buzz/shared/custom_emoji/custom_emoji_provider.dart';
13
import 'package:buzz/features/channels/reaction_row.dart';
24
import 'package:buzz/features/channels/timeline_message.dart';
35
import 'package:buzz/shared/theme/theme.dart';
@@ -9,6 +11,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
911
// xcrun simctl io <simulator> screenshot <path>
1012
void main() => runApp(
1113
ProviderScope(
14+
overrides: [customEmojiListProvider.overrideWithValue(const [])],
1215
child: MaterialApp(
1316
debugShowCheckedModeBanner: false,
1417
theme: AppTheme.light(),
@@ -20,13 +23,27 @@ void main() => runApp(
2023
crossAxisAlignment: CrossAxisAlignment.start,
2124
children: [
2225
const SizedBox(height: 24),
23-
const Text('Reaction rendering'),
26+
const Text('Hearts and text rendering'),
2427
const SizedBox(height: 24),
2528
const Text('Selected'),
2629
_reactions(true),
2730
const SizedBox(height: 24),
2831
const Text('Unselected'),
2932
_reactions(false),
33+
const SizedBox(height: 24),
34+
const Text('Message text'),
35+
const SizedBox(height: 8),
36+
_message('Plain ❤ Emoji ❤️ Text ❤︎'),
37+
_message('**Bold ❤️** *Italic ❤️*'),
38+
_message('Warnings: ⚠ ⚠️ ⚠︎'),
39+
const SizedBox(height: 16),
40+
const Text('Preserved symbols and text'),
41+
const SizedBox(height: 8),
42+
_message('© ® ™ ↑ ↓ − ∕ • … café naïve'),
43+
_message('Ελληνικά · Кириллица · Tiếng Việt'),
44+
const SizedBox(height: 16),
45+
const Text('Emoji-only message'),
46+
_message('❤️'),
3047
],
3148
),
3249
),
@@ -49,3 +66,8 @@ Widget _reactions(bool selected) => ReactionRow(
4966
],
5067
onToggle: (_) {},
5168
);
69+
70+
Widget _message(String content) => MessageContent(
71+
content: content,
72+
channelNames: const {'general': 'general'},
73+
);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
"""Check native captures of heart_sim_app.dart on iPhone 17 Pro, iOS 26.5.
3+
4+
Usage: python verify_heart_screenshots.py before.png after.png
5+
Requires Pillow. Inputs are original 1206x2622 simctl screenshots, not PR crops.
6+
"""
7+
8+
import sys
9+
10+
from PIL import Image, ImageChops
11+
12+
13+
def red_pixels(image, box):
14+
left, top, right, bottom = box
15+
return [
16+
(x, y)
17+
for y in range(top, bottom)
18+
for x in range(left, right)
19+
if is_red(image.getpixel((x, y)))
20+
]
21+
22+
23+
def is_red(color):
24+
red, green, blue = color
25+
return red > 140 and red > green * 1.5 and red > blue * 1.5
26+
27+
28+
def main():
29+
before, after = [Image.open(path).convert("RGB") for path in sys.argv[1:]]
30+
assert before.size == after.size == (1206, 2622), "Use the documented simulator and fixture"
31+
regions = {
32+
"selected reaction": (95, 522, 150, 606),
33+
"unselected reaction": (95, 744, 150, 828),
34+
"plain message heart": (175, 980, 225, 1035),
35+
"emoji-presentation message heart": (375, 980, 435, 1035),
36+
# Native iOS fallback currently renders VS15 as a color heart too.
37+
"text-presentation message heart": (550, 980, 620, 1035),
38+
"bold message heart": (170, 1040, 220, 1090),
39+
"italic message heart": (355, 1040, 425, 1090),
40+
"emoji-only message": (65, 1490, 125, 1545),
41+
}
42+
for name, box in regions.items():
43+
assert not red_pixels(before, box), f"{name}: original must reproduce monochrome heart"
44+
pixels = red_pixels(after, box)
45+
assert len(pixels) > 500, f"{name}: expected native red heart"
46+
if "reaction" in name:
47+
center = (min(y for _, y in pixels) + max(y for _, y in pixels)) / 2
48+
pill_center = (box[1] + box[3] - 1) / 2
49+
assert abs(center - pill_center) <= 1.5, f"{name}: heart is not centered"
50+
print(f"PASS: {name}")
51+
# The two preceding message lines gain one logical pixel each from the
52+
# fallback font's metrics. Compare unchanged text after that translation.
53+
for name, box in {
54+
"warning signs": (65, 1090, 1000, 1145),
55+
"preserved symbols and languages": (65, 1260, 1100, 1385),
56+
}.items():
57+
shifted = (box[0], box[1] + 6, box[2], box[3] + 6)
58+
difference = ImageChops.difference(before.crop(box), after.crop(shifted))
59+
assert difference.getbbox() is None, f"{name}: unexpected rendering change"
60+
print(f"PASS: {name} is pixel-identical")
61+
62+
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)