1use core::ptr::null_mut;
2use {ffi, Bitmap};
3
4pub struct BitmapGlyph {
5 library_raw: ffi::FT_Library,
6 raw: ffi::FT_BitmapGlyph
7}
8
9impl BitmapGlyph {
10 pub unsafe fn from_raw(library_raw: ffi::FT_Library, raw: ffi::FT_BitmapGlyph) -> Self {
11 ffi::FT_Reference_Library(library_raw);
12 BitmapGlyph { library_raw, raw }
13 }
14
15 #[inline(always)]
16 pub fn left(&self) -> i32 { unsafe { (*self.raw).left } }
17
18 #[inline(always)]
19 pub fn top(&self) -> i32 { unsafe { (*self.raw).top } }
20
21 #[inline(always)]
22 pub fn bitmap(&self) -> Bitmap {
23 unsafe { Bitmap::from_raw(&(*self.raw).bitmap) }
24 }
25
26 #[inline(always)]
27 pub fn raw(&self) -> &ffi::FT_BitmapGlyphRec { unsafe { &*self.raw } }
28}
29
30impl ::fallible::TryClone for BitmapGlyph {
31 type Error = ::error::Error;
32 fn try_clone(&self) -> ::FtResult<Self> { unsafe {
33 let mut target = null_mut();
34 ::error::from_ftret(ffi::FT_Glyph_Copy(self.raw as ffi::FT_Glyph, &mut target))?;
35 Ok(BitmapGlyph::from_raw(self.library_raw, target as ffi::FT_BitmapGlyph))
36 } }
37}
38
39impl Drop for BitmapGlyph {
40 fn drop(&mut self) { unsafe {
41 ffi::FT_Done_Glyph(self.raw as ffi::FT_Glyph);
42 ::error::from_ftret(ffi::FT_Done_Library(self.library_raw)).expect("Failed to drop bitmap glyph");
43 } }
44}