1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::{borrow::Cow, ffi::CStr};
use super::Font;
use crate::bind;
pub trait AttributeExt {
fn faces(&self) -> usize;
fn is_fixed_width(&self) -> bool;
fn family_name(&self) -> Option<Cow<str>>;
fn style_name(&self) -> Option<Cow<str>>;
}
impl AttributeExt for Font<'_> {
fn faces(&self) -> usize {
unsafe { bind::TTF_FontFaces(self.ptr.as_ptr()) as _ }
}
fn is_fixed_width(&self) -> bool {
unsafe { bind::TTF_FontFaceIsFixedWidth(self.ptr.as_ptr()) != 0 }
}
fn family_name(&self) -> Option<Cow<str>> {
let ptr = unsafe { bind::TTF_FontFaceFamilyName(self.ptr.as_ptr()) };
(!ptr.is_null()).then(|| unsafe { CStr::from_ptr(ptr) }.to_string_lossy())
}
fn style_name(&self) -> Option<Cow<str>> {
let ptr = unsafe { bind::TTF_FontFaceStyleName(self.ptr.as_ptr()) };
(!ptr.is_null()).then(|| unsafe { CStr::from_ptr(ptr) }.to_string_lossy())
}
}