Okey first the short explanation: read [wiki]Font[/wiki] there are all the methods you need.
Long explanation:
You can use the function [wiki]Font:getWrap[/wiki]("your text",limit) to get how many lines long the text is gonna be:
Code: Select all
local text,limit = "This is the text passed to the function",100 --This is the width of the control
local font = love.graphics.getFont()
local rw,lines = font:getWrap(text,limit)
Then you can get the height of a line, there are three different things here, there is the height you can get with [wiki]Font:getHeight[/wiki] which is the one you pass to [wiki]love.graphics.newFont[/wiki], but this is not the real height, the real height can be calculated with [wiki]Font:getAscent[/wiki] and [wiki]Font:getDescent[/wiki], if you sum them up you get the complete height of the font. Then there is also [wiki]Font:getLineHeight[/wiki], this is the data that will tell you if there is spacing between two lines of text, but this is not measured in pixels, so you need to multiply it with the REAL height of the font:
Code: Select all
lineheight = font:getLineHeight() * (Font:getAscent() + Font:getDescent())
This is the total height of a line of text, if you want to know the spacing just get the difference:
Code: Select all
spacing = lineheight - (Font:getAscent() + Font:getDescent())
If you then multiply the lineheight by the number of lines you get the height!!
Also you can use "rw" which is that other variable you can get from Font:getWrap, that is the real width, since your text may not cover the whole width of the element, you can use this to shrink your control automatically
NOTE: Remember to always leave some padding so that it looks right