cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Christoph
Level 8

Chinese RTFText in Scrollable Text Control

I have a custom dialog to summary the selections the user has made in the UI.

This dialog contains a Scrollable text control.

In this control, I want to display RTF text. This works fine for all languages except for Chinese(Traditional/Simplified).

This has probably something to do with my RTF Initialisation which should be modified when running on a Chinese OS but I don't know what to change.

My current initialization looks like this:

function void RTFInit(Rtf)
begin
Rtf->Indent = 0;
Rtf->Contents =
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033" +
"{\\colortbl;\\red0\\green0\\blue0;\\red128\\green128\\blue128;}" +
"{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}}" +
"\\viewkind4\\uc1\\pard\\f0\\fs18";
Rtf->InText = FALSE;
end;

I've already tried to modify the deflang1033 parameter into 'deflang2052' or 'deflang1028' but this doesn't work. My RTF text in the control isn't displayed correctly(see attached screenshot).

Does someone knows how that I need to modify the RTF initialisation string to display the text correctly on Chinese OS?
Labels (1)
0 Kudos
(3) Replies
MichaelU
Level 12 Flexeran
Level 12 Flexeran

I don't know much about RTF itself, but \ansicpg1252 looks like it's specifying the Western European codepage which will be unable to handle Chinese characters. Per a quick search on "2052 codepage" it looks like you might want to try 936 or 950 instead of 1252.
0 Kudos
Christoph
Level 8

MichaelU wrote:
I don't know much about RTF itself, but \ansicpg1252 looks like it's specifying the Western European codepage which will be unable to handle Chinese characters. Per a quick search on "2052 codepage" it looks like you might want to try 936 or 950 instead of 1252.


Michael,

I tried it already with the codepage nr. 936 but this still doesn't display the chinese RTF correctly.

I will need to take a furthur look into this...

Thanks for the information however.
0 Kudos
Christoph
Level 8

For those who are interested... I found the solution to this problem.
The initialisation of the RTF had nothing to do with the problem... this was correct.

The problem is to encode the decimal value of the (chinese) character into RTFCode. For chinese characters, the solution is Sprintf(Result, "\\u%d?", n) where n is the decimal value of the chinese character.

So a possible function could look like this:

function STRING RTFEncodeChar(ch)
INT n;
STRING Result;
begin
n = ch;
if (n < 0x020) then
switch (n)
case 0: Result = "";
case 9: Result = "\\tab ";
case 10: Result = "\\par ";
case 13: Result = "";
default: Sprintf(Result, "\\'%2lx", n);
endswitch;
elseif (n > 0x07f) && (n < 0x0ff) then
Sprintf(Result, "\\'%2lx", n);
elseif (n > 0x0ff) && (n < 0xffff) then
Sprintf(Result, "\\u%d?", n);
else
if ((ch == "\\") || (ch == "{") || (ch == "}")) then
Sprintf(Result, "\\'%2lx", n);
else
Result = " ";
Result[0] = ch;
endif;
endif;
return Result;
end;
0 Kudos