pub struct Fontconfig { /* private fields */ }Expand description
Handle obtained after Fontconfig has been initialised.
Implementations§
Source§impl Fontconfig
impl Fontconfig
Sourcepub fn new() -> Option<Self>
pub fn new() -> Option<Self>
Initialise Fontconfig and return a handle allowing further interaction with the API.
If Fontconfig fails to initialise, returns None.
§Example
use fontconfig::{Fontconfig};
let fc = Fontconfig::new().expect("unable to initialise Fontconfig");Examples found in repository?
examples/fc-match.rs (line 6)
5fn main() -> Result<(), FontconfigError> {
6 let fc = Fontconfig::new().expect("unable to init Fontconfig");
7
8 let Some(family) = env::args().nth(1) else {
9 eprintln!("Error: font family not specified");
10 eprintln!(
11 "Usage: {}: family",
12 env::args().next().as_deref().unwrap_or("fc-list")
13 );
14 return Ok(());
15 };
16 let family = CString::new(family)?;
17
18 let mut pattern = fontconfig::Pattern::new(&fc)?;
19 pattern.add_string(fontconfig::FC_FAMILY, &family)?;
20
21 let matched = pattern.font_match()?;
22 let mut fontset = FontSet::new(&fc)?;
23 fontset.add_pattern(matched)?;
24
25 for pattern in fontset.iter() {
26 println!(
27 "{}[{}] ({}): {}, weight = {}, width = {}, slant = {}",
28 pattern.filename()?,
29 pattern.face_index()?,
30 pattern
31 .format()
32 .map(|f| f.to_string())
33 .unwrap_or_else(|_| String::from("Unknown")),
34 pattern.name()?,
35 pattern.weight()?,
36 pattern.width()?,
37 pattern.slant()?
38 )
39 }
40 Ok(())
41}More examples
examples/fc-list.rs (line 6)
5fn main() -> Result<(), FontconfigError> {
6 let fc = Fontconfig::new().expect("unable to init Fontconfig");
7
8 let Some(family) = env::args().nth(1) else {
9 eprintln!("Error: font family not specified");
10 eprintln!(
11 "Usage: {}: family",
12 env::args().next().as_deref().unwrap_or("fc-list")
13 );
14 return Ok(());
15 };
16 let family = CString::new(family)?;
17
18 let mut pattern = fontconfig::Pattern::new(&fc)?;
19 pattern.add_string(fontconfig::FC_FAMILY, &family)?;
20
21 let mut objects = fontconfig::ObjectSet::new(&fc)?;
22 objects.add(fontconfig::FC_FAMILY)?;
23 objects.add(fontconfig::FC_FILE)?;
24 objects.add(fontconfig::FC_FONTFORMAT)?;
25 objects.add(fontconfig::FC_INDEX)?;
26 objects.add(fontconfig::FC_STYLE)?;
27
28 let fontset = fontconfig::list_fonts(&pattern, Some(&objects))?;
29
30 for pattern in fontset.iter() {
31 let family = pattern.get_string(fontconfig::FC_FAMILY)?;
32 let style = pattern.get_string(fontconfig::FC_STYLE)?;
33
34 println!(
35 "{}[{}] ({}): {}:style={}",
36 pattern.filename()?,
37 pattern.face_index()?,
38 pattern
39 .format()
40 .map(|f| f.to_string())
41 .unwrap_or_else(|_| String::from("Unknown")),
42 family,
43 style
44 )
45 }
46 Ok(())
47}Auto Trait Implementations§
impl Freeze for Fontconfig
impl RefUnwindSafe for Fontconfig
impl Send for Fontconfig
impl Sync for Fontconfig
impl Unpin for Fontconfig
impl UnsafeUnpin for Fontconfig
impl UnwindSafe for Fontconfig
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