GFX HAT fonts

Hi, anyone know how to work out how to use the installed fonts?

For example, in /usr/local/lib/python3.9/dist-packages/gfxhat/fonts/ AmaticSC-Bold.ttf can be loaded using “font = ImageFont.truetype(fonts.AmaticSCBold, 38)”, but AmaticSC-Regular.ttf called as AmaticSCRegular throws a ‘no attribute’ error.

Re font sizes, you can load ‘Bitbuntu’ but how do we work out what pixel sizes are available? With AmaticSCBold, from trial and error 19 works but what is the formula for working out what is a valid pixel size?

Thanks

Hm, strange. In contrast to bitmap fonts the TTF fonts just scale, i.e. one ttf-file for all pixel sizes. So this must be a software problem in the ImageFont-code.

I’ve gotten this working now. I’m using FredokaOne which, as you say, seems to just scale. I can now see that with the .bdf fonts you just look for PIXEL_SIZE in the bdf file (and there is just one size). As for mapping the font file names to your code with, e.g. “font1 = ImageFont.truetype(fonts.FredokaOne, font1_size)” it’s just trial and error (but not sure why AmaticSC-Regular.ttf isn’t AmaticSCRegular, as with AmaticSCBold). I guess this is what it’s like with an obscure bit of kit. Fortunately, though, these days ChatGPT is very helpful with this stuff!

What I usually do: I use FontForge to create a BDF font from a TTF-font with the pixel size I need. Since I’m using this on a microcontroller, I also strip down the font to the actual characters I need. This saves a lot of flash-space and also the font loads faster and uses less RAM. On a Pi this is of course not relevant.