Skip to content

fonts: Fix emoji font selection on macOS - #32122

Merged
mrobinson merged 1 commit into
servo:mainfrom
mrobinson:fix-get-glyph-and-fallback-lists-macos
Apr 22, 2024
Merged

mrobinson merged 1 commit into
servo:mainfrom
mrobinson:fix-get-glyph-and-fallback-lists-macos

Conversation

@mrobinson

@mrobinson mrobinson commented Apr 21, 2024 •

Copy link
Copy Markdown
Member

This fixes two issues that were preventing emojis from being properly
selected from fonts on macOS.

  1. CTFont::get_glyphs_for_characters takes the input characters as
    UniChar which are UTF-16 encoded characters. We need to encode the
    input char as UTF-16 before passing it to CoreText.
  2. The font fallback list is updated with the latest logic from Gecko,
    which importantly adds "Apple Color Emoji" to the list of fallback
    fonts. Sorry for the big change, but this is just a direct port of
    the code from Gecko.

With these two changes, emojis display but in grayscale. 😅 To fix this,
another part of the font stack will need to detect when the font
supports color and pass that information to WebRender when creating the
font instance. We will likely do this in platform independent way later
that will depend on some more preliminary changes.


This fixes two issues that were prevented emojis from being properly
selected from fonts on macOS.

1. `CTFont::get_glyphs_for_characters` takes the input characters as
   UniChar which are UTF-16 encoded characters. We need to encode the
   input `char` as UTF-16 before passing it to CoreText.
2. The font fallback list is updated with the latest logic from Gecko,
   which importantly adds "Apple Color Emoji" to the list of fallback
   fonts. Sorry for the big change, but this is just a direct port of
   the code from Gecko.

With these two changes, emojis display but in grayscale. 😅 To fix this,
another part of the font stack will need to detect when the font
supports color and pass that information to WebRender when creating the
font instance. We will likely do this in platform independent way later
that will depend on some more preliminary changes.
@mrobinson

Copy link
Copy Markdown
Member Author

Here is the rendering of the test case in #17267 after this change:

Screenshot 2024-04-21 at 14 17 46

@mrobinson
mrobinson added this pull request to the merge queue Apr 22, 2024
Merged via the queue into servo:main with commit 363651c Apr 22, 2024
@mrobinson
mrobinson deleted the fix-get-glyph-and-fallback-lists-macos branch April 22, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants