#font #wrapper #fontconfig #search #linux

fontconfig-rs

Safe, higher-level wrapper around the fontconfig library

2 releases

0.1.1 Jun 21, 2022
0.1.0 Jun 21, 2022

#1548 in Text processing

Download history 39/week @ 2024-03-11 24/week @ 2024-03-18 33/week @ 2024-03-25 59/week @ 2024-04-01 147/week @ 2024-04-08 81/week @ 2024-04-15 25/week @ 2024-04-22 7/week @ 2024-04-29 14/week @ 2024-05-06 10/week @ 2024-05-13 24/week @ 2024-05-20 15/week @ 2024-05-27 80/week @ 2024-06-03 40/week @ 2024-06-10 13/week @ 2024-06-17 26/week @ 2024-06-24

161 downloads per month
Used in fontloader

MIT license

95KB
2.5K SLoC

fontconfig


A wrapper around freedesktop.org's Fontconfig library, for locating fonts on a UNIX like systems such as Linux and FreeBSD. Requires Fontconfig to be installed.

Dependencies

  • Alpine Linux: fontconfig-dev
  • Arch Linux: fontconfig
  • Debian-based systems: libfontconfig1-dev
  • FreeBSD: fontconfig
  • Void Linux: fontconfig-devel

Usage

main.rs:

use fontconfig::FontConfig;

fn main() {
    let fc = FontConfig::new().unwrap();
    // `FontConfig::find()` returns `Option` (will rarely be `None` but still could be)
    let font = fc.find("freeserif", None).unwrap();
    // `name` is a `String`, `path` is a `Path`
    println!("Name: {}\nPath: {}", font.name, font.path.display());
}

You could then, for example, use font.path to create a GlyphCache from opengl_graphics and pass it to conrod.

Cargo Features

Feature Description Default Enabled Extra Dependencies
dlopen dlopen libfontconfig at runtime

The dlopen feature enables building this crate without dynamically linking to the Fontconfig C library at link time. Instead, Fontconfig will be dynamically loaded at runtime with the dlopen function. This can be useful in cross-compiling situations as you don't need to have a version of Fontcofig available for the target platform available at compile time.

Other Fontconfig Crates

  • servo-fontconfig — This crate provides a low-level interface only. It depends on servo-fontconfig-sys, which will fall back to building a vendored version of Fontconfig if a compatible version can't be found. It in-turn depends on expat-sys, which does the same thing regarding a vendored version of Expat. This makes it easier if you are distributing a code base that needs Fontconfig, but provides less control over the libraries that will be used.
  • fontconfig-sys — superceded by yeslogic-fontconfig-sys.
  • fontconfig — Which crate that we forked from.

Credits

Dependencies

~0.5–6MB
~20K SLoC