zpl_forge/engine/
backend.rs

1use crate::{FontManager, ZplResult};
2
3/// Defines the interface for rendering ZPL instructions.
4///
5/// Implementing this trait allows `zpl-forge` to output label formats to
6/// different targets such as images (PNG, JPG), PDF documents, or raw byte streams.
7#[allow(clippy::too_many_arguments)]
8pub trait ZplForgeBackend {
9    /// Initializes the rendering surface with the specified dimensions.
10    fn setup_page(&mut self, width: f64, height: f64, resolution: f32);
11
12    /// Configures the font manager used for text rendering.
13    fn setup_font_manager(&mut self, font_manager: &FontManager);
14
15    /// Renders a text field.
16    fn draw_text(
17        &mut self,
18        x: u32,
19        y: u32,
20        font: char,
21        height: Option<u32>,
22        width: Option<u32>,
23        text: String,
24        reverse_print: bool,
25        color: Option<String>,
26    ) -> ZplResult<()>;
27
28    /// Draws a rectangular box.
29    fn draw_graphic_box(
30        &mut self,
31        x: u32,
32        y: u32,
33        width: u32,
34        height: u32,
35        thickness: u32,
36        color: char,
37        custom_color: Option<String>,
38        rounding: u32,
39        reverse_print: bool,
40    ) -> ZplResult<()>;
41
42    /// Draws a circle.
43    fn draw_graphic_circle(
44        &mut self,
45        x: u32,
46        y: u32,
47        radius: u32,
48        thickness: u32,
49        color: char,
50        custom_color: Option<String>,
51        reverse_print: bool,
52    ) -> ZplResult<()>;
53
54    /// Draws an ellipse.
55    fn draw_graphic_ellipse(
56        &mut self,
57        x: u32,
58        y: u32,
59        width: u32,
60        height: u32,
61        thickness: u32,
62        color: char,
63        custom_color: Option<String>,
64        reverse_print: bool,
65    ) -> ZplResult<()>;
66
67    /// Renders a raw graphic field (bitmap data).
68    fn draw_graphic_field(
69        &mut self,
70        x: u32,
71        y: u32,
72        width: u32,
73        height: u32,
74        data: Vec<u8>,
75        reverse_print: bool,
76    ) -> ZplResult<()>;
77
78    /// Renders a custom color image from base64 data.
79    ///
80    /// If width and height are 0, natural size is used.
81    /// If one is 0, the other is scaled proportionally.
82    fn draw_graphic_image_custom(
83        &mut self,
84        x: u32,
85        y: u32,
86        width: u32,
87        height: u32,
88        data: String,
89    ) -> ZplResult<()>;
90
91    /// Draws a Code 128 barcode.
92    fn draw_code128(
93        &mut self,
94        x: u32,
95        y: u32,
96        orientation: char,
97        height: u32,
98        module_width: u32,
99        interpretation_line: char,
100        interpretation_line_above: char,
101        check_digit: char,
102        mode: char,
103        data: String,
104        reverse_print: bool,
105    ) -> ZplResult<()>;
106
107    /// Draws a QR Code.
108    fn draw_qr_code(
109        &mut self,
110        x: u32,
111        y: u32,
112        orientation: char,
113        model: u32,
114        magnification: u32,
115        error_correction: char,
116        mask: u32,
117        data: String,
118        reverse_print: bool,
119    ) -> ZplResult<()>;
120
121    /// Draws a Code 39 barcode.
122    fn draw_code39(
123        &mut self,
124        x: u32,
125        y: u32,
126        orientation: char,
127        check_digit: char,
128        height: u32,
129        module_width: u32,
130        interpretation_line: char,
131        interpretation_line_above: char,
132        data: String,
133        reverse_print: bool,
134    ) -> ZplResult<()>;
135
136    /// Finalizes the rendering process and returns the resulting data.
137    fn finalize(&mut self) -> ZplResult<Vec<u8>>;
138}