🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Cahnge Font Size in Python

    Micropython
    6
    22
    89.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RopR
      Rop @loboris
      last edited by

      @loboris While you are working on this, could you also make it an output option to create the .h files needed to use the font with Adafruit's gfx library? (See here for details.) Is there any way for me to help?

      loborisL 1 Reply Last reply Reply Quote 0
      • loborisL
        loboris @Rop
        last edited by

        @rop 在 Cahnge Font Size in Python 中说:

        @loboris While you are working on this, could you also make it an output option to create the .h files needed to use the font with Adafruit's gfx library? (See here for details.) Is there any way for me to help?

        Maybe, if you can provide the exact and detailed description of the format.

        RopR 1 Reply Last reply Reply Quote 0
        • RopR
          Rop @loboris
          last edited by

          @loboris Not sure what server you would be running this on. If linux or other unix it should be relatively easy. As per the link I sent earlier:

          Adding New Fonts
          If you want to create new font sizes not included with the library, or adapt entirely new fonts, we have a command-line tool (in the fontconvert folder) for this. It should work on many Linux- or UNIX-like systems (Raspberry Pi, Mac OS X, maybe Cygwin for Windows, among others).
          Building this tool requires the gcc compiler and FreeType library. Most Linux distributions include both by default. For others, you may need to install developer tools and download and build FreeType from the source. Then edit the Makefile to match your setup before invoking make.
          fontconvert expects at least two arguments: a font filename (such as a scalable TrueType vector font) and a size, in points (72 points = 1 inch; the code presumes a screen resolution similar to the Adafruit 2.8" TFT displays). The output should be redirected to a .h file…you can call this whatever you like but I try to be somewhat descriptive:

          ./fontconvert myfont.ttf 12 > myfont12pt7b.h
          
          1 Reply Last reply Reply Quote 0
          • loborisL
            loboris
            last edited by loboris

            I have finished the font converter (written in Python) for the font format used in this MicroPython port and it works wery well.
            I'm working on the web interface now, the online converter will be available soon on my server, after some more testing.
            It will also be available as a standalone Python program (should work on any OS).

            Some features:

            • Converting any ttf font to C source file which can be compiled with tft.font_compile() or included into the build to be compiled into the firmware is supported

            • Converting directly to binary fon file which can be used with tft.font() is also supported

            • Convert full ascii character set (32 - 127) or only the selected characters

            • Adding characters from cp1252 and cp1250 code pages is supported (more code pages will be probably added later).
              Including characters like Ä, €, ß, Č, Đ, ž, ø, µ, ° is now supported
              I'll try to add support for non-Latin character sets like Cyrillic, Hebrew, Arabic, Chinese, later.

            • Font sizes from 8 to 110 pixels are supported

            At the moment I don't have enough free time to support conversion to any other format.

            D 1 Reply Last reply Reply Quote 0
            • D
              devros @loboris
              last edited by

              @loboris
              thanks :) can test it when its ready ...

              1 Reply Last reply Reply Quote 0
              • lukasmaximusL
                lukasmaximus
                last edited by

                Awesome can we share this or do you want to keep the testing to a small number of people?

                loborisL 1 Reply Last reply Reply Quote 0
                • loborisL
                  loboris @lukasmaximus
                  last edited by

                  @lukasmaximus 在 Cahnge Font Size in Python 中说:

                  Awesome can we share this or do you want to keep the testing to a small number of people?

                  It should be ready for use, by "testing" I've meant I would like to get some information if any issue is detected or any improvement is wanted.
                  I've already found a small "bug", if hebrew characters are included the wrong C file is generated (caused by right to left writting), the bynary fon file is OK.

                  1 Reply Last reply Reply Quote 0
                  • world101W
                    world101
                    last edited by

                    Super old thread, but I'm curious if @loboris's tool still works to convert fonts (ttf or otf) to be used with the m5stack, since the firmware moved to use the mainline MicroPython code base.

                    I used the tool and created a font (name is Flighter20) and copied it to /flash. When I try to load it, the m5stack crashes.

                    >>> 
                    >>> 
                    MicroPython c24d12861-dirty on 2020-08-06; M5Stack with ESP32
                    Type "help()" for more information.
                    >>> os.listdir()
                    ['Flighter20.c', 'Flighter20.fon', 'apps', 'blocks', 'boot.py', 'emojiImg', 'img', 'main.py', 'res', 'temp.py', 'test.py']
                    >>> lcd.font("Flighter20")
                    Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
                    Core 1 register dump:
                    PC      : 0x4010a2f5  PS      : 0x00060f30  A0      : 0x80116f3d  A1      : 0x3ffcea40  
                    A2      : 0x00000001  A3      : 0x3f81b150  A4      : 0x3ffceaf0  A5      : 0x00000008  
                    A6      : 0x3ffceaa0  A7      : 0x00000000  A8      : 0x3ffbdbec  A9      : 0x3ffbdbec  
                    A10     : 0x00000000  A11     : 0x00000000  A12     : 0x80096333  A13     : 0x3ffce950  
                    A14     : 0x00000003  A15     : 0x00060023  SAR     : 0x00000020  EXCCAUSE: 0x0000001c  
                    EXCVADDR: 0x00000000  LBEG    : 0x40095234  LEND    : 0x4009523f  LCOUNT  : 0x00000000  
                    
                    ELF file SHA256: 0000000000000000000000000000000000000000000000000000000000000000
                    
                    Backtrace: 0x4010a2f5:0x3ffcea40 0x40116f3a:0x3ffcea60 0x400e3be1:0x3ffceaf0 0x400df959:0x3ffceb20 0x400dfa8d:0x3ffceb40 0x400ed9b3:0x3ffceb60 0x400e3cb0:0x3ffcec00 0x400df959:0x3ffcec70 0x400df982:0x3ffcec90 0x4011c6a7:0x3ffcecb0 0x4011c8c1:0x3ffced40 0x400f6f1c:0x3ffced80 0x4009613a:0x3ffcedb0
                    
                    Rebooting...
                    ets Jun  8 2016 00:22:57
                    
                    rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
                    configsip: 0, SPIWP:0xee
                    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
                    mode:DIO, clock div:1
                    load:0x3fff0018,len:4
                    load:0x3fff001c,len:5116
                    load:0x40078000,len:11608
                    load:0x40080400,len:6176
                    entry 0x400806c0
                    

                    Is there any way to load custom fonts to the m5stack now?

                    1 Reply Last reply Reply Quote 0
                    • lukasmaximusL
                      lukasmaximus
                      last edited by

                      I have a vague recollection that the command lcd.compileFont() was required, I could be wrong though, it's a long time since I experimented with adding fonts

                      1 Reply Last reply Reply Quote 0
                      • world101W
                        world101
                        last edited by

                        The compileFont command quickly returns True, which seems to me that it’s not doing anything when I run it.

                        His online font conversion tool still works to create the custom font (.fon) files, but they only seem to work on his lobo branch of MicroPython, not the standard uiFlow version of MP. It’s just crashes when I try to load the font and the lobo build does not crash when I do the import. Bummer!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post