lvgl / lv_font_conv

Converts TTF/WOFF fonts to compact bitmap format
https://lvgl.io/tools/fontconverter
MIT License
178 stars 77 forks source link
c conveter font lvgl ttf woff

lv_font_conv - font convertor to compact bitmap format

CI NPM version

Converts TTF/WOFF/OTF fonts to __compact format__, suitable for small embedded systems. Main features are:

Install the script

node.js v14+ required.

Global install of the last version, execute as "lv_font_conv"

# install release from npm registry
npm i lv_font_conv -g
# install from github's repo, master branch
npm i lvgl/lv_font_conv -g

run via npx without install

# run from npm registry
npx lv_font_conv -h
# run from github master
npx github:lvgl/lv_font_conv -h

Note, running via npx may take some time until modules installed, be patient.

CLI params

Common:

Per font:

Additional debug options:

Examples

Merge english from Roboto Regular and icons from Font Awesome, and show debug info:

env DEBUG=* lv_font_conv --font Roboto-Regular.ttf -r 0x20-0x7F --font FontAwesome.ttf -r 0xFE00=>0x81 --size 16 --format bin --bpp 3 --no-compress -o output.font

Merge english & russian from Roboto Regular, and show debug info:

env DEBUG=* lv_font_conv --font Roboto-Regular.ttf -r 0x20-0x7F -r 0x401,0x410-0x44F,0x451 --size 16 --format bin --bpp 3 --no-compress -o output.font

Dump all Roboto glyphs to inspect icons and font details:

lv_font_conv --font Roboto-Regular.ttf -r 0x20-0x7F --size 16 --format dump --bpp 3 -o ./dump

Note. Option --no-compress exists temporary, to avoid confusion until LVGL adds compression support.

Technical notes

Supported output formats

  1. bin - universal binary format, as described in https://github.com/lvgl/lv_font_conv/tree/master/doc.
  2. lvgl - format for LVGL, C file. Has minor limitations and a bit bigger size, because C does not allow to effectively define relative offsets in data blocks.
  3. dump - create folder with each glyph in separate image, and other font data as json. Useful for debug.

Merged font metrics

When multiple fonts merged into one, sources can have different metrics. Result will follow principles below:

  1. No scaling. Glyphs will have exactly the same size, as intended by font authors.
  2. The same baseline.
  3. OS/2 metrics (sTypoAscender, sTypoDescender, sTypoLineGap) will be used from the first font in list.
  4. hhea metrics (ascender, descender), defined as max/min point of all font glyphs, are recalculated, according to new glyphs set.

Development

Current package includes WebAssembly build of FreeType with some helper functions. Everything is wrapped into Docker and requires zero knowledge about additional tools install. See package.json for additional commands. You may need those if decide to upgrade FreeType or update helpers.

This builds image with emscripten & freetype, usually should be done only once:

npm run build:dockerimage

This compiles helpers and creates WebAssembly files:

npm run build:freetype