找回密码
 注册
查看: 1912|回复: 11

GtkTextView不能显示扩展ASCII字符

[复制链接]
发表于 2006-10-4 22:33:24 | 显示全部楼层 |阅读模式
最近学习GTK2编程,发现GtkTextView不能显示扩展ASCII,如'\200‘,如果含有这类字符,则整行的内容都不能显示。label空间也一样,不知道什么地方不对?
发表于 2006-10-5 01:14:48 | 显示全部楼层
对了 gtk2 和gtk+编程有什么区别阿。。。
回复

使用道具 举报

 楼主| 发表于 2006-10-5 13:42:20 | 显示全部楼层
一样的吧,看不出分别来了,好像GTK+有一个1.x的版本,然后后面又出了一个2.x的版本,所以偶就说GTK2了
回复

使用道具 举报

发表于 2006-10-5 15:54:46 | 显示全部楼层
是吗??
回复

使用道具 举报

 楼主| 发表于 2006-10-5 22:43:37 | 显示全部楼层
管他是不是,能不能解决问题??
回复

使用道具 举报

发表于 2006-10-6 11:32:48 | 显示全部楼层
试试先转换为UTF8
回复

使用道具 举报

 楼主| 发表于 2006-10-6 16:22:35 | 显示全部楼层
还是不行,中文可以,但是扩展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);
回复

使用道具 举报

发表于 2006-10-6 18:03:42 | 显示全部楼层
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。
回复

使用道具 举报

 楼主| 发表于 2006-10-7 12:43:47 | 显示全部楼层
(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()试了一下,好像不行。
回复

使用道具 举报

 楼主| 发表于 2006-10-7 12:51:25 | 显示全部楼层
可以显示了,但是字符,但是结果还不对,\200应该显示Ç,现在显示的是乱码,看看是不是字体的问题。
回复

使用道具 举报

 楼主| 发表于 2006-10-7 13:27:38 | 显示全部楼层
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
回复

使用道具 举报

 楼主| 发表于 2006-10-7 14:54:03 | 显示全部楼层
最终的解决办法,使用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.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-6 16:51 , Processed in 0.043104 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表