Makie - How do I calculate the pixel length of a formatted string?

It seems like the best way is to render the text somewhere and then get the size of the rendered object. I’ve chosen Makie for this, but am open to alternatives. The best I’ve managed is this code, but the width is Auto(true, 1.0f0)

function line_length(text; font="Open Sans", f=Figure(), fontsize=12)
    t = Label(f[1,1], text, font=font, fontsize=fontsize, tellwidth=true, tellheight=true)
    return t.width[]
end

Before I try complicated suggestions, what do you actually need this for?

I’m trying to convert a word document holding poetry-formatted text into an html document. However, the document is formatted primarily via a large margin on the right, meaning it’s functionally just a single long repeatedly wrapped line. The line-delineation on the poetry is essentially arbitrary, just needing to be within a certain maximum visual width.

So, what I’m trying to do is to snip that single line of text into lines of less than maximum visual width (plus some bonus rules like not ending with the word “and” or “the”, but that’s next step).

edit: my main alternative is to OCR a pdf and then verify via the original text, so that’s the bar for complication. I assumed this would be less complicated. Then of course there’s the least complicated way of character-count, but I’m hopeful I can do it right.

Ah ok then maybe it would be easier to work with FreeTypeAbstraction directly and the different glyph boundingbox functions it has. Basic text layouting is just sticking glyphs together based on their origins and horizontal advance values. That’s what Makie uses, too. You can also look for GlyphCollection in the Makie source and the layout functions that produce them.

That sounds like exactly what I need, thank you!