typst / typst

A new markup-based typesetting system that is powerful and easy to learn.
https://typst.app
Apache License 2.0
31.18k stars 837 forks source link

`measure()` treats objects in `rotate(reflow: true, …)` as zero-width #4237

Closed Jollywatt closed 2 days ago

Jollywatt commented 2 months ago

Description

The dimensions of an object that has been rotated with reflow: true seem to be different according to 1) an enclosing rect and 2) the contextual measure function. Specifically, the bounding box reported by measure is that of a rotated zero-width object.

MWE:

#set rect(inset: 0pt, stroke: red)

#let obj = rotate(30deg, reflow: true)[hello]

#rect(obj)

#context rect(
  width: measure(obj).width,
  height: measure(obj).height,
  obj,
)
Screenshot 2024-05-24 at 00 44 06

This is also observed for rotated objects other than text (see reproduction URL).

Perhaps related: the dimensions seem to be incorrect when the parent container sizes automatically to content:

#set page(width: auto, height: auto)
#set rect(inset: 0pt, stroke: red)

Auto-sizing page:
#rect(rotate(30deg, reflow: true)[hello])
Screenshot 2024-05-24 at 02 19 18

Reproduction URL

https://typst.app/project/rUM1E564AvpxiKtmw50JMW

Operating system

Web app, Windows, Linux, macOS

Typst version

Jollywatt commented 2 months ago

Related discussion: cetz-package/cetz#604 and Jollywatt/typst-fletcher/issues/34.

kram-tm commented 1 month ago

This seems to apply to scale(reflow: true, …) as well.

kram-tm commented 1 month ago

I experimented a bit with rotate(reflow: true). I have no idea to what extent this can be mapped to other things, but after the rotation of a rect(height: 100pt, width: 50pt), one of the lines appears to be the hypotenuse of the measured width and height. The "hypotenuse" is initially a vertical line of the original rectangle for 0 < α ≤ 90 and switches for every 90deg (i.e. horizontal line — zero-height — for 90 < α ≤ 180 and so on).

page-1