Crate fontconfig

source ·
Expand description

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. Alternatively, set the environment variable RUST_FONTCONFIG_DLOPEN=on or enable the dlopen Cargo feature to load the library at runtime rather than link at build time (useful for cross compiling).

See the Fontconfig developer reference for more information.

§Dependencies

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

§Usage

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());
}

§Cargo Features

FeatureDescriptionDefault EnabledExtra Dependencies
dlopendlopen 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.

Structs§

  • A very high-level view of a font, only concerned with the name and its file location.
  • Wrapper around FcFontSet.
  • Handle obtained after Fontconfig has been initialised.
  • Wrapper around FcObjectSet.
  • A safe wrapper around fontconfig’s FcPattern.
  • Wrapper around FcStrList
  • Error type returned from Pattern::format.

Enums§

  • The format of a font matched by Fontconfig.

Constants§

Functions§

  • Return a FontSet containing Fonts that match the supplied pattern and objects.
  • Returns a FontSet containing fonts sorted by closeness to the supplied pattern. If trim is true, elements in the list which don’t include Unicode coverage not provided by earlier elements in the list are elided.