I am trying to display unicode from Code Page 437
http://en.wikipedia.org/wiki/Code_page_437
My gnome terminal supports this. But jcurses can't display it properly.
Test case:
String test = "String is ~████████████~ blah blah"; jcurses.system.Toolkit.printString(test, 2, 2, test.length(), 1, new jcurses.system.CharColor( jcurses.system.CharColor.BLACK, jcurses.system.CharColor.WHITE, jcurses.system.CharColor.BOLD ) );
Output:
String is ~M~~M~~M~~M~~M~~M~~M~~M~V
Expected output:
String is ~████████████~ blah blah
So the issue here is that wide character support is not enabled.
Here is a diff with a partial suggested fix. I'll also add the diff and source as an attachment if I can.
This still has some issues though. As soon as the TextComponent loses focus, the characters go back to being displayed incorrectly. It is not until the area regains focus and a scroll operation takes place that the wide characters are again displayed correctly.
Someone more familiar with the framework might have an idea of why that is more quickly than me digging around for it.
Also the ./configure and build portion is not working for me on Ubuntu 13 (Doesn't find java)
For this fix, need to use the following compiler switches and include / link ncursesw for curses with wide support.
gcc -fPIC -Wall -shared -I/usr/lib/jvm/java-6-openjdk-amd64/include -I/usr/include/ncursesw -o lib/libjcurses.so src/native/Toolkit.c -lncursesw
diff -w src/native/Toolkit.c.orig src/native/Toolkit.c
0a1
> #define _XOPEN_SOURCE_EXTENDED 1
2c3
< #include <curses.h>
---
> #include <ncurses.h>
343a345,360
> // fprintf(logStream, "Byte array len %d\n", length);
>
> // Create a null terminated copy of the byte array
> // I.e. an actual C style string.
> unsigned char copy = malloc( sizeof(copy) * (length+1) );
> snprintf(copy, length+1, "%s", charArray);
>
> // fprintf(logStream, "String len %d\n", strlen(copy));
>
> // Determine converted length of of the wide character string
> int cLen = mbstowcs(NULL, copy, 0) + 1;
>
> // fprintf(logStream, "Converted string len %d\n", cLen);
>
> wchar_t wCharArray = malloc( sizeof(wchar_t) * (cLen+1) );
> mbstowcs(wCharArray, copy, cLen+1);
350,351c367,374
< for (j=0; j<length; j++)="" {="" <="" c="charArray<span">[j]; --- > for (j=0; j<cLen-1; j++)="" {="">
> wchar_t wc = wCharArray[j];
> char mb[2];
> wctomb(mb, wc);
>
> c = mb[0];
>
352a376
>
377c401,407
< addch(c);
---
>
> wchar_t wc = wCharArray[j];
> cchar_t cc;
> setcchar(&cc, &wc, 0, COLOR_PAIR(0), NULL);
> add_wch(&cc);
>
> // addch(c);
384a415,417
> free(copy);
> free(wCharArray);
>
Attach diff.
Attach .c source.