brilliantlabsAR / monocle-micropython

Micropython ported to the Monocle
ISC License
215 stars 27 forks source link

UTF-8 support for font-renedering using the sprites API #260

Closed josuah closed 1 year ago

josuah commented 1 year ago

There will be a host-side fontgen.py script to generate a packed font file, to upload as either a file on the filesystem, either built into the firmware.

There will be a device-side font.py to render a font out of that font data onto a canvas, and use that canvas to send it to the FPGA.

josuah commented 1 year ago

This is only the font generation, along with a script for plotting it as text, but this means both sides of the implementation currently work:

$ wget http://unifoundry.com/pub/unifont/unifont-15.0.06/font-builds/unifont-15.0.06.bdf.gz
$ gunzip unifont-15.0.06.bdf.gz
$ python3 fontgen unifont-15.0.06.bdf unifont-15.0.06.bin
$ python3 fontdraw.py unifont-15.0.06.bin  "八つ橋"
八
        #     |
    #   #     |
    #   #     |
    #   #     |
    #   #     |
    #   #     |
    #    #    |
   #     #    |
   #     #    |
   #      #   |
  #       #   |
  #        #  |
 #         #  |
 #          # |
#            #|
つ
     #####  |
#  ##     # |
 ##        #|
           #|
           #|
           #|
          # |
        ##  |
     ###    |
橋
   #       ##  |
   #   ####    |
   #     #     |
   #  #########|
######  #   #  |
   #   # ### # |
  ##  #  # #  #|
  ###    ###   |
 # # #         |
 # # # ####### |
#  #   #     # |
   #   # ### # |
   #   # # # # |
   #   # ### # |
   #   #     # |
   #   #    ## |
$
josuah commented 1 year ago

This format has an index that can be read in Python array, and can tell where to find the data in the rest of the file. As opposed to a full memory-mapped bitmap like http://unifoundry.com/pub/unifont/unifont-15.0.01/unifont-15.0.01.bmp, this permits: