reflexo/vector/ir/visualize.rs
1use super::preludes::*;
2use crate::StaticHash128;
3
4/// Item representing an `<image/>` element.
5#[derive(Debug, Clone, Hash, PartialEq, Eq)]
6#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
7#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
8pub struct ImageItem {
9 /// The source image data.
10 pub image: Arc<Image>,
11 /// The target size of the image.
12 pub size: Size,
13}
14
15/// Item representing an `<image/>` element.
16#[derive(Debug, Clone, Hash, PartialEq, Eq)]
17#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
18#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
19pub struct HtmlItem {
20 /// The sanitized source code.
21 pub html: ImmutStr,
22 /// The target size of the image.
23 pub size: Size,
24}
25
26/// Data of an `<image/>` element.
27#[derive(Debug, Clone, PartialEq, Eq)]
28#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
29#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
30pub struct Image {
31 /// The encoded image data.
32 pub data: Vec<u8>,
33 /// The format of the encoded `buffer`.
34 pub format: ImmutStr,
35 /// The size of the image.
36 pub size: Axes<u32>,
37 /// A text describing the image.
38 pub alt: Option<ImmutStr>,
39 /// prehashed image content.
40 pub hash: Fingerprint,
41}
42
43impl Image {
44 /// Returns the width of the image.
45 pub fn width(&self) -> u32 {
46 self.size.x
47 }
48 /// Returns the height of the image.
49 pub fn height(&self) -> u32 {
50 self.size.y
51 }
52}
53
54/// Prehashed image data.
55impl Hash for Image {
56 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
57 self.hash.hash(state);
58 }
59}
60
61impl StaticHash128 for Image {
62 /// Returns the hash of the image data.
63 fn get_hash(&self) -> u128 {
64 self.hash.to_u128()
65 }
66}
67
68/// Item representing an `<path/>` element.
69#[derive(Debug, Clone, Hash, PartialEq, Eq)]
70#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
71#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
72pub struct PathItem {
73 /// The path instruction.
74 pub d: ImmutStr,
75 /// bbox of the path.
76 pub size: Option<Size>,
77 /// The path style.
78 /// See [`PathStyle`] for more information.
79 pub styles: Vec<PathStyle>,
80}
81
82/// Attributes that is applicable to the [`PathItem`].
83#[derive(Debug, Clone, Hash, PartialEq, Eq)]
84#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
85#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
86pub enum PathStyle {
87 /// `fill` attribute.
88 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill>
89 Fill(ImmutStr),
90
91 /// `stroke` attribute.
92 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke>
93 Stroke(ImmutStr),
94
95 /// `stroke-linecap` attribute.
96 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap>
97 StrokeLineCap(ImmutStr),
98
99 /// `stroke-linejoin` attribute.
100 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linejoin>
101 StrokeLineJoin(ImmutStr),
102
103 /// `stroke-miterlimit` attribute.
104 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-miterlimit>
105 StrokeMitterLimit(Scalar),
106
107 /// `stroke-dashoffset` attribute.
108 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dashoffset>
109 StrokeDashOffset(Abs),
110
111 /// `stroke-dasharray` attribute.
112 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray>
113 StrokeDashArray(Arc<[Abs]>),
114
115 /// `stroke-width` attribute.
116 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width>
117 StrokeWidth(Abs),
118
119 /// `fill-rule` attribute.
120 /// See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule>
121 FillRule(ImmutStr),
122}
123
124/// Item representing an `<pattern/>` element.
125#[derive(Debug, Clone, Hash, PartialEq, Eq)]
126#[cfg_attr(feature = "rkyv", derive(Archive, rDeser, rSer))]
127#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
128pub struct PatternItem {
129 /// The pattern's rendered content.
130 pub frame: Fingerprint,
131 /// The pattern's tile size.
132 pub size: Size,
133 /// The pattern's tile spacing.
134 pub spacing: Size,
135}