Skip to content

Text: emoji fall back to Apple Color Emoji and draw in colour - #693

Open
NikitkaRa wants to merge 1 commit into
storytold:mainfrom
NikitkaRa:cursor/apple-color-emoji-7e0f
Open

NikitkaRa wants to merge 1 commit into
storytold:mainfrom
NikitkaRa:cursor/apple-color-emoji-7e0f

Conversation

@NikitkaRa

Copy link
Copy Markdown
Contributor

Summary

  • Emoji resolve to an installed colour-emoji family even when that file is larger than the general system-font scan. Apple Color Emoji is about 180 MB, so the 64 MB scan never opened it.
  • Those glyphs paint their embedded PNG strikes (sbix, and CBDT when the strike is a PNG), so a grinning face draws in colour instead of an empty outline.
  • Checked on macOS: 😀 uses the colour emoji face, and a 72 pt grinning face renders yellow, right way up, inside the text box.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace, apart from the three known macOS environment failures
  • cargo xtask assets, cargo xtask layers, cargo xtask wasm
  • The existing COLR layer test passes, and the emoji cascade test (skin tone, variation selector, ZWJ family) passes with the colour font loaded

Colour-emoji families over the 64 MB scan cap, including Apple Color
Emoji, load by name. sbix and CBDT PNG strikes paint in colour, so a
grinning face is no longer an empty outline.

Co-authored-by: Cursor <cursoragent@cursor.com>

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the head of the diff: emoji fall back to the installed colour font and draw in colour (Apple Color Emoji on macOS, from its sbix PNG strikes). The code looks for named colour-emoji families first, because Apple Color Emoji is one file of about 180 MB, over the general scan's cap. Apple Color Emoji is Apple's font, licensed for use on Apple systems: drawing with it on screen is fine, but its glyph images must not be copied into exported files (a PDF or PPTX) or bundled, and the PR should say that the export path uses a different, openly licensed emoji font (Noto Color Emoji, OFL) or text. Loading a 180 MB file affects memory and start time, so it should be loaded lazily and only when an emoji appears (the code seems to do that). I have not run it (macOS), and no exact-head CI result exists for this head. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@aiongg aiongg added the bugfix Fixes something that is broken: wrong result, crash, data loss label Nov 4, 2026

@aiongg aiongg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (Opus). Not a maintainer decision.

Small fixes needed (not certain):

Colour emoji now come from the installed colour-emoji font even when it is over the colour-font scan's size cap, and glyphs with embedded PNG strikes (sbix, CBDT) draw from those images instead of their empty outlines.

  • crates/fonts/src/fontdb.rs:1411-1422 reimplements load_cataloged without taking the loading lock, so two threads can each read the 180 MB file at once. Calling self.load_cataloged(fam) keeps one load at a time and uses the usual file-size cap.
  • crates/render/src/bitmap.rs:66-70 decodes the PNG before checking its size. Only the image decoder's default allocation limit protects against a strike that claims a huge size.
  • crates/render/src/bitmap.rs:16-19: the cache can hold 128 strikes of up to 2048x2048 pixels each, which is large next to real emoji strikes.
  • crates/fonts/src/fontdb.rs:1399 also matches the monochrome Noto Emoji family, so that font loads as a side effect when it is installed.
  • crates/render/src/lib.rs:2268-2272 tries COLR first and then the bitmap strike, so faces with only COLR glyphs draw as before.

Claims checked:

  • verified: Emoji resolve to an installed colour-emoji family even when its file is larger than the 64 MB colour-font scan cap. (crates/fonts/src/fontdb.rs:1372 calls load_named_emoji_font before the 64 MB scan at line 1379. Lines 1397-1428 load the cataloged emoji families from SYSTEM_FALLBACKS (fontdb.rs:366…
  • verified: Colour glyphs paint their embedded PNG strikes (sbix, and CBDT when the strike is a PNG) instead of an empty outline. (crates/render/src/lib.rs:2270 falls back to bitmap::paint when colr::paint returns false. crates/render/src/bitmap.rs:38-48 looks up the strike for the current ppem, and bitmap.rs:…
  • unverified: On macOS a 72 pt grinning face renders yellow, right way up, inside the text box. (The placement logic is at crates/render/src/bitmap.rs:78-85: outer bearings in font units, inner bearings in pixels, and the bitmap moved up by its height for an sbix strike. The check for it, crates/render/src/tests…

Recommendation: merge after the fixes above; they may be pushed to this branch.

Reviewed at ea7d5da.

@aiongg

aiongg commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Automated message. Not a maintainer decision.

This branch conflicts with main. Could you merge or rebase main into it? The conflict needs a person to resolve.

@psperera

Copy link
Copy Markdown

Thanks for this. I tried it against current main (e86c25a) on macOS and found two things.

Where the call goes after a rebase. main has since gained system_plain_fallback, just above system_color_fallback. A fuzzy apply of this branch puts the load_named_emoji_font(c) call into system_plain_fallback, where it never runs for emoji. It belongs in system_color_fallback, after the MISSES check, as in this PR.

A machine whose first colour font lacks skin tones. With the call in the right place, emoji_take_a_colour_face_when_one_is_installed still fails on a Mac that also has a small colour emoji font in ~/Library/Fonts that draws 👍 but not 🏽 (U+1F3FD): 👍🏽 is drawn in Noto Sans Symbols 2. color_face_for searches by the cluster's base pictograph, and load_named_emoji_font('👍') returns true at the first named family that has 👍 (SYSTEM_FALLBACKS lists Segoe UI Emoji before Apple Color Emoji), so Apple Color Emoji is never loaded for the sequence.

I have a small companion change: when no loaded colour face draws the whole cluster, search by the first part none of them draws (🏽 here) instead of the base. It's about 20 lines in fallback.rs and fontdb.rs plus a unit test. With this PR and that change together, the test passes and 👍🏽 is drawn from Apple Color Emoji; with either alone it still fails.

Would you like to fold it into this PR, or shall I open it as a separate PR once this one lands?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants