Skip to main content

Module google_fonts

Module google_fonts 

Source
Expand description

Google Fonts download and disk-cache helpers.

§Cache layout

~/.cache/rustmotion/fonts/
    inter-400.ttf
    inter-700.ttf
    jetbrains-mono-400.ttf

File names are derived from the family name by lower-casing and replacing spaces with hyphens: "JetBrains Mono""jetbrains-mono".

§Network protocol

  1. GET https://fonts.googleapis.com/css2?family=<Family+Name>:wght@<w1>;<w2> with ureq’s default (non-browser) User-Agent. Google returns a CSS stylesheet containing url(…) entries pointing at .ttf files.
  2. We extract every url(…) from the CSS and download each TTF.

No new crate dependencies are introduced; ureq (v3) is already in rustmotion-core.

Functions§

build_css2_url
Build the Google Fonts CSS2 API URL.
family_slug
Convert a font family name to a filesystem-safe slug.
font_cache_dir
Returns the platform-appropriate font cache directory.
parse_ttf_urls
Extract all url(…) values that end with .ttf from a Google Fonts CSS response. No regex crate is used — we find url( markers and extract the inner content.
resolve_google_font
Ensure TTFs for family + weights are present on disk (download if needed) and return their paths.