ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Unicode symbol in textbox
Posted by medic89 on Jan-21-2022 23:26
Hello Peter,

I am desparately trying to display a unicode symbol (‣ = U+2023) in a textbox. Please see my code below, I already checked in word, that this symbol is available in Cambria Math. Unfortunately all I get is a question mark (in Cambria Math though).


TextBox* Kopfzeile6 = firstPage.addText(740, 303, "<*xoffset=40,yoffset=-12*>Zugang<*advance=90*>Abgang<*advance=90*>Bestandnnn<*advance=100*>in g, mg, ml oder Stücknnn<*advance=140*>Übertrag   <*font=Cambria Math,size=13,color=FF0000*>u2023", "Arial", 13, 1, RGB(0, 0, 0));

  Re: Unicode symbol in textbox
Posted by Peter Kwan on Jan-23-2022 00:35
Hi medic89.

Your text string is a C style string in the source code like "abcd". It is not a UCS2 unicode string (2 bytes per character). The C compiler will interpret the source code using the default code page of your system. There are several potential issues:

(a) Your current code page does not support the \u2023 character. In this case, the compiler finds that it is impossible to compile the text string into machine code. So it just puts a placeholder character (such as a ?) in the compile code.

(b) ChartDirector only supports the UTF8 code page, which is compatible with the ASCII code page. Even if your compiler can compile the \u2023 using your code page, ChartDirector may not understand your code page if it is not UTF8.

(c) Even though the "Cambria Math" exists, it may not contain the \u2023 character. I have checked the  "Cambria Math" in my Windows 10 computer, and it does not contain \u2023. (You can use the Windows Character Map to determine which characters it contains. See the attached image.) In this case, Windows may try to come up with an alternative font from its default font list. This may or may not be successful.

For your case, the suggested method is to use UCS2 text strings (wchar_t* in C++ syntax), and then converted it to UTF8. Windows has an API WideCharToMultiByte that can be used. ChartDirector also includes a utility WCHARtoUTF8 for that purpose. See:

https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte

https://www.advsofteng.com/doc/cdcpp.htm#WCHARtoUTF8.htm

An example is:

// Use unicode (UCS2/UTF16) text string
wchar_t *t = L"<*font=SomeFont,size=13,color=FF0000*>aaaa \u2023 bbbb";

// Convert from wchar_t* to char* in UTF8 encoding
c->addText(100, 100, WCHARtoUTF8(t), .....);

Hope this can help.

Regards
Peter Kwan

  Re: Unicode symbol in textbox
Posted by medic89 on Jan-23-2022 18:16
Hello Peter,

I changed the symbol to +25B6 which is included in Cambria Math with no luck, but then I jused the TCHARtoUTF8() function and now everything works fine!


TextBox* Fusszeile4 = firstPage.addText(903, BeginnZeilen, TCHARtoUTF8(L"<*xoffset=9,yoffset=-24*> Übertrag  <*font=Cambria Math,size=13*> u25B6"), "Arial", 13, 1, RGB(0, 0, 0));