2024-09-09 01:25 AM
Hi!
So I am doing a program that supports spanish as language, and in spanish we use the "tilde" which is just used sometimes to mark the accent of a word it looks like this: "Actualización", and when I put it in a wildcard it just shows the fallback character, even though I have put the ´áéíóú as wildcard characters.
Solved! Go to Solution.
2024-09-11 11:35 PM
Okay so the solution for me was the following,
I created the following function in my utils static class so that i can use it:
void Utils::Set_Text(const std::string &text, Unicode::UnicodeChar *buffer, size_t bufferSize)
{
Unicode::fromUTF8((const uint8_t *)text.c_str(), buffer, bufferSize);
Unicode::snprintf(buffer, bufferSize, "%s", buffer);
}
Now we just use Set_Text() as any other strncpy or snprintf and every (at least in spanish) special char will appear.
Have a nice day.
2024-09-09 03:14 AM - edited 2024-09-09 03:17 AM
Hello @Iñaki_Bidasoro ,
I also struggled with it at first but I found a solution.
In most ascii table I found online, ñ was 164, but on wikipedia, it is 241 : List_of_Unicode_characters#Latin_script
I just had to do :
char s[10] = {' '};
s[0] = char(241);
Unicode::snprintf(textArea1Buffer, 10, s);
textArea1.invalidate();
It is weird however that this
Unicode::snprintf(textArea1Buffer, 10, 'ñ");
textArea1.invalidate();
did not work.
You can also check this discussion : stm32cubeide-can-t-convert-touchgfx-wildcard-characters/td-p/183410
Tell me if that solution is enough for you.
Hope this helps.
If this comment solves your problem, I invite you to select it as "best answer".
Regards,
2024-09-09 03:46 AM - edited 2024-09-09 03:47 AM
It is true that this does work
char s[10] = {' '};
s[0] = char(241);
Unicode::snprintf(textArea1Buffer, 10, s);
textArea1.invalidate();
But what i want is to pass a string that contains any char used in the spanish keyboard and know that it will work, as we don't know what we maybe displaying in the future, I don´t know if I explain myself.
And in that solution I need to know what char is the one that we need to snpritf as char(whatever) and know it's postition right?
Also, if I add a e.g. the text Actualización to the touchgfx text database using the Designer it does work. So there must be a way.
2024-09-09 07:08 AM
"But what i want is to pass a string that contains any char used in the spanish keyboard and know that it will work, as we don't know what we maybe displaying in the future, I don´t know if I explain myself."
Yes, I understand. You want it to work for every character, at every position and for every textArea.
"And in that solution I need to know what char is the one that we need to snpritf as char(whatever) and know it's position right?"
You could simply us "replace" to replace all instances of 'ñ' by char 241 as such :
std::replace(s.begin(), s.end(), 'ñ', char(241));
But you would have to add that line before every instances where you want to update a wildcard that could contain a Spanish character.
Also, you would have to do that for all Spanish specific character (Ñ, ó, etc).
"Also, if I add a e.g. the text Actualización to the touchgfx text database using the Designer it does work. So there must be a way."
So you add it a text and then, during runtime use it into a wildcard?
I assume it should be possible, but I still don't understand why we have this behavior in the first place so it is hard to fix.
Regards,
2024-09-11 11:35 PM
Okay so the solution for me was the following,
I created the following function in my utils static class so that i can use it:
void Utils::Set_Text(const std::string &text, Unicode::UnicodeChar *buffer, size_t bufferSize)
{
Unicode::fromUTF8((const uint8_t *)text.c_str(), buffer, bufferSize);
Unicode::snprintf(buffer, bufferSize, "%s", buffer);
}
Now we just use Set_Text() as any other strncpy or snprintf and every (at least in spanish) special char will appear.
Have a nice day.
2024-09-12 01:15 AM
I am glad you found a solution!