From aff5b4974e72bb047de61eeafe1c1db846dbe6a5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 9 Mar 2024 01:26:17 +0100 Subject: [PATCH] Measure width and decide on chunk height The chunk height was tested by printing a widget with height 1200 and continuous vertical lines. It printed perfectly and in one go. --- showbits-thermal-printer/src/drawer.rs | 13 ++++++------- showbits-thermal-printer/src/printer.rs | 15 +++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/showbits-thermal-printer/src/drawer.rs b/showbits-thermal-printer/src/drawer.rs index 2058661..62d085d 100644 --- a/showbits-thermal-printer/src/drawer.rs +++ b/showbits-thermal-printer/src/drawer.rs @@ -1,8 +1,9 @@ use cosmic_text::{Attrs, Metrics}; use palette::Srgba; use showbits_common::{ + color, widgets::{Block, FontStuff, HasFontStuff, Text}, - Node, Tree, WidgetExt, + Tree, WidgetExt, }; use taffy::style_helpers::{length, percent}; use tokio::sync::mpsc; @@ -80,19 +81,17 @@ impl Drawer { .register(&mut tree)?; let wrap = Block::new() - .background(Srgba::new(0.0, 1.0, 0.0, 0.3)) + .border(color::BLACK) .node() + .border_all(length(2.0)) .child(text) .register(&mut tree)?; let root = Block::new() - .border(Srgba::new(1.0, 0.0, 0.0, 0.5)) + .border(color::BLACK) .node() .size_width(percent(1.0)) - .border_top(length(5.0)) - .border_right(length(10.0)) - .border_bottom(length(15.0)) - .border_left(length(20.0)) + .border_all(length(2.0)) .padding_all(length(10.0)) .child(wrap) .register(&mut tree)?; diff --git a/showbits-thermal-printer/src/printer.rs b/showbits-thermal-printer/src/printer.rs index 530c763..abc5030 100644 --- a/showbits-thermal-printer/src/printer.rs +++ b/showbits-thermal-printer/src/printer.rs @@ -23,13 +23,20 @@ impl Printer { const PAGE_CODE: PageCode = PageCode::PC437; /// Width of the printable area in pixels. - // TODO Figure out actual width - const WIDTH: u32 = 8 * 32; + /// + /// Assumed to be a multiple of 8, then measured to that precision. + const WIDTH: u32 = 8 * 48; /// Images are printed in chunks because a single print command can only /// print so much data. - // TODO Figure out sensible chunk height - const CHUNK_HEIGHT: u32 = 42; + /// + /// Looking at the [epson docs][0], most printers seem to support a max + /// height of 2303, though some go up to 4095. Because I don't want to waste + /// a bunch of paper trying various different heights, I'll go with 1023 + /// because it's nice and round and slightly conservative. + /// + /// [0]: https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/gs_lv_0.html + const CHUNK_HEIGHT: u32 = 0b0000_0011_1111_1111; pub fn new( printer_path: Option,