|
How can I use 2byte code characters in Chart Director? |
Posted by Cramade on Nov-13-2003 17:32 |
|
Hello!
I have a question about the Chart Director.
Is it possible to show 2byte code character(ex. japanese, korean) in Chart Director c++ version.
I make an effort to follow the method referred in this forum..
c->addTitle("2byte Character", "adaptable font");
But It do not work well...
Is there any solution to do more?
How can I use 2 byte code in your product? |
Re: How can I use 2byte code characters in Chart Director? |
Posted by Peter Kwan on Nov-13-2003 18:22 |
|
Hi Cramade,
To use any character in ChartDirector in C++, just enter the character in UTF8 encoding and use a font file that supports that character.
Personally, I do not know how to write Korean or Japanese, but I know Chinese. I have attached a sample code that can display Chinese. It is using the "mingliu.ttc" font.
If in your code, it does not work, please email your source code to me. I can check why it does not work.
Regards
Peter Kwan
|
Re: How can I use 2byte code characters in Chart Director? |
Posted by Cramade on Nov-14-2003 10:48 |
|
Hello...
I wrote your message well... but it does not work well.T.T
What's mean character in UTF8 encoding? I use Microsoft VIsual Studio .NET 2003 and complied both Multibyte Character set and Unicode Character set.
But neither do not work well...
I'll upload 2byte font at http://www.cramade.com/HMKMRHD.TTF
Please test this code c->addTitle("한글", "HMKMRHD.TTF"); |
Re: How can I use 2byte code characters in Chart Director? |
Posted by Peter Kwan on Nov-15-2003 02:46 |
|
Hi Cramade,
Thank you very much for your font file.
I just tried your code myself. It works normally in my case. Please see the attached code file and the chart that is produced.
If you are using Visual Studio.NET, to save the file using UTF8 encoding, do the followings:
Under the File Menu, select "Advanced Save Options". In the Encoding section, select "Unicode (UTF-8 without signature) - Codepage 65001".
Regards
Peter Kwan
|
Re: How can I use 2byte code characters in Chart Director? |
Posted by Cramade on Nov-15-2003 10:44 |
|
Thanks for your answer.. The way as you said it work well...
BUt I have another problem.
I use Chart Director in activex as lib.
So if I use 2byte code all HTML save as UTF-8 format.. but.. I think it's some problem..
So I used UTF-8 converting cord.
As like
BYTE* AsciiToUTF(CString strText)
{
int nLen = MultiByteToWideChar(CP_ACP, 0, strText, -1, 0, 0);
WCHAR* pWTitle = new WCHAR[nLen];
memset(pWTitle, 0, nLen*2);
MultiByteToWideChar(CP_ACP, 0, strText, -1, pWTitle, nLen);
BYTE* pBTitle = NULL;
nLen = WideCharToMultiByte(CP_ACP, 0, pWTitle, nLen, (char*)pBTitle, 0, NULL, NULL);
pBTitle = new BYTE[nLen];
memset(pBTitle , 0, nLen);
WideCharToMultiByte(CP_ACP, 0, pWTitle, -1, (char*)pBTitle, nLen, NULL, NULL);
return pBTitle;
}
But unfortunate it still has problem...
This code has any problem?
Thanks for your support... and forgive my poor English.T.T |
Find my mistake & Recompose my code |
Posted by Cramade on Nov-17-2003 10:40 |
|
LPSTR XChartCtrl2::AsciiToUTF(CString strText)
{
int nLen = MultiByteToWideChar(CP_ACP, 0, strText, -1, 0, 0);
LPWSTR pWTitle = new WCHAR[nLen+1];
pWTitle[nLen] = '\\0';
MultiByteToWideChar(CP_ACP, 0, strText, -1, pWTitle, nLen+sizeof(WCHAR));
nLen = WideCharToMultiByte(CP_UTF8, 0, pWTitle, nLen, 0, 0, NULL, NULL);
LPSTR pBTitle = new CHAR[nLen+1];
pBTitle[nLen] = '\\0';
WideCharToMultiByte(CP_UTF8, 0, pWTitle, -1, pBTitle, nLen+sizeof(CHAR), NULL, NULL);
return pBTitle;
}
Sample for the user who want display 2byte code character without save utf-8 foramt file..
I mistaked WideChartToMutliByte fuction's option. |
Re: Find my mistake & Recompose my code |
Posted by Peter Kwan on Nov-17-2003 16:19 |
|
Hi Cramade,
In your code, you translate the text from ANSI to 2-byte Unicode, then from 2-byte Unicode to UTF8.
However, are you sure your first step is correct - from ANSI to 2-byte Unicode? From your earlier email, it looks like your original text is not in ANSI, but is in some Korean code page.
From the Microsoft documentation on MultiByteToWideChar, you can specify any code page that is installed in your system. I suspect you should use a Korean code page instead of ANSI code page.
Also, I saw in your previous posting that you mention "HTML" in your code.
Note that HTML is executed on the browser side. So even your C++ code or compiler does not understand Korean, the system may still work, because your C++ code just pass the text to the browser byte by byte transparently. But for ChartDirector, the text string is handled on the server side, so your C++ code need to understand your text.
I suggest you may try the following methods:
(a) Instead of using the ANSI code page, use the correct code page to translate from Korean to Unicode. Note that even if you get it correct, your code will only work on a computer with the Korean code page installed.
(b) If your Korean text are string literals in your source code, may be you can consider to just entering them as 2-byte Unicode directly. You can enter 2-byte Unicode text strings in source code by add "L" in front of the string literal. For example:
wchar_t *unicodeText = L"<some_Korean_text>";
char *utf8Text = translatetoUTF8(unicodeText);
In this way, you do not need to translate from Korean to 2-byte Unicode. You just need to translate from 2-byte Unicode to UTF8. This also means you code can run on any computer (even computers without the Korean code page).
(3) You may just use UTF8 in the source code, and add an HTML header to tell the browser that you are using UTF8. Virtually all browsers support UTF8. In my opinion, this is the best options, because it works on all computers (not just Korean computers).
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
Regards
Peter Kwan |
|