How to calculate bounding box of a text primitive BEFORE Luxor.Drawing()

I want to determine the appropriate size of a drawing before calling Luxor.Drawing()… This results in needing to calculate the bounding box of all components within my drawing. Luxor provides the convenient method BoundingBox, which can calculate the size of a bounding box for a lot of primitives, including text. However, this function only works when a Drawing is instantiated, and hence, it defeats the point of why I need it.

I see there is also an internal method textextents, which I thought I could use. But this also requires having a Drawing instantiated before it can be called. Is there a way to calculate the appropriate size of a bounding box of text before using Luxor.Drawing() ?

We do similar things in Makie for layouting, so maybe you can also use FreeTypeAbstraction for that purpose. Some useful functions are here FreeTypeAbstraction.jl/layout.jl at master · JuliaGraphics/FreeTypeAbstraction.jl · GitHub

1 Like

You’re right. In the past I’ve sometimes had to create a temporary drawing to do stuff, then create a new drawing to actually draw stuff using that knowledge (eg this nonsense).

Perhaps it’s not very appealing aesthetically to do this … :slight_smile: