skia_safe/core/
path_utils.rs

1use crate::{prelude::*, Matrix, Paint, Path, Rect};
2use skia_bindings as sb;
3
4/// Returns the filled equivalent of the stroked path.
5///
6/// * `src` - [`Path`] read to create a filled version
7/// * `paint` - uses settings for stroke cap, width, miter, join, and patheffect.
8/// * `dst` - results are written to this builder.
9/// * `cull_rect` - optional limit passed to [`crate::PathEffect`]
10/// * `ctm` - matrix to take into acount for increased precision (if it scales up).
11///
12/// Returns: `true` if the result can be filled, or `false` if it is a hairline (to be stroked).
13pub fn fill_path_with_paint<'a>(
14    src: &Path,
15    paint: &Paint,
16    dst: &mut Path,
17    cull_rect: impl Into<Option<&'a Rect>>,
18    ctm: impl Into<Option<Matrix>>,
19) -> bool {
20    let cull_rect: Option<&'a Rect> = cull_rect.into();
21    let matrix = ctm.into().unwrap_or(Matrix::scale((1.0, 1.0)));
22
23    unsafe {
24        sb::C_PathUtils_FillPathWithPaint(
25            src.native(),
26            paint.native(),
27            dst.native_mut(),
28            cull_rect.native_ptr_or_null(),
29            matrix.native(),
30        )
31    }
32}