path_kit/
corner_path_effect.rs1use crate::path::Path;
7use crate::pathkit;
8
9pub struct CornerPathEffect {
12 inner: pathkit::sk_sp<pathkit::SkPathEffect>,
13}
14
15impl CornerPathEffect {
16 pub fn new(radius: f32) -> Option<Self> {
21 if radius <= 0.0 {
22 return None;
23 }
24 let inner = unsafe { pathkit::SkCornerPathEffect_Make(radius) };
25 if inner.fPtr.is_null() {
26 return None;
27 }
28 Some(Self { inner })
29 }
30
31 pub fn filter_path(&self, path: &Path, stroke_width: f32) -> Option<Path> {
33 let mut dst = Path::new();
34 let mut rec = unsafe {
35 pathkit::SkStrokeRec::new(pathkit::SkStrokeRec_InitStyle::kHairline_InitStyle)
36 };
37 unsafe {
38 rec.setStrokeStyle(stroke_width, false);
39 }
40 let bounds = path.tight_bounds();
41 let cull: pathkit::SkRect = bounds.into();
42 let ok = unsafe {
43 pathkit::SkPathEffect_filterPath(
44 self.inner.fPtr,
45 dst.as_raw_mut() as *mut _,
46 path.as_raw() as *const _,
47 &mut rec as *mut _,
48 &cull as *const _,
49 )
50 };
51 if ok {
52 Some(dst)
53 } else {
54 None
55 }
56 }
57}