Skip to main content
ferro
Lead
November 15, 2023
Solved

How to get number of glyphs in a font ?

  • November 15, 2023
  • 1 reply
  • 1599 views

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

This topic has been closed for replies.
Best answer by Mohammad MORADI ESFAHANIASL

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

1 reply

ST Employee
November 20, 2023

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 MORADIST Software Developer | TouchGFX
ferro
ferroAuthor
Lead
November 20, 2023

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).