#font #search #wrapper

fontconfig

Safe, higher-level wrapper around the Fontconfig library

8 breaking releases

0.9.0 Jul 3, 2024
0.8.0 Jan 18, 2024
0.7.0 Nov 21, 2023
0.6.0 Oct 18, 2022
0.0.1 Dec 11, 2014

#145 in Text processing

Download history 331/week @ 2024-07-23 333/week @ 2024-07-30 376/week @ 2024-08-06 967/week @ 2024-08-13 1067/week @ 2024-08-20 1075/week @ 2024-08-27 1258/week @ 2024-09-03 1564/week @ 2024-09-10 1006/week @ 2024-09-17 761/week @ 2024-09-24 594/week @ 2024-10-01 600/week @ 2024-10-08 659/week @ 2024-10-15 769/week @ 2024-10-22 1217/week @ 2024-10-29 1213/week @ 2024-11-05

3,973 downloads per month
Used in 7 crates (6 directly)

MIT license

55KB
1K SLoC

fontconfig


A wrapper around freedesktop.org's Fontconfig library, for locating fonts on UNIX-like systems such as Linux and BSD. 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 — superseded by yeslogic-fontconfig-sys.
  • yeslogic-fontconfig — This crate was previously published under this name before we were given access to publish it as fontconfig.

For our needs in Prince we wanted higher-level bindings that did not fall back on vendored versions of libraries, which is what the crates in this repo provide.

Credits

Thanks to Austin Bonander for originally creating the fontconfig crate and allowing us to publish ours under that name.

Dependencies

~0.1–4.5MB