python-tcod icon indicating copy to clipboard operation
python-tcod copied to clipboard

Better options for TrueType Fonts.

Open jsbeckr opened this issue 5 years ago • 3 comments

Hey! :)

I was playing around with TrueType fonts (OpenSans, Courier New, Fira Code) on MacOS. And it seems that the font is rendered to small in comparison to the tile size.

image

tcod.tileset.set_truetype_font("data/OpenSans-Regular.ttf", 24, 24)

Is it possible to control the size of the font inside a tile?

There is also an issue with Fira Code (it doesn't render correctly). But I think that might be the custom glyphs they included in the font?

jsbeckr avatar May 13 '19 22:05 jsbeckr

As far I've gotten the best option is to exclude the width (use a width of 0) of the font, then the font loader will automatically pick the width with the best fit. If you pick both a width and height then the font will be scaled down to fit without stretching it. The best results will come from fonts designed to be used as monospace fonts.

There's no options for fine tuning the font size, but now is a good time to make suggestions.

HexDecimal avatar May 13 '19 22:05 HexDecimal

I guess if I could wish for an API I would like the following:

tcod.tileset.set_truetype_font("data/OpenSans-Regular.ttf", 24, 24, font_size=16, antialiasing=True)

It would be cool to set an anchor point for the tiles where the bounding box of the font sits. Something like upper_left, bottom_right, etc. Which could enable nice effects like distinguishing small and big items for example?

jsbeckr avatar May 14 '19 17:05 jsbeckr

A new example using FreeType to generate a tileset can be found here.

This example builds the font from Python so it's easier to modify. It's recommended to use ttf.py if the tileset generated by tcod.tileset.set_truetype_font is too small or narrow.

tcod.tileset.set_truetype_font

tcod.tileset.set_truetype_font

ttf.py / FreeType screenshot

ttf.py screenshot

HexDecimal avatar Apr 06 '21 06:04 HexDecimal