nopnop2002 / esp-idf-st7789

ST7789 Driver for esp-idf
MIT License
234 stars 56 forks source link

About create font #43

Open nguyentrungg opened 2 weeks ago

nguyentrungg commented 2 weeks ago

Hi. Thank you for creating a perfect library. I want to ask you how to create file .FNT from .ttf file example: concielian.ttf. Thank you so much.

nopnop2002 commented 2 weeks ago

TTF fonts are scalable fonts.

FNT fonts are bitmap fonts.

Searching for this keyword brings up several hits, but I have never tried it.

convert scalable fonts to bitmap font
nopnop2002 commented 2 weeks ago

Using TTF font

step1)
convert TTF fonts to BDF fonts.
You can use otf2bdf to convert TTF font files to BDF format.
Only monospaced TTF fonts can be used. You can download free fonts from here.

There may be other TTF to BDF conversion tools that I haven't found yet.

sudo apt install otf2bdf
# 16 dot font
otf2bdf -p 16 CamingoCode-Regular.ttf > CamingoCode16.BDF
# 24 dot font
otf2bdf -p 24 CamingoCode-Regular.ttf > CamingoCode24.BDF
# 32 dot font
otf2bdf -p 32 CamingoCode-Regular.ttf > CamingoCode32.BDF

step2)
convert BDF fonts to FONTX fonts.
You can use fontedit.exe to convert BDF format to FONTX format.

Please follow the README from this point on.

    InitFontx(fx16M,"/spiffs/CamingoCode16.FNT",""); // 8x16Dot
    InitFontx(fx24M,"/spiffs/CamingoCode24.FNT",""); // 12x24Dot
    InitFontx(fx32M,"/spiffs/CamingoCode32.FNT",""); // 16x32Dot

NewFont