2023-11-15 06:15 AM
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
Solved! Go to Solution.
2023-11-20 05:35 AM
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
2023-11-20 05:35 AM
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
2023-11-20 07:11 AM
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:
The getNumberOfGlyphs () funtion will tell whether a font is installed (returning 0 if not).