Expand description
§rust-fontconfig
Pure-Rust rewrite of the Linux fontconfig library (no system dependencies). Enable the parsing feature to parse .woff, .woff2, .ttc, .otf and .ttf with allsorts.
NOTE: Also works on Windows, macOS and WASM - without external dependencies!
§Usage
§Basic Font Query
use rust_fontconfig::{FcFontCache, FcPattern};
fn main() {
// Build the font cache
let cache = FcFontCache::build();
// Query a font by name
let results = cache.query(
&FcPattern {
name: Some(String::from("Arial")),
..Default::default()
},
&mut Vec::new() // Trace messages container
);
if let Some(font_match) = results {
println!("Font match ID: {:?}", font_match.id);
println!("Font unicode ranges: {:?}", font_match.unicode_ranges);
} else {
println!("No matching font found");
}
}§Resolve Font Chain and Query for Text
use rust_fontconfig::{FcFontCache, FcWeight, PatternMatch};
fn main() {
let cache = FcFontCache::build();
// Build font fallback chain (without text parameter)
let font_chain = cache.resolve_font_chain(
&["Arial".to_string(), "sans-serif".to_string()],
FcWeight::Normal,
PatternMatch::DontCare,
PatternMatch::DontCare,
&mut Vec::new(),
);
// Query which fonts to use for specific text
let text = "Hello 你好 Здравствуйте";
let font_runs = font_chain.query_for_text(&cache, text);
println!("Text split into {} font runs:", font_runs.len());
for run in font_runs {
println!(" '{}' -> font {:?}", run.text, run.font_id);
}
}Re-exports§
pub use config::FcFallbackConfig;pub use config::FcScriptFallback;pub use config::GenericFamily;pub use fallback::CssFallbackGroup;pub use fallback::FontFallbackChain;pub use fallback::ScriptFallbackGroup;
Modules§
- config
- OS-specific font configuration.
- fallback
- Precomputed font fallback chains for resolving font stacks.
- utils
Structs§
- FcFont
- In-memory font data.
- FcFont
Cache - Font cache, initialized at startup.
- FcFont
Metadata - Font metadata from the OS/2 table.
- FcFont
Path - Path to a font file.
- FcFont
Render Config - Per-font rendering configuration from system font config (Linux fonts.conf).
- FcPattern
- Font pattern for matching.
- FontId
- UUID to identify a font (collections are broken up into separate fonts).
- Font
Match - Font match result with UUID.
- Font
Match NoFallback - Font match result with UUID (without fallback).
- Named
Font - A named font to be added to the font cache from memory.
- Resolved
Font Run - A run of text that uses the same font.
- StLock
- Shared interior of
FcFontCache. - StRead
Guard - StWrite
Guard - Trace
Msg - Trace message for debugging font matching.
- Unicode
Range - Unicode range representation for font matching.
Enums§
- FcHint
Style - Hinting style for font rendering.
- FcLcd
Filter - LCD filter mode for subpixel rendering.
- FcRgba
- Subpixel rendering order.
- FcStretch
- CSS font-stretch values.
- FcWeight
- Font weight values as defined in CSS specification.
- Font
Bytes - A handle to font bytes returned by
FcFontCache::get_font_bytes. - Match
Reason - Reason for font matching failure or success.
- Operating
System - Operating system type for generic font family resolution.
- Owned
Font Source - Owned font-source descriptor, returned by.
- Pattern
Match - Whether a field is required to match (yes / no / don’t care).
- Trace
Level - Log levels for trace messages.
Constants§
- DEFAULT_
UNICODE_ FALLBACK_ SCRIPTS - The default set of Unicode-block fallback scripts that.
Functions§
- expand_
font_ families Deprecated - Expand a CSS font stack against the built-in per-OS tables.
- has_
arabic_ ranges - Check if any range covers the Arabic block.
- has_
cjk_ ranges - Check if any range covers CJK Unified Ideographs, Hiragana, Katakana, or Hangul.
- has_
cyrillic_ ranges - Check if any range covers the Cyrillic block.
- has_
hebrew_ ranges - Check if any range covers the Hebrew block.
- has_
thai_ ranges - Check if any range covers the Thai block.