skia_safe/modules/svg/fe/
types.rs

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::fmt;

use crate::interop;
use skia_bindings as sb;

pub type InputType = sb::SkSVGFeInputType_Type;
variant_name!("InputType::SourceGraphic");

#[repr(C)]
#[derive(Clone)]
pub struct Input {
    kind: InputType,
    id: interop::String,
}
native_transmutable!(sb::SkSVGFeInputType, Input, svg_fe_input_layout);

impl fmt::Debug for Input {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SvgFeInput")
            .field("kind", &self.kind())
            .field("id", &self.id())
            .finish()
    }
}

impl Input {
    pub fn kind(&self) -> InputType {
        self.kind
    }

    pub fn id(&self) -> Option<&str> {
        if self.kind == InputType::FilterPrimitiveReference {
            Some(self.id.as_str())
        } else {
            None
        }
    }

    pub fn source_graphic() -> Self {
        Self {
            kind: InputType::SourceGraphic,
            id: interop::String::default(),
        }
    }

    pub fn source_alpha() -> Self {
        Self {
            kind: InputType::SourceAlpha,
            id: interop::String::default(),
        }
    }

    pub fn background_image() -> Self {
        Self {
            kind: InputType::BackgroundImage,
            id: interop::String::default(),
        }
    }

    pub fn background_alpha() -> Self {
        Self {
            kind: InputType::BackgroundAlpha,
            id: interop::String::default(),
        }
    }

    pub fn fill_paint() -> Self {
        Self {
            kind: InputType::FillPaint,
            id: interop::String::default(),
        }
    }

    pub fn stroke_paint() -> Self {
        Self {
            kind: InputType::StrokePaint,
            id: interop::String::default(),
        }
    }

    pub fn unspecified() -> Self {
        Self {
            kind: InputType::Unspecified,
            id: interop::String::default(),
        }
    }

    pub fn new<T: AsRef<str>>(id: T) -> Self {
        Self {
            kind: InputType::FilterPrimitiveReference,
            id: interop::String::from_str(id.as_ref()),
        }
    }
}