StyledText not accept Multi-bytes characters

John Reimer terminal.node at gmail.com
Mon Aug 18 21:25:21 PDT 2008


Frank Benoit wrote:

> yidabu schrieb:
>> program crashed when StyledText.text encounter multi-bytes characters,
>> e.g. Chinese.
>> 
>> code below causes EXCEPTION_ACCESS_VIOLATION :
>> Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at ntdll.dll
>> (0x7c90316c) thread(1260) ->us
>> #0 ?? () from ntdll.dll
>> 
>> Code:
>> 
>> import dwt.DWT;
>> import dwt.custom.StyledText;
>> import dwt.custom.StyleRange;
>> import dwt.layout.FillLayout;
>> import dwt.widgets.Display;
>> import dwt.widgets.Shell;
>> import dwt.widgets.Listener;
>> import dwt.widgets.Event;
>> import dwt.graphics.Color;
>> import dwt.graphics.Point;
>> 
>> import dwt.dwthelper.utils;
>> 
>> void main() {
>>     static String SEARCH_STRING = "box";
>>     Display display = new Display();
>>     Color RED = display.getSystemColor(DWT.COLOR_RED);
>>     Shell shell = new Shell(display);
>>     shell.setBounds(10,10,250,250);
>>     StyledText text = new StyledText(shell, DWT.NONE);
>>     text.setBounds(10,10,200,200);
>>     text.setText("StyledText not accept Chinese 中国? ");
>>     shell.open();
>>     while (!shell.isDisposed()) {
>>         if (!display.readAndDispatch()) display.sleep();
>>     }
>>     display.dispose();
>> }
>> 
>> 
>> 
>> 
> 
> 
> Yes, there is indeed trouble with it. StyledText uses
> dwt.graphics.TextLayout which implements all this and is the troublemaker.
> Especially on windows the ported code is not working correctly.
> This is because of dwt uses utf8 storage but the windows api uses utf16.
> This make the calculation of indices very hard.
> It is on my TODO list since a while now :/


So what does this mean?  Can't the utf8 text just be upconverted to utf16
using something like tango.text.convert.Utf.toString16 before the system
function is called? 

I'd be interested to see the problem fully described so that I understand
what to look out for while porting code.  Is the information somewhere on
our site?  I recall you mentioning the issue in IRC recently.

Thanks.

-JJR


More information about the Digitalmars-d-dwt mailing list