Use new typst rendering in /test endpoint

This commit is contained in:
Joscha 2025-02-28 23:10:31 +01:00
parent 8526566f39
commit 428b825e43
15 changed files with 128 additions and 14 deletions

View 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)

View 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
}

View file

@ -0,0 +1 @@
../lib.typ

View 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
}

View 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"))
}
}