Jump to content

Font problem when compiling for Linux-SDL with chars above 0x7f


AndyD

Recommended Posts

I'm finding that any character that I try to display above 0x7f is producing the fallback character (this works ok for an STM32 Discovery board). I wonder if the routine in mf_font.c (mf_render_character) needs a call to MFCHAR2UINT16, as there is in mf_character_width in the same file?

i.e. width = font->render_character(font, x0, y0, MFCHAR2UINT16(character), callback, state);

Thanks,

Andy

Link to comment
Share on other sites

Hello Andy,

This is most likely just a case of using the proper font.  You tell us which font you're using but I assume you're using one of the built-in fonts. These built-in fonts have a very restricted set of glyphs (characters) in them. Each glyph takes up memory, every glyph that is in your font that you don't use is therefore a waste of memory. When I remember correctly the built-in fonts are only including characters from A to Z (both upper and lower case) as well as the numbers and the most common symbols (punctuation marks).

You can take any font that you like (the built-in ones are DejaVu Sans) and set the filter range when converting it to include all the glyphs that you need.
Note that the online font converter only allows setting one filter range. You can use the offline font encoder that you can find in the /tools directory of the µGFX library directory to convert your font using any number of any arbitrary filter ranges. This means that you can simply cherry-pick single glyphs or whole ranges.

I hope that helps. Please don't hesitate to ask if you have any further questions.

Link to comment
Share on other sites

Hi Joel,

No, this is a custom font generated from a bdf and we need to use some of the more "interesting" characters. As I said, with the Discovery board the display of characters above 0x7f works fine. I've made the suggested change in mf_font.c and then the linux display also works :-)

Thanks,

Andy

Link to comment
Share on other sites

When uGFX does not have GDISP_NEED_UTF8 set to TRUE it operates in ASCII mode.

This is therefore a problem with the definition of ASCII. Officially ASCII is characters ' ' (space) to '~' (tilde). For any characters outside that range ( > 0x7E or < 0x20) the operation is officially undefined.

Although this is undefined, the characters above 0x7F work on your Discovery board because the compiler uses unsigned chars and we don't explicitly filter illegal characters. It doesn't work on Linux as that compiler uses signed chars. As you also found, the current operation was also inconsistent between drawing and width routines.

Despite the formal ASCII definition, I agree that it is reasonable and more useful to expect that the full character range 1 to 255 works when in non-UTF8 mode.

I have therefore made the change that you suggested and uploaded it to the repository.

 

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