From f061bd964e8ac0e51f4243af7bed3560beeeca1f Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Thu, 13 Jun 2024 12:02:31 +0200 Subject: [PATCH] added width param to render --- src/renderer.typ | 30 ++++++++++++++++++++++++++++-- src/schema.typ | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/renderer.typ b/src/renderer.typ index 238a0fb..6b61674 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -433,7 +433,7 @@ return (shapes, desc-y) } -#let render(config, structures) = { +#let render(config, structures, width: 100%) = { set text( font: config.default-font-family, size: config.default-font-size @@ -458,7 +458,7 @@ set page(..params) - canvas(length: 1pt, background: config.background, { + let cnvs = canvas(length: 1pt, background: config.background, { let (shapes, _) = draw-structure( config, main, structures, ox: ox, @@ -475,6 +475,32 @@ fill: none ) }) + + layout(size => { + let m = measure(cnvs) + let w = m.width + let h = m.height + let base-w = if type(width) == ratio { + size.width * width + } else { + width + } + let r = if w == 0 { + 0 + } else { + base-w / w + } + + let new-w = w * r + let new-h = h * r + r *= 100% + + box( + width: new-w, + height: new-h, + scale(x: r, y: r, cnvs, reflow: true) + ) + }) } #let make(config) = { diff --git a/src/schema.typ b/src/schema.typ index a3328ba..a34efdc 100644 --- a/src/schema.typ +++ b/src/schema.typ @@ -56,10 +56,10 @@ return structures } -#let render(structures, config: auto) = { +#let render(structures, width: 100%, config: auto) = { if config == auto { config = conf.config() } let renderer_ = renderer.make(config) - (renderer_.render)(structures) + (renderer_.render)(structures, width: width) } \ No newline at end of file