lvgl / lv_font_conv

Converts TTF/WOFF fonts to compact bitmap format
https://lvgl.io/tools/fontconverter
MIT License
185 stars 79 forks source link

Codepoint delta out of range #62

Closed fvanroie closed 3 years ago

fvanroie commented 3 years ago

Goal

We're trying to create an lvgl font with material design icons instead of fontawesome. All MDI icons are in "Unicode Plane 15 Private Use, First" with glyph ids 0xF0000-0xF1743.

Font files:

Observation

Depending on the range of characters selected, the Error: Codepoint delta out of range is displayed. The same occurs in the online font converter as offline npm package.

Problem

It seems the problem lies with the cmap_split function that only takes the number of (consecutive) glyphs into account for sparse ranges and not the gap between the glyphs.

Workaround

If I place a small range of characters before the MDI icons, an extra index with format0_tiny is created. The MDI icons then start with their own sparse_tiny index and a starting_index of 0xF0045.

Examples

This works:

lv_font_conv --font RobotoCondensed-Regular.ttf -r 0x20-0x7F,0xB7-0xBF --font materialdesignicons-webfont.ttf -r 0xF0045,0xF004D,0xF0054 --size 12 --format bin --bpp 3 -o output.font

start 104 - end 106 - dist 54 sparse_tiny
start 95 - end 103 - dist 32 format0_tiny
start 0 - end 94 - dist 16 format0_tiny

This doesn't work:

lv_font_conv --font RobotoCondensed-Regular.ttf -r 0x20-0x7F,0xB8-0xBF --font materialdesignicons-webfont.ttf -r 0xF0045,0xF004D,0xF0054 --size 12 --format bin --bpp 3 -o output.font

start 95 - end 105 - dist 54 sparse_tiny
start 0 - end 94 - dist 16 format0_tiny
Error: Codepoint delta out of range
    at Cmap.collect_sparse_data (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:154:55)
    at Cmap.create_sparse_tiny_data (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:177:23)
    at Cmap.compile (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:61:33)
    at Cmap.toBin (/usr/local/lib/node_modules/lv_font_conv/lib/font/table_cmap.js:183:30)
    at Font.toBin (/usr/local/lib/node_modules/lv_font_conv/lib/font/font.js:118:17)
    at Object.write_images [as bin] (/usr/local/lib/node_modules/lv_font_conv/lib/writers/bin.js:15:25)
    at convert (/usr/local/lib/node_modules/lv_font_conv/lib/convert.js:25:35)
    at async Object.module.exports.run (/usr/local/lib/node_modules/lv_font_conv/lib/cli.js:300:15)

Conclusion

The 0xB7-0xBF or 0xB8-0xBF block determines wheter the conversion succeeds or fails.

It would be nice if the cmap_split function automatically adds an intermediate sparse list if the delta between glyphs is larger then 65535.

rlidwka commented 3 years ago

Fixed, thanks for reporting.

Check for gap size between sparse items was indeed missing. It should generate 2 small sparse lists now for this case.

puzrin commented 3 years ago

Released 1.5.1

fvanroie commented 3 years ago

thanks!

fvanroie commented 3 years ago

@embeddedt or @kisvegabor can the online converter be updated too please? It seems this issue is still present there.

kisvegabor commented 3 years ago

@puzrint I've updated npm a few weeks ago and now npm run build fails. I don't know if it's an error on my end or not. I've run npm update too.

For npm run build I got: image

Do you have any idea?

fvanroie commented 3 years ago

That error seems to be an issue with Parcel. type="module" should be added in the script tag. I don't know how the online tool integrates, so not sure if this helps...

puzrin commented 3 years ago
embeddedt commented 3 years ago

@kisvegabor I've just tried to build https://github.com/lvgl/lv_font_conv/commit/36ead11bd93085bdb149abfe6ccaba66e90bc8da and it seemed to work properly for me. NPM 7.17.0, Ubuntu 18.04, Node v14.15.5.

Parcel 1.x is supposed to be unmaintained so there shouldn't have been any breaking updates from their end.

kisvegabor commented 3 years ago

npm@7.21.0 Node.js v16.8.0 Linux Mint 19

It seems thre some problem on my end. If I check out 1.5.2 I got

> lv_font_conv@1.5.2 build
> parcel build ./web/index.html ./web/content.html --public-url ./

sh: 1: parcel: not found

Anyway, @embeddedt can you send the built files in order to update them as soon as possible.

puzrin commented 3 years ago

@kisvegabor when "shit happens" - drop node_modules folder and run npm i again.

kisvegabor commented 3 years ago

when "shit happens" - drop node_modules folder and run npm i again.

That's experience. :slightly_smiling_face: Working now, thank you!

The online converter is updated.

fvanroie commented 3 years ago

Thanks!