google-fonts

Crates.iogoogle-fonts
lib.rsgoogle-fonts
version0.1.5
sourcesrc
created_at2024-07-19 23:25:38.512663
updated_at2024-07-23 22:23:58.791602
descriptionDownload and cache TTF fonts from Google.
homepage
repositoryhttps://github.com/rana/google-fonts
max_upload_size
id1309149
size31,534,440
Rana Ian (rana)

documentation

https://docs.rs/google-fonts

README

google-fonts

Download and cache TTF fonts from Google.

11,689 fonts and 1,708 font families.

Similar to Downloadable Fonts in Android Studio, and Web Fonts Google API.

Example

Download font data with a few approaches.

use google_fonts::lemonada_variable;
use google_fonts::Font::NotoSansRegular;
use google_fonts::Font::RobotoRegular;
use ttf_parser::Face;

fn main() {
    // Get and cache font data with a named function.
    let font_data = lemonada_variable().unwrap();
    let face = Face::parse(&font_data, 0).unwrap();
    eprintln!("Font data: {:?}", face);

    // Get and cache font data with an enum variant function.
    let font_data = NotoSansRegular.get_with_cache().unwrap();
    let face = Face::parse(&font_data, 0).unwrap();
    eprintln!("Font data: {:?}", face);

    // Get font data without caching by using an enum variant function.
    let font_data = RobotoRegular.get().unwrap();
    let face = Face::parse(&font_data, 0).unwrap();
    eprintln!("Font data: {:?}", face);
}

Crate features

full, variable, and static crate features are available.

  • variable enables only fonts with variable font technology.
  • static enables only fonts with static font technology.
  • full enables both variable and static features.

variable is the default feature.

Variable font technology is newer, more flexible, and provides style variations in one or two files. Static font technology uses more font files to accomplish the same thing. A majority of the fonts are in the static feature.

Prefer the variable feature when possible.

Enable the variable feature to significantly improve build time, crate size, and rust-analyzer performance.

Doc comment font images

View font images from docs.

tooltip

Commit count: 0

cargo fmt