feat: add fontVariantCaps#1161
Merged
Brooooooklyn merged 1 commit intomainfrom Dec 6, 2025
Merged
Conversation
248cf2d to
8dbf2b5
Compare
1. Support `fontVariantCaps`, corresponding to `CanvasRenderingContext2D.fontVariantCaps` in the Canvas API 2. Support for `<font-variant-css2>= normal | small-caps` within the `font` shorthand. e.g. ```js // ✅ Valid ctx.font = ‘small-caps 36px Roboto Mono’; ctx.font = ‘normal 36px Roboto Mono’; // ❌ Other `font-variant-caps` values are invalid, consistent with the specification ctx.font = ‘petite-caps 36px Roboto Mono’; ```
8dbf2b5 to
5948330
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for the fontVariantCaps property to the Canvas API, matching the standard CanvasRenderingContext2D.fontVariantCaps specification. The implementation enables developers to control how text is rendered with different capitalization variants (small-caps, all-small-caps, petite-caps, all-petite-caps, unicase, and titling-caps) both via the dedicated property and through the CSS font shorthand notation.
Key changes:
- Added
FontVariantCapsenum with all seven standard values (normal, small-caps, all-small-caps, petite-caps, all-petite-caps, unicase, titling-caps) - Integrated font-variant-css2 support (
normal | small-caps) in the CSS font shorthand parser - Implemented OpenType font feature mapping in the C++ layer to properly render variant caps using tags like 'smcp', 'c2sc', 'pcap', 'c2pc', 'unic', and 'titl'
Reviewed changes
Copilot reviewed 6 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/state.rs | Added font_variant_caps field to Context2dRenderingState with default value Normal |
| src/sk.rs | Defined FontVariantCaps enum with 7 variants, implemented FromStr and as_str() methods, and added parameter to draw_text and get_line_metrics functions |
| src/ctx.rs | Added getter/setter methods for fontVariantCaps property and integrated font shorthand parsing to automatically set fontVariantCaps based on CSS font-variant-css2 |
| skia-c/skia_c.hpp | Added variant_caps parameter to skiac_canvas_get_line_metrics_or_draw_text function signature |
| skia-c/skia_c.cpp | Implemented OpenType font feature mapping logic using conditional branches to apply appropriate feature tags (smcp, c2sc, pcap, c2pc, unic, titl) based on variant_caps value |
| test/text.spec.ts | Added comprehensive test coverage including default value tests, invalid value handling, all variant values, visual rendering tests, CSS shorthand integration tests, and equivalence tests |
| test/snapshots/font-variant-caps.png | Snapshot file for visual regression testing of all fontVariantCaps values |
| test/snapshots/font-variant-caps-from-css-font-shorthand.png | Snapshot file for visual regression testing of font shorthand integration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
|
cursor review |
Owner
|
@codex review |
Brooooooklyn
approved these changes
Dec 6, 2025
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.
fontVariantCaps, corresponding toCanvasRenderingContext2D.fontVariantCapsin the Canvas APIChrome bug#40457093
<font-variant-css2>= normal | small-capswithin thefontshorthand.e.g.
Fixed: #804
Part of #113
Note
Adds
fontVariantCapsacross the JS API and rendering pipeline (including small-caps viafontshorthand) and maps variants to OpenType features in Skia; includes tests.FontVariantCapsenum and plumbvariant_capsthrough FFI (skia_c.hpp/.cpp),src/sk.rs, andsrc/ctx.rsdraw/metrics paths.font-variant-capsvalues to OpenType features (smcp,c2sc,pcap,c2pc,unic,titl).CanvasRenderingContext2Dstate withfontVariantCaps(defaultnormal) plus getters/setters.fontshorthand to setfontVariantCapsfornormal | small-caps.font-variant-capsvalues, rendering snapshots, shorthand vs property equivalence, and shorthand parsing.Written by Cursor Bugbot for commit 5948330. This will update automatically on new commits. Configure here.