Skip to content

Align font features#1167

Open
Brooooooklyn wants to merge 1 commit intonew-fontfrom
align-font-features
Open

Align font features#1167
Brooooooklyn wants to merge 1 commit intonew-fontfrom
align-font-features

Conversation

@Brooooooklyn
Copy link
Owner

@Brooooooklyn Brooooooklyn commented Dec 8, 2025

Note

Adds broad Canvas2D text/font support aligned with W3C/WHATWG and MDN examples.

  • New properties: textRendering, lang, fontOpticalSizing, fontFeatureSettings, fontVariantLigatures, fontVariantNumeric, fontVariantPosition, fontSizeAdjust (getters/setters, state, typings)
  • Skia integration: passes explicit features, applies opsz (auto), honors variable axes (wght/wdth unless overridden), computes font-size-adjust via x-height, locale-aware ligatures (e.g., Turkish disables fi), and textRendering toggles kerning/ligatures
  • Parsing: support font-feature-settings syntax; improve font shorthand parsing (reject global keywords, default oblique 14deg with clamping, round numeric weights, disallow negative sizes, handle percentage as size)
  • API surface: updates index.d.ts for new types/fields; adds FFI structs (FontFeature) and extends C++/Rust bridges and render paths to carry features/options
  • Tests: extensive unit and snapshot tests for kerning, ligatures, numeric forms, superscripts/subscripts, optical sizing, size-adjust, text-rendering modes, locale effects, and parsing edge cases

Written by Cursor Bugbot for commit 343be29. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings December 8, 2025 11:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fontFeatureSettings for direct OpenType feature control
  • Implements fontVariantLigatures, fontVariantNumeric, and fontVariantPosition for standardized font variant control
  • Adds textRendering, fontOpticalSizing, lang, and fontSizeAdjust properties 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.

// 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)});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me do it at #1162.

}

// Apply language/locale for language-specific glyph variants
// lang: BCP-47 language tag (e.g., "en", "tr", "zh-Hans") or
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

font-style 需要重写,这块也比较复杂,单独来做吧。

fontVariantLigatures: CanvasFontVariantLigatures
fontVariantNumeric: CanvasFontVariantNumeric
fontVariantPosition: CanvasFontVariantPosition
fontSizeAdjust: number | null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

让我们标识出哪些是目前 canvas 规范中的,哪些是我们实验性的私有方法。

@yisibl
Copy link
Collaborator

yisibl commented Dec 21, 2025

总的来说,请把 font 属性相关的改进交给 #1183 来完成吧。这需要系统性的解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants