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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use { ffi };

#[repr(u32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum StrokerLineCap {
    Butt = ffi::FT_STROKER_LINECAP_BUTT,
    Round = ffi::FT_STROKER_LINECAP_ROUND,
    Square = ffi::FT_STROKER_LINECAP_SQUARE,
}

#[repr(u32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum StrokerLineJoin {
    Round = ffi::FT_STROKER_LINEJOIN_ROUND,
    Bevel = ffi::FT_STROKER_LINEJOIN_BEVEL,
    MiterVariable = ffi::FT_STROKER_LINEJOIN_MITER_VARIABLE,
    MiterFixed = ffi::FT_STROKER_LINEJOIN_MITER_FIXED,
}

pub struct Stroker {
    library_raw: ffi::FT_Library,
    raw: ffi::FT_Stroker,
}

impl Stroker {
    pub unsafe fn from_raw(library_raw: ffi::FT_Library, raw: ffi::FT_Stroker) -> Self {
        ffi::FT_Reference_Library(library_raw);
        Stroker { library_raw, raw }
    }

    pub fn set(&self, radius: ffi::FT_Fixed, line_cap: StrokerLineCap, line_join: StrokerLineJoin, miter_limit: ffi::FT_Fixed) {
        unsafe {
            ffi::FT_Stroker_Set(self.raw, radius, line_cap as u32, line_join as u32, miter_limit);
        }
    }

    pub fn raw(&self) -> &ffi::FT_StrokerRec {
        unsafe {
            &*self.raw
        }
    }

    pub fn raw_mut(&mut self) -> &mut ffi::FT_StrokerRec {
        unsafe {
            &mut *self.raw
        }
    }

    pub(crate) fn raw_stroker(&self) -> ffi::FT_Stroker {
        self.raw
    }
}

impl Drop for Stroker {

    fn drop(&mut self) {
        let err = unsafe {
            ffi::FT_Stroker_Done(self.raw);
            ffi::FT_Done_Library(self.library_raw)
        };
        if err != ffi::FT_Err_Ok {
            panic!("Failed to drop library");
        }
    }
}