WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Unicode symbols in a string within quotes (https://www.wowinterface.com/forums/showthread.php?t=58079)

Clayent 07-06-20 06:01 AM

Unicode symbols in a string within quotes
 
Hi.
How can I put a unicode symbol in a string within quotes? For example, if I have this code in .lua:
['MAIN_TAB'] = "Some text and <unicode symbol of rightwards arrow>"
Then in game I will see this - "Some text and →".

I've found this article - https://stackoverflow.com/questions/...-symbol-in-lua
The solution is: "The UTF-8 encoding of a Unicode character can be inserted in a literal string with the escape sequence \u{XXX} (note the mandatory enclosing brackets), where XXX is a sequence of one or more hexadecimal digits representing the character code point."

I've tried this - ['MAIN_TAB'] = "Some text and \u{2192}" and this - ['MAIN_TAB'] = "Some text and \u2192".
And it is not helpful.

PS: rightwards arrow code is here - https://www.fileformat.info/info/uni...2192/index.htm

Rilgamon 07-06-20 07:03 AM

For the german special chars I use this notation

-- ö \195\182 ß \195\159
-- ü \195\188 ä \195\164
-- Ä \195\132
-- ö \195\182
-- Ü \195\156

Not sure how to translate it for your symbol. And I'm not even sure if the symbol is included in the game fonts.

Clayent 07-06-20 07:12 AM

Quote:

Originally Posted by Rilgamon (Post 336296)
And I'm not even sure if the symbol is included in the game fonts.

I forgot about this. Seems font Friz Quadrata TT doesn't have this symbol.

SDPhantom 07-06-20 04:11 PM

You can save Lua files in UTF-8. WoW will even ignore the BOM if you wish to add one, which is needed for most Unicode-capable IDEs to recognize that Unicode is being used.

Even though WoW will ignore the BOM in Lua files, this isn't standard feature of Lua. As such, I would avoid using Unicode symbols in function and variable names. However, Lua boasts that its strings are binary-safe, meaning you can put literally anything in them, even embeded null characters. How the host program (WoW in this case) reacts to them in their API functions is a different story.

In summary, UTF-8 symbols are fine in strings and WoW will read them as-is.

Clayent 07-07-20 03:23 AM

Quote:

Originally Posted by SDPhantom (Post 336298)
In summary, UTF-8 symbols are fine in strings and WoW will read them as-is.

In this case, could you please add this symbol "→" in any text of any addon and show me a code and an ingame screenshot with result?

sezz 07-07-20 02:48 PM

Quote:

Originally Posted by Clayent (Post 336300)
In this case, could you please add this symbol "→" in any text of any addon and show me a code and an ingame screenshot with result?

Not sure what you're using the symbol for, maybe something like this works for you (the problem is that you can't use multiple different fonts at once, so you have to split the text and and anchor the segments manually unless there's a widget I don't know of that that support that):



Lua Code:
  1. local f = CreateFrame("Frame", nil, UIParent);
  2. f:SetPoint("CENTER");
  3. f:SetSize(200, 100);
  4.  
  5. local fs1 = f:CreateFontString(nil, "OVERLAY");
  6. fs1:SetFont([[Fonts\FRIZQT__.TTF]], 12);
  7. fs1:SetPoint("LEFT");
  8. fs1:SetText("This arrow");
  9.  
  10. local fs2 = f:CreateFontString(nil, "OVERLAY");
  11. fs2:SetFont([[Fonts\ARKai_T.TTF]], 12);
  12. fs2:SetPoint("LEFT", fs1, "RIGHT");
  13. fs2:SetText(" → ");
  14.  
  15. local fs3 = f:CreateFontString();
  16. fs3:SetFont([[Fonts\FRIZQT__.TTF]], 12);
  17. fs3:SetPoint("LEFT", fs2, "RIGHT");
  18. fs3:SetText("points right.");

PS: You can also use https://icomoon.io/app/ to generate a font that only contains the symbols you need and use it in your addon.

Edit: Removed LibSharedMedia

Clayent 07-07-20 03:03 PM

sezz
Don't know how you did this. I use a standard font Friz Quadrata TT (or PT Sans Narrow, or any other) but no one has this symbol - when I paste "→" in chat or in any addon, then "?" shows.

sezz 07-10-20 07:49 PM

Quote:

Originally Posted by Clayent (Post 336302)
sezz
Don't know how you did this. I use a standard font Friz Quadrata TT (or PT Sans Narrow, or any other) but no one has this symbol - when I paste "→" in chat or in any addon, then "?" shows.

You can't see it in chat if your chat is not is using a font that includes that character.

Where exactly do you want your addon to show the arrow?


All times are GMT -6. The time now is 07:45 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI