Add color emoji support via SBIX bitmap rendering#1690
Add color emoji support via SBIX bitmap rendering#1690jspears wants to merge 13 commits intofoliojs:masterfrom
Conversation
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
Co-authored-by: Luiz Américo <camara_luiz@yahoo.com.br>
Agent-Id: agent-c3182b15-f411-4263-9a49-36ee6676ea0a
Agent-Id: agent-b0c62276-e9f4-41e5-abae-9371fa38a6ed
Agent-Id: agent-85aa884b-a6ba-49b0-b980-3b0990124217
… on fontkit 2.x) Agent-Id: agent-07ae24ff-5c31-44bc-bc98-7d99f3de7a6b
|
Please look at test fails |
moved into single test -- ran prettier -- probably should add it lint command in package.json or add it to CONTRIBUTING.md |
tests are passing now. |
|
Is good to go. Just some NIT:
|
|
@jspears tried to run the tests in my local setup and noted the font file is not in the PR Downloaded a font from https://github.com/samuelngs/apple-emoji-ttf/releases Tested with AppleColorEmoji-Linux.ttf and got the error below I believe you did not commit the font because of copyright concerns Is there other font that don't have copyright issues that can be used to test this feature? |
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