EMwin ttf font

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

    • EMwin ttf font


      This is my label create call back function. I am using ttf font create library.
      Mp problem is whenever label changed , again and again calling GUI_TTF_CreateFont(&Font, &Cs); function.
      it creates function every changed. So it will takes time.
      I want to create it at startup once.

      Source Code

      1. void _cbChildLabel(WM_MESSAGE * pMsg) {
      2. GUI_TTF_DATA TTF;
      3. GUI_TTF_CS Cs;
      4. GUI_FONT Font;
      5. char caption[15];
      6. GUI_BITMAP pImage_565;
      7. int id = pMsg->hWin;
      8. U8 * pData;
      9. int cSn = 0;
      10. switch (pMsg->MsgId) {
      11. case WM_PAINT:
      12. if( 1 )
      13. {
      14. GUI_SetColor(GUI_RED);
      15. TTF.NumBytes = sizeof(rawData_roboto);
      16. TTF.pData = rawData_roboto;
      17. Cs.FaceIndex = 0;
      18. Cs.pTTF = &TTF;
      19. Cs.PixelHeight = 12;
      20. // Create the font by pointing to a font struct and the CS struct
      21. //
      22. GUI_TTF_CreateFont(&Font, &Cs);
      23. //
      24. // Set the newly created font as the current font
      25. //
      26. GUI_SetFont(&Font);
      27. //#endif
      28. GUI_SetTextMode(GUI_TM_TRANS);
      29. GUI_DispStringAt((char *)"Test", 0, 0);
      30. GUI_TTF_DestroyCache();
      31. break;
      32. // case WM_PID_STATE_CHANGED:
      33. // break;
      34. default:
      35. WM_DefaultProc(pMsg);
      36. }
      37. }
      Display All
    • Hi,

      You should create the font only once, you could do this in the "case WM_CREATE" of the callback or in the MainTask after GUI_Init() has been called.

      But note that all the data needs to be static and has to stay valid the entire time the font is being used. To be more specific, the GUI_TTF_DATA, GUI_TTF_CS, GUI_FONT structure as well as the data pointer to the TTF file need to stay valid.

      Another thing is that you should only call GUI_TTF_DestroyCache() if you're absolutely sure that no TTF fonts at all are being used anymore. This function destroys the entire TrueType cache which is shared for all TTF fonts that were created during runtime.

      You can find an example on loading TTF fonts from memory in our wiki.

      Best regards,
      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.