skia_safe/modules/svg/types/
iri.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
use std::fmt;

use crate::{
    interop::{self, AsStr},
    prelude::*,
};
use skia_bindings as sb;

pub type IriKind = sb::SkSVGIRI_Type;
pub type IriFuncKind = sb::SkSVGFuncIRI_Type;

pub type Iri = Handle<sb::SkSVGIRI>;

impl NativeDrop for sb::SkSVGIRI {
    fn drop(&mut self) {
        unsafe { sb::C_SkSVGIRI_destruct(self) }
    }
}

impl Default for Iri {
    fn default() -> Self {
        Self::construct(|uninitialized| unsafe { sb::C_SkSVGIRI_Construct(uninitialized) })
    }
}

impl fmt::Debug for Iri {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("SvgIri")
            .field("data", &self.data())
            .finish()
    }
}

impl Iri {
    pub fn data(&self) -> &str {
        self.native().fIRI.as_str()
    }

    pub fn new<T: AsRef<str>>(value: T, kind: IriKind) -> Self {
        Self::construct(|uninitialized| unsafe {
            let iri = interop::String::from_str(value.as_ref());

            sb::C_SkSVGIRI_Construct1(uninitialized, kind, iri.native())
        })
    }
}

pub type IriFunc = Handle<sb::SkSVGFuncIRI>;

impl NativeDrop for sb::SkSVGFuncIRI {
    fn drop(&mut self) {
        unsafe { sb::C_SkSVGFuncIRI_destruct(self) }
    }
}

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

impl IriFunc {
    pub fn iri(&self) -> Option<&Iri> {
        let func = self.native();

        if matches!(func.fType, IriFuncKind::IRI) {
            Some(Iri::from_native_ref(&self.native().fIRI))
        } else {
            None
        }
    }

    pub fn kind(&self) -> IriFuncKind {
        self.native().fType
    }

    pub fn from_iri(value: Iri) -> Self {
        Self::construct(|uninitialized| unsafe {
            sb::C_SkSVGFuncIRI_Construct1(uninitialized, value.native())
        })
    }

    pub fn none() -> Self {
        Self::construct(|uninitialized| unsafe { sb::C_SkSVGFuncIRI_Construct(uninitialized) })
    }
}