1#[derive(Debug)]
6pub enum ZplInstruction {
7 Text {
9 x: u32,
11 y: u32,
13 font: char,
15 height: Option<u32>,
17 width: Option<u32>,
19 text: String,
21 reverse_print: bool,
23 color: Option<String>,
25 },
26 GraphicBox {
28 x: u32,
29 y: u32,
30 width: u32,
31 height: u32,
32 thickness: u32,
33 color: char,
34 custom_color: Option<String>,
35 rounding: u32,
36 reverse_print: bool,
37 },
38 GraphicCircle {
40 x: u32,
41 y: u32,
42 radius: u32,
43 thickness: u32,
44 color: char,
45 custom_color: Option<String>,
46 reverse_print: bool,
47 },
48 GraphicEllipse {
50 x: u32,
51 y: u32,
52 width: u32,
53 height: u32,
54 thickness: u32,
55 color: char,
56 custom_color: Option<String>,
57 reverse_print: bool,
58 },
59 GraphicField {
61 x: u32,
62 y: u32,
63 width: u32,
64 height: u32,
65 data: Vec<u8>,
66 reverse_print: bool,
67 },
68 CustomImage {
70 x: u32,
72 y: u32,
74 width: u32,
76 height: u32,
78 data: String,
80 },
81 Code128 {
83 x: u32,
84 y: u32,
85 orientation: char,
86 height: u32,
87 module_width: u32,
88 interpretation_line: char,
89 interpretation_line_above: char,
90 check_digit: char,
91 mode: char,
92 data: String,
93 reverse_print: bool,
94 },
95 QRCode {
97 x: u32,
98 y: u32,
99 orientation: char,
100 model: u32,
101 magnification: u32,
102 error_correction: char,
103 mask: u32,
104 data: String,
105 reverse_print: bool,
106 },
107 Code39 {
109 x: u32,
110 y: u32,
111 orientation: char,
112 check_digit: char,
113 height: u32,
114 module_width: u32,
115 interpretation_line: char,
116 interpretation_line_above: char,
117 data: String,
118 reverse_print: bool,
119 },
120}
121
122#[derive(Debug, Clone, Copy, PartialEq)]
124pub enum Resolution {
125 Dpi152,
127 Dpi203,
129 Dpi300,
131 Dpi600,
133 Custom(f32),
135}
136
137impl Resolution {
138 pub fn dpmm(&self) -> f32 {
140 match self {
141 Resolution::Dpi152 => 6.0,
142 Resolution::Dpi203 => 8.0,
143 Resolution::Dpi300 => 12.0,
144 Resolution::Dpi600 => 24.0,
145 Resolution::Custom(val) => val / 25.4,
146 }
147 }
148
149 pub fn dpi(&self) -> f32 {
151 match self {
152 Resolution::Dpi152 => 152.0,
153 Resolution::Dpi203 => 203.2,
154 Resolution::Dpi300 => 304.8,
155 Resolution::Dpi600 => 609.6,
156 Resolution::Custom(val) => *val,
157 }
158 }
159}
160
161#[derive(Debug, Clone, Copy, PartialEq)]
163pub enum Unit {
164 Dots(u32),
166 Inches(f32),
168 Millimeters(f32),
170 Centimeters(f32),
172}
173
174impl Unit {
175 pub fn to_dots(&self, resolution: Resolution) -> u32 {
177 match self {
178 Unit::Dots(dots) => *dots,
179 Unit::Inches(inches) => (inches.max(0.0) * resolution.dpi()).round() as u32,
180 Unit::Millimeters(mm) => (mm.max(0.0) * resolution.dpmm()).round() as u32,
181 Unit::Centimeters(cm) => (cm.max(0.0) * 10.0 * resolution.dpmm()).round() as u32,
182 }
183 }
184}