• Hi,

    Try the code below. The font gets created within the parent window of a button. The font data and the handle to the file needs to be valid as long as the button uses the font. Therefore the variables are declared static.

    On delete of the window (which does not occur in this example) the button gets also deleted (automatically). At this point the font is not used anymore and can be deleted, too. Although, the window never gets deleted in this example it should show how to make sure a font stays valid as long as it is used.


    Regards,
    Sven

    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: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Hi,

    CreateFile() is a function provided by the Win32-API. It is used in the above example so it can be run in the emWin simulation on Windows.

    If you want to use an XBF font from external memory, your target needs a file system. You can then adapt the sample by replacing the Win32-functions by the equal functions provided by the target file system you are going to use.

    You can find an example in the SEGGER Wiki that demonstrates how external XBF fonts can be used in emWin, demonstrated via both the Windows and the emFile system.

    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: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Florian,

    I have tried that example but for some reason it doesn't work on widgets.
    Is there a way to set this external Font as default font or this function has to be called every time a new screen is drawn?

    Best regards,
    BMD

  • Hi,

    since a regular GUI_FONT is created from the XBF-file, the font can be used at any point where a font can be set, including widgets.

    Though it is crucial the pointers to GUI_FONT and GUI_XBF_DATA stay valid and the file is kept open while using the font. This is because, every time the font is redrawn (like when a widget uses it), the pixel data of the font is read from the file.

    When the font is not needed anymore (e.g. when the widget is deleted), GUI_XBF_DeleteFont() can be called and the file can be closed.

    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: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • HI Florian,

    Appreciate all your help. So I tried the following code but I don't see anything on the display whatsoever. Could you please tell me where I am possibly going wrong?
    Thank you for all your help.

    Best regards,
    BMD

  • Hi,

    I noticed a few things:

    1. You must not comment out the super-loop in your main-task when using the Window Manager. This will only work when only using GUI_... functions in the MainTask. Otherwise emWin isn't kept alive and no more routines will be called after the MainTask finished.
    2. You also have to initialize emFile and mount the external volume.

    Once again, have a closer look at the XBF font sample, the file is read exactly the same way.

    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: https://www.segger.com/ticket/

    Or you can contact us via e-mail.

  • Florian,

    Thank you for looking into it. Really appreciate it.

    But I am initializing emWin and emFile in another file before calling Maintask().
    I have tried the XBF font sample. That works perfectly fine. But now I am trying to incorporate it into widgets and that doesn't seem to work at all whatsoever.

    Best regards,
    BMD

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!