pub struct FcFontCache { /* private fields */ }Expand description
Font cache, initialized at startup
Implementations§
Source§impl FcFontCache
impl FcFontCache
Sourcepub fn with_memory_fonts(
&mut self,
fonts: Vec<(FcPattern, FcFont)>,
) -> &mut Self
pub fn with_memory_fonts( &mut self, fonts: Vec<(FcPattern, FcFont)>, ) -> &mut Self
Adds in-memory font files
Sourcepub fn with_memory_font_with_id(
&mut self,
id: FontId,
pattern: FcPattern,
font: FcFont,
) -> &mut Self
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)
Sourcepub fn get_font_by_id(&self, id: &FontId) -> Option<FontSource<'_>>
pub fn get_font_by_id(&self, id: &FontId) -> Option<FontSource<'_>>
Get font data for a given font ID
Sourcepub fn get_metadata_by_id(&self, id: &FontId) -> Option<&FcPattern>
pub fn get_metadata_by_id(&self, id: &FontId) -> Option<&FcPattern>
Get metadata directly from an ID
Sourcepub fn get_font_bytes(&self, id: &FontId) -> Option<Vec<u8>>
pub fn get_font_bytes(&self, id: &FontId) -> Option<Vec<u8>>
Get font bytes (either from disk or memory)
Sourcepub fn build() -> Self
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
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}Sourcepub fn list(&self) -> Vec<(&FcPattern, FontId)>
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
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}Sourcepub fn query(
&self,
pattern: &FcPattern,
trace: &mut Vec<TraceMsg>,
) -> Option<FontMatch>
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}Sourcepub fn query_all(
&self,
pattern: &FcPattern,
trace: &mut Vec<TraceMsg>,
) -> Vec<FontMatch>
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}Sourcepub fn query_for_text(
&self,
pattern: &FcPattern,
text: &str,
trace: &mut Vec<TraceMsg>,
) -> Vec<FontMatch>
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
Sourcepub fn get_memory_font(&self, id: &FontId) -> Option<&FcFont>
pub fn get_memory_font(&self, id: &FontId) -> Option<&FcFont>
Get in-memory font data
Trait Implementations§
Source§impl Clone for FcFontCache
impl Clone for FcFontCache
Source§fn clone(&self) -> FcFontCache
fn clone(&self) -> FcFontCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FcFontCache
impl Debug for FcFontCache
Source§impl Default for FcFontCache
impl Default for FcFontCache
Source§fn default() -> FcFontCache
fn default() -> FcFontCache
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for FcFontCache
impl RefUnwindSafe for FcFontCache
impl Send for FcFontCache
impl Sync for FcFontCache
impl Unpin for FcFontCache
impl UnwindSafe for FcFontCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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