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.
This commit is contained in:
parent
2c8f9685b9
commit
aff5b4974e
2 changed files with 17 additions and 11 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
use cosmic_text::{Attrs, Metrics};
|
use cosmic_text::{Attrs, Metrics};
|
||||||
use palette::Srgba;
|
use palette::Srgba;
|
||||||
use showbits_common::{
|
use showbits_common::{
|
||||||
|
color,
|
||||||
widgets::{Block, FontStuff, HasFontStuff, Text},
|
widgets::{Block, FontStuff, HasFontStuff, Text},
|
||||||
Node, Tree, WidgetExt,
|
Tree, WidgetExt,
|
||||||
};
|
};
|
||||||
use taffy::style_helpers::{length, percent};
|
use taffy::style_helpers::{length, percent};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
@ -80,19 +81,17 @@ impl Drawer {
|
||||||
.register(&mut tree)?;
|
.register(&mut tree)?;
|
||||||
|
|
||||||
let wrap = Block::new()
|
let wrap = Block::new()
|
||||||
.background(Srgba::new(0.0, 1.0, 0.0, 0.3))
|
.border(color::BLACK)
|
||||||
.node()
|
.node()
|
||||||
|
.border_all(length(2.0))
|
||||||
.child(text)
|
.child(text)
|
||||||
.register(&mut tree)?;
|
.register(&mut tree)?;
|
||||||
|
|
||||||
let root = Block::new()
|
let root = Block::new()
|
||||||
.border(Srgba::new(1.0, 0.0, 0.0, 0.5))
|
.border(color::BLACK)
|
||||||
.node()
|
.node()
|
||||||
.size_width(percent(1.0))
|
.size_width(percent(1.0))
|
||||||
.border_top(length(5.0))
|
.border_all(length(2.0))
|
||||||
.border_right(length(10.0))
|
|
||||||
.border_bottom(length(15.0))
|
|
||||||
.border_left(length(20.0))
|
|
||||||
.padding_all(length(10.0))
|
.padding_all(length(10.0))
|
||||||
.child(wrap)
|
.child(wrap)
|
||||||
.register(&mut tree)?;
|
.register(&mut tree)?;
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,20 @@ impl Printer {
|
||||||
const PAGE_CODE: PageCode = PageCode::PC437;
|
const PAGE_CODE: PageCode = PageCode::PC437;
|
||||||
|
|
||||||
/// Width of the printable area in pixels.
|
/// 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
|
/// Images are printed in chunks because a single print command can only
|
||||||
/// print so much data.
|
/// 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(
|
pub fn new(
|
||||||
printer_path: Option<PathBuf>,
|
printer_path: Option<PathBuf>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue