显示标签为“chinese”的博文。显示所有博文
显示标签为“chinese”的博文。显示所有博文

2005年3月6日星期日

xpdf的中文支持问题

今天在公司又有朋友在问xpdf的中文支持问题,

不管2.03还是3.0,都需要安装语言包(简体中文语言包直接下载),
语言包内包含了CMap files, text encodings, and various other configuration
information necessary or useful for specific character sets.
记得Debian对于语言包的自动安装做了一些改进[4](但Debian中似乎没有见到针对xpdf-3.0的语言包?)。

然后就是对于CJK字体的支持了,有两个补丁:

一个来自lucida's linux patch,可用于2.03和3.0

另一个来自原作者(补丁下载, 但在xpdf主页上没有发现) ,可以正确显示不带内嵌字体的中文pdf文件,但仅能用于3.0

还有一个问题就是对书签中中文的支持,这个在lucida的网页上有详细说明


另:

3.0不再支持X server字体,不再支持freetype 1.x,而支持TTF字体(不支持TTC)

3.0支持PDF 1.5, 而2.03最高支持PDF 1.4




以下内容摘自lucida的网页:

中文书签的显示需要额外的配置工作。

1. 在~/.Xdefaults里面加入资源项

xpdf*.fontList:
-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1;-misc-simsun-medium-r-normal--12-*-*-*-*-*-gbk-0:

注意标点,另外确保使用的字体的确存在,然后

xrdb -merge ~/.Xdefaults

使修改生效

2. 正确设置PDF文件的encoding

方法1. 在/etc/xpdfrc里面增加一行

textEncoding GBK

方法2. 使用参数启动xpdf,如下

xpdf -enc GBK aa.pdf

3. 关于编译以及使用中的一些问题

a. 无法在Freetype版本≧2.1.6的系统上编译

这是因为Freetype从此版本开始,强制引用"ft2build.h"而非"freetype/freetype.h",造成xpdf configure检测Freetype版本失败。本地下载

b.
关于资源项的设置,某些系统上应使用Xpdf*.fontList:(首字母X大写)而非xpdf*.fontList:。我不知道原因,不过如果您自觉资源项设置没有生效,可以试试。

另外一个设置资源项的方法是,修改或者新建/etc/X11/app-defaults/Xpdf,加入对应内容,这样可以省略xrdb
-merge的步骤(感谢seb@smth的建议)

c. 某些PDF制作不规范(比如Linux国家标准草案PDF档),请使用

xpdf -enc Latin1 buggy.pdf

启动xpdf,以便读取书签。

d. 注意修改/etc/xpdfrc,加入合适的ttf字体,比如

displayCIDFontTT Adobe-GB1 /usr/share/fonts/simhei.ttf

xpdf3不再支持老的XLFD字体(以及displayCIDFontX资源项),所以以前的设置文章不再有效。另外,xpdf3目前只支持ttf字体,不支持ttc(TrueType
font Collection)字体。




2005年1月20日星期四

转: debian 中文系统配置

我对于过于复杂地寻求"美化"之道不是没有兴趣,而是没有精力去琢磨。这篇文章提供的方法比较简单,用来show给新手看,其实我是不喜欢拿 simsun这种有版权的字体来搞的。(另外,初装系统需要中文支持的话,可以先试试从tasksel里面选择Simplified Chinese, 这样比较省事情)

也无非就是这么几步:

1. 安装 simsun.ttf 字体, 美化字体
2. 安装中文locale
3. 安装中文输入法

原文出处: http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=office&Number=511481&page=&view=&sb=&o=

[@more@]


1. 安装 simsun.ttf 字体:
# mkdir /usr/share/fonts/truetype/simsun
# cd /usr/share/fonts/truetype/simsun
# cp /mnt/gentoo/usr/share/fonts/truetype/simsun/SIMSUN.TTF . (将 Simsun 字体拷贝过来)
# mkfontscale (生成 font.scale 文件)
# cp fonts.scale fonts.dir

# vi /etc/X11/XF86Config-4
在相应的地方加入如下行:
FontPath "/usr/share/fonts/truetype/simsun"

2. 安装中文系统

安装 locale:
# apt-get install locales
选择 en_US en_US.ISO-8859-15 en_US.UTF-8 zh_CN zh_CN.GB18030 zh_CN.GBK zh_CN.UTF-8。选择 zh_CN 作为缺省的 locale。

安装中文输入法:
# apt-get install fcitx

安装词典:
# apt-get install stardict
# exit
$ mkdir ~/.stardict
$ cp /mnt/gentoo/usr/share/stardict/dic ~/.stardict -r
(将gentoo的词典拷过来用)

3. 美化字体

# vi /etc/fonts/fonts.conf
1) 在所有的 AR PL KaitiM GB 前插入 SimSun,并将其后面的 SimSun 删掉,让系统先找 SimSun 字体。

2) 为了不让字体模糊,在文件后面(前)加入: (FIXME)

4. 修改 .xsession,形成中文环境

$ vi .xsession
将其内容修改为:
export G_BROKEN_FILENAMES=1
export LANG=zh_CN
export LC_ALL=zh_CN
export XMODIFIERS="@im=fcitx"
fcitx &
gnome-session || exec xterm

然后退出 session 在重新登录就能在漂亮中文环境下生活了。

2004年11月7日星期日

搞定了GNOME下中文件名乱码的问题

Q1: gtk-2.4打开文件对话框对中文显示乱码,都是xxxxxx之类;beep-media-player的id3信息对话框显示的文件名也是乱码

A:设置G_FILENAME_ENCODING=GBK可以解决这个问题 (奇怪的是,我在Cygwin下没有设置这个也很正常,甚至CHARSET, LC_CTYPE都没有设置)


Q2: 上述问题是解决了。但通过gdm登录时,仍然出现乱码,在~/.bashrc和~/.bash_profile设置都不管用,/etc/bash.bashrc和/etc/profile也不好使
A: 查看了一下/etc/X11/Xsession.d/55gnome-session_gnomerc, 发现这个设置应该写在~/.gnomerc中

2004年11月3日星期三

rox-2.1.2文件名UTF-8补丁

nautilus太笨重了; 新版本的xffm似乎比以前更难移至了; gnome-commander的gnome-1版本在没有FAM的情况下总需要手工刷新,gnome2也老是出问题。于是我开始沉下心来用rox。

但它似乎对于在中文文件名(应该是非ANSI字符)上有不少问题,比如对路径包含中文的话,加到书签里之后又无法跳过去,拷贝、移动、删除的时候老是报告路径找不到。

琢磨了一阵,基本上可以用了: rox对于文件名没有进行编码转换就直接交给了gtk2显示,但gtk2要求非ansi字符在显示时必须采用UTF-8编码。这个补丁可以修正这个问题,在Cygwin上和Linux都试过了,但在Cygwin上还不太稳定。

diff -Nurp rox-2.1.2.orig/ROX-Filer/src/action.c rox-2.1.2/ROX-Filer/src/action.c --- rox-2.1.2.orig/ROX-Filer/src/action.c 2004-01-22 04:03:16.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/action.c 2004-10-11 19:23:10.000000000 +0800 @@ -887,12 +887,14 @@ static void do_usage(const char *src_pat } /* dest_path is the dir containing src_path */ -static void do_delete(const char *src_path, const char *unused) +static void do_delete(const char *src_path_req, const char *unused) { struct stat info; gboolean write_prot; char *safe_path; + gchar *src_path = filename_from_utf8(src_path_req); + check_flags(); if (mc_lstat(src_path, &info)) @@ -994,10 +996,12 @@ static void do_eject(const char *path) /* path is the item to check. If is is a directory then we may recurse * (unless prune is used). */ -static void do_find(const char *path, const char *unused) +static void do_find(const char *path_req, const char *unused) { FindInfo info; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (!quiet) @@ -1081,11 +1085,13 @@ static struct mode_change *nice_mode_com return retval; } -static void do_chmod(const char *path, const char *unused) +static void do_chmod(const char *path_req, const char *unused) { struct stat info; mode_t new_mode; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (mc_lstat(path, &info)) @@ -1159,10 +1165,12 @@ static void do_chmod(const char *path, c } } -static void do_settype(const char *path, const char *unused) +static void do_settype(const char *path_req, const char *unused) { struct stat info; + gchar *path = filename_from_utf8(path_req); + check_flags(); if (mc_lstat(path, &info)) @@ -1257,8 +1265,9 @@ static const char *make_dest_path(const else leaf++; } + gchar *leaf_copy = filename_from_utf8(leaf); - return make_path(dir, leaf); + return make_path(dir, leaf_copy); } /* If action_leaf is not NULL it specifies the new leaf name */ @@ -1510,8 +1519,11 @@ static void do_move2(const char *path, c /* Copy path to dest. * Check that path not copied into itself. */ -static void do_copy(const char *path, const char *dest) +static void do_copy(const char *path_req, const char *dest_req) { + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + if (is_sub_dir(make_dest_path(path, dest), path)) printf_send(_("!ERROR: Can't copy object into itselfn")); else @@ -1524,8 +1536,11 @@ static void do_copy(const char *path, co /* Move path to dest. * Check that path not moved into itself. */ -static void do_move(const char *path, const char *dest) +static void do_move(const char *path_req, const char *dest_req) { + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + if (is_sub_dir(make_dest_path(path, dest), path)) printf_send( _("!ERROR: Can't move/rename object into itselfn")); @@ -1536,10 +1551,13 @@ static void do_move(const char *path, co } } -static void do_link(const char *path, const char *dest) +static void do_link(const char *path_req, const char *dest_req) { const char *dest_path; + gchar *path = filename_from_utf8(path_req); + gchar *dest = filename_from_utf8(dest_req); + check_flags(); dest_path = make_dest_path(path, dest); @@ -1566,6 +1584,7 @@ static void do_mount(const guchar *path, const char *argv[3] = {NULL, NULL, NULL}; char *err; + /* path = filename_from_utf8(path); */ check_flags(); argv[0] = mount ? "mount" : "umount"; diff -Nurp rox-2.1.2.orig/ROX-Filer/src/bookmarks.c rox-2.1.2/ROX-Filer/src/bookmarks.c --- rox-2.1.2.orig/ROX-Filer/src/bookmarks.c 2004-03-25 21:03:44.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/bookmarks.c 2004-10-11 16:58:26.000000000 +0800 @@ -380,8 +380,10 @@ static xmlNode *bookmark_find(const gcha same = strcmp(mark, path) == 0; xmlFree(path); - if (same) + if (same) { + printf("This path already in bookmark listn.", path); return node; + } } return NULL; @@ -410,10 +412,12 @@ static void bookmarks_add(GtkMenuItem *m bookmarks_add_dir(filer_window->sym_path); } -static void bookmarks_add_dir(const guchar *dir) +static void bookmarks_add_dir(const guchar *dir_req) { xmlNode *bookmark; + gchar *dir = filename_to_utf8(dir_req); + if (bookmark_find(dir)) return; @@ -439,8 +443,10 @@ static void bookmarks_activate(GtkMenuSh mark = gtk_label_get_text(label); } - if (strcmp(mark, filer_window->sym_path) != 0) - filer_change_to(filer_window, mark, NULL); + gchar *path = filename_from_utf8(mark); + + if (strcmp(path, filer_window->sym_path) != 0) + filer_change_to(filer_window, path, NULL); if (g_hash_table_lookup(fstab_mounts, filer_window->real_path) && !mount_is_mounted(filer_window->real_path, NULL, NULL)) { diff -Nurp rox-2.1.2.orig/ROX-Filer/src/display.c rox-2.1.2/ROX-Filer/src/display.c --- rox-2.1.2.orig/ROX-Filer/src/display.c 2004-04-27 18:34:30.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/display.c 2004-10-11 18:00:40.000000000 +0800 @@ -759,15 +759,24 @@ void display_update_view(FilerWindow *fi view->layout = NULL; } + gchar *u8 = filename_to_utf8(item->leafname); if (view->layout) { /* Do nothing */ } +#ifndef __CYGWIN__ else if (g_utf8_validate(item->leafname, -1, NULL)) { view->layout = gtk_widget_create_pango_layout( filer_window->window, item->leafname); } +#else /* on Cygwin(Windows), filenames should be in local charset, rather than UTF-8, */ + else if (g_utf8_validate(u8, -1, NULL)) + { + view->layout = gtk_widget_create_pango_layout( + filer_window->window, u8); + } +#endif else { PangoAttribute *attr; diff -Nurp rox-2.1.2.orig/ROX-Filer/src/dropbox.c rox-2.1.2/ROX-Filer/src/dropbox.c --- rox-2.1.2.orig/ROX-Filer/src/dropbox.c 2004-01-22 04:03:16.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/dropbox.c 2004-10-11 18:00:50.000000000 +0800 @@ -177,6 +177,7 @@ void drop_box_set_path(DropBox *drop_box gtk_widget_set_sensitive(drop_box->buttons, FALSE); } + ensure_utf8(&copy); gtk_label_set_text(GTK_LABEL(drop_box->label), copy); g_free(copy); } diff -Nurp rox-2.1.2.orig/ROX-Filer/src/filer.c rox-2.1.2/ROX-Filer/src/filer.c --- rox-2.1.2.orig/ROX-Filer/src/filer.c 2004-04-13 17:04:04.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/filer.c 2004-10-11 16:58:38.000000000 +0800 @@ -2102,10 +2102,12 @@ void filer_add_tip_details(FilerWindow * g_object_unref(info); } +#ifndef __CYGWIN__ /* TODO: use G_BROKEN_FILENAME/G_FILENAME_ENCODINGS ?? */ if (!g_utf8_validate(item->leafname, -1, NULL)) g_string_append(tip, _("This filename is not valid UTF-8. " "You should rename it.n")); +#endif } /* Return the selection as a text/uri-list. diff -Nurp rox-2.1.2.orig/ROX-Filer/src/menu.c rox-2.1.2/ROX-Filer/src/menu.c --- rox-2.1.2.orig/ROX-Filer/src/menu.c 2004-05-01 00:36:42.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/menu.c 2004-10-11 16:59:02.000000000 +0800 @@ -1024,7 +1024,7 @@ static void find(FilerWindow *filer_wind * both the current and new paths. * NOTE: This function unrefs 'image'! */ -static void savebox_show(const gchar *action, const gchar *path, +static void savebox_show(const gchar *action, const gchar *path_req, MaskedPixmap *image, SaveCb callback, GdkDragAction dnd_action) { @@ -1032,6 +1032,7 @@ static void savebox_show(const gchar *ac GtkWidget *check_relative = NULL; g_return_if_fail(image != NULL); + gchar *path = filename_to_utf8(path_req); savebox = gtk_savebox_new(action); gtk_savebox_set_action(GTK_SAVEBOX(savebox), dnd_action); @@ -1293,8 +1294,10 @@ void menu_show_options(gpointer data, gu } static gboolean new_directory_cb(GObject *savebox, - const gchar *initial, const gchar *path) + const gchar *initial, const gchar *path_req) { + gchar *path = filename_from_utf8(path_req); + if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO)) { report_error("mkdir: %s", g_strerror(errno)); @@ -1325,9 +1328,11 @@ static void new_directory(gpointer data, } static gboolean new_file_cb(GObject *savebox, - const gchar *initial, const gchar *path) + const gchar *initial, const gchar *path_req) { int fd; + + gchar *path = filename_from_utf8(path_req); fd = open(path, O_CREAT | O_EXCL, 0666); diff -Nurp rox-2.1.2.orig/ROX-Filer/src/pinboard.c rox-2.1.2/ROX-Filer/src/pinboard.c --- rox-2.1.2.orig/ROX-Filer/src/pinboard.c 2004-03-07 02:50:48.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/pinboard.c 2004-10-11 19:23:38.000000000 +0800 @@ -753,6 +753,7 @@ static void drag_backdrop_dropped(GtkWid radios = g_object_get_data(G_OBJECT(dialog), "rox-radios"); g_return_if_fail(radios != NULL); + /*gchar *path = filename_from_utf8(path_req); */ if (mc_stat(path, &info)) { delayed_error( @@ -2088,12 +2089,13 @@ static void create_pinboard_window(Pinbo } /* Load image 'path' and scale according to 'style' */ -static GdkPixmap *load_backdrop(const gchar *path, BackdropStyle style) +static GdkPixmap *load_backdrop(const gchar *path_req, BackdropStyle style) { GdkPixmap *pixmap; GdkPixbuf *pixbuf; GError *error = NULL; + gchar *path = filename_from_utf8(path_req); pixbuf = gdk_pixbuf_new_from_file(path, &error); if (error) { diff -Nurp rox-2.1.2.orig/ROX-Filer/src/support.c rox-2.1.2/ROX-Filer/src/support.c --- rox-2.1.2.orig/ROX-Filer/src/support.c 2004-04-27 18:34:30.000000000 +0800 +++ rox-2.1.2/ROX-Filer/src/support.c 2004-10-11 17:20:42.000000000 +0800 @@ -1083,6 +1083,34 @@ void ensure_utf8(gchar **sp) } } +/* +void filename_from_utf8(gchar **pathp) +{ + gchar *foo = g_filename_from_utf8(*pathp, -1, NULL, NULL, NULL); + if (foo) { + *pathp = g_strdup(foo); + g_free(foo); + } +} */ + +gchar* filename_from_utf8(const gchar* path_u) +{ + gchar *foo = g_filename_from_utf8(path_u, -1, NULL, NULL, NULL); + if (foo) { + return foo; + } else + return g_strdup(path_u); +} + +gchar* filename_to_utf8(const gchar* path) +{

Powered by ScribeFire.

2004年9月28日星期二

Cygwin中文How-to

大致写了一下,有待补充。

本来一年前就打算写的,但后来觉得老黄写更合适,但这家伙似乎只对代码有兴趣,总不写文档。
[@more@]

终端

locale支持

Cygwin的locale支持一直都不太好,采用zh_CN.gb2312好像问题很多,我一直采用的是zh_CN.gbk
~/.bashrc
LC_CTYPE=zh_CN.gbk
CHARSET=GBK #(glib2需要使用找个环境变量确定文件名的编码)
export LC_CTYPE CHARSET

一些小问题

允许bash输入、输出中文字符
~/.inputrc
set convert-meta off
set input-meta on
set output-meta on

ls显示中文文件名(而不是一堆问号)
alias ls="/bin/ls --show-control-chars"

less浏览中文文件
less --raw-control-chars
另外LESSCHARSET环境变量也很有用

X下的中文支持

locale支持

Cygwin的locale支持一直都有问题,好在X程序还可以使用XLOCALE。
建议还是使用zh_CN.gbk, 不要使用zh_CN.GB2312

在移植程序时需要注意不要让程序连接libcygwin.a里面的setlocale,而是采用libX11.a里面的_Xsetlocale。方法是:检查被移植程序的全部源代码,发现
#include
就修改为
#define X_LOCALE
#include
同时注意程序的连接库要添加-lX11.
如果对于结果没有把握,可以找个Dependency Walker查看程序是否连接到了cygwin1.dll里面的setlocale,如果是,就说明有遗漏。

中文字体

PCF点阵字体
GTK1.x 和其他一些老的X程序都是用X字体,

注意必须要有编码与locale一致的字体,比如用zh_CN.gbk就必须要由GBK编码的字体,用zh_CN.GB2312就必须要有GB2312编码的字体

如果使用zh_CN.GB2312,这里有一个RedOffice面带的点阵字体包

可以采用ttf2bdf从TTF抽取得到bdf格式,然后再用bdf2pcf得到pcf格式的字体文件。
(这里有一个Windows版本的TTF2BDF,可以将Windows TTF字体转换出BDF字体, 注意得到bdf后要手工编辑一下文件头,将编码声明修改正确)

得到字体之后,放到某个目录下,执行mkfontdir生成fonts.dir,然后用xset +fp /path/to/your/fonts将字体路径加入即可(注意与fontconfig的配置不同,这里路径是不递归的,如果有的字体放在子目录里面,子目录也需要添加进去才行)。
TTF字体
很多新的应用程序(比如GTK2)都使用fontconfig/libxft2来显示字体,它对TTF字体的支持比较好(X以前通过freetype, xft模块也支持TTF字体,但对中日韩字体的支持不是太好,而且也在Cygwin下似乎也没有这些模块)

完全可以使用Linux下的arphic字体包. 如果没有安装Linux,可以到http://packages.debian.org下载相应的包,然后用7zip解压提取出ttf文件。

得到字体文件之后,放到某个目录之下,编辑/etc/fonts/local.conf,将字体路径加入:
/path/to/my/ttf/fonts如果只是自己使用,可以将字体文件放到~/.fonts下,不需要修改任何配置,最多三十秒fontconfig就能够发现这些字体了。

中文输入法

老黄(hzhr)移植了miniChinput到Cygwin,我也移植了fcitx-1.8.5和3.0,均可以从我的网站上找到 http://www.oliwen.com/bamanzi/cygwin/chinese/

一般设置了LC_CTYPE和XMODIFIERS就可以在程序中激活输入输入法了(除非这个程序没有XIM支持):

LC_CTYPE=zh_CN.gbk
XMODIFIERS="@im=Chinput"
export LC_CTYPE XMODIFIERS

对于fcitx而言,XMODIFIERS设置为什么都可以(但必须要设置),所以设置为"@im=Chinput"的话chinput和fcitx都可以正常使用