Use new typst rendering in /test endpoint
This commit is contained in:
parent
8526566f39
commit
428b825e43
15 changed files with 128 additions and 14 deletions
21
showbits-thermal-printer/src/documents/lib.typ
Normal file
21
showbits-thermal-printer/src/documents/lib.typ
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#let init(it) = {
|
||||
set page(
|
||||
width: 384pt,
|
||||
height: auto,
|
||||
margin: (x: 0pt, y: 4pt),
|
||||
)
|
||||
set text(
|
||||
font: ("Unifont", "Unifont-JP", "Unifont Upper"),
|
||||
size: 16pt,
|
||||
fallback: false,
|
||||
)
|
||||
set par(
|
||||
leading: 8pt, // Between lines
|
||||
spacing: 26pt, // Between paragraphs
|
||||
)
|
||||
it
|
||||
}
|
||||
|
||||
// Determined by experiments so that the top and bottom white border are roughly
|
||||
// the same size after tearing off the paper.
|
||||
#let feed = v(64pt + 32pt)
|
||||
5
showbits-thermal-printer/src/documents/text/data.json
Normal file
5
showbits-thermal-printer/src/documents/text/data.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"text": "Hello world! äöüßÄÖÜẞ😒\nSecond line\nThird line\n\nNew paragraph, with a very long line that hopefully will be word wrapped if everything goes according to plan.\n\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH",
|
||||
"force_wrap": true,
|
||||
"feed": true
|
||||
}
|
||||
1
showbits-thermal-printer/src/documents/text/lib.typ
Symbolic link
1
showbits-thermal-printer/src/documents/text/lib.typ
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../lib.typ
|
||||
13
showbits-thermal-printer/src/documents/text/main.typ
Normal file
13
showbits-thermal-printer/src/documents/text/main.typ
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#import "lib.typ";
|
||||
#show: it => lib.init(it)
|
||||
|
||||
#let data = json("data.json")
|
||||
|
||||
#if data.at("force_wrap", default: false) {
|
||||
show regex("."): it => it + sym.zws
|
||||
data.text
|
||||
} else { data.text }
|
||||
|
||||
#if data.at("feed", default: false) {
|
||||
lib.feed
|
||||
}
|
||||
19
showbits-thermal-printer/src/documents/text/mod.rs
Normal file
19
showbits-thermal-printer/src/documents/text/mod.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use showbits_typst::Typst;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Text {
|
||||
pub text: String,
|
||||
#[serde(default)]
|
||||
pub force_wrap: bool,
|
||||
#[serde(default)]
|
||||
pub feed: bool,
|
||||
}
|
||||
|
||||
impl From<Text> for Typst {
|
||||
fn from(value: Text) -> Self {
|
||||
super::typst_with_lib()
|
||||
.with_json("/data.json", &value)
|
||||
.with_main_file(include_str!("main.typ"))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue