mirror of
https://codeberg.org/icewind/ptouch-api.git
synced 2026-06-03 10:54:07 +02:00
use tape px width instead of device max
This commit is contained in:
parent
678fdf5185
commit
f7910f967b
5 changed files with 20 additions and 14 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1213,7 +1213,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ptouch-api"
|
name = "ptouch-api"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
@ -1222,7 +1222,7 @@ dependencies = [
|
||||||
"main_error",
|
"main_error",
|
||||||
"ptouch-rs",
|
"ptouch-rs",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror 1.0.69",
|
"thiserror 2.0.16",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml 0.9.6",
|
"toml 0.9.6",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ptouch-api"
|
name = "ptouch-api"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -11,7 +11,7 @@ image = { version = "0.25.8", features = ["png", "jpeg", "bmp"] }
|
||||||
axum = { version = "0.8.4", features = ["macros", "json"] }
|
axum = { version = "0.8.4", features = ["macros", "json"] }
|
||||||
listenfd = "1.0.2"
|
listenfd = "1.0.2"
|
||||||
serde = { version = "1.0.225", features = ["derive"] }
|
serde = { version = "1.0.225", features = ["derive"] }
|
||||||
thiserror = "1.0.69"
|
thiserror = "2.0.16"
|
||||||
toml = "0.9.6"
|
toml = "0.9.6"
|
||||||
clap = { version = "4.5.47", features = ["derive"] }
|
clap = { version = "4.5.47", features = ["derive"] }
|
||||||
tracing-subscriber = "0.3.20"
|
tracing-subscriber = "0.3.20"
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,18 @@ on the system access to the label printer.
|
||||||
|
|
||||||
### Status
|
### Status
|
||||||
|
|
||||||
The returned status is a json with the following fields
|
The returned status is a json with the following fields:
|
||||||
|
|
||||||
- `media_width`: width of the loaded tape in mm.
|
- `media_width`: width of the loaded tape in mm.
|
||||||
- `pixel_width`: the width of the printed image in pixels.
|
- `pixel_width`: the width of the printed image in pixels.
|
||||||
|
- `margin_width`: the left and right margin on the tape that can't be printed.
|
||||||
- `media_type`: material type of the loaded tape.
|
- `media_type`: material type of the loaded tape.
|
||||||
- `text_color`: text color for the loaded tape.
|
- `text_color`: text color for the loaded tape.
|
||||||
- `tape_color`: tape color for the loaded tape.
|
- `tape_color`: tape color for the loaded tape.
|
||||||
|
|
||||||
|
(note that the tape is assumed to be horizontal here, so "width" is the short
|
||||||
|
short direction)
|
||||||
|
|
||||||
## Supported printers
|
## Supported printers
|
||||||
|
|
||||||
The following printers are currently supported
|
The following printers are currently supported
|
||||||
|
|
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -177,7 +177,7 @@ async fn status(State(state): State<App>) -> Result<Json<PStatus>, ApiError> {
|
||||||
let mut printer = state.printer.lock().await;
|
let mut printer = state.printer.lock().await;
|
||||||
debug!("reloading printer status");
|
debug!("reloading printer status");
|
||||||
printer.reload_status().await?;
|
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> {
|
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()
|
.unwrap()
|
||||||
.decode()?;
|
.decode()?;
|
||||||
let printer = state.printer.lock().await;
|
let printer = state.printer.lock().await;
|
||||||
let printer_info = printer.ty().info();
|
|
||||||
|
|
||||||
if image.height() != printer_info.max_px {
|
let max_px = printer.status().media_width.info().px;
|
||||||
let width = image.width() * printer_info.max_px / image.height();
|
if image.height() != max_px {
|
||||||
debug!(width, height = printer_info.max_px, "scaling image");
|
let width = image.width() * max_px / image.height();
|
||||||
image = image.resize(width, printer_info.max_px, FilterType::CatmullRom);
|
debug!(width, height = max_px, "scaling image");
|
||||||
|
image = image.resize(width, max_px, FilterType::CatmullRom);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(width = image.width(), height = image.height(), "printing");
|
info!(width = image.width(), height = image.height(), "printing");
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use ptouch_rs::{MediaType, PrinterType, Status, TapeColor, TapeSize, TextColor};
|
use ptouch_rs::{MediaType, Status, TapeColor, TapeSize, TextColor};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
@ -6,16 +6,18 @@ pub struct PStatus {
|
||||||
/// width in mm
|
/// width in mm
|
||||||
media_width: f32,
|
media_width: f32,
|
||||||
pixel_width: u32,
|
pixel_width: u32,
|
||||||
|
margin_width: f32,
|
||||||
media_type: &'static str,
|
media_type: &'static str,
|
||||||
text_color: &'static str,
|
text_color: &'static str,
|
||||||
tape_color: &'static str,
|
tape_color: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PStatus {
|
impl PStatus {
|
||||||
pub fn new(status: Status, printer_type: PrinterType) -> Self {
|
pub fn new(status: Status) -> Self {
|
||||||
PStatus {
|
PStatus {
|
||||||
media_width: tape_size(&status.media_width),
|
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),
|
media_type: media_type(&status.media_type),
|
||||||
text_color: text_color(&status.text_color),
|
text_color: text_color(&status.text_color),
|
||||||
tape_color: tape_color(&status.tape_color),
|
tape_color: tape_color(&status.tape_color),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue