qiaogang chen wrote:
> OK, The idea to take UTF8 as future's main coding method is a good idea. But 
> now in china, 2 byte chinese character mix with 1 byte english character in 
> ANSI text is widly spreaded. A free editor software Notepad++ support this 
> mode.
> 
> As your wish, I provide the UTF8 chinese text in hex format as following:
> ef bb bf 20 20 31 20 e5 b9 bf e8 a5 bf e5 8c 97 e9 83 a8 e6 b9 be e6 b5 b7 e5 
> 9f 9f e6 b5 b7 e4 b8 8a e6 b2 bb e5 ae 89
> e5 9f ba e7 a1 80 e4 bf a1 e6 81 af e7 b3 bb e7 bb 9f 32 20 e7 ae a1 e7 90 86 
> 33 20 e7 ae a1 e7 90 86 e6 b8 af e5 8f a3
> e7 a0 81 e5 a4 b4 34 20 e7 ae a1 e7 90 86 e5 85 bb e6 ae 96 e5 9c ba 35 20 e7 
> ae a1 e7 90 86 e6 b8 94 e8 88 b9 36 20 e7
> ae a1 e7 90 86 e6 b8 94 e6 b0 91 37 20 e7 b3 bb e7 bb 9f 38 20 e5 b8 ae e5 8a 
> a9 39 20 e9 80 80 e5 87 ba ff
> 
> I save this text in a UTF8 text file, and read it into memory in my app,
> Then assign them to widget label and menu item. some of the text are
> display in mess.

        Does the following program display inconsistently?

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Menu_Bar.H>
#include <stdlib.h>

int main(int argc, char **argv)
{
    // Chinese utf8 text from Qiaogang Chen
    char *utf8str 
="\xef\xbb\xbf\x20\x20\x31\x20\xe5\xb9\xbf\xe8\xa5\xbf\xe5\x8c\x97\xe9\x83"
                   
"\xa8\xe6\xb9\xbe\xe6\xb5\xb7\xe5\x9f\x9f\xe6\xb5\xb7\xe4\xb8\x8a\xe6\xb2"
                   
"\xbb\xe5\xae\x89\xe5\x9f\xba\xe7\xa1\x80\xe4\xbf\xa1\xe6\x81\xaf\xe7\xb3"
                   
"\xbb\xe7\xbb\x9f\x32\x20\xe7\xae\xa1\xe7\x90\x86\x33\x20\xe7\xae\xa1\xe7"
                   
"\x90\x86\xe6\xb8\xaf\xe5\x8f\xa3\xe7\xa0\x81\xe5\xa4\xb4\x34\x20\xe7\xae"
                   
"\xa1\xe7\x90\x86\xe5\x85\xbb\xe6\xae\x96\xe5\x9c\xba\x35\x20\xe7\xae\xa1"
                   
"\xe7\x90\x86\xe6\xb8\x94\xe8\x88\xb9\x36\x20\xe7\xae\xa1\xe7\x90\x86\xe6"
                   
"\xb8\x94\xe6\xb0\x91\x37\x20\xe7\xb3\xbb\xe7\xbb\x9f\x38\x20\xe5\xb8\xae"
                   "\xe5\x8a\xa9\x39\x20\xe9\x80\x80\xe5\x87\xba\xff";
    printf("UTF8STR=<%s>\n", utf8str);

    // WINDOW
    Fl_Window *window = new Fl_Window(500,180,utf8str);

    // BOX
    {
      Fl_Box *box = new Fl_Box(FL_UP_BOX,20,40,500-40,100, utf8str);
      box->labelsize(24);
      box->labeltype(FL_SHADOW_LABEL);
    }

    // MENUBAR
    {
      Fl_Menu_Bar *bar = new Fl_Menu_Bar(0,0,500,25);
      char *menuname = (char*)malloc(strlen(utf8str) + strlen("File/") + 2);
      strcpy(menuname, "File/");
      strcat(menuname, utf8str);
      bar->add(menuname);
    }
    window->end();
    window->show(argc, argv);
    return Fl::run();
}


        If this too displays inconsistently, it might be something
        wrong in FLTK or with the font.

        If this displays *correctly*, then it could be your code.
        When loading UTF8 strings from a file, be sure:

                1) The file is being read in binary mode
                   (eg. under MS Windows, use "rb" instead of "r" with fopen())

                2) Be extra careful you NULL terminate the string after loading 
it.

                3) Be sure the string doesn't go out of scope (not getting 
de-allocated)
                   before Fl::run() takes control.

        Usually when something displays inconsistently, it's memory related..
        missing NULLs can cause random memory data to get appended to the string
        and thus overlay it, making a mess. Or strings that go out of scope
        can have the same effect.

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to