Skip to content

Commit

Permalink
Add fit-to-width functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ntjess authored Sep 2, 2023
1 parent f98e7c4 commit b99eb36
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion utils/utils.typ
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#let last-slide-number = locate(loc => logic.logical-slide.final(loc).first())


// HEIGHT FITTING
// HEIGHT/WIDTH FITTING

#let _size-to-pt(size, styles, container-dimension) = {
let to-convert = size
Expand Down Expand Up @@ -129,6 +129,25 @@
})
}

#let fit-to-width(width: 100%, content) = {
style(styles => {
let content-size = measure(content, styles)
let content-width = content-size.width
if width < content-width {
let ratio = width / content-width * 100%
// The first box keeps content from prematurely wrapping
let scaled = scale(
box(content, width: content-width), origin: top + left, x: ratio, y: ratio
)
// The second box lets typst know the post-scaled dimensions, since `scale`
// doesn't update layout information
box(scaled, width: width, height: content-size.height * ratio)
} else {
content
}
})
}

// SIDE BY SIDE

#let side-by-side(columns: none, gutter: 1em, ..bodies) = {
Expand Down

0 comments on commit b99eb36

Please sign in to comment.