Bug 249943

Summary: Emoji character is horizontally misaligned when using COLR font
Product: WebKit Reporter: Nolan Lawson <nolan>
Component: TextAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: bfulgham, fantasai.bugs, karlcow, mmaxfield, simon.fraser, vitor.roriz, webkit-bug-importer, zalan
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Screenshot of Chrome, Firefox, and Safari TP
none
Repro HTML and TTF file none

Description Nolan Lawson 2022-12-29 09:48:52 PST
Created attachment 464247 [details]
Screenshot of Chrome, Firefox, and Safari TP

When using the Twemoji Mozilla COLR font [1], Safari Technology Preview Release 160 (Safari 16.4, WebKit 18615.1.14.3) renders certain emoji characters with the wrong alignment inside of a flexbox container with `align-items: center; justify-content: center;`.

Minimal repro: https://nolanlawson.github.io/webkit-emoji-font-repro/

Note that the fourth character (☺️) is not horizontally centered, whereas the other characters are.

This issue only repros in Safari. In Firefox and Chrome, all emoji characters are rendered with the correct horizontal center alignment. (See attached screenshots.)

Based on my testing, this only repros with a custom COLR font (not the built-in Apple Color Emoji font), and only certain emoji characters are misaligned: ☺️, 😐, ♥️, 👍️, etc.

[1]: https://github.com/mozilla/twemoji-colr/releases/tag/v0.7.0
Comment 1 Nolan Lawson 2022-12-29 09:49:17 PST
Created attachment 464248 [details]
Repro HTML and TTF file
Comment 2 zalan 2022-12-29 10:03:58 PST
Thank you for filing this bug report! It looks like the preferred width computation has some issues with fallback fonts. It fails with any flexing type of layout (e.g. shrink to fit) ->

.emoji {
 float: left;
 font-size: 22px;
 font-family: MozillaTwemojiColr;
 border: 1px solid black;
}
Comment 3 zalan 2022-12-29 14:07:43 PST
This is about measuring the emoji character. ComplexTextController returns 24px for Apple Color Emoji font, while 44px for MozillaTwemojiColr.
When measured using MozillaTwemojiColr, ComplexTextController sees 2 glyphs U+263A and U+FE0F (variant selection) and they advance 22px individually.
Myles, do you know what's going on here?
Comment 4 Radar WebKit Bug Importer 2022-12-29 14:08:21 PST
<rdar://problem/103764035>