Greetings,
I am looking for a way to swap letters within a font file.
Specifically i want that printing a space with love.graphics.print(" ") renders for example a dot like •.
I also need font:getWidth(" ") to return the size of said dot then.
From the wiki it looks like it is possible to extract glyphs from a font. But there is no obvious way to use that data let alone to arrange it back into a font.
Does someone here have experience with such a problem?
Editing a font from within Löve
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- BrotSagtMist
- Party member
- Posts: 613
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Editing a font from within Löve
No, but maybe you could monkey-patch the functions to substitute text before doing the action?
Like:
and so on with all functions you need replaced.
Like:
Code: Select all
local function replaceText(s)
return s:gsub(" ", "·")
end
local registry = debug.getregistry()
local print = love.graphics.print
local font_getWidth = registry.Font.getWidth
function love.graphics.print(s, ...)
return print(replaceText(s), ...)
end
function registry.Font.getWidth(s, ...)
return font_getWidth(replaceText(s), ...)
end
- BrotSagtMist
- Party member
- Posts: 613
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Editing a font from within Löve
That works fine for the exact scenario i gave as example i guess.
But there is more which makes this less ideal:
Print accepts a table with color information like {c1,"a b",c2,"c d"} which needs no stay working. The resulting replace logic needs to be a tad bigger.
It probably wont stay limited to just one char to be switched, so the replace must called several times.
font:getWidth may be needed a few dozen times per frame resulting in a lot of replaces.
Nothing impossible to do, but i am concerned about cpu usage with that method also the code would be a Pita to write.
Whereas switching the actual picture of a letter would solve that all in a fast elegant way. This is why i want to go that route.
But there is more which makes this less ideal:
Print accepts a table with color information like {c1,"a b",c2,"c d"} which needs no stay working. The resulting replace logic needs to be a tad bigger.
It probably wont stay limited to just one char to be switched, so the replace must called several times.
font:getWidth may be needed a few dozen times per frame resulting in a lot of replaces.
Nothing impossible to do, but i am concerned about cpu usage with that method also the code would be a Pita to write.
Whereas switching the actual picture of a letter would solve that all in a fast elegant way. This is why i want to go that route.
obey
Re: Editing a font from within Löve
If you use a bitmap font with fixed letter size (monospace maybe ?) it should be easier to edit the input bitmap to build the font, no ?
Re: Editing a font from within Löve
Alternatively you could use something like fontforge to put that dot in place of a space
- BrotSagtMist
- Party member
- Posts: 613
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Editing a font from within Löve
I am working on making a themable text box.
Relying on bitmap or edited fonts kinda defeats the purpose.
Relying on bitmap or edited fonts kinda defeats the purpose.
obey
Who is online
Users browsing this forum: No registered users and 215 guests