Expand description
A wrapper around freedesktop.org’s Fontconfig library, for locating fonts on
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
To use this crate, you need to have Fontconfig installed on your system. For example, install the package:
- Arch Linux:
fontconfig - Debian-based systems:
libfontconfig1-dev - FreeBSD:
fontconfig - Void Linux:
fontconfig-devel
§Usage
§Example
use fontconfig::{Fontconfig, FontconfigError};
fn main() -> Result<(), FontconfigError> {
let fc = Fontconfig::new().expect("unable to init Fontconfig");
// `Fontconfig::find()` returns `Result` (will rarely be `Err` but still could be)
let font = fc.find("freeserif", None)?;
// `name` is a `String`, `path` is a `Path`
println!("Name: {}\nPath: {}", font.name, font.path.display());
Ok(())
}For more advanced usage, see list_fonts and the Pattern type.
See the examples directory in the repository for more examples.
§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 Fontconfig available for the target platform available at compile time. This can also
be enabled by setting the RUST_FONTCONFIG_DLOPEN environment variable.
§Thread Safety
Note:
Structs§
- CharSet
- Wrapper around
FcCharSet. - Font
- A high-level view of a font, only concerned with the name and its file location.
- FontSet
- Wrapper around
FcFontSetrepresenting a set of fonts. - Fontconfig
- Handle obtained after Fontconfig has been initialised.
- Object
Set - Wrapper around
FcObjectSet. - Pattern
- A safe wrapper around fontconfig’s
FcPattern. - StrList
- Wrapper around
FcStrList. - Unknown
Font Format - Error type returned from Pattern::format.
Enums§
- Font
Format - The format of a font matched by Fontconfig.
- Fontconfig
Error - Fontconfig error
- Unicode
Coverage - Flag indicating whether results from Pattern::sort_fonts should be trimmed to exclude fonts that do not cover the Unicode coverage in the pattern.
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 - Returns a FontSet containing Fonts that match the supplied
patternandobjects.