Added defaults
This commit is contained in:
parent
817d5efc9e
commit
ffa562d252
1 changed files with 12 additions and 8 deletions
|
|
@ -13,35 +13,39 @@ pub enum EscPosError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Default)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum QREcc {
|
pub enum QREcc {
|
||||||
Low = 48,
|
Low = 48,
|
||||||
|
#[default]
|
||||||
Medium = 49,
|
Medium = 49,
|
||||||
Quartile = 50,
|
Quartile = 50,
|
||||||
High = 51,
|
High = 51,
|
||||||
}
|
}
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Default)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum BARTextPosition {
|
pub enum BARTextPosition {
|
||||||
Hidden = 0,
|
Hidden = 0,
|
||||||
Above = 1,
|
Above = 1,
|
||||||
|
#[default]
|
||||||
Below = 2,
|
Below = 2,
|
||||||
Both = 3,
|
Both = 3,
|
||||||
}
|
}
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Default)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum BARType {
|
pub enum BARType {
|
||||||
|
#[default]
|
||||||
Code128 = 0x49,
|
Code128 = 0x49,
|
||||||
Ean13 = 0x43,
|
Ean13 = 0x43,
|
||||||
Upca = 0x41,
|
Upca = 0x41,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Default)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum ImageOrientation {
|
pub enum ImageOrientation {
|
||||||
|
#[default]
|
||||||
Preserve,
|
Preserve,
|
||||||
Largest,
|
Largest,
|
||||||
LargestOrientation,
|
LargestOrientation,
|
||||||
|
|
@ -155,7 +159,7 @@ impl EscPosBuilder {
|
||||||
img: &DynamicImage,
|
img: &DynamicImage,
|
||||||
orientation: Option<ImageOrientation>,
|
orientation: Option<ImageOrientation>,
|
||||||
) -> () {
|
) -> () {
|
||||||
let orientation = orientation.unwrap_or(ImageOrientation::Preserve);
|
let orientation = orientation.unwrap_or_default();
|
||||||
let mw = self.max_width as u32;
|
let mw = self.max_width as u32;
|
||||||
|
|
||||||
let mut image = img.clone();
|
let mut image = img.clone();
|
||||||
|
|
@ -207,7 +211,7 @@ impl EscPosBuilder {
|
||||||
|
|
||||||
pub fn write_qr(&mut self, text: &str, size: Option<u8>, ecc: Option<QREcc>) -> () {
|
pub fn write_qr(&mut self, text: &str, size: Option<u8>, ecc: Option<QREcc>) -> () {
|
||||||
let mut buf: Vec<u8> = vec![];
|
let mut buf: Vec<u8> = vec![];
|
||||||
let ecc = ecc.unwrap_or(QREcc::Medium);
|
let ecc = ecc.unwrap_or_default();
|
||||||
let size = match size {
|
let size = match size {
|
||||||
Some(v) => v.clamp(6, 15),
|
Some(v) => v.clamp(6, 15),
|
||||||
None => 10,
|
None => 10,
|
||||||
|
|
@ -259,8 +263,8 @@ impl EscPosBuilder {
|
||||||
) -> Result<(), EscPosError> {
|
) -> Result<(), EscPosError> {
|
||||||
let height: u8 = height.unwrap_or(80);
|
let height: u8 = height.unwrap_or(80);
|
||||||
let mod_width: u8 = mod_width.unwrap_or(2);
|
let mod_width: u8 = mod_width.unwrap_or(2);
|
||||||
let text_position = text_position.unwrap_or(BARTextPosition::Below) as u8;
|
let text_position = text_position.unwrap_or_default() as u8;
|
||||||
let bar_type = bar_type.unwrap_or(BARType::Code128);
|
let bar_type = bar_type.unwrap_or_default();
|
||||||
|
|
||||||
let text = text.as_bytes();
|
let text = text.as_bytes();
|
||||||
let len = text.len() as u8;
|
let len = text.len() as u8;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue