use tape px width instead of device max

This commit is contained in:
Robin Appelman 2025-09-24 17:30:46 +02:00
commit f7910f967b
5 changed files with 20 additions and 14 deletions

View file

@ -177,7 +177,7 @@ async fn status(State(state): State<App>) -> Result<Json<PStatus>, ApiError> {
let mut printer = state.printer.lock().await;
debug!("reloading printer status");
printer.reload_status().await?;
Ok(Json(PStatus::new(printer.status(), printer.ty())))
Ok(Json(PStatus::new(printer.status())))
}
async fn print(State(state): State<App>, bytes: Bytes) -> Result<(), ApiError> {
@ -186,12 +186,12 @@ async fn print(State(state): State<App>, bytes: Bytes) -> Result<(), ApiError> {
.unwrap()
.decode()?;
let printer = state.printer.lock().await;
let printer_info = printer.ty().info();
if image.height() != printer_info.max_px {
let width = image.width() * printer_info.max_px / image.height();
debug!(width, height = printer_info.max_px, "scaling image");
image = image.resize(width, printer_info.max_px, FilterType::CatmullRom);
let max_px = printer.status().media_width.info().px;
if image.height() != max_px {
let width = image.width() * max_px / image.height();
debug!(width, height = max_px, "scaling image");
image = image.resize(width, max_px, FilterType::CatmullRom);
}
info!(width = image.width(), height = image.height(), "printing");

View file

@ -1,4 +1,4 @@
use ptouch_rs::{MediaType, PrinterType, Status, TapeColor, TapeSize, TextColor};
use ptouch_rs::{MediaType, Status, TapeColor, TapeSize, TextColor};
use serde::Serialize;
#[derive(Debug, Serialize)]
@ -6,16 +6,18 @@ pub struct PStatus {
/// width in mm
media_width: f32,
pixel_width: u32,
margin_width: f32,
media_type: &'static str,
text_color: &'static str,
tape_color: &'static str,
}
impl PStatus {
pub fn new(status: Status, printer_type: PrinterType) -> Self {
pub fn new(status: Status) -> Self {
PStatus {
media_width: tape_size(&status.media_width),
pixel_width: printer_type.info().max_px,
pixel_width: status.media_width.info().px,
margin_width: status.media_width.info().margins,
media_type: media_type(&status.media_type),
text_color: text_color(&status.text_color),
tape_color: tape_color(&status.tape_color),