tuupola / hagl

Hardware Agnostic Graphics Library for embedded
https://www.appelsiini.net/tags/hagl/
MIT License
303 stars 49 forks source link

Generating new fonts #51

Open ronangaillard opened 3 years ago

ronangaillard commented 3 years ago

Hi,

Thanks for your helpful project !

How do you generate new fontx fonts in c code to be used with your library ?

Thanks, Ronan

tuupola commented 3 years ago

I first convert BDF fonts to FONTX and then use xxd to create the header files. I quickly hacked the conversion tools from code I found online and some blogposts. All that code is needs to be cleaned up when I have time.

https://github.com/tuupola/fontx_tools https://linux.die.net/man/1/xxd

I also converted some public domain fonts to FONTX format using these tools. You could check the Makefile to see all the conversion steps.

https://github.com/tuupola/embedded-fonts/blob/master/Makefile https://github.com/tuupola/embedded-fonts/tree/master/X11 https://github.com/tuupola/embedded-fonts/tree/master/misc/viznut

tuupola commented 3 years ago

Also I have not tried it myself but @allenck has a FONTX editor for Windows.

https://github.com/allenck/FontXEdit

ronangaillard commented 3 years ago

Thanks for your quick and detailed answer ! :)

ronangaillard commented 2 years ago

For future reference :

I convert otf fonts to bdf with otf2bdf :

otf2bdf -p 24 -o roboto.bdf RobotoMono-Regular.otf

You can also select a subset using the l option. For instance to select only digits :

otf2bdf -p 24 -l '48_57' -o roboto.bdf RobotoMono-Regular.otf

I then use fontxedit on a Windows XP VM to convert the generated bdf font to a FONTX one.

EDIT : easier solution is to use bdf2fontx to convert bdf to fontx format :

cat roboto.bdf | bdf2fontx > roboto.fnt

I then use bin2header to convert the generated FONTX font to a .h header :

bin2header roboto.fnt
tuupola commented 2 years ago

Thanks! I will try this myself too.

vbenso commented 10 months ago

Hello, I'm having some fun with hagl in the past days. I've followed the above instructions to generate some fonts, and got some results. I've noticed some vertical misalignment that is probably coming from bdf2fontx. image This doesn't happen when using the 6x9 font that is already in hagl source, only in my generated fonts. Fonts were generated from RobotoMono-Regular.ttf by the fontx tools from the fix-fonts branch, since I would get a malloc failure when using tools from master.

What am I doing wrong?

Thanks for any help