Jump to content

Special Character Usage


Adam M

Recommended Posts

I have read up on the forum posts - and it sounds like other people have successfully gotten special characters to work, so I must be missing something. I went out and got this font (https://www.fontsquirrel.com/fonts/acme?filter[download]=local) which includes the special characters I want to use (° / ñ / é) and converted it to c using the uGFX font converted with anti-aliasing, and no filtering.  When I type the ° symbol and use gwinSetText() on a label the ° symbol actually shows up without issue - but I also get a Â character also appears just in front of the ° symbol. I have attempted the use of two distinct fonts that each have the special characters I need - when I used another font, named Alef - I also got the ° printed using that font, but a rogue ? showed up in front of the symbol. I was curious if anyone had any ideas as to why this is happening or suggestions on what I should try next?

Example:

snprintf(temp_temp, 8, "%d°F", left_target_temp);
gwinSetText(ghLeftCommandedTemp, temp_temp, TRUE);

 

Link to comment
Share on other sites

For others who might run into this...

I found that the issue had to do with how I formatting the string. When I changed the code to:

snprintf(temp_temp, 8, "%d%cF", left_target_temp, '°');
gwinSetText(ghLeftCommandedTemp, temp_temp, TRUE);

I was able to get only the ° character displayed.

Link to comment
Share on other sites

Yeah - to give some more information to the discussion - I later discovered that I was just lucky that I was getting a degree symbol (in that I was actually truncating the first character of the result). This 'hack' didn't work when I attempted to enter the spanish character I mentioned in my original post. When using the UTF-8 code \u00B0 I get some garbage (I'll comment back later with exact garbage) and if I use the exact ASCII code - I also get some garbage.

The editor I'm using is Sublime Text - if that helps. I've tried both typing the character and using the pure unicode '\u00B0' and get the same result, so I don't think the editor is to blame.

Link to comment
Share on other sites

@inmarket - Yeah, I have that enabled as:

#define GDISP_NEED_TEXT                              TRUE
#define GDISP_NEED_TEXT_UTF8                         TRUE
#define GDISP_NEED_ANTIALIAS                         TRUE
#define GDISP_NEED_PIXELREAD                         TRUE
#define GDISP_NEED_TEXT_KERNING                      TRUE
#define GDISP_INCLUDE_USER_FONTS                     TRUE

I'll try and grab the exact result of my various attempts to get these special characters to print sometime today.

Link to comment
Share on other sites

As a entry condition I ensured that UTF-8 encoding was enabled in my SublimeText instance:

"default_encoding" : "utf-8",

Here comes a list of things I tried and their results:

# Shows ° for the degree symbol
snprintf(temp_temp, 20, "%d°F", target_temp);
gwinSetText(temp_label, temp_temp, TRUE);

# Shows ° for the degree symbol
snprintf(temp_temp, 20, "%d\u00B0F", target_temp);
gwinSetText(temp_label, temp_temp, TRUE);

# Shows ° for the degree symbol
gwinSetText(temp_label, "°F", TRUE);

# Shows ° for the degree symbol
snprintf(temp_temp, 20, "%d%sF", target_temp, "°");
gwinSetText(temp_label, temp_temp, TRUE);

# Shows ° for the degree symbol
gdispDrawString(10, 10, "°", font1, Yellow);

# I then included the cyrillic font implementation from your cyrillic demo and tried to print the demo text.
# I got some "?"'s as well as 'not the characters' in the demo string.
font_t large_font = gdispOpenFont("Archangelsk Regular 12");
gdispDrawString(10, 10, "привет мир", large_font, Yellow);

 

A thought just occurred to me, perhaps I'm compiling uGFX incorrectly? I'm using this option set in my Makefile:

-c -ggdb -O0 -march=armv7 -mfpu=vfp -mfloat-abi=hard -fomit-frame-pointer \
-Wall -Wextra -Wstrict-prototypes -fverbose-asm -ffunction-sections \
-fdata-sections -fno-common -flto -MMD -MP

I haven't added dependency management yet - so the -MF that is added by default during "normal" compilation through your own makefiles isn't in use. Think that has anything to do with it?

Edited by Adam M
Link to comment
Share on other sites

Scratch that dependency comment - I added dependencies to our Makefile, and still got the same behavior - since I was running make clean / make each time I probably ended up with the same behavior to begin with. Still though, I could be compiling uGFX improperly (if you don't like the options I used). I copied the options used from a make run of uGFX through your own makefiles - so I assumed / assume they are right.

Link to comment
Share on other sites

Unlikely the compile will affect anything.

Try just outputting directly a string with Unicode characters in it without using snprintf.

If that doesn't work there can only be one of a few problems...

1. Utf8 support is not turned on

2. Your editor is not putting the Utf8 characters into the string correctly

3. Your compiler is stripping them out of the string or not encoding them correctly.

4. The font you are using doesn't map the particular characters used.

In your case I think 1 or 2 would be the problem as you are seeing 'extra' characters.

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