You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi Scott,

    That'd be great! Yes, the vector font is a bit of a pain - it was an attempt to balance flash memory usage with visual quality, but at the end of a day it was made with an algorithm and there wasn't as much effort put in as there could have been :)

    To add to this at one point in the past the font had quite a few more points in it, but then I had to make it lower resolution because on some platforms I was running out of flash memory.

    We could potentially create a new font with higher quality and use it on platforms that do have enough memory though.

    I guess you figured out that there's a built-in (small) bitmap font as well, and you can drag in other bitmap fonts if you need? http://www.espruino.com/Fonts

    The actual vector font is at:

    https://github.com/espruino/Espruino/blo­b/master/libs/graphics/vector_font.h

    and the rendering code is:

    https://github.com/espruino/Espruino/blo­b/master/libs/graphics/graphics.c#L416

    As far as I recall:

    • The data is in a .h file - there's no good reason for that :)
    • vectorFonts[ch - vectorFontOffset] contains the width and the number of vertices. We just iterate through summing the vertex count to get the actual offset in vectorFontPolys (rather than using a 16 bit index for each character)
    • vectorFontPolys contains the vertices as 7 bit unsigned X/Y pairs. It's just a series of regular polygons, and the top bit of 'Y' marks when one polygon ends
    • The actual font is only 96 high out of the 128 value range to allow for some overshoot - eg on W where the font is wider than it is high.
    • The font code is scattered with IN_FLASH_MEMORY and READ_FLASH_UINT8 defines - these are just for the ESP8266 as it hates reading unaligned data from flash memory.

    The code I used to generate it isn't shared as it relies on a whole bunch of code I had lying around from another project that may not be shareable. I could send it to you personally but it's obviously not doing such a good job, so it may be better to just start from scratch.

About

Avatar for Gordon @Gordon started