Skip to content

feat: add fontStretch and fontKerning support#1160

Merged
Brooooooklyn merged 1 commit intomainfrom
feat/font-stretch-kerning
Dec 6, 2025
Merged

feat: add fontStretch and fontKerning support#1160
Brooooooklyn merged 1 commit intomainfrom
feat/font-stretch-kerning

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Owner

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

Copilot AI review requested due to automatic review settings December 6, 2025 07:40
@Brooooooklyn Brooooooklyn force-pushed the feat/font-stretch-kerning branch from e7e30cf to 22bb41a Compare December 6, 2025 07:44
Copy link
Copy Markdown
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 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 fontStretch property supporting 9 values from ultra-condensed to ultra-expanded, with "normal" as default
  • Added fontKerning property 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.

@Brooooooklyn Brooooooklyn force-pushed the feat/font-stretch-kerning branch 3 times, most recently from 25108de to e769a5c Compare December 6, 2025 08:09
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>
@Brooooooklyn Brooooooklyn force-pushed the feat/font-stretch-kerning branch from e769a5c to 6ef8a4f Compare December 6, 2025 08:22
@Brooooooklyn Brooooooklyn merged commit 8da5eea into main Dec 6, 2025
37 checks passed
@Brooooooklyn Brooooooklyn deleted the feat/font-stretch-kerning branch December 6, 2025 08:39
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.

2 participants