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

Re: Debian for ARM710的中文化问题



On Fri, Jan 26, 2001 at 12:44:33PM +0800, hashao@chinese.com wrote:
> On Thu, Jan 25, 2001 at 11:34:37PM +0800, shuyong@public.nn.gx.cn wrote:
> > 应该是:(这也是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 函数全完了。
> 

In omText.c, you can find that the cast is from (char *) to (_Xconst XChar2b *).
Which is totally wrong with XChar2b != char * 2.
In your example, simply replace i < length /sizeof(XChar2b) with 
i < (length>>1) will do the job. I think the DrawStringWidthFontSet should
changed to your example, Of course if we sure sizeof(XChar2b) could be 4.

-- 
Best regard
hashao



Reply to: