[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Debian for ARM710的中文化问题



On Thu, Jan 25, 2001 at 11:34:37PM +0800, shuyong@public.nn.gx.cn wrote:
> 
> 这倒不是xfree86的bug,而是X Window的传统。每个window初始都没有前景色,然后程序
> 亲自设置。这也是X程序的惯例。
> 

这种不同平台上的不一致,还是有问题,惯例是一回事,兼容是另
一回事。我去 debian-x 上问一下吧,看是不是debian才有的问题。

> >
> > sizeof(XChar2b) == 4会影响吗?这些都应该在 xfree86 的 ARM port 上
> > 解决,debian-x 主要讨论的是在 debian 上对 X 系统的包装,安装。
> >
> 
> 因为一个假设,sizeof(XChar2b) == 4会有影响。
> 一般显示汉字是这样:
> char *chinese = "这是中文字符串";
> char *ch_str;
> XFontStruct *font = XLoadQueryFont (display,
> "-isas-*-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0");
> 
>  XSetFont (display, gc, font->fid);
>  length = strlen (chinese);
>  ch_str = strdup (chinese);
>  for (i = 0; i < length; i++) {
>   ch_str[i] &= 0x7F;
>  }
>  length /= 2;
>  XDrawString16 (display, window, gc, x, y, (_Xconst XChar2b *)ch_str, length + 1);
> 
> 注意ch_str的使用,这是不规范和不可移植的。主要是little/big endian的问题。XChar2b是
> 这样定义:
> 
> typedef struct {
>  unsigned char byte1;
>  unsigned char byte2;
> } XChar2b;
> 或:
> typedef struct {
>  unsigned char byte2;
>  unsigned char byte1;
> } XChar2b;
> 
> 这是由little/big endian的特性来决定。不管怎样,sizeof (XChar2b) == 2。上述代码
> 应该是:(这也是X内部代码使用的技巧)
> 
> char *chinese = "这是中文字符串";
> XChar2b *ch_str;
> XFontStruct *font = XLoadQueryFont (display,
> "-isas-*-medium-r-normal--16-160-72-72-c-160-gb2312.1980-0");
> 
>  length = strlen (chinese);
>  ch_str = (XChar2b *)malloc (length + sizeof (XChar2b));
>  memset (ch_str, 0, length + sizeof (XChar2b));
>  for (i = 0; i < length / sizeof (XChar2b); i++) {
>   ch_str[i].byte1 = chinese[i * 2] & 0x7F;
>   ch_str[i].byte2 = chinese[i * 2 + 1] & 0x7F;
>  }
>  length /= sizeof (XChar2b);
>  XDrawString16 (display, window, gc, x, y, (_Xconst XChar2b *)ch_str, length + 1);
> 
> 可能是因为效率问题,XDrawString16假设每个字是紧密排列进行显示的。你可以想象
> 当sizeof(XChar2b) == 4时的情况。所以我要寻找gcc关于结构对齐的选项。看看我的想法
> 是否正确。
> 

你肯定 ARM 上 sizeof(XChart2b) == 4 ? 如果肯定,那上面这种hack完全
错了。XmbDrawString... 都不对了。XDrawString16 没问题,
(_Xconst XChar2b *)ch_str 这种cast 就肯定乱套了。相应的Xmb 函数全完了。


-- 
Best regard
hashao



Reply to: