Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements comprehensive font feature support for the canvas API to align with W3C/WHATWG standards. It adds eight new text rendering properties that control OpenType font features, ligatures, numeric styles, text positioning, and language-specific rendering.
- Adds
fontFeatureSettingsfor direct OpenType feature control - Implements
fontVariantLigatures,fontVariantNumeric, andfontVariantPositionfor standardized font variant control - Adds
textRendering,fontOpticalSizing,lang, andfontSizeAdjustproperties for enhanced typography control - Extends FFI to pass font features to the native Skia rendering layer
Reviewed changes
Copilot reviewed 8 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/state.rs | Adds new font feature state fields with appropriate defaults |
| src/sk.rs | Implements enums and parsing for font feature properties, includes OpenType feature tag generation |
| src/ctx.rs | Adds getters/setters and font feature collection logic |
| src/font.rs | Enhances font parsing with CSS Fonts Level 4 compliance (property-independent keyword rejection, oblique angle defaults, weight rounding) |
| src/lib.rs | Removes unused initialization function |
| skia_c/skia_c.hpp | Updates FFI signature to accept font features and related parameters |
| skia_c/skia_c.cpp | Implements font-size-adjust calculation, font feature application, language-specific handling, and textRendering overrides |
| index.d.ts | Adds TypeScript type definitions for new properties |
| test/text.spec.ts | Adds comprehensive test coverage including snapshot tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
skia-c/skia_c.cpp
Outdated
| // Apply font weight as 'wght' variation for variable fonts | ||
| // 'wght' tag = 0x77676874 | ||
| if (weight != 400) { | ||
| coords.push_back({SkSetFourByteTag('w', 'g', 'h', 't'), static_cast<float>(weight)}); |
| } | ||
|
|
||
| // Apply language/locale for language-specific glyph variants | ||
| // lang: BCP-47 language tag (e.g., "en", "tr", "zh-Hans") or |
There was a problem hiding this comment.
按照 Chrome 开发者给出的答复,这里我们不需要兼容 BCP-47 算法,交给底层的 harfbuzz 来处理就好了
| } else { | ||
| // Per W3C CSS Fonts Level 4: default oblique angle is 14deg | ||
| // See: https://drafts.csswg.org/css-fonts-4/#font-style-prop | ||
| font.oblique_angle = Some(14.0); |
There was a problem hiding this comment.
font-style 需要重写,这块也比较复杂,单独来做吧。
| fontVariantLigatures: CanvasFontVariantLigatures | ||
| fontVariantNumeric: CanvasFontVariantNumeric | ||
| fontVariantPosition: CanvasFontVariantPosition | ||
| fontSizeAdjust: number | null |
There was a problem hiding this comment.
让我们标识出哪些是目前 canvas 规范中的,哪些是我们实验性的私有方法。
|
总的来说,请把 |
1367a2f to
343be29
Compare
Note
Adds broad Canvas2D text/font support aligned with W3C/WHATWG and MDN examples.
textRendering,lang,fontOpticalSizing,fontFeatureSettings,fontVariantLigatures,fontVariantNumeric,fontVariantPosition,fontSizeAdjust(getters/setters, state, typings)opsz(auto), honors variable axes (wght/wdthunless overridden), computesfont-size-adjustvia x-height, locale-aware ligatures (e.g., Turkish disablesfi), andtextRenderingtoggles kerning/ligaturesfont-feature-settingssyntax; improvefontshorthand parsing (reject global keywords, defaultoblique14deg with clamping, round numeric weights, disallow negative sizes, handle percentage as size)index.d.tsfor new types/fields; adds FFI structs (FontFeature) and extends C++/Rust bridges and render paths to carry features/optionsWritten by Cursor Bugbot for commit 343be29. This will update automatically on new commits. Configure here.