Max Size of TTF Font

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Max Size of TTF Font

      Hello,
      I am trying to use TTF Fonts for a new project where font sizes up to 300 pixels are required.
      I have written some test code to test the sizes where problems occur on large font sizes.
      At font size 140 everything seems to be ok. By using font size 150 the letters "M" or "m" disappears.
      Each step I am increasing font size, some more letters disappear. At font 180 only a few are available.

      I have played with cache size but the problem doesn't change. Maybe there is a max size where TTF Font works?

      I am using emWin v6.32b.

      Some threads with similar questions are:
      TTF FONT SIZE problem
      Issue displaying EmWin fonts with size large that 255
    • Hi Mali,

      The font size of a GUI_FONT is limited to 255 because the font height is stored in an unsigned char (8 bits).

      The same is true for fonts generated with the FreeType engine. However, FreeType only allows to request a given pixel size instead of setting a pixel size directly. It entirely depends on the metrics of the font which pixel size will be actually used. This behavior is explained in more detail in the FreeType documentation.

      I'm assuming that when you request a size of 140px, the height of some characters of your font already exceeds the 8 bit limit. Could you maybe share the TTF font you are using? I'd like to reproduce this to see what happens in the code.

      Thanks and best regards,
      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hi Florian,
      thank you for your reply.
      To reproduce the behaviour I have used emWin Simulation from segger.com/downloads/emwin/SeggerEval_WIN32_MSVC_MinGW_GUI
      Attached you can find modified files which should be copied to the project. (in addition to TTF-Files)

      As you say 255 is the max size of GUI_FONT, is there a possibility to draw a bigger one (eg to scale it)?

      BR
      Martin
      Files

      The post was edited 1 time, last by Mali ().

    • Hi Martin,

      Our TTF module uses FreeType's caching sub-system, which also uses 8bit variables to store height and width of character glyph bitmaps (see the struct members "height" and "width" of FTC_SBitRec).

      FreeType is able to render glyphs bigger than 255px without the cache system, just by using the normal FreeType API. Our TTF code also renders without a cache when the font is emboldened or obliqued.
      But again, because emWin's font structure limits the height to 255px, it's not possible to display bigger glyphs with emWin API functions. Because of the 8bit overflow, the clipping rectangle set by emWin won't be big enough for a font above 255px, therefore nothing will be displayed.

      You would have to work around this by rendering and displaying the glyphs manually. This means, rendering the glyphs without cache (as it is done in our TTF/BDF glue code) and displaying the glyph bitmaps, e.g. using GUI_AA__DrawCharAA8().

      Best regards,
      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Hi Florian,
      thank you for your answer.
      You wrote cache isn't used when the font is emboldened or obliqued. Surprisingly the font size can be higher (of course 255 is maximum) than with using the cache. If the TTF source code is manipulated so that the cache isn't used any more, the font size can get up to 255 like using emboldened or obliqued.

      So what is the fault behind using cache (see my example code from 4.10.23, could you reproduce the behaviour)?

      Is there a plan to increase possible font size in the near future, because more and more will get the same problem by using LCDs with more pixel depth in the future (in my case 4" TFT with 720x720 pixels)?

      Best regards,
      Martin