hayro_interpret/
types.rs

1use crate::CacheKey;
2use crate::color::Color;
3use crate::pattern::Pattern;
4use crate::util::hash128;
5use kurbo::{BezPath, Cap, Join};
6use smallvec::{SmallVec, smallvec};
7
8/// A clip path.
9#[derive(Debug, Clone)]
10pub struct ClipPath {
11    /// The clipping path.
12    pub path: BezPath,
13    /// The fill rule.
14    pub fill: FillRule,
15}
16
17impl CacheKey for ClipPath {
18    fn cache_key(&self) -> u128 {
19        hash128(&(&self.path.to_svg(), &self.fill))
20    }
21}
22
23/// A structure holding 3-channel RGB data.
24#[derive(Clone)]
25pub struct RgbData {
26    /// The actual data. It is guaranteed to have the length width * height * 3.
27    pub data: Vec<u8>,
28    /// The width.
29    pub width: u32,
30    /// The height.
31    pub height: u32,
32    /// Whether the image should be interpolated.
33    pub interpolate: bool,
34}
35
36/// A structure holding 1-channel luma data.
37#[derive(Clone)]
38pub struct LumaData {
39    /// The actual data. It is guaranteed to have the length width * height.
40    pub data: Vec<u8>,
41    /// The width.
42    pub width: u32,
43    /// The height.
44    pub height: u32,
45    /// Whether the image should be interpolated.
46    pub interpolate: bool,
47}
48
49/// A type of paint.
50#[derive(Clone, Debug)]
51pub enum Paint<'a> {
52    /// A solid RGBA color.
53    Color(Color),
54    /// A PDF pattern.
55    Pattern(Box<Pattern<'a>>),
56}
57
58/// Stroke properties.
59#[derive(Clone, Debug)]
60pub struct StrokeProps {
61    /// The line width.
62    pub line_width: f32,
63    /// The line cap.
64    pub line_cap: Cap,
65    /// The line join.
66    pub line_join: Join,
67    /// The miter limit.
68    pub miter_limit: f32,
69    /// The dash array.
70    pub dash_array: SmallVec<[f32; 4]>,
71    /// The dash offset.
72    pub dash_offset: f32,
73}
74
75impl Default for StrokeProps {
76    fn default() -> Self {
77        Self {
78            line_width: 1.0,
79            line_cap: Cap::Butt,
80            line_join: Join::Miter,
81            miter_limit: 10.0,
82            dash_array: smallvec![],
83            dash_offset: 0.0,
84        }
85    }
86}
87
88/// A fill rule.
89#[derive(Clone, Debug, Copy, Hash, PartialEq, Eq)]
90pub enum FillRule {
91    /// Non-zero filling.
92    NonZero,
93    /// Even-odd filling.
94    EvenOdd,
95}