diff --git a/Cargo.lock b/Cargo.lock index 57d07db..6b607ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1481,6 +1481,15 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +[[package]] +name = "openssl-src" +version = "300.5.5+3.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f1787d533e03597a7934fd0a765f0d28e94ecc5fb7789f8053b1e699a56f709" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.109" @@ -1489,6 +1498,7 @@ checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -1626,6 +1636,7 @@ dependencies = [ "dotenvy", "env_logger", "log", + "openssl", "teloxide-core", "thiserror 2.0.16", "tokio", diff --git a/brother_ql/src/driver.rs b/brother_ql/src/driver.rs index ebca72f..b0c8a39 100644 --- a/brother_ql/src/driver.rs +++ b/brother_ql/src/driver.rs @@ -119,6 +119,50 @@ pub struct PrinterStatus { phase_state: PhaseState, } +impl PrinterStatus { + /// Get the pixel width (print area width in dots) for the loaded media + pub fn pixel_width(&self) -> Option { + match (self.media_width, self.media_length) { + // Endless tapes (length = 0) - dots_total - offset_r + (12, 0) => Some(142 - 29), // 113 + (18, 0) => Some(256 - 171), // 85 + (29, 0) => Some(342 - 6), // 336 + (38, 0) => Some(449 - 12), // 437 + (50, 0) => Some(590 - 12), // 578 + (54, 0) => Some(636 - 0), // 636 + (62, 0) => Some(732 - 12), // 720 + (102, 0) => Some(1200 - 12), // 1188 + (104, 0) => Some(1224 - 12), // 1212 + + // Die-cut labels + (17, 54) => Some(201 - 0), // 201 + (17, 87) => Some(201 - 0), // 201 + (23, 23) => Some(272 - 42), // 230 + (29, 42) => Some(342 - 6), // 336 + (29, 90) => Some(342 - 6), // 336 + (38, 90) => Some(449 - 12), // 437 + (39, 48) => Some(461 - 6), // 455 + (52, 29) => Some(614 - 0), // 614 + (54, 29) => Some(630 - 60), // 570 + (60, 87) => Some(708 - 18), // 690 + (62, 29) => Some(732 - 12), // 720 + (62, 100) => Some(732 - 12), // 720 + (102, 51) => Some(1200 - 12), // 1188 + (102, 153) => Some(1200 - 12), // 1188 + (104, 164) => Some(1224 - 12), // 1212 + + // Round die-cut labels + // This can't be right + //(12, 12) => Some(142 - 113), // 29 + (24, 24) => Some(284 - 42), // 242 + (58, 58) => Some(688 - 51), // 637 + + // Unknown media + _ => None, + } + } +} + #[derive(Clone)] pub enum PrinterCommandMode { /// ESC/P mode (normal) @@ -255,6 +299,7 @@ impl PrinterCommander { } pub fn read_status(&mut self) -> Result { + self.send_command(PrinterCommand::StatusInfoRequest)?; let res = self.printer.read(32)?; assert!(res[0] == 0x80); assert!(res[1] == 0x20); diff --git a/brother_ql/src/image.rs b/brother_ql/src/image.rs index b4c8519..96f6998 100644 --- a/brother_ql/src/image.rs +++ b/brother_ql/src/image.rs @@ -1,3 +1,5 @@ +use std::env; + use crate::driver::{PrinterCommand, PrinterCommandMode, PrinterExpandedMode, PrinterMode}; use crate::error::BrotherQlError; use crate::{driver, Settings}; @@ -58,7 +60,10 @@ fn apply_threshold( Ok(img) } -fn img_to_lines(img: ImageBuffer, Vec>) -> Result, BrotherQlError> { +fn img_to_lines( + img: ImageBuffer, Vec>, + image_width: u32, +) -> Result, BrotherQlError> { // convert to vec of line bits /* let mut lines = Vec::new(); @@ -83,13 +88,14 @@ fn img_to_lines(img: ImageBuffer, Vec>) -> Result, Br */ let mut lines = Vec::new(); + let padding = 720 - image_width; for y in 0..img.height() { let mut line = [0u8; 90]; for x in 0..img.width() { let i = img.get_pixel(x, y).0[0]; - + let x = x + padding; let byte = x / 8; let bit = x % 8; @@ -133,8 +139,10 @@ pub fn render_image(file_path: &str, settings: &Settings) -> Result Result