Determine the width of a character



  • How can I determine the width of a character from the freefonts? I tried: "M5. Lcd.width('W',myfont)
    This reported that width is not known.



  • I think there's a translation error here: I want to read the width of the characters. (Google translated :-))

    I can determine the size of the characters. With FreeFonts, not all characters are the same width. An "i" is narrower than an "M".
    Since I want to split my screen into two areas, the left part should not write in the right part. If I can read the width of the characters, I know when to start a new line.



  • @hansim

    in the this lib file , you can find the str width return function:

    https://github.com/m5stack/M5Stack/blob/master/src/utility/In_eSPI.h

      int16_t  textWidth(const char *string, uint8_t font),
               textWidth(const char *string),
               textWidth(const String& string, uint8_t font),
               textWidth(const String& string),
               fontHeight(int16_t font),
               fontHeight(void);