Font properties are not working properly
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Font properties are not working properly
I am getting bad values for fontHeight, fontAscent and fontDescent (on multiple fonts)
Re: Font properties are not working properly
I think I'm seeing a similar thing.
The other day I d'ld a bunch of free fonts and wanted to see how they all might look at various sizes. So I started by simply printing them up, 4 at a time across the top of the screen (y=0). Most of them seemed just fine, but a few of the fonts were displayed as if y started at a negative value. Like a font scaled to 12 would be printed as if y=-6.
Is this a love2d issue, or is it some of those fonts (ttf) are somehow wonky. Just wondering...
The other day I d'ld a bunch of free fonts and wanted to see how they all might look at various sizes. So I started by simply printing them up, 4 at a time across the top of the screen (y=0). Most of them seemed just fine, but a few of the fonts were displayed as if y started at a negative value. Like a font scaled to 12 would be printed as if y=-6.
Is this a love2d issue, or is it some of those fonts (ttf) are somehow wonky. Just wondering...
Re: Font properties are not working properly
You can check its properties using FontForge or similar tool.
BTW, could you give a link to the one of such (incorrectly displayed) fonts?
BTW, could you give a link to the one of such (incorrectly displayed) fonts?
Re: Font properties are not working properly
I've no idea where I got them all from but the file I downloaded was named digital-7.zip.
Inside it contained:
digital-7 (italic).ttf Size:22924
digital-7 (mono).ttf Size:33992
digital-7.ttf Size:33976
readme.txt
No idea where Americorps came from cuz its been on my machine for ages.
Window size was set to 1024x768 for both window and full-screen modes. Consider everything else love2d related to be at default values. Running Love2d under WIN XP.
A simple code snippet from my experimenting:
The only text that showed up seemingly acceptable was the default love2d font. The 'digital' font was clipped off as if y was a negative number. The 'Americorps' font showed up as if Y was a positive number (Way too far down on the screen). And notice what happens with the filled rectangles. They Y values for both font and rectangle are equal, yet the font shows up offset for some reason. Seems to do that even with the love2d default font. Oddly enough, I can go back and tweak the Y values either + or - and compensate for the 'love.graphics.print' output.
So I have no idea what's up here if anything. Anyone got ideas or suggestions?
Maybe a screen shot will help?
Inside it contained:
digital-7 (italic).ttf Size:22924
digital-7 (mono).ttf Size:33992
digital-7.ttf Size:33976
readme.txt
No idea where Americorps came from cuz its been on my machine for ages.
Window size was set to 1024x768 for both window and full-screen modes. Consider everything else love2d related to be at default values. Running Love2d under WIN XP.
A simple code snippet from my experimenting:
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)
So I have no idea what's up here if anything. Anyone got ideas or suggestions?
Maybe a screen shot will help?
Re: Font properties are not working properly
I found that Digital-7 font on dafont.com.
I tried it out and I too get weird negative offsets with all 3 of the fonts.
As for Americorps, that I think is somewhat expected because the font has a fairly high specified ascent height compared to how high each character actually ascends, so that is how it should look. You may wish to write a custom font loading wrapper which can tweak these fonts automatically depending on offsets you can apply yourself.
I tried it out and I too get weird negative offsets with all 3 of the fonts.
As for Americorps, that I think is somewhat expected because the font has a fairly high specified ascent height compared to how high each character actually ascends, so that is how it should look. You may wish to write a custom font loading wrapper which can tweak these fonts automatically depending on offsets you can apply yourself.
Re: Font properties are not working properly
I've got text aligned to the top using this code:
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
Re: Font properties are not working properly
First off, I think I'm going to go off and research fonts. Clearly, I'm missing something here.
Oh well, guess I'm going to learn something whether I like it or not. Yup.
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:
Oh well, guess I'm going to learn something whether I like it or not. Yup.
Re: Font properties are not working properly
Problem with the font itself.
I've installed digital-7.ttf normally through font manager (in Xubuntu) and tried it in LibreOffice - letters are slightly shifted up and clipped.
EDIT: If this problem handled correctly in Windows / MS Office then it is freetype (or SDL_ttf or whatever LÖVE uses for fonts) library to blame, not LÖVE itself.
I've installed digital-7.ttf normally through font manager (in Xubuntu) and tried it in LibreOffice - letters are slightly shifted up and clipped.
EDIT: If this problem handled correctly in Windows / MS Office then it is freetype (or SDL_ttf or whatever LÖVE uses for fonts) library to blame, not LÖVE itself.
Who is online
Users browsing this forum: Bing [Bot] and 3 guests