Skip to content

Conversation

@Brooooooklyn
Copy link
Owner

This commit adds comprehensive support for variable fonts to the canvas library.

Changes:

  • Added C++ FFI functions to query variable font axes and check if a font has variations
  • Extended text rendering to support custom variable font axis values
  • Added Rust bindings for new variable font functions
  • Exposed JavaScript API through GlobalFonts:
    • getVariationAxes(familyName, weight, width, slant): returns array of axis information
    • hasVariations(familyName, weight, width, slant): checks if font is variable
  • Added TypeScript definitions for FontVariationAxis interface
  • Created tests demonstrating the new functionality

The implementation leverages Skia's existing variable font support through SkTypeface::getVariationDesignPosition() and allows setting variation coordinates via SkFontArguments::setVariationDesignPosition() in TextStyle.

Variable fonts allow continuous interpolation of font properties like weight, width, slant, optical size, and custom axes, providing much more flexibility than traditional static fonts.

This commit adds comprehensive support for variable fonts to the canvas library.

Changes:
- Added C++ FFI functions to query variable font axes and check if a font has variations
- Extended text rendering to support custom variable font axis values
- Added Rust bindings for new variable font functions
- Exposed JavaScript API through GlobalFonts:
  - getVariationAxes(familyName, weight, width, slant): returns array of axis information
  - hasVariations(familyName, weight, width, slant): checks if font is variable
- Added TypeScript definitions for FontVariationAxis interface
- Created tests demonstrating the new functionality

The implementation leverages Skia's existing variable font support through
SkTypeface::getVariationDesignPosition() and allows setting variation
coordinates via SkFontArguments::setVariationDesignPosition() in TextStyle.

Variable fonts allow continuous interpolation of font properties like weight,
width, slant, optical size, and custom axes, providing much more flexibility
than traditional static fonts.
The TextStyle::setFontArguments method expects std::optional<SkFontArguments>,
not a raw SkFontArguments object. This commit fixes the C++ compilation issue.
Skia's API has changed from (pointer, count) to SkSpan. Updated all
calls to getVariationDesignPosition to use the modern SkSpan API:
- Call with empty span {} to get count
- Call with {data, size} to retrieve coordinates
napi-rs doesn't support f32, only f64. Updated FontVariationAxis
struct to use f64 for all float fields.
ES modules don't have __dirname by default. Use the standard pattern
of dirname(fileURLToPath(import.meta.url)) to get the directory path,
consistent with other test files in the project.
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