1pub use crate::ast::commons::Barcode1DKind;
2
3#[derive(Debug)]
8pub enum ZplInstruction {
9 PageBreak,
14 Text {
16 x: u32,
18 y: u32,
20 font: char,
22 height: Option<u32>,
24 width: Option<u32>,
26 orientation: char,
28 text: String,
30 reverse_print: bool,
32 color: Option<String>,
34 block: Option<TextBlock>,
36 condition: Option<(String, String)>,
38 },
39 GraphicBox {
41 x: u32,
42 y: u32,
43 width: u32,
44 height: u32,
45 thickness: u32,
46 color: char,
47 custom_color: Option<String>,
48 rounding: u32,
49 reverse_print: bool,
50 condition: Option<(String, String)>,
51 },
52 GraphicCircle {
54 x: u32,
55 y: u32,
56 radius: u32,
57 thickness: u32,
58 color: char,
59 custom_color: Option<String>,
60 reverse_print: bool,
61 condition: Option<(String, String)>,
62 },
63 GraphicEllipse {
65 x: u32,
66 y: u32,
67 width: u32,
68 height: u32,
69 thickness: u32,
70 color: char,
71 custom_color: Option<String>,
72 reverse_print: bool,
73 condition: Option<(String, String)>,
74 },
75 GraphicField {
77 x: u32,
78 y: u32,
79 width: u32,
80 height: u32,
81 data: Vec<u8>,
82 reverse_print: bool,
83 condition: Option<(String, String)>,
84 },
85 CustomImage {
87 x: u32,
89 y: u32,
91 width: u32,
93 height: u32,
95 data: String,
97 condition: Option<(String, String)>,
98 },
99 Code128 {
101 x: u32,
102 y: u32,
103 orientation: char,
104 height: u32,
105 module_width: u32,
106 interpretation_line: char,
107 interpretation_line_above: char,
108 check_digit: char,
109 mode: char,
110 data: String,
111 reverse_print: bool,
112 condition: Option<(String, String)>,
113 },
114 QRCode {
116 x: u32,
117 y: u32,
118 orientation: char,
119 model: u32,
120 magnification: u32,
121 error_correction: char,
122 mask: u32,
123 data: String,
124 reverse_print: bool,
125 condition: Option<(String, String)>,
126 },
127 Barcode1D {
129 kind: Barcode1DKind,
130 x: u32,
131 y: u32,
132 orientation: char,
133 height: u32,
134 module_width: u32,
135 interpretation_line: char,
136 interpretation_line_above: char,
137 data: String,
138 reverse_print: bool,
139 condition: Option<(String, String)>,
140 },
141 GraphicDiagonal {
143 x: u32,
144 y: u32,
145 width: u32,
146 height: u32,
147 thickness: u32,
148 color: char,
149 custom_color: Option<String>,
150 diagonal_orientation: char,
152 reverse_print: bool,
153 condition: Option<(String, String)>,
154 },
155 DataMatrix {
157 x: u32,
158 y: u32,
159 orientation: char,
160 module_size: u32,
162 data: String,
163 reverse_print: bool,
164 condition: Option<(String, String)>,
165 },
166 Pdf417 {
168 x: u32,
169 y: u32,
170 orientation: char,
171 row_height: u32,
173 module_width: u32,
175 security_level: u32,
177 data: String,
178 reverse_print: bool,
179 condition: Option<(String, String)>,
180 },
181 Code39 {
183 x: u32,
184 y: u32,
185 orientation: char,
186 check_digit: char,
187 height: u32,
188 module_width: u32,
189 interpretation_line: char,
190 interpretation_line_above: char,
191 data: String,
192 reverse_print: bool,
193 condition: Option<(String, String)>,
194 },
195}
196
197#[derive(Debug, Clone, Copy, PartialEq)]
199pub struct TextBlock {
200 pub width: u32,
202 pub max_lines: u32,
204 pub line_spacing: i32,
206 pub justification: char,
208 pub indent: u32,
210}
211
212#[derive(Debug, Clone, Copy, PartialEq)]
214pub enum Resolution {
215 Dpi152,
217 Dpi203,
219 Dpi300,
221 Dpi600,
223 Custom(f32),
225}
226
227impl Resolution {
228 pub fn dpmm(&self) -> f32 {
230 match self {
231 Resolution::Dpi152 => 6.0,
232 Resolution::Dpi203 => 8.0,
233 Resolution::Dpi300 => 12.0,
234 Resolution::Dpi600 => 24.0,
235 Resolution::Custom(val) => val / 25.4,
236 }
237 }
238
239 pub fn dpi(&self) -> f32 {
241 match self {
242 Resolution::Dpi152 => 152.0,
243 Resolution::Dpi203 => 203.2,
244 Resolution::Dpi300 => 304.8,
245 Resolution::Dpi600 => 609.6,
246 Resolution::Custom(val) => *val,
247 }
248 }
249}
250
251#[derive(Debug, Clone, Copy, PartialEq)]
253pub enum Unit {
254 Dots(u32),
256 Inches(f32),
258 Millimeters(f32),
260 Centimeters(f32),
262}
263
264impl Unit {
265 pub fn to_dots(&self, resolution: Resolution) -> u32 {
267 match self {
268 Unit::Dots(dots) => *dots,
269 Unit::Inches(inches) => (inches.max(0.0) * resolution.dpi()).round() as u32,
270 Unit::Millimeters(mm) => (mm.max(0.0) * resolution.dpmm()).round() as u32,
271 Unit::Centimeters(cm) => (cm.max(0.0) * 10.0 * resolution.dpmm()).round() as u32,
272 }
273 }
274}