Font properties are not working properly
Posted: Sat May 09, 2015 10:13 pm
I am getting bad values for fontHeight, fontAscent and fontDescent (on multiple fonts)
Code: Select all
local fonts = {
default10 = love.graphics.newFont(10),
default12 = love.graphics.newFont(12),
digital7 = love.graphics.newFont("/Res/digital-7.ttf", 24),
digital7m = love.graphics.newFont("/Res/digital-7m.ttf", 24),
digital7i = love.graphics.newFont("/Res/digital-7i.ttf", 48),
Americorps = love.graphics.newFont("/Res/Americorps.ttf", 48),
}
...
love.graphics.setFont(fonts.default12)
love.graphics.print("Love2d 12", 0, 0)
love.graphics.setFont(fonts.digital7)
love.graphics.print("digital7:", 128, 0)
love.graphics.setFont(fonts.digital7m)
love.graphics.print("Digital7m", 256, 0)
love.graphics.setFont(fonts.digital7i)
love.graphics.print("Digital7i", 400, 0)
love.graphics.setFont(fonts.Americorps)
love.graphics.print("Americorps", 600, 0)
-- Rectangles
love.graphics.setColor(64, 64, 64, 255)
love.graphics.rectangle( "fill", 450, 100, 224, 50 )
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(fonts.default10)
love.graphics.print("Love2d 10", 450, 100)
love.graphics.setColor(64, 64, 64, 255)
love.graphics.rectangle( "fill", 450, 200, 224, 50 )
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(fonts.default12)
love.graphics.print("Love2d 12", 450, 200)
love.graphics.setColor(64, 64, 64, 255)
love.graphics.rectangle( "fill", 450, 300, 224, 50 )
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(fonts.digital7m)
love.graphics.print("Digital7m", 450, 300)
love.graphics.setColor(64, 64, 64, 255)
love.graphics.rectangle( "fill", 450, 400, 224, 50 )
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(fonts.Americorps)
love.graphics.print("Americorps", 450, 400)
Code: Select all
function love.load()
font10 = love.graphics.newFont("digital-7.ttf", 10)
font24 = love.graphics.newFont("digital-7.ttf", 24)
font48 = love.graphics.newFont("digital-7.ttf", 48)
y10 = font10:getBaseline() - font10:getDescent()
y24 = font24:getBaseline() - font24:getDescent()
y48 = font48:getBaseline() - font48:getDescent()
end
function love.draw()
love.graphics.setFont(font10)
love.graphics.print("hello", 0, y10)
love.graphics.setFont(font24)
love.graphics.print("hello", 200, y24)
love.graphics.setFont(font48)
love.graphics.print("hello", 400, y48)
end
So why does it seem you're compensating for what 'love.graphics.newFont' should(?) probably do by default. Wait. What exactly DOES 'love.graphics.newFont' actually do? In most of my font usage, I'd expect the font to print precisely where I tell it to assuming top left is 0,0. I wouldn't expect some extra code and/or variables need to be created to achieve this.I've got text aligned to the top using this code: