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
use mupdf_sys::*;

use crate::{context, IRect};

#[derive(Debug)]
pub struct Glyph {
    pub(crate) inner: *mut fz_glyph,
}

impl Glyph {
    pub fn width(&self) -> i32 {
        unsafe { fz_glyph_width(context(), self.inner) }
    }

    pub fn height(&self) -> i32 {
        unsafe { fz_glyph_height(context(), self.inner) }
    }

    pub fn bounds(&self) -> IRect {
        let bbox = unsafe { fz_glyph_bbox(context(), self.inner) };
        bbox.into()
    }
}

impl Drop for Glyph {
    fn drop(&mut self) {
        if !self.inner.is_null() {
            unsafe {
                fz_drop_glyph(context(), self.inner);
            }
        }
    }
}