Convert BDF font to LVGL v6.0 format

Description

I’m trying to convert some old monochrome, pixel perfect BDF fonts in LVGL-handled format (version 6.0), which is proving way harder than I thought it would be. From this issue I understand BDF direct support was dropped from 6.0, so I need to find an alternative way to move from BDF to TTF/WOFF.

What MCU/Processor/Board and compiler are you using?

SDL emulator

What do you want to achieve?

Include a BDF font into LVGL.

What have you tried so far?

I tried to convert the BDF file to TTF using Fontforge but the resulting TTF is empty (the online converter accepts it but all characters are empty when displayed).

What I’m asking is more of a suggestion than an LVGL direct question. Given a BDF font, how should I proceed to have it included in my project?

I’m attaching the font for reference.hsw_8x16.bdf.zip (3.5 KB)

The simplest solution is to find a pixel-perfect TTF font that looks similar enough and just use that. It’s not straightforward to convert from BDF to TTF.

This apparently works with 6.0, but I’ve never needed a pixel-perfect font besides the built-in one.

Yeah, I see it now too. Unfortunately one of my colleagues is extremely fond of those fonts and won’t settle for anything else.

I was beginning to fear I would have had to redraw them from scratch as TTF when I realized I can just create a custom font engine with get_glyph_dsc and get_glyph_bitmap callbacks from lv_font_t.
The library we were using before LVGL required a very simple C array format, so it’s pretty easy to adapt LVGL fonts to that.

1 Like

I’ve had some success using FontForge on Linux to import bitmap fonts, convert the glyphs to outlines and export as TrueType (the “Generate Fonts…” command in the File menu does this) and then feed those into the node.js font conversion tool. I also found that many pixel perfect outline fonts needed to have their metrics adjusted to reduce the character spacing, esp. for small fonts for use on low-DPI monochrome OLEDs, which FontForge is also very handy for.

1 Like