added width param to render

This commit is contained in:
Louis Heredero 2024-06-13 12:02:31 +02:00
parent 8bcedbfc53
commit f061bd964e
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 30 additions and 4 deletions

View File

@ -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) = {

View File

@ -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)
}