Add color emoji support via SBIX bitmap rendering#1690
Open
jspears wants to merge 3 commits intofoliojs:masterfrom
Open
Add color emoji support via SBIX bitmap rendering#1690jspears wants to merge 3 commits intofoliojs:masterfrom
jspears wants to merge 3 commits intofoliojs:masterfrom
Conversation
blikblum
requested changes
Feb 22, 2026
Member
blikblum
left a comment
There was a problem hiding this comment.
Some nit
Please add only one visual test
We should prefer unit tests going forward
Comment on lines
+43
to
+44
| // Do NOT pass family to fontkit.create — for TTCs it calls getVariation() | ||
| // which fails on emoji fonts that lack fvar/gvar tables. |
Member
There was a problem hiding this comment.
Is this bug reported in fontkit?
In the long run is better to fix it down stream so open font code path can be shared
| return null; | ||
| } | ||
|
|
||
| if (!imgData || !imgData.data || imgData.data.length === 0) { |
Member
There was a problem hiding this comment.
Suggested change
| if (!imgData || !imgData.data || imgData.data.length === 0) { | |
| if (!imgData?.data?.length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds color emoji rendering to PDFKit. When an emoji font is registered, text containing emoji is automatically segmented into plain text and emoji runs. Emoji glyphs are rendered as inline bitmap images (PNG XObjects) extracted from the font's sbix table, while surrounding text continues to render normally through the existing font pipeline.
There is a follow up PR stacked on this one that adds support for COLR/CPAL and CBDT/CBLC
Motivation
PDFKit currently discards color emoji data during font subsetting. The PDF either shows monochrome outlines or blank spaces where emoji should appear. This is a common pain point for anyone generating PDFs with user-supplied text that may contain emoji.
How It Works
Text Segmentation
A new emoji segmenter (lib/emoji/segmenter.js) splits input text into text vs emoji segments using Unicode range heuristics. It correctly handles ZWJ sequences, regional indicator pairs (flag emoji), skin tone modifiers, variation selectors, and keycap sequences.
Emoji Font Registration
A new registerEmojiFont method (lib/mixins/fonts.js, lib/font_factory.js) loads an emoji font via fontkit. TrueType Collections are handled by iterating the font collection and matching by postscriptName or familyName, avoiding the getVariation call that crashes on emoji fonts lacking fvar/gvar tables.
Can also be set via document constructor options:
Rendering
Line Wrapping
No changes needed. LineWrapper calls widthOfString which is now emoji-aware, so word wrapping works correctly with mixed text/emoji content.
Usage
Testing
Limitations