Dimentions of text rendered with Printf

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
JayKyburzNew
Prole
Posts: 3
Joined: Fri Oct 21, 2022 1:17 am

Dimentions of text rendered with Printf

Post by JayKyburzNew »

Hi Folks,

I vaguely remember reading somewhere that it was possible to work out the dimensions of text that had been rendered by Printf so I could draw a box around it.

I quick scan of the docs and I didn't see anything.

Anybody know how?
Koxinga
Prole
Posts: 13
Joined: Sun Oct 02, 2022 12:29 am

Re: Dimentions of text rendered with Printf

Post by Koxinga »

Not sure if that is what you are asking for but I use Font:getWidth() and Font:getHeight()
https://love2d.org/wiki/Font:getWidth
(you have to define a font first or use https://love2d.org/wiki/love.graphics.getFont)

It's ok for text that doesn't wrap, but if it's displayed on multiple lines I suppose these won't match. I never had to deal with that case so I can't tell really.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Dimentions of text rendered with Printf

Post by slime »

You can use Font:getWrap to get the width and number of lines, and then multiply the number of lines with Font:getHeight to get the total height.
JayKyburzNew
Prole
Posts: 3
Joined: Fri Oct 21, 2022 1:17 am

Re: Dimentions of text rendered with Printf

Post by JayKyburzNew »

Thanks for the tips folks.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 15 guests