Font density

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
TC1061
Prole
Posts: 32
Joined: Sat Oct 14, 2017 3:50 pm

Font density

Post 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?
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Font density

Post 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
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Font density

Post 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.
User avatar
SirRanjid
Prole
Posts: 39
Joined: Sun Nov 19, 2017 1:44 pm
Contact:

Re: Font density

Post 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.
User avatar
TC1061
Prole
Posts: 32
Joined: Sat Oct 14, 2017 3:50 pm

Re: Font density

Post 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 5882 times
fonts.png
fonts.png (27.09 KiB) Viewed 5879 times
You didn't help me. I'll try super bad solution: I'll replace original love.graphics text functions.
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Font density

Post 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.
User avatar
TC1061
Prole
Posts: 32
Joined: Sat Oct 14, 2017 3:50 pm

Re: Font density

Post 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.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Font density

Post 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.
User avatar
TC1061
Prole
Posts: 32
Joined: Sat Oct 14, 2017 3:50 pm

Re: Font density

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests