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())
}
}