TTF FONT issue?

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

    • TTF FONT issue?

      Hi,

      Use GUI_TTF_CreateFontAA to create 6 different font sizes. The initial display of the window is normal. After the WM_PAINT, the display is abnormal. Is this a bug?


      Please clarify. Thanks a lots
      Images
      • WM_INIT_DIALOG.png

        954.98 kB, 1,440×1,080, viewed 26 times
      • WM_PAINT.png

        880.6 kB, 1,440×1,080, viewed 38 times
    • Hi,
      Create a font of one size and display it as normal. Exception when creating multiple sizes.
      example code, Please review.

      //Ëmwin ver 5.32 or 5.44 same issue

      #include "MainTask.h"
      #include "includes.h"

      GUI_TTF_CS Cs0, Cs1, Cs2, Cs3, Cs4, Cs5;
      GUI_TTF_DATA Data;
      GUI_FONT Font16, Font24, Font32, Font48, Font72, Font120;

      static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      { FRAMEWIN_CreateIndirect, "TEST", 0, 0, 0, 800, 600,0, 0},
      { TEXT_CreateIndirect, "GUI_Font16B_ASCII is ok.", GUI_ID_TEXT0, 0, 100, 800, 16, 0,0},
      { TEXT_CreateIndirect, "TTF24 The width of the space is abnormal.", GUI_ID_TEXT1, 0, 116, 800, 24, 0,0},
      { TEXT_CreateIndirect, "TTF32 The width of the space is abnormal.", GUI_ID_TEXT2, 0, 140, 800, 32, 0,0},
      { TEXT_CreateIndirect, "TTF48 The width of the space is abnormal.", GUI_ID_TEXT3, 0, 172, 800, 48, 0,0},
      { TEXT_CreateIndirect, "TTF72 The width of the space is abnormal.", GUI_ID_TEXT4, 0, 220, 800, 72, 0,0},
      { TEXT_CreateIndirect, "TTF120 The width of the space is abnormal.", GUI_ID_TEXT5, 0, 292, 800, 120, 0,0},
      };

      void PaintDialog(WM_MESSAGE * pMsg)
      {
      // int X=0;
      // WM_HWIN hWin = pMsg->hWin;
      // GUI_SetFont(&Font16);
      // X=GUI_GetCharDistX(0x20);
      // TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT0), "Abnormal display after WM_PAINT");
      // GUI_SetFont(&Font24);
      // X=GUI_GetCharDistX(0x20);
      // TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT1), "Abnormal display after WM_PAINT");
      // GUI_SetFont(&Font32);
      // X=GUI_GetCharDistX(0x20);
      // TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT2), "Abnormal display after WM_PAINT");
      // GUI_SetFont(&Font32);
      // X=GUI_GetCharDistX(0x20);
      // TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT3), "Abnormal display after WM_PAINT");
      // GUI_SetFont(&Font32);
      // X=GUI_GetCharDistX(0x20);
      // TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT4), "Abnormal display after WM_PAINT");
      // GUI_SetFont(&Font32);
      // X=GUI_GetCharDistX(0x20);
      // TEXT_SetText(WM_GetDialogItem(hWin,GUI_ID_TEXT5), "Abnormal display after WM_PAINT");
      }

      void InitDialog(WM_MESSAGE * pMsg)
      {
      WM_HWIN hWin = pMsg->hWin;
      FRAMEWIN_SetFont(hWin,&Font32);
      FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER);
      FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
      FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
      FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
      FRAMEWIN_SetTitleHeight(hWin,35);
      TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT0), GUI_BLACK);
      TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT1), GUI_BLUE);
      TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT2), GUI_ORANGE);
      TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT3), GUI_MAGENTA);
      TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT4), GUI_BLUE);
      TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT5), GUI_RED);

      TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT0), &GUI_Font16B_ASCII);
      TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT1), &Font24);
      TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT2), &Font32);
      TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT3), &Font48);
      TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT4), &Font72);
      TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT5), &Font120);
      }

      static void _cbCallback(WM_MESSAGE * pMsg)
      {
      int NCode, Id;
      WM_HWIN hWin = pMsg->hWin;
      switch (pMsg->MsgId)
      {
      case WM_PAINT:
      PaintDialog(pMsg);
      break;

      case WM_INIT_DIALOG:
      InitDialog(pMsg);
      break;
      default:
      WM_DefaultProc(pMsg);
      }
      }

      void LoadFontTTF(const char *sFilename)
      {
      U8 *_acBuffer;
      GUI_HMEM hMem;
      result = f_open(&file, sFilename, FA_OPEN_EXISTING | FA_READ | FA_OPEN_ALWAYS); //FatFS
      if (result != FR_OK)
      {
      return;
      }
      hMem = GUI_ALLOC_AllocZero(file.fsize);
      _acBuffer = GUI_ALLOC_h2p(hMem);

      result = f_read(&file, _acBuffer, file.fsize, &bw);
      if (result != FR_OK)
      {
      return;
      }

      Data.pData = _acBuffer;
      Data.NumBytes = file.fsize;
      Cs0.pTTF = &Data;
      Cs0.PixelHeight = 16;
      Cs0.FaceIndex = 0;
      Cs1.pTTF = &Data;
      Cs1.PixelHeight = 24;
      Cs1.FaceIndex = 0;
      Cs2.pTTF = &Data;
      Cs2.PixelHeight = 32;
      Cs2.FaceIndex = 0;
      Cs3.pTTF = &Data;
      Cs3.PixelHeight = 48;
      Cs3.FaceIndex = 0;
      Cs4.pTTF = &Data;
      Cs4.PixelHeight = 72;
      Cs4.FaceIndex = 0;
      Cs5.pTTF = &Data;
      Cs5.PixelHeight = 120;
      Cs5.FaceIndex = 0;
      GUI_TTF_CreateFontAA(&Font16, &Cs0);
      GUI_TTF_CreateFontAA(&Font24, &Cs1);
      GUI_TTF_CreateFontAA(&Font32, &Cs2);
      GUI_TTF_CreateFontAA(&Font48, &Cs3);
      GUI_TTF_CreateFontAA(&Font72, &Cs4);
      GUI_TTF_CreateFontAA(&Font120, &Cs5);
      f_close(&file);
      }

      void MainTask(void)
      {
      uint16_t i;
      char cDispBuf[80];
      GUI_Init();
      WM_MULTIBUF_Enable(1);
      GUI_SetBkColor(GUI_BLUE);
      GUI_Clear();
      GUI_SetFont(GUI_FONT_20_1);

      GUI_DispStringAt("1. Please make sure the song.ttf is saved in SD", 0, 0);
      GUI_DispStringAt("2. if the song.ttf is not saved in SD, this lab will fail", 0, 24);
      GUI_DispStringAt("Loading song.ttf file from sdcard, please wait....", 0, 72);
      GUI_UC_SetEncodeUTF8();
      LoadFontTTF("song.ttf");
      WM_SetDesktopColor(GUI_BLUE);
      GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
      while(1)
      {
      GUI_Delay(10);
      }
      }

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

    • Hi,

      I gave it a try but on my end seems to be ok.

      I tested with both, V5.44 and the most recent one V5.50b.

      Attached are some screenshots. Unfortunately, I don't have the same font, so I can not say if this is related to the font. I used Noto Sans Bold.

      Regards,
      Sven
      Images
      • Image0.png

        36.86 kB, 800×600, viewed 9 times
      • Image1.png

        45.26 kB, 800×600, viewed 8 times
    • Hi,

      Look at your picture, like the simulator used. The simulator is normal, the microcontroller display is abnormal.

      Using other fonts also has the same problem.

      Attach a font file.

      thanks a lots.
      Images
      • 1.jpg

        76.98 kB, 1,440×1,080, viewed 10 times
      • 2.jpg

        68.25 kB, 1,440×1,080, viewed 10 times
      Files
      • Open24.zip

        (7.92 kB, downloaded 9 times, last: )