Add automatic fontsource font detection and downloading#246
Merged
Conversation
ed148bb to
29c9209
Compare
29c9209 to
d437728
Compare
8714c5d to
5a77b20
Compare
jonmmease
added a commit
that referenced
this pull request
Mar 5, 2026
CSS font-family parser, Vega spec font traversal, and first-font resolution for the auto_fontsource pipeline. Ported from PR #246. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CSS font-family parser, Vega spec font traversal, and first-font resolution for the auto_fontsource pipeline. Ported from PR #246. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Lightweight metadata-only check (no blob download) to determine if a font ID exists on Fontsource. Returns true/false, propagating network errors. Used by the auto_fontsource pipeline to classify fonts before attempting downloads. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add MissingFontsPolicy enum (Fallback/Warn/Error) and auto_fontsource flag to VlConverterConfig. Implement preprocess_fonts() pipeline that extracts font references from Vega specs, checks local availability via fontdb, queries Fontsource API for missing fonts, and downloads them on-demand. Hook font preprocessing into all vega_to_* and vegalite_to_* conversion methods. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add MissingFontsArg enum mapping to MissingFontsPolicy, and wire both --auto-fontsource and --missing-fonts global flags through all CLI subcommands into VlConverterConfig. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add auto_fontsource and missing_fonts kwargs to configure(), expose them in get_converter_config() output, and update vl_convert.pyi type stubs with both sync and async signatures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
93a76b3 to
2adfb92
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace naive comma-splitting with svgtypes::parse_font_families, which correctly handles quoted names, escaping, and multi-word unquoted families. Falls back to naive parsing for non-standard idents that svgtypes rejects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove config keys that don't exist in the Vega spec and can't appear in compiled Vega output: - 4 VL-only axis keys (axisDiscrete, axisPoint, axisQuantitative, axisTemporal) - 4 header config keys (header, headerColumn, headerRow, headerFacet) - config.font top-level (not in Vega's Config interface) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove parse_css_font_family_naive and strip_quotes helpers — svgtypes handles all real-world font names; invalid CSS idents now return an empty list instead of attempting naive parsing. Also remove decorative section-header comments and add CSS Fonts Level 4 spec link. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ation Delete tests/test_extract.rs (266 lines) — its 10 tests were a subset of the 42 inline tests in extract.rs. Moved the 2 unique cases (whitespace-only input, quoted font with comma) inline. Also removed section-header comments from the test module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update docstrings on MissingFontsPolicy enum, its variants, preprocess_fonts, and the VlConverterConfig field to make clear that only the first non-generic font in each CSS font-family string is checked. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eline preprocess_fonts() now returns Vec<FontsourceFontRequest> instead of globally registering fonts via register_fontsource_font(). The caller adds auto-detected font requests to VgOpts.fontsource_fonts, letting the existing resolve → with_font_overlay! pipeline handle download and per-request registration/cleanup. This prevents unbounded memory growth from auto-downloaded fonts persisting for the process lifetime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Mar 7, 2026
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.
Summary
Add automatic font detection and downloading from Fontsource during Vega/Vega-Lite conversions. When
auto_fontsourceis enabled, vl-convert parses the compiled Vega spec to find referenced fonts, checks them against the local fontdb, and downloads missing fonts from Fontsource before rendering.Builds on PR #245 (fontsource crate + explicit
register_fontsource_font()API). This PR adds automatic detection/download plus configurable missing-font handling.Motivation
With explicit
register_fontsource_font(), users must manually identify which fonts a spec references and pre-install them. This is error-prone, especially for theme-driven fonts or specs with many font references.This PR separates two independent concerns:
auto_fontsource(bool) — whether to download missing fonts from Fontsource automaticallymissing_fonts(policy) — what happens when referenced fonts are unavailable:fallback(silent, default),warn, orerrorBehavior Matrix
auto_fontsourcemissing_fontsfalsefallbackfalsewarnfalseerrortruefallbacktruewarntrueerrorGeneric CSS families (
serif,sans-serif, etc.) are never flagged as missing. For multi-font CSS strings like"Roboto, Arial, sans-serif", only the first entry is checked/downloaded — this matches Vega's rendering behavior, which tries the first font and falls back to system generics.Backwards compatible: Both options default to off (
auto_fontsource: false,missing_fonts: "fallback"), so existing behavior is unchanged.Changes
New module:
vl-convert-rs/src/extract.rsfont-familyparsing viasvgtypes::parse_font_families()(spec-compliant quoting/escaping) with naive-split fallback for non-standard identsresolve_first_fonts()classifies each font string's first entry asAvailable,NeedsDownload,Generic, orUnavailabletests/test_extract.rsFontsource client:
vl-convert-fontsource/src/client.rsis_known_font()/is_known_font_blocking()— lightweight metadata-only check (no font file downloads)falseon 404Core library:
vl-convert-rs/src/converter.rsMissingFontsPolicyenum (Fallback,Warn,Error)auto_fontsourceandmissing_fontsfields onVlConverterConfigpreprocess_fonts()pipeline: extract → check local fontdb → query Fontsource → report/downloadmaybe_compile_vl_with_preprocessed_fonts()for VL→* methods (compiles VL→Vega first to avoid double compilation, preprocesses fonts, renders via Vg→* path)maybe_preprocess_vega_fonts()for Vg→* methodsCLI:
vl-convert/src/main.rs--auto-fontsource(bool flag)--missing-fonts <fallback|warn|error>(value enum)Python bindings:
vl-convert-python/src/lib.rs+vl_convert.pyiauto_fontsourceandmissing_fontskwargs onconfigure()get_converter_config()pyo3-logintegration: Rustlog::warn!()/log::error!()messages (missing font warnings, Fontsource API errors) are forwarded to Python'sloggingmodule