hayro_interpret/
device.rs

1use crate::font::Glyph;
2use crate::soft_mask::SoftMask;
3use crate::{BlendMode, ClipPath, Image};
4use crate::{GlyphDrawMode, Paint, PathDrawMode};
5use kurbo::{Affine, BezPath};
6
7/// A trait for a device that can be used to process PDF drawing instructions.
8pub trait Device<'a> {
9    /// Set the properties for future stroking operations.
10    /// Set a soft mask to be used for future drawing instructions.
11    fn set_soft_mask(&mut self, mask: Option<SoftMask<'a>>);
12    /// Set the blend mode that should be used for rendering operations.
13    fn set_blend_mode(&mut self, blend_mode: BlendMode);
14    /// Draw a path.
15    fn draw_path(
16        &mut self,
17        path: &BezPath,
18        transform: Affine,
19        paint: &Paint<'a>,
20        draw_mode: &PathDrawMode,
21    );
22    /// Push a new clip path to the clip stack.
23    fn push_clip_path(&mut self, clip_path: &ClipPath);
24    /// Push a new transparency group to the blend stack.
25    fn push_transparency_group(
26        &mut self,
27        opacity: f32,
28        mask: Option<SoftMask<'a>>,
29        blend_mode: BlendMode,
30    );
31    /// Draw a glyph.
32    fn draw_glyph(
33        &mut self,
34        glyph: &Glyph<'a>,
35        transform: Affine,
36        glyph_transform: Affine,
37        paint: &Paint<'a>,
38        // TODO: Move this into outline glyph.
39        draw_mode: &GlyphDrawMode,
40    );
41    /// Draw an image.
42    fn draw_image(&mut self, image: Image<'a, '_>, transform: Affine);
43    /// Pop the last clip path from the clip stack.
44    fn pop_clip_path(&mut self);
45    /// Pop the last transparency group from the blend stack.
46    fn pop_transparency_group(&mut self);
47}