added auto fit wrapper function

This commit is contained in:
Louis Heredero 2024-08-04 00:22:20 +02:00
parent b5c34c154f
commit b9bbe6f93d
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 25 additions and 4 deletions

View File

@ -1,4 +1,4 @@
#import "utils.typ": get-group-span
#import "utils.typ": get-group-span, fit-canvas
#import "renderer.typ": render
#import "participant.typ" as participant: _par, PAR-SPECIALS
@ -18,7 +18,7 @@
),)
}
#let diagram(elements) = {
#let diagram(elements, width: auto) = {
if elements == none {
return
}
@ -188,7 +188,8 @@
}
set text(font: "Source Sans 3")
render(participants, elmts)
let canvas = render(participants, elmts)
fit-canvas(canvas, width: width)
}
#let from-plantuml(code) = {

View File

@ -41,3 +41,23 @@
panic("Invalid type for parameter mods, expected auto or dictionary, got " + str(type(mods)))
}
#let fit-canvas(canvas, width: auto) = layout(size => {
let m = measure(canvas)
let w = m.width
let h = m.height
let r = if w == 0pt {0} else {
if width == auto {1} else {
size.width * width / 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, reflow: true, canvas)
)
})