Jump to content

mcufont text bounding box


pgeiem

Recommended Posts

Hi all,

I am using mcufont in one of my project and need to get the text bounding box (width and height of the text in a selected font).

I use attribute font->height to get height and function mf_get_string_width() to get text width.

I have an issue with mf_get_string_width() as the returned width seems to be always slightly too width. It's also seems to depend of the displayed text and the font. Do you know how to find the real text width ?

Thanks in advance for any help

PGE

Link to comment
Share on other sites

Whilst we are not the developers of MCU font, we should still be able to help you.

The function you mention is the correct one. What you are missing is that it also adds an inter - character gap which is font dependant. It could be that it is just an extra single gap but more likely your drawing routine is not taking into account the gap between characters thus leading to incorrect rendering and an error that appears to be string length dependent.

When implementing the gfxGetStringWidth() function for ugfx and the matching drawing implementation, the code needed to take account of this. The ugfx function should return the correct result.

In general you should use the ugfx functions rather than the base mcufont functions where ever possible if you are using ugfx. If not you will need to contact the author directly.

Link to comment
Share on other sites

Thanks for your answer.

I finally found the issue I had. As you say it's related to kerning. I am using a monospace font (created by your online converter) so I was expecting a fixed character width. This is correct only if the flag MF_FONT_FLAG_MONOSPACE is set on the font file. This was not the case in my font.

I have manually added this flag and everything work perfectly.

The question now is why the online converter don't set this flag with monospace font ? Do we have to add an extra parameter ?

PGE

Link to comment
Share on other sites

I would suspect the error is in the original font. A font with every character the same width is not the same as a monospace font because of kerning. If there is no kerning information in the original font then the two are equivalent.

That your font changed its display based on kerning information implies the original font had kerning information in it which a true monospace font should not have had.

Well done on finding the problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...