I think that the main stream users don't want to learn/understand all those functions and only want to have this.
- Use a text string for example using the newText and set a font.
- And then the magic happens, now we can draw it on the screen and get the actual pixel drawing width and height.
In other words:
Code: Select all
textHeight = font:getGetPixelsThatAreDrawOnScreenHeight(text)
textWidth = font:getGetPixelsThatAreDrawOnScreenWidth(text)
textHeight = text:getGetPixelsThatAreDrawOnScreenHeight(text)
textWidth = text:getGetPixelsThatAreDrawOnScreenWidth(text)
Every time it cost me too much time to get the correct text width and height.
A snippet that I found in my old code.
Code: Select all
self.y + ((self.textObj.font.resource:getAscent() / 2) * self.scale) - (self.textObj:getHeight() / 2)
Today I create this simple test, without scaling and other things (that makes it more complex), that give me not what I expected.
Code: Select all
function love.load()
love.graphics.setDefaultFilter("nearest", "nearest")
love.graphics.setLineStyle("rough")
font = love.graphics.newFont("press-start-2p.ttf", 8)
font:setFilter("nearest", "nearest")
text = "Hello"
text2 = love.graphics.newText(font, text)
end
function love.update(dt)
end
function love.draw()
love.graphics.setFont(font)
font:getHeight(text) -- 8, but in photoshop it is 7px
font:getWidth(text) -- 40, but in photoshop it is 39px
font:getLineHeight() -- 1
font:getAscent() -- 8
font:getBaseline() -- 8
font:getDescent() -- 0
text2:getHeight() -- 8, but in photoshop it is 7px
text2:getWidth() -- 40, but in photoshop it is 39px
love.graphics.print(text, 60, 60)
love.graphics.draw(text2, 80, 20)
end
I did try the https://love2d.org/wiki/Rasterizer things, but that is overkill and more complex.
For the people like me, that just don't understand the complex font things, and only want 1 line to get the getPixelsOnScreenWidth() and getPixelsOnScreenHeight() would be cool.
Thanks