Page 1 of 1

Font density

Posted: Thu Nov 30, 2017 4:18 am
by TC1061
How to increase density of a Font?
I tried this:

Code: Select all

Font=love.graphics.newFont("somefont.ttf",24)
Font:setLineHeight(0.5)
But text become bigger. How to increase density of the Font but save the text size?

Re: Font density

Posted: Thu Nov 30, 2017 5:31 am
by Sir_Silver
When you say change the font density do you mean increase/decrease the space between each character in a string of text?

There are no methods of a font object for handling that from what I can tell, I think the only solution is to use a different font with the density that you desire.

Here's the Font page wiki if you want to check out the functions https://love2d.org/wiki/Font

Re: Font density

Posted: Thu Nov 30, 2017 6:16 am
by ivan
I'll assume this topic is about "letter spacing".
You see, most fonts are designed to look well at a predefined spacing.
Some fonts contain kerning info that adjusts the positions of specific pairs of letters.
All you need to do is start FontForge and open up the font that you want to massacre... I mean edit!
...then press Ctrl-A to select all glyphs and choose Metrics->Set Width.
But yea, as you may have guessed, what you end up with will look awful.

Re: Font density

Posted: Thu Nov 30, 2017 9:14 am
by SirRanjid
You could cut the string and put each letter into an array. Then iterate the draw over each letter and add a custom spacing.
Could be sufficient for a spaced out title line. Don't know how much perf-loss it actually is over the build in version so a löve based ebook reader could be damn slow if not optimized well.

Re: Font density

Posted: Thu Nov 30, 2017 11:23 am
by TC1061
ivan wrote: Thu Nov 30, 2017 6:16 am I'll assume this topic is about "letter spacing".
You see, most fonts are designed to look well at a predefined spacing.
Some fonts contain kerning info that adjusts the positions of specific pairs of letters.
All you need to do is start FontForge and open up the font that you want to massacre... I mean edit!
...then press Ctrl-A to select all glyphs and choose Metrics->Set Width.
But yea, as you may have guessed, what you end up with will look awful.
This topic is NOT about "letter spacing"! How to fix pixelated font effect when the font is .ttf?
fixpixel.png
fixpixel.png (131.17 KiB) Viewed 5931 times
fonts.png
fonts.png (27.09 KiB) Viewed 5928 times
You didn't help me. I'll try super bad solution: I'll replace original love.graphics text functions.

Re: Font density

Posted: Thu Nov 30, 2017 12:31 pm
by ivan
Hey TC, we all tried to help you but your question was not stated clearly.
The problem is with the way you are loading the font:
Font=love.graphics.newFont("somefont.ttf",24)
tells Love2d that your font should be rasterized so that it's exactly 24 pixels high.
The easiest solution is to load multiple font sizes:
SmallFont=love.graphics.newFont("somefont.ttf",24)
LargeFont=love.graphics.newFont("somefont.ttf",48)
Or load just the largest font and then scale it down when drawing.
Never scale up your fonts UP or you will get pixelation.

Re: Font density

Posted: Thu Nov 30, 2017 2:17 pm
by TC1061
ivan wrote: Thu Nov 30, 2017 12:31 pm Hey TC, we all tried to help you but your question was not stated clearly.
The problem is with the way you are loading the font:
Font=love.graphics.newFont("somefont.ttf",24)
tells Love2d that your font should be rasterized so that it's exactly 24 pixels high.
The easiest solution is to load multiple font sizes:
SmallFont=love.graphics.newFont("somefont.ttf",24)
LargeFont=love.graphics.newFont("somefont.ttf",48)
Or load just the largest font and then scale it down when drawing.
Never scale up your fonts UP or you will get pixelation.
Function love.graphics.newFont by default makes font rasterized with 12 pixel high.

Re: Font density

Posted: Thu Nov 30, 2017 2:26 pm
by grump
TC1061 wrote: Thu Nov 30, 2017 2:17 pm Function love.graphics.newFont by default makes font rasterized with 12 pixel high.
You can just put the size you want, as ivan has shown you.

Re: Font density

Posted: Fri Dec 01, 2017 5:04 pm
by TC1061
grump wrote: Thu Nov 30, 2017 2:26 pm
TC1061 wrote: Thu Nov 30, 2017 2:17 pm Function love.graphics.newFont by default makes font rasterized with 12 pixel high.
You can just put the size you want, as ivan has shown you.
Oh. Yes. This variant is helped me, and I replaced text functions (because my game's code is very big and I'll waste a lot of time in search of them), and it really works without any bugs:

Code: Select all

do
  core=core or {}
  fontsizes={}
  local crf=love.graphics.newFont
  function love.graphics.newFont(f,s)
    local size=s or f
    local font=crf(f,s)
    fontsizes[font]=size
    return font
  end
  local font=love.graphics.newFont(12)
  local text=love.graphics.newText(font)
  function love.graphics.setFont(font2)
    font=font2
    text:setFont(font)
  end
  local size=12
--  local fsize=12
  local function getScale()
    local scale=size/fontsizes[font]
    return scale
  end
  function core.setTextSize(size2)
    size=size2 end
  function love.graphics.print(texts,x,y,r,sx,sy,...)
    local scale=getScale()
    text:set(texts)
    local sx=sx or 1
    local sy=sy or sx
    love.graphics.draw(text,x,y,r,sx*scale,sy*scale,...)
  end
  function love.graphics.printf(texts,x,y,limit,align,r,sx,sy,...)
    local scale=getScale()
    local sx=sx or 1
    local sy=sy or sx
    text:setf(texts,(limit or love.graphics.getWidth())/scale,align or "left")
    love.graphics.draw(text,x,y,0,sx*scale,sy*scale,...)
  end
end