Repository navigation
fix: embed the Latin block, not Google's first (Cyrillic) @font-face - #28
Merged
Merged
Conversation
…27) The Google Fonts CSS API splits its response into one @font-face block per script, listing Cyrillic first. The CSS download fallback took the first url() it found, so the cached "full" WOFF2 was actually the Cyrillic subset (82 glyphs, no a-z/digits/pt-BR accents) and save_svg() without subset_fonts embedded a font unable to render Latin text. - New google_css_latin_url() parses every @font-face block and picks the one whose unicode-range covers Basic Latin (tests U+0041), with a first-URL fallback for single-block responses (&text= subsets, TTF). Applied to both the WOFF2 and the TTF fallback paths. - Validate downloaded WOFF2 files by magic bytes and unlink failed or invalid downloads so they never poison the cache via the early file.exists() return. - One-time cache migration (.cache-v2 marker in font_cache_dir()): full fonts cached by earlier versions are discarded and re-downloaded on demand; glyph subsets (_sub<hash>) are kept. - 6 new offline tests (realistic CSS2 fixture, unicode-range parsing, magic bytes, cache migration). R CMD check: 0 errors, 0 warnings, 0 notes. Bump version to 0.3.1 (first commit of the new cycle). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Cache migration no longer deletes anything: pre-0.3.1 full fonts are moved to a stale-pre-0.3.1/ quarantine folder (register_font() copies local, possibly irreplaceable fonts into the same cache with the same naming scheme), with a one-time cli message. Extracted to migrate_font_cache() and skipped when the marker cannot be written (read-only cache dirs no longer rescan on every call). - TTF fallback downloads are validated by sfnt magic bytes (00 01 00 00 / true / ttcf / OTTO), like the WOFF2 path. - google_css_latin_url() takes multiple URL patterns and tries them PER BLOCK, so a response mixing URL styles across blocks cannot hide the latin block behind the first-URL fallback. - download_google_font_woff2() checks the cache for alternative extensions (ttf/woff/otf) on entry instead of re-downloading a font cached by the TTF fallback or gfonts on every call. - Migration test runs on an isolated directory instead of mutating the shared per-session cache; new tests for is_ttf_file() and the mixed-URL-style response. 215 tests, R CMD check 0/0/0. - NEWS.md documents the quarantine and the latin-ext known limitation (full-font embedding covers Basic Latin + Latin-1; use subset_fonts for arbitrary text). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Oct 27, 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.
Fixes #27
Problem
The Google Fonts CSS API splits its response into one
@font-faceblock per script, listing Cyrillic first.download_google_font_woff2()took the firsturl()it found, so the cached "full"Jost.woff2was actually the Cyrillic subset (82 glyphs, noa-z, digits or pt-BR accents).save_svg()withoutsubset_fontsembedded a font unable to render Latin text and viewers fell back to system fonts, defeating deterministic rendering. The TTF fallback path had the same defect. Only the CSS fallback path was affected — downloads viagfontswere always correct, andsubset_fonts = TRUEwas never affected.Fix
google_css_latin_url()parses every@font-faceblock and picks the one whoseunicode-rangecovers Basic Latin (testsU+0041), with a first-URL fallback for single-block responses (&text=subsets, TTF). Applied to both the WOFF2 and the TTF fallback paths. Backed byunicode_range_covers()(ranges, single code points,U+4??wildcards).wOF2) in addition to the size rule; failed or invalid downloads areunlink()ed so they never poison the cache via the earlyfile.exists()return..cache-v2marker infont_cache_dir()): full fonts cached by earlier versions (potentially the Cyrillic subset) are discarded and re-downloaded on demand; glyph subsets (_sub<hash>) are kept.Validation
...-Cw.woff2); the fix picks the latin block URL, whoseunicode-rangecoversU+0041, and the downloaded file passes WOFF2 validation.unicode-rangeparsing, magic bytes, cache migration) — 208 passing total.R CMD check: 0 errors, 0 warnings, 0 notes.Version bumped to 0.3.1 (first commit of the new cycle),
NEWS.mdupdated. Candidate for the next CRAN submission window (~2026-11-25).🤖 Generated with Claude Code