freetype/
stroker.rs

1use { ffi };
2
3#[repr(u32)]
4#[derive(Copy, Clone, Debug, PartialEq, Eq)]
5pub enum StrokerLineCap {
6    Butt = ffi::FT_STROKER_LINECAP_BUTT,
7    Round = ffi::FT_STROKER_LINECAP_ROUND,
8    Square = ffi::FT_STROKER_LINECAP_SQUARE,
9}
10
11#[repr(u32)]
12#[derive(Copy, Clone, Debug, PartialEq, Eq)]
13pub enum StrokerLineJoin {
14    Round = ffi::FT_STROKER_LINEJOIN_ROUND,
15    Bevel = ffi::FT_STROKER_LINEJOIN_BEVEL,
16    MiterVariable = ffi::FT_STROKER_LINEJOIN_MITER_VARIABLE,
17    MiterFixed = ffi::FT_STROKER_LINEJOIN_MITER_FIXED,
18}
19
20pub struct Stroker {
21    library_raw: ffi::FT_Library,
22    raw: ffi::FT_Stroker,
23}
24
25impl Stroker {
26    pub unsafe fn from_raw(library_raw: ffi::FT_Library, raw: ffi::FT_Stroker) -> Self {
27        ffi::FT_Reference_Library(library_raw);
28        Stroker { library_raw, raw }
29    }
30
31    pub fn set(&self, radius: ffi::FT_Fixed, line_cap: StrokerLineCap, line_join: StrokerLineJoin, miter_limit: ffi::FT_Fixed) {
32        unsafe { ffi::FT_Stroker_Set(self.raw, radius, line_cap as u32, line_join as u32, miter_limit); }
33    }
34
35    pub fn raw(&self) -> &ffi::FT_StrokerRec { unsafe { &*self.raw } }
36
37    pub fn raw_mut(&mut self) -> &mut ffi::FT_StrokerRec { unsafe { &mut *self.raw } }
38
39    pub(crate) fn raw_stroker(&self) -> ffi::FT_Stroker { self.raw }
40}
41
42impl Drop for Stroker {
43    fn drop(&mut self) { unsafe {
44        ffi::FT_Stroker_Done(self.raw);
45        ffi::FT_Done_Library(self.library_raw);
46    } }
47}