1use lotus_script_sys::FfiObject;
2use lotus_shared::content::ContentId;
3pub use lotus_shared::font::*;
4
5pub struct BitmapFont(ContentId);
7
8impl BitmapFont {
9 pub fn new(content_id: ContentId) -> Self {
11 Self(content_id)
12 }
13
14 pub fn properties(&self) -> Option<BitmapFontProperties> {
18 let font = FfiObject::new(&self.0);
19 let properties = unsafe { lotus_script_sys::font::bitmap_font_properties(font.packed()) };
20
21 if properties == 0 {
22 None
23 } else {
24 Some(FfiObject::from_packed(properties).deserialize())
25 }
26 }
27
28 pub fn text_len(&self, text: &str, letter_spacing: i32) -> Option<u32> {
32 let font = FfiObject::new(&self.0);
33 let text = FfiObject::new(&text);
34
35 let len = unsafe {
36 lotus_script_sys::font::text_len(font.packed(), text.packed(), letter_spacing)
37 };
38
39 if len < 0 {
40 None
41 } else {
42 Some(len as u32)
43 }
44 }
45}