skia_safe/core/
path_utils.rs

1use crate::prelude::*;
2use crate::{Matrix, Paint, Path, Rect};
3use skia_bindings as sb;
4
5/// Returns the filled equivalent of the stroked path.
6///
7/// * `src` - [`Path`] read to create a filled version
8/// * `paint` - [`Paint`], from which attributes such as stroke cap, width, miter, and join,
9///                  as well as `path_effect` will be used.
10/// * `dst` - resulting [`Path`]
11/// * `cull_rect` - optional limit passed to [`crate::PathEffect`]
12/// * `matrix` - if scale > 1, increase precision, else if (0 < scale < 1) reduce precision
13///                  to favor speed and size
14///
15/// Returns: `true` if the dst path was updated, `false` if it was not (e.g. if the path
16///                  represents hairline and cannot be filled).
17pub fn fill_path_with_paint<'a>(
18    src: &Path,
19    paint: &Paint,
20    dst: &mut Path,
21    cull_rect: impl Into<Option<&'a Rect>>,
22    matrix: impl Into<Option<Matrix>>,
23) -> bool {
24    let cull_rect: Option<&'a Rect> = cull_rect.into();
25    let matrix = matrix.into().unwrap_or(Matrix::scale((1.0, 1.0)));
26
27    unsafe {
28        sb::C_PathUtils_FillPathWithPaint(
29            src.native(),
30            paint.native(),
31            dst.native_mut(),
32            cull_rect.native_ptr_or_null(),
33            matrix.native(),
34        )
35    }
36}