Inaccurate results from Font:getWidth()
Posted: Fri Nov 03, 2017 5:59 pm
I'm getting unexpected values from Font:getWidth() with some fonts. The reported width for a given string is too small. This code should draw an "A" and a red box that encloses it:
The result looks like this:
It happens only with some fonts, and not with all glyphs of a font. And it doesn't seem to be a problem with the glyph width, since the error remains constant even with longer strings:
Anyone know what causes this and how to fix it or work around it?
Code: Select all
local gfx = love.graphics
gfx.setNewFont("Power.ttf", 128)
function love.draw()
local test = "A"
gfx.setColor(255, 255, 255)
gfx.print(test, 10, 10)
gfx.setColor(255, 0, 0)
gfx.rectangle("line", 10.5, 10.5, gfx.getFont():getWidth(test), gfx.getFont():getHeight())
end
It happens only with some fonts, and not with all glyphs of a font. And it doesn't seem to be a problem with the glyph width, since the error remains constant even with longer strings:
Anyone know what causes this and how to fix it or work around it?