#[derive(Debug)]
pub enum ZplInstruction {
Text {
x: u32,
y: u32,
font: char,
height: Option<u32>,
width: Option<u32>,
text: String,
reverse_print: bool,
color: Option<String>,
condition: Option<(String, String)>,
},
GraphicBox {
x: u32,
y: u32,
width: u32,
height: u32,
thickness: u32,
color: char,
custom_color: Option<String>,
rounding: u32,
reverse_print: bool,
condition: Option<(String, String)>,
},
GraphicCircle {
x: u32,
y: u32,
radius: u32,
thickness: u32,
color: char,
custom_color: Option<String>,
reverse_print: bool,
condition: Option<(String, String)>,
},
GraphicEllipse {
x: u32,
y: u32,
width: u32,
height: u32,
thickness: u32,
color: char,
custom_color: Option<String>,
reverse_print: bool,
condition: Option<(String, String)>,
},
GraphicField {
x: u32,
y: u32,
width: u32,
height: u32,
data: Vec<u8>,
reverse_print: bool,
condition: Option<(String, String)>,
},
CustomImage {
x: u32,
y: u32,
width: u32,
height: u32,
data: String,
condition: Option<(String, String)>,
},
Code128 {
x: u32,
y: u32,
orientation: char,
height: u32,
module_width: u32,
interpretation_line: char,
interpretation_line_above: char,
check_digit: char,
mode: char,
data: String,
reverse_print: bool,
condition: Option<(String, String)>,
},
QRCode {
x: u32,
y: u32,
orientation: char,
model: u32,
magnification: u32,
error_correction: char,
mask: u32,
data: String,
reverse_print: bool,
condition: Option<(String, String)>,
},
Code39 {
x: u32,
y: u32,
orientation: char,
check_digit: char,
height: u32,
module_width: u32,
interpretation_line: char,
interpretation_line_above: char,
data: String,
reverse_print: bool,
condition: Option<(String, String)>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Resolution {
Dpi152,
Dpi203,
Dpi300,
Dpi600,
Custom(f32),
}
impl Resolution {
pub fn dpmm(&self) -> f32 {
match self {
Resolution::Dpi152 => 6.0,
Resolution::Dpi203 => 8.0,
Resolution::Dpi300 => 12.0,
Resolution::Dpi600 => 24.0,
Resolution::Custom(val) => val / 25.4,
}
}
pub fn dpi(&self) -> f32 {
match self {
Resolution::Dpi152 => 152.0,
Resolution::Dpi203 => 203.2,
Resolution::Dpi300 => 304.8,
Resolution::Dpi600 => 609.6,
Resolution::Custom(val) => *val,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Unit {
Dots(u32),
Inches(f32),
Millimeters(f32),
Centimeters(f32),
}
impl Unit {
pub fn to_dots(&self, resolution: Resolution) -> u32 {
match self {
Unit::Dots(dots) => *dots,
Unit::Inches(inches) => (inches.max(0.0) * resolution.dpi()).round() as u32,
Unit::Millimeters(mm) => (mm.max(0.0) * resolution.dpmm()).round() as u32,
Unit::Centimeters(cm) => (cm.max(0.0) * 10.0 * resolution.dpmm()).round() as u32,
}
}
}