Add COLR/CPAL and CBDT/CBLC color emoji support#1692
Open
jspears wants to merge 23 commits intofoliojs:masterfrom
Open
Add COLR/CPAL and CBDT/CBLC color emoji support#1692jspears wants to merge 23 commits intofoliojs:masterfrom
jspears wants to merge 23 commits intofoliojs:masterfrom
Conversation
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
…ort-color-emoji-google
Some glyphs are marked as type 'COLR' by fontkit but have null layers (e.g. certain emoji sequences where the COLR table doesn't contain an entry). This caused TypeError: Cannot read properties of null (reading 'length') when iterating glyph.layers. - Add glyph.layers check at call site so null-layer glyphs fall through to the image/bitmap rendering path - Add defensive null guard inside _renderCOLREmoji itself
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 support for two additional color emoji font formats, building on the SBIX support in #1690.
COLR/CPAL (Vector Emoji)
_renderCOLREmoji()— Renders COLR glyphs by iterating color layers, setting fill colors from the CPAL palette, converting path commands (including quadratic→cubic bezier conversion) to PDF operators.CBDT/CBLC (Bitmap Emoji — Google Noto Color Emoji)
_extractCBDTBitmap()— Navigates the CBLC strike index to find the best bitmap size, looks up glyph offsets via IndexSubtable (versions 1-5), and reads raw PNG data from CBDT (formats 17, 18, 19)._calcGlyphOffsetInCBDT()— Computes glyph offsets from fontkit's parsed subtable data._manualCBLCLookup()— Fallback that manually parses raw CBLC binary data when fontkit's parser doesn't cover the target glyph._emojiFragmentFallback()— Graceful degradation for fonts where fontkit'slayout()fails (e.g., NotoColorEmoji). Uses_cmapProcessor.lookup()per codepoint and extracts CBDT bitmaps directly. Should work with PR fontkit pr 366Routing
_emojiFragment()updated to route based onglyph.type:COLR→ vector rendering, else → bitmap (SBIX or CBDT fallback)._emojiFragmentFallback()for fonts wherelayout()crashes.Bug Fixes
Q(graphics state pop). Explicit fill color reset ensures subsequent text renders correctly.getGlyph()returns null for CBDT-only fonts. Added try-catch in both_emojiWidthOfStringand_emojiFragmentwith fallback paths.Tests
_calcGlyphOffsetInCBDT,_extractCBDTBitmap,_manualCBLCLookup,_getEmojiImage,_emojiFragment, and_renderCOLREmoji.Usage
Limitations
Pull Request opened by Augment Code with guidance from the PR author