feat: add fontStretch and fontKerning support#1160
Merged
Brooooooklyn merged 1 commit intomainfrom Dec 6, 2025
Merged
Conversation
e7e30cf to
22bb41a
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements two new properties for CanvasRenderingContext2D: fontStretch and fontKerning, per the HTML Canvas specification. These properties allow fine-grained control over font rendering characteristics independent of the font string.
Key changes:
- Added
fontStretchproperty supporting 9 values from ultra-condensed to ultra-expanded, with "normal" as default - Added
fontKerningproperty with auto/none/normal values, with "auto" as default - Both properties silently ignore invalid values per the Canvas spec
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/state.rs | Added font_stretch, font_stretch_raw, and font_kerning fields to Context2dRenderingState with appropriate defaults |
| src/sk.rs | Added FontKerning enum with FromStr implementation and updated FFI function signatures to pass kerning parameter |
| src/font.rs | Made parse_font_stretch function public to support the new fontStretch setter |
| src/ctx.rs | Added getter/setter methods for fontStretch and fontKerning properties, updated text rendering to use state.font_stretch instead of font_style.stretch |
| skia-c/skia_c.hpp | Updated function signature to include kerning parameter |
| skia-c/skia_c.cpp | Implemented kerning via OpenType "kern" font feature with proper value mapping (0=auto/no-op, 1=disable, 2=enable) |
| test/text.spec.ts | Added comprehensive tests for both properties including default values, visual rendering, and invalid value handling |
| test/snapshots/font-stretch.png | Snapshot for visual verification of fontStretch rendering |
| test/snapshots/font-kerning.png | Snapshot for visual verification of fontKerning rendering |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
25108de to
e769a5c
Compare
Implement fontStretch and fontKerning properties on CanvasRenderingContext2D per the HTML Canvas specification. fontStretch: - Accepts: ultra-condensed, extra-condensed, condensed, semi-condensed, normal, semi-expanded, expanded, extra-expanded, ultra-expanded - Default: "normal" - Invalid values are silently ignored fontKerning: - Accepts: auto, none, normal - Default: "auto" - Implemented via OpenType "kern" font feature - Invalid values are silently ignored 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
e769a5c to
6ef8a4f
Compare
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.
Implement fontStretch and fontKerning properties on CanvasRenderingContext2D per the HTML Canvas specification.
fontStretch:
fontKerning:
🤖 Generated with Claude Code