-
Notifications
You must be signed in to change notification settings - Fork 289
Port to harfrust/skrifa with hinting and variable font support #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
oetiker
wants to merge
8
commits into
linebender:main
Choose a base branch
from
oetiker:skrifa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
8ec6bd8 to
6662a49
Compare
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy fontdb 0.23.0 source code into crates/fontdb/ as a first step toward replacing ttf-parser with skrifa for font metadata parsing. Source: https://github.com/RazrFalcon/fontdb (MIT licensed) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
8f31d4e to
6688502
Compare
This eliminates the ttf-parser dependency by modifying the vendored fontdb to use skrifa for font parsing. Key changes: - Replace ttf_parser::fonts_in_collection with FileRef::new().len() - Replace ttf_parser::RawFace with FontRef::from_index() - Replace ttf_parser name table parsing with font.localized_strings() - Replace OS/2 table parsing with font.attributes() - Replace post table parsing with font.metrics() and font.post() - Add local Language enum (simplified: EnglishUnitedStates + Unknown) - Add local Stretch enum with to_number() for CSS matching - Add stretch_from_skrifa() for skrifa::attribute::Stretch conversion - Update usvg to use vendored fontdb via path dependency - Update Rust 2024 edition patterns (remove redundant ref bindings) The MAC_ROMAN encoding table is removed as skrifa handles all name table encodings internally via LocalizedString::chars(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix incorrect safety comment on mmap (fontdb) - Replace deprecated core::u64::MAX with u64::MAX (fontdb) - Use .first() instead of .get(0) (fontdb) - Fix potential panics on empty slices in font fallback (usvg/text/mod.rs) - Add empty path check in path_length() (usvg/parser/text.rs) - Add ASCII validation for font variation tags (usvg/parser/text.rs) - Use idiomatic .or() instead of .map_or() (usvg/parser/text.rs) - Return &TextFlow instead of clone in text_flow() (usvg/tree/text.rs) - Add logging for checked_sub failure (usvg/text/layout.rs) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move `variations`, `font_optical_sizing`, and `hinting` fields from `PositionedGlyph` to `Span` struct since these values are uniform for all glyphs within a span. Benefits: - Reduces memory by not duplicating Vec<FontVariation> per glyph - Cleaner data model: span-level properties at span level - Minor perf improvement: needs_variations check once per span Based on PR linebender#997 review feedback. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The empty --drop-tables= flag doesn't do anything. Remove it. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace the simple (font_id, glyph_id) HashMap cache with a comprehensive LRU cache that captures all parameters affecting glyph outline shape: - Font ID and glyph ID - PPEM for hinting (stored as f32::to_bits() for exact matching) - Hinting settings (target, mode, engine, symmetric, preserve_linear_metrics) - Variation hash (computed from sorted variations + auto-opsz) Key changes: - Add `lru` crate dependency for bounded cache with LRU eviction - Add OutlineCacheKey struct capturing all outline-affecting parameters - Add CacheStats for tracking hits/misses/evictions - Add compute_variation_hash() for consistent variation hashing - Replace HashMap with LruCache (default capacity: 10,000 entries) - Unify three code paths (simple/variable/hinted) into single cache lookup - Add cache management methods (stats, clear, resize, len, capacity) This ensures that hinted outlines and variable font outlines are now cached, significantly improving performance for text-heavy documents with repeated glyphs at the same settings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document all changes from the skrifa branch: - Hinting support with CSS custom properties - Variable font support with avar normalization - LRU outline cache with full parameter support - Port from ttf-parser/rustybuzz to skrifa/harfrust - Vendored fontdb ported to skrifa - Various bug fixes and improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
Author
|
I will be producing additional PRs based on this branch once the skrifa switch is merged |
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.
Supersedes #922 (nicoburns' "Port resvg to harfrust and fontations")
This patch builds upon the excellent groundwork laid out in PR #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 #922)
Additional Changes
New Features
1. Font Hinting Support
HintingOptionsin parser optionstext-renderingproperty controls per-element hinting:geometricPrecision: disables hinting (preserve exact outlines)optimizeLegibility/optimizeSpeed: enables full hintingCustom Hinting Properties (resvg extensions)
Fine-grained control via custom CSS properties or SVG attributes:
-resvg-hinting-targetsmooth,monosmooth-resvg-hinting-modenormal,light,lcd,vertical-lcdnormal-resvg-hinting-engineauto,native,auto-fallbackauto-fallback-resvg-hinting-symmetrictrue,falsetrue-resvg-hinting-preserve-linear-metricstrue,falsefalseUsage as SVG attributes (with
resvg:namespace) or CSS properties (with-resvg-prefix):2. Full Variable Font Support
font-variation-settingsCSS propertyfont-optical-sizingCSS property (auto/none)font-weight→wghtaxisfont-stretch→wdthaxisfont-style: italic→italaxisfont-style: oblique→slntaxisopszaxis based on font size whenfont-optical-sizing: autoPositionedGlyph3. Bitmap Font Mask Support
4. PNG Output with DPI Metadata
New public API for PNG encoding with resolution metadata:
resvg::encode_png_with_dpi()- Encode pixmap with DPI in pHYs chunkresvg::save_png_with_dpi()- Save pixmap with DPI metadataUseful for print output and e-ink displays where physical resolution matters.
5. Enhanced COLR Support
skrifa_colr.rsDocumentation
usvgandresvgcratesHintingSettings,HintingTarget,HintingMode,HintingEngineFontVariation,FontOpticalSizingHintingOptionsgenerate_hinting_comparison.rsTest Infrastructure
tests-hinted/directory with hinted reference imagesTrade-offs
We appreciate the careful analysis in #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.
🤖 Generated with Claude Code