cancel
Showing results for 
Search instead for 
Did you mean: 

How to get number of glyphs in a font ?

ferro
Senior III

Hi,

How to get number of glyphs in a font ?

numGlyphs variable is not accsesible in GeneratedFont (linked with application) neither in BinaryFont (installed from .bin). Or is it ?

// from GeneratedFont.hpp

namespace touchgfx
{
class GeneratedFont : public ConstFont
{
public:
    GeneratedFont(const GlyphNode* glyphs, uint16_t numGlyphs, uint16_t height, ... );
...
}

class BinaryFont : public GeneratedFont
{
}

 

Thanks, Ferro

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @ferro ,

You can add a function to ConstFont.hpp file that returns the number of glyphs for you. For instance, add this function in the public section of the class definition:

uint16_t getNumberOfGlyphs() const { return listSize; }

then you can easily use it wherever you want. Like:

    const ConstFont* fn = (const ConstFont*)(textArea1.getTypedText().getFont());
    uint16_t numberOfGlyphs = fn->getNumberOfGlyphs();
    touchgfx_printf("%d\n",numberOfGlyphs);

I hope this helps you, good luck

Mohammad MORADI
ST Software Developer | TouchGFX

View solution in original post

2 REPLIES 2

Hello @ferro ,

You can add a function to ConstFont.hpp file that returns the number of glyphs for you. For instance, add this function in the public section of the class definition:

uint16_t getNumberOfGlyphs() const { return listSize; }

then you can easily use it wherever you want. Like:

    const ConstFont* fn = (const ConstFont*)(textArea1.getTypedText().getFont());
    uint16_t numberOfGlyphs = fn->getNumberOfGlyphs();
    touchgfx_printf("%d\n",numberOfGlyphs);

I hope this helps you, good luck

Mohammad MORADI
ST Software Developer | TouchGFX

Hi @Mohammad MORADI ESFAHANIASL ,

Thanks for the suggestion. I thought about that but wanted to confirm I do not miss some part of library where this parameter is accessible via user API as the GFX library implementation might change in the future. Maybe a candidate for API with next release.

This is related to my other question:

https://community.st.com/t5/stm32-mcus-touch-gfx-and-gui/how-to-check-in-application-whether-binary-font-needs-to-be/m-p/610203#M35279

The getNumberOfGlyphs () funtion will tell whether a font is installed (returning 0 if not).