Skip to main content
ferro
Lead
February 13, 2024
Question

What tool can show font properties that class touchgfx::Font provides

  • February 13, 2024
  • 2 replies
  • 1213 views

Hi,

Gfx::Font class returns many font properties e.g. Font::getBaseline (), Font::getPixelsAboveTop () etc.
https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_font

Is there a tool that can show all these properties ? With FontForge somehow ?

Thanks
Ferro

This topic has been closed for replies.

2 replies

ST Employee
February 16, 2024

Hello @ferro ,

There's no tool since the font is compiled into a ".cpp" file, but you can see what values has been pass in "touchgfx/generated/fonts/src/Table_<typography>.cpp" for each properties : 

 

 

And the "GeneratedFont" constructor is :

 

I hope that answers your question,
Regards

ferro
ferroAuthor
Lead
February 22, 2024

Hi @LouisB ,

Thanks for the GeneratedFont reference.

Do you think, that some of these font properties (or at least font height based on user selected size) could be shown in Gfx Designer dynamically, before running font code generator ?

Reason I am asking is realisation that, even though I set the same 'Text:Typography:font size' for 2 fonts (which sets font's baseline), the font heights differ - font_1.getHeight () is 25px and font_2.getHeight () is 26px.

ferro_0-1708602470803.png

font_1;  size(or baseline) 20px, height 25px

 

touchgfx::GeneratedFont& getFont_verdana_20_4bpp()
{
 static touchgfx::GeneratedFont verdana_20_4bpp
	(
		glyphs_verdana_20_4bpp, * @param glyphs 
		512, * @param numGlyphs 
		25, * @param height 
		20, * @param baseline 
		0, * @param pixAboveTop 
		...
	);
 return verdana_20_4bpp;
}

 

 

font_2;  size(or baseline) 20px, height 26px

 

touchgfx::GeneratedFont& getFont_NotoSC_20_4bpp()
{
 static touchgfx::GeneratedFont NotoSC_20_4bpp
	(
		glyphs_NotoSC_20_4bpp, * @param glyphs 
		375, * @param numGlyphs 
		26, * @param height 
		20, * @param baseline 
		2, * @param pixAboveTop 
		...
	);
 return NotoSC_20_4bpp;
}

 

 

Therefore, the font's height would be a valuable information while setting font size/baseline. Before running font code generator and having to check laboriously resulting "touchgfx/generated/fonts/src/Table_<typography>.cpp". Something like this:

ferro_1-1708603411289.png

What do you think ?

Ferro

ST Employee
February 27, 2024

Hi @ferro ,
I'm reposting one of the answer that solves your issue but was delete since it was mark as a spam

#include "touchgfx/Font.hpp"

void fontProperties()
{
// Using the Font class to get font properties
// For example:
// Baseline of the font
int baseline = Font::getBaseline();

// Pixels above the top of the font
int pixelsAboveTop = Font::getPixelsAboveTop();

// You can explore more font properties using the Font class

// For detailed information on the Font class and its properties,
// refer to the TouchGFX documentation:
// https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_font

}