use crate::{haru_bindings as hb, HpdfBox};
#[derive(Debug, Copy, Clone)]
pub struct PdfFont {
pub font_ref: hb::HPDF_Font,
}
impl PdfFont {
pub fn get_font_name(&self) -> String {
let name = unsafe { hb::HPDF_Font_GetFontName(self.font_ref) };
let name = unsafe { std::ffi::CStr::from_ptr(name) };
name.to_str().unwrap().to_string()
}
pub fn get_encoding_name(&self) -> String {
let name = unsafe { hb::HPDF_Font_GetEncodingName(self.font_ref) };
let name = unsafe { std::ffi::CStr::from_ptr(name) };
name.to_str().unwrap().to_string()
}
pub fn get_unicode_width(&self, code: u16) -> i32 {
unsafe { hb::HPDF_Font_GetUnicodeWidth(self.font_ref, code) }
}
pub fn get_b_box(&self) -> HpdfBox {
unsafe { HpdfBox::from(hb::HPDF_Font_GetBBox(self.font_ref)) }
}
pub fn get_ascent(&self) -> i32 {
unsafe { hb::HPDF_Font_GetAscent(self.font_ref) }
}
pub fn get_descent(&self) -> i32 {
unsafe { hb::HPDF_Font_GetDescent(self.font_ref) }
}
pub fn get_x_height(&self) -> u32 {
unsafe { hb::HPDF_Font_GetXHeight(self.font_ref) }
}
pub fn get_cap_height(&self) -> u32 {
unsafe { hb::HPDF_Font_GetCapHeight(self.font_ref) }
}
pub fn text_width(&self, text: &str) -> hb::HPDF_TextWidth {
let text = std::ffi::CString::new(text).unwrap();
unsafe {
hb::HPDF_Font_TextWidth(
self.font_ref,
text.as_ptr() as *const u8,
text.as_bytes().len() as u32,
)
}
}
}