floem_renderer/
lib.rs

1pub mod swash;
2pub mod text;
3
4use crate::text::LayoutRun;
5use peniko::{
6    kurbo::{Affine, Point, Rect, Shape, Stroke},
7    BlendMode, BrushRef,
8};
9pub use resvg::tiny_skia;
10pub use resvg::usvg;
11use text::TextLayout;
12
13pub mod gpu_resources;
14
15pub struct Svg<'a> {
16    pub tree: &'a usvg::Tree,
17    pub hash: &'a [u8],
18}
19
20pub struct Img<'a> {
21    pub img: peniko::Image,
22    pub hash: &'a [u8],
23}
24
25pub trait Renderer {
26    fn begin(&mut self, capture: bool);
27
28    fn set_transform(&mut self, transform: Affine);
29
30    fn set_z_index(&mut self, z_index: i32);
31
32    /// Clip to a [`Shape`].
33    fn clip(&mut self, shape: &impl Shape);
34
35    fn clear_clip(&mut self);
36
37    /// Stroke a [`Shape`].
38    fn stroke<'b, 's>(
39        &mut self,
40        shape: &impl Shape,
41        brush: impl Into<peniko::BrushRef<'b>>,
42        stroke: &'s Stroke,
43    );
44
45    /// Fill a [`Shape`], using the [non-zero fill rule].
46    ///
47    /// [non-zero fill rule]: https://en.wikipedia.org/wiki/Nonzero-rule
48    fn fill<'b>(&mut self, path: &impl Shape, brush: impl Into<BrushRef<'b>>, blur_radius: f64);
49
50    /// Push a layer (This is not supported with Vger)
51    fn push_layer(
52        &mut self,
53        blend: impl Into<BlendMode>,
54        alpha: f32,
55        transform: Affine,
56        clip: &impl Shape,
57    );
58
59    /// Pop a layer (This is not supported with Vger)
60    fn pop_layer(&mut self);
61
62    /// Draw a [`TextLayout`].
63    ///
64    /// The `pos` parameter specifies the upper-left corner of the layout object
65    /// (even for right-to-left text).
66    fn draw_text(&mut self, layout: &TextLayout, pos: impl Into<Point>) {
67        self.draw_text_with_layout(layout.layout_runs(), pos);
68    }
69
70    fn draw_text_with_layout<'b>(
71        &mut self,
72        layout: impl Iterator<Item = LayoutRun<'b>>,
73        pos: impl Into<Point>,
74    );
75
76    fn draw_svg<'b>(&mut self, svg: Svg<'b>, rect: Rect, brush: Option<impl Into<BrushRef<'b>>>);
77
78    fn draw_img(&mut self, img: Img<'_>, rect: Rect);
79
80    fn finish(&mut self) -> Option<peniko::Image>;
81
82    fn debug_info(&self) -> String {
83        "Unknown".into()
84    }
85}