[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: japanese print
From: |
Thomas Dickey |
Subject: |
Re: japanese print |
Date: |
Sat, 18 Sep 2010 17:29:26 -0400 (EDT) |
On Mon, 13 Sep 2010, ?~]??~U~Y?~D? wrote:
I compiled following source printing japanese and linked with libcursesw
5.7 library.
The First and second print was displayed well.
But the third print was broken.
What should I do to print the third well?
The third case breaks because of the cursor-movement.
After 5.3, I (re)wrote the handling of multibyte/multicolumn characters,
to make it work with UTF-8. Shift-JIS, by the way, is a different
encoding. Probably in 5.3 it just "happened" to appear as if it worked.
Repainting would be a different matter.
Your program is attempting to print a multibyte character byte-by-byte.
However, it is positioning each byte on a new column.
UTF-8 encoding isn't like that - its individual bytes are all associated
with the starting column of the character.
ncurses keeps a small amount of state to see if the cursor is moved via
mv-functions to anywhere but the expected location (seems that I did all
of this after 5.3). If that happens, it treats the partly built-up
multibyte character as just 8-bit junk, and prints it as you see.
Printing multibyte characters byte-by-byte is an ncurses extension vs
X/Open. The standard (X/Open) way is more cumbersome, e.g., using add_wch
which requires a type-conversion to cchar_t's, or using addwnstr (again, a
type conversion).
On linking with libcurses 5.3 library, all are displayed well.
#include <ncurses.h>
#include <locale.h>
int main()
{
int i;
char japanese[]="????????????";
setlocale(LC_ALL,"");
initscr();
/* first print */
mvprintw(1,0,"%s\n",japanese);
/* second print */
for(i=0;i<8;i++)
printw("%c",japanese[i]);
/* third print */
for(i=0;i<9;i++)
mvprintw(3,i,"%c",japanese[i]);
refresh();
sleep(10);
endwin();
return 0;
}
Following is my current environment.
- emulator : putty ( Character set translation: Use font encoding, Font:
MS Gothic, Script: Japanese)
- termianl : xterm
- locale
LANG=ja_JP.shiftjis
LC_CTYPE="ja_JP.shiftjis"
LC_NUMERIC="ja_JP.shiftjis"
LC_TIME="ja_JP.shiftjis"
LC_COLLATE="ja_JP.shiftjis"
LC_MONETARY="ja_JP.shiftjis"
LC_MESSAGES="ja_JP.shiftjis"
LC_PAPER="ja_JP.shiftjis"
LC_NAME="ja_JP.shiftjis"
LC_ADDRESS="ja_JP.shiftjis"
LC_TELEPHONE="ja_JP.shiftjis"
LC_MEASUREMENT="ja_JP.shiftjis"
LC_IDENTIFICATION="ja_JP.shiftjis"
LC_ALL=
I attached original source file.
Thank you.
[?usn=1948988&address@hidden&key=fad08084ff719d1902deb6e5cc3471f7$2c4b3
address@hidden
--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net