FcFontCache

Struct FcFontCache 

Source
pub struct FcFontCache { /* private fields */ }
Expand description

Font cache, initialized at startup

Implementations§

Source§

impl FcFontCache

Source

pub fn with_memory_fonts( &mut self, fonts: Vec<(FcPattern, FcFont)>, ) -> &mut Self

Adds in-memory font files

Source

pub fn with_memory_font_with_id( &mut self, id: FontId, pattern: FcPattern, font: FcFont, ) -> &mut Self

Adds a memory font with a specific ID (for testing)

Source

pub fn get_font_by_id(&self, id: &FontId) -> Option<FontSource<'_>>

Get font data for a given font ID

Source

pub fn get_metadata_by_id(&self, id: &FontId) -> Option<&FcPattern>

Get metadata directly from an ID

Source

pub fn get_font_bytes(&self, id: &FontId) -> Option<Vec<u8>>

Get font bytes (either from disk or memory)

Source

pub fn build() -> Self

Builds a new font cache from all fonts discovered on the system

Examples found in repository?
examples/query.rs (line 5)
3fn main() {
4    println!("building cache...");
5    let cache = FcFontCache::build();
6    println!("cache built!");
7    let list = cache.list();
8    println!("{} fonts:", list.len());
9    let fonts = cache.query_all(
10        &FcPattern {
11            monospace: PatternMatch::True,
12            ..Default::default()
13        },
14        &mut Vec::new(),
15    );
16
17    println!("total fonts: {}", fonts.len());
18
19    if let Some(first) = fonts.first() {
20        println!("MATCH: {:#?}", first);
21    }
22}
More examples
Hide additional examples
examples/getfont.rs (line 6)
4fn main() {
5    let start = Instant::now();
6    let cache = FcFontCache::build();
7    let end = Instant::now();
8
9    println!("cache list: found {} fonts", cache.list().len());
10
11    let start2 = Instant::now();
12    let results = cache.query(
13        &FcPattern {
14            name: Some(String::from("Gilroy")),
15            ..Default::default()
16        },
17        &mut Vec::new(),
18    );
19    let end2 = Instant::now();
20
21    println!("built cache in: {:?}", end - start);
22    println!("queried in {:?}", end2 - start2);
23}
Source

pub fn list(&self) -> Vec<(&FcPattern, FontId)>

Returns the list of fonts and font patterns

Examples found in repository?
examples/query.rs (line 7)
3fn main() {
4    println!("building cache...");
5    let cache = FcFontCache::build();
6    println!("cache built!");
7    let list = cache.list();
8    println!("{} fonts:", list.len());
9    let fonts = cache.query_all(
10        &FcPattern {
11            monospace: PatternMatch::True,
12            ..Default::default()
13        },
14        &mut Vec::new(),
15    );
16
17    println!("total fonts: {}", fonts.len());
18
19    if let Some(first) = fonts.first() {
20        println!("MATCH: {:#?}", first);
21    }
22}
More examples
Hide additional examples
examples/getfont.rs (line 9)
4fn main() {
5    let start = Instant::now();
6    let cache = FcFontCache::build();
7    let end = Instant::now();
8
9    println!("cache list: found {} fonts", cache.list().len());
10
11    let start2 = Instant::now();
12    let results = cache.query(
13        &FcPattern {
14            name: Some(String::from("Gilroy")),
15            ..Default::default()
16        },
17        &mut Vec::new(),
18    );
19    let end2 = Instant::now();
20
21    println!("built cache in: {:?}", end - start);
22    println!("queried in {:?}", end2 - start2);
23}
Source

pub fn query( &self, pattern: &FcPattern, trace: &mut Vec<TraceMsg>, ) -> Option<FontMatch>

Queries a font from the in-memory cache, returns the first found font (early return)

Examples found in repository?
examples/getfont.rs (lines 12-18)
4fn main() {
5    let start = Instant::now();
6    let cache = FcFontCache::build();
7    let end = Instant::now();
8
9    println!("cache list: found {} fonts", cache.list().len());
10
11    let start2 = Instant::now();
12    let results = cache.query(
13        &FcPattern {
14            name: Some(String::from("Gilroy")),
15            ..Default::default()
16        },
17        &mut Vec::new(),
18    );
19    let end2 = Instant::now();
20
21    println!("built cache in: {:?}", end - start);
22    println!("queried in {:?}", end2 - start2);
23}
Source

pub fn query_all( &self, pattern: &FcPattern, trace: &mut Vec<TraceMsg>, ) -> Vec<FontMatch>

Queries all fonts matching a pattern

Examples found in repository?
examples/query.rs (lines 9-15)
3fn main() {
4    println!("building cache...");
5    let cache = FcFontCache::build();
6    println!("cache built!");
7    let list = cache.list();
8    println!("{} fonts:", list.len());
9    let fonts = cache.query_all(
10        &FcPattern {
11            monospace: PatternMatch::True,
12            ..Default::default()
13        },
14        &mut Vec::new(),
15    );
16
17    println!("total fonts: {}", fonts.len());
18
19    if let Some(first) = fonts.first() {
20        println!("MATCH: {:#?}", first);
21    }
22}
Source

pub fn query_for_text( &self, pattern: &FcPattern, text: &str, trace: &mut Vec<TraceMsg>, ) -> Vec<FontMatch>

Find fonts that can render the given text, considering Unicode ranges

Source

pub fn get_memory_font(&self, id: &FontId) -> Option<&FcFont>

Get in-memory font data

Trait Implementations§

Source§

impl Clone for FcFontCache

Source§

fn clone(&self) -> FcFontCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FcFontCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FcFontCache

Source§

fn default() -> FcFontCache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.