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§

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

Enums§

FontFormat
The format of a font matched by Fontconfig.

Constants§

FC_ANTIALIAS
FC_ASPECT
FC_AUTOHINT
FC_CACHE_SUFFIX
FC_CAPABILITY
FC_CHARCELL
FC_CHARSET
FC_CHARSET_DONE
FC_CHARSET_MAP_SIZE
FC_CHARWIDTH
FC_CHAR_HEIGHT
FC_CHAR_WIDTH
FC_COLOR
FC_DECORATIVE
FC_DIR_CACHE_FILE
FC_DPI
FC_DUAL
FC_EMBEDDED_BITMAP
FC_EMBOLDEN
FC_FAMILY
FC_FAMILYLANG
FC_FILE
FC_FONTFORMAT
FC_FONTVERSION
FC_FONT_FEATURES
FC_FONT_HAS_HINT
FC_FONT_VARIATIONS
FC_FOUNDRY
FC_FT_FACE
FC_FULLNAME
FC_FULLNAMELANG
FC_GLOBAL_ADVANCE
FC_HASH
FC_HINTING
FC_HINT_FULL
FC_HINT_MEDIUM
FC_HINT_NONE
FC_HINT_SLIGHT
FC_HINT_STYLE
FC_INDEX
FC_LANG
FC_LCD_DEFAULT
FC_LCD_FILTER
FC_LCD_LEGACY
FC_LCD_LIGHT
FC_LCD_NONE
FC_MATRIX
FC_MINSPACE
FC_MONO
FC_NAMELANG
FC_ORDER
FC_OUTLINE
FC_PIXEL_SIZE
FC_POSTSCRIPT_NAME
FC_PRGNAME
FC_PROPORTIONAL
FC_RASTERIZER
FC_RGBA
FC_RGBA_BGR
FC_RGBA_NONE
FC_RGBA_RGB
FC_RGBA_UNKNOWN
FC_RGBA_VBGR
FC_RGBA_VRGB
FC_SCALABLE
FC_SCALE
FC_SIZE
FC_SLANT
FC_SLANT_ITALIC
FC_SLANT_OBLIQUE
FC_SLANT_ROMAN
FC_SOURCE
FC_SPACING
FC_STYLE
FC_STYLELANG
FC_SYMBOL
FC_USER_CACHE_FILE
FC_UTF8_MAX_LEN
FC_VARIABLE
FC_VERTICAL_LAYOUT
FC_WEIGHT
FC_WEIGHT_BLACK
FC_WEIGHT_BOLD
FC_WEIGHT_BOOK
FC_WEIGHT_DEMIBOLD
FC_WEIGHT_EXTRABLACK
FC_WEIGHT_EXTRABOLD
FC_WEIGHT_EXTRALIGHT
FC_WEIGHT_HEAVY
FC_WEIGHT_LIGHT
FC_WEIGHT_MEDIUM
FC_WEIGHT_NORMAL
FC_WEIGHT_REGULAR
FC_WEIGHT_SEMIBOLD
FC_WEIGHT_THIN
FC_WEIGHT_ULTRABLACK
FC_WEIGHT_ULTRABOLD
FC_WEIGHT_ULTRALIGHT
FC_WIDTH
FC_WIDTH_CONDENSED
FC_WIDTH_EXPANDED
FC_WIDTH_EXTRACONDENSED
FC_WIDTH_EXTRAEXPANDED
FC_WIDTH_NORMAL
FC_WIDTH_SEMICONDENSED
FC_WIDTH_SEMIEXPANDED
FC_WIDTH_ULTRACONDENSED
FC_WIDTH_ULTRAEXPANDED

Functions§

list_fonts
Return a FontSet containing Fonts that match the supplied pattern and objects.
sort_fonts
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.