Jump to content

Accented characters not showing properly on Console widget


Joshua

Recommended Posts

Maybe there's a note about this somewhere, but when gwinPrintf-ing accented characters from my custom font to a console, they don't render correctly. gwinSetText works fine for labels.

So for example,

gwinSetText(ghLabel, "é", gFalse); // works
gwinPrintf(ghConsole, "é"); // doesn't work, prints "é"

Is there a way to make this work using the console widget?

Thanks

Link to comment
Share on other sites

Hmm. Without looking at the code, it looks like a utf8 encoding problem. The reason I have this suspicion is that for the label you are getting a single character output, for the console you are getting a two character output. I suspect that while the two strings look the same they are actually encoded differently.

Both the console and the label use the same underlying font routines so the only way they would give different output for the same input is if perhaps the console is printing byte by byte instead of character by character or string print.

Try putting the string into a variable and then using that variable to print both the label and the console. If you get the same result let me know and I will go digging.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 2 months later...
  • 2 months later...

Hi Joel, attached is the font converter output. It's the DejaVuSans font. I'm pretty sure I used the one that's included in the ugfx source. I converted it with anti aliasing and a custom range to include accented characters used in French and the degree symbol.

This same font is displaying accented characters fine in label widgets, but not in our console widget.

Thanks for looking into this.

DejaVuSans20_aa_c.c

Edited by Joshua
clarification
Link to comment
Share on other sites

I have had a decent look at this. Unfortunately it is not easy to fix. The issue is that gwinPrintf is processing the string byte by byte rather than utf8 character by utf8 character. This is completely consistent with the original C standard printf but definitely not what you need.

To get around this in the short term gsprintf it into a text buffer and then string print that. Note: even with this, %c will not work for utf8 extended chars but %s will.

I am currently deep in implementing generic rotation for text drawing for ugfx v3 so it will probably be a while before I can come back to solve this properly. 

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

The function might be called sprintg or something like that (I am off-computer presently so can't see the proper function name). It is the ugfx equivalent of sprintf. 

Note: sprintf from the c library won't work as it is also not utf8 aware at all.

Sprintg (the ugfx equivalent) may work when you use %s to include the character (obviously as part of a string). I don't expect it to work with %c or as part of the format string itself.

Note: this is a work around that should work but there are no guarantees. To be fixed properly this requires substantial changes to the printf engine in ugfx. The extra complexity is the whole reason very few sprintf implementations support it except on desktop systems like Windows or Linux.

 

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