Jump to content

Using unicode characters


Sting

Recommended Posts

my prototype application for ugfx is an electric brewery, so, I need the degree symbol.    I want to make a string like:  "Temperature: \u00B0 C"

Unicode escape characters in strings are only available in c99 standard so I add the -std=c99.

When I build I get the error:

/usr/local/arm/ugfx_2.5/src/gos/gos_linux.c:104:16: error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
  clock_gettime(CLOCK_MONOTONIC, &ts);

Is there another way to do this?
 

Link to comment
Share on other sites

The other way is to use byte escape sequences that match the utf8 version of the unicode character.

As for the undefined symbol when compiling c99 - that is a question to ask in linux forums as it is a linux defined symbol. I am surprised that changing the language standard would cause t h e symbol to be undefined in the standard linux headers.

 

Link to comment
Share on other sites

I write the value into an allocated buffer as follows:

    sprintf(gh2obj->celsius, "%d °C", t1);

the relevant defines in my config file are

#define GDISP_NEED_TEXT                                    TRUE
#define GDISP_NEED_TEXT_UTF8                         TRUE
#define GDISP_INCLUDE_FONT_UI2                       TRUE
 

I draw the string as

    gdispDrawString(gw->g.x + GTHERMO_CTEMP_XOFFSET, gw->g.y + GTHERMO_TEMP_YOFFSET, gw2obj->celsius, gw->g.font, Black);
 

and the string shows with that character blank => 120  C

Link to comment
Share on other sites

9 minutes ago, Sting said:

sprintf(gh2obj->celsius, "%d °C", t1);

We'd strongly recommend you using the snprintf provided by the GFILE module. This way you don't pull dependencies from your c standard lib and therefore your program stays as small as possible and your code is portable across any platform. More information can be found here: http://wiki.ugfx.org/index.php/GFILE#String_manipulation_.26_printing

 

32 minutes ago, Sting said:

#define GDISP_INCLUDE_FONT_UI2

Regarding the actual issue: You are using the UI2 font. This is a font that we designed ourselves to both look well at small resolutions and to take up as little memory as possible. Following the second goal, we kept the character set at a minimum. This means that the font only contains alphanumeric characters, numbers and some other special characters. Most likely the degree symbol is not part of the font. @inmarket might confirm this as he's the one who designed the font.
Also, the UI2 font isn't an unicode font. It wont help to enable unicode support there.
So to get a degree symbol on your display you have to use a font that actually contains the degree symbol.

Link to comment
Share on other sites

I changed to the font

#define GDISP_INCLUDE_FONT_DEJAVUSANS12_AA             TRUE

in main I set this font as the default with

    gwinSetDefaultFont(gdispOpenFont("DejaVuSans12_AA"));

and the string is written as => 120 ??C

I will use snprintf, i just picked sprintf because it's automatic.  Thanks for the reminder.
 

Link to comment
Share on other sites

Just now, Sting said:

and the string is written as => 120 ??C

the '??' are the "missing/unknown glyph" of the DejaVu font. It means that it doesn't know the glyph that it is supposed to render. The fonts that are built-in into the library have been encoded to be as small as possible. The filtering range most likely didn't cover the degree symbol, but it's just a guess.
I'd recommend you to pick any font you like and convert it yourself, choosing filter ranges appropriate to include the degree glyph. The documentation tells you how you can use custom fonts.

 

3 minutes ago, Sting said:

I will use snprintf, i just picked sprintf because it's automatic.  Thanks for the reminder.

Well, the actual recommendation is to use the snprintf() equivalent of the GFILE module (which is snprintg() if I remember correctly). This way you don't have to include the string.h file from your clib and your stuff stays small and portable.

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