feat: Add font hinting support via skrifa#1000
Closed
oetiker wants to merge 1 commit into
Closed
Conversation
Collaborator
|
I appreciate the effort, but unfortunately I don't think we can pull in skrifa as a dependency right now, otherwise we have ttf-parser AND skrifa in the dependency tree. We have plans for replacing ttf-parser, but it requires quite a few changes and I don't know yet when that will happen. |
Collaborator
|
The transition to Skrifa/Fontations is implemented in #922 (except for fontdb). I suggest we merge that after the next release at which point we could look at this PR again. |
Collaborator
|
I agree. #922 should be merged first. |
Supersedes linebender#922 (nicoburns' "Port resvg to harfrust and fontations") This patch builds upon the excellent groundwork laid out in PR linebender#922, which identified harfrust and skrifa as the path forward for long-term maintainability. As noted in that discussion, these actively-maintained libraries offer significant advantages: harfrust passes substantially more shaping tests than rustybuzz, and skrifa provides a modern, well-designed API for font parsing. Core migration (shared with linebender#922): - Replace rustybuzz with harfrust for OpenType text shaping - Replace ttf-parser with skrifa for font parsing and metrics - Update font metrics extraction to use skrifa's MetadataProvider Where this implementation extends linebender#922: 1. Font Hinting Support - Add optional `hinting` feature and HintingOptions in parser options - Implement hinted outline extraction via skrifa's HintingInstance - Honor CSS text-rendering property: geometricPrecision disables hinting, optimizeLegibility/optimizeSpeed enable full hinting - Configurable DPI for ppem calculation 2. Full Variable Font Support - Parse font-variation-settings CSS property - Parse font-optical-sizing CSS property (auto/none) - Auto-map standard properties to variation axes: * font-weight → wght axis * font-stretch → wdth axis * font-style: italic → ital axis * font-style: oblique → slnt axis - Auto-set opsz axis based on font size when font-optical-sizing: auto - Store per-glyph variation context in PositionedGlyph for correct outline extraction with variations applied 3. Modular Skrifa Integration - New skrifa_metrics.rs: Font metrics via skrifa's MetadataProvider - New skrifa_colr.rs: COLR rendering via skrifa's ColorPainter trait - Delete legacy colr.rs (ttf-parser based implementation) 4. Enhanced COLR Support - Implement skrifa's ColorPainter trait for SVG output - Support COLRv1 features: transforms, clips, composite modes - Handle linear, radial gradients with proper spread methods 5. Test Infrastructure - Add tests-hinted/ directory with hinted reference images - Add font-variation-settings test suite - Include RobotoFlex variable font for variation testing We appreciate the careful analysis in linebender#922 regarding the ecosystem trade-offs, particularly around compile times and binary size. This implementation accepts those trade-offs in exchange for the additional capabilities (hinting, variable fonts) that skrifa enables. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
Author
|
closing and opening fresh |
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.
Implement optional font hinting using Google's skrifa library for better
text rendering at small sizes. Hinting grid-fits glyph outlines to pixel
boundaries, improving legibility.
Features:
hintingcargo feature flag (requirestextfeature)Implementation:
to work with existing transform pipeline
Tests: