use escpos::{driver::Driver, errors::PrinterError, printer::Printer, utils::JustifyMode}; use crate::types::Spell; const WIDTH: usize = 32; pub fn print_test_page(printer: &mut Printer) -> Result<(), PrinterError> { printer .writeln("---Printer Test Page---")? .bold(true)? .writeln("This text should be bold.")? .bold(false)? .underline(escpos::utils::UnderlineMode::Single)? .writeln("This text should be single underline.")? .underline(escpos::utils::UnderlineMode::Double)? .writeln("This text should be double underline.")? .underline(escpos::utils::UnderlineMode::None)? .double_strike(true)? .writeln("This text should be double striked.")? .double_strike(true)? .writeln("Text alignment")? .justify(JustifyMode::CENTER)? .writeln("CENTER")? .justify(JustifyMode::RIGHT)? .writeln("RIGHT")? .justify(JustifyMode::LEFT)? .size(1, 1)? .writeln("size 1")? .size(5, 5)? .writeln("size 5")? .reset_size()? .font(escpos::utils::Font::A)? .write("Font A ")? .font(escpos::utils::Font::B)? .write("Font B ")? .font(escpos::utils::Font::C)? .writeln("Font C")? .font(escpos::utils::Font::A)? .flip(true)? .writeln("Fliped")? .flip(false)? .line_spacing(8)? .writeln("Line")? .writeln("Spacing")? .reset_line_spacing()? .upside_down(true)? .writeln("Upside down")? .upside_down(false)? // Barcodes .writeln("EAN-13 (978020137962)")? .ean13("978020137962")? .writeln("EAN-8 (9031101)")? .ean8("9031101")? .writeln("UPC-A")? .upca("72527273070")? .writeln("CODE-39")? .code39("1234")? .writeln("CODABAR")? .writeln("1234")? .writeln("ITF")? .itf("1234")? // 2D Codes .writeln("QR Code")? .qrcode("Hello world")? .writeln("2D GS1 DataBar")? .gs1_databar_2d("1234567890123")? .writeln("pdf417")? .pdf417("Hello world")? .writeln("Maxi code")? .maxi_code("Hello world")? .writeln("Data matrix")? .data_matrix("Hello world")? .writeln("aztec")? .aztec("Hello world")? // Image .writeln("raster image")? // .bit_image("./rust-logo-small.png")? .print()?; return Ok(()); } fn left_right_print(printer: &mut Printer,left: &str, right: &str ) -> Result<(), PrinterError> { printer .write(left)? .write(&".".repeat(WIDTH - left.len() - right.len()))? .writeln(right)?; return Ok(()); } pub fn print_spell(printer: &mut Printer, spell: &Spell) -> Result<(), PrinterError> { printer .size(4, 4)? .writeln(&spell.name)? .reset_size()? .line_spacing(1)?; if spell.level > 0 { if spell.ritual { printer.writeln(&format!("Lvl. {} {} (ritual)", spell.level, spell.school))?; }else{ printer.writeln(&format!("Lvl. {} {}", spell.level, spell.school))?; } } else { printer.writeln(&format!("{} cantrip", spell.school))?; } printer.feed()?; match &spell.components { Some(comp) => { left_right_print(printer, "Components:", &comp)?; } _ => {} } left_right_print(printer, "Casting time:", &spell.casting_time)?; left_right_print(printer, "Range:", &spell.range)?; left_right_print(printer, "Duration:", &spell.duration)?; printer .reset_line_spacing()? .write(&spell.desc)? .feeds(3)? .print()?; return Ok(()); }