打印

GtkTextView不能显示扩展ASCII字符

GtkTextView不能显示扩展ASCII字符

最近学习GTK2编程,发现GtkTextView不能显示扩展ASCII,如'\200‘,如果含有这类字符,则整行的内容都不能显示。label空间也一样,不知道什么地方不对?
我爱Aquamarine!

TOP

对了 gtk2 和gtk+编程有什么区别阿。。。
Weiwei加油   我要追三顺!

TOP

一样的吧,看不出分别来了,好像GTK+有一个1.x的版本,然后后面又出了一个2.x的版本,所以偶就说GTK2了
我爱Aquamarine!

TOP

是吗??
Weiwei加油   我要追三顺!

TOP

管他是不是,能不能解决问题??
我爱Aquamarine!

TOP

试试先转换为UTF8

TOP

还是不行,中文可以,但是扩展ASCII还是不行  

text_view = gtk_text_view_new ();
  gtk_box_pack_start (GTK_BOX (vbox), text_view, 1, 1, 0);
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
  gtk_text_buffer_set_text (buffer, g_locale_to_utf8("\200",2,NULL,NULL,NULL),  -1);
我爱Aquamarine!

TOP

utf8str = g_convert ("\200", 1, "UTF-8", "ISO-8859-1", NULL, NULL, &error);
g_locale_to_utf8从系统当前的locale转换成UTF-8。 如果你的系统已经是UTF-8,g_locale_to_utf8会报错G_CONVERT_ERROR_ILLEGAL_SEQUENCE, 因为
"\200"不是合法的utf8字符。
在程序里一定要检查返回值和error。

TOP

(test.exe:1332): Gtk-CRITICAL **: gtk_text_buffer_insert_with_tags_by_name: a ssertion `text != NULL' failed

windows下用的是unicode,如果不转换也是一样的。
有没有能将ASCII转换成utf-8的函数?g_convert()试了一下,好像不行。
我爱Aquamarine!

TOP

可以显示了,但是字符,但是结果还不对,\200应该显示Ç,现在显示的是乱码,看看是不是字体的问题。
我爱Aquamarine!

TOP

g_convert ("\200", 1, "UTF-8", "CP1252", NULL, NULL, &error); 可以了,hoho,ISO-8859-1没有包含扩展部分的字符,但是ms自己的cp1252带了的。
见http://www.answers.com/topic/extended-ascii#after_ad2,多谢dzho002
我爱Aquamarine!

TOP

最终的解决办法,使用CP437,原味的美国ASCII标准,从0-255都有,参考文档
http://www.cs.tut.fi/~jkorpela/chars.html
引用如下:
DOS character codes, or "code pages" (CP)
    In MS DOS systems, different character codes are used; they are called "code pages". The original American code page was CP 437, which has e.g. some Greek letters, mathematical symbols, and characters which can be used as elements in simple pseudo-graphics. Later CP 850 became popular, since it contains letters needed for West European languages - largely the same letters as ISO 8859-1, but in different code positions. See DOS code page to Unicode mapping tables for detailed information. Note that DOS code pages are quite different from Windows character codes, though the latter are sometimes called with names like cp-1252 (= windows-1252)! For further confusion, Microsoft now prefers to use the notion "OEM code page" for the DOS character set used in a particular country.
我爱Aquamarine!

TOP