- 论坛徽章:
- 0
|
不好意思,因为思绪比较乱,只好多个论坛求学了,请见谅
继续求学:
今天早上试着安装,把编译器里面的locale相关的全部铐过来了,
# locale -a
显示有zh_CN.gb2312了,setlocale()函数终于没有返回出错,但是程序运行起来还是和上面截图一样,还是没有能把中文字体画出来
找了个小程序来测试(在x86正常显示)在setlocale()也没有报错了,在板子上还是不能输出中文。晚上继续看看,先弄明白小程序的中文为什么也画不出来~
用于测试输出 "abc 你好“的小程序,网上找的:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iconv.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
/*
#include <locale.h>
*/
#include <X11/Xlocale.h>
void DrawCenteredMbString ( Display *, Window, XFontSet, GC, char*, int, int,
int, int, int );
int
main (argc, argv)
int argc;
char *argv[];
{
Display *dpy;
Window w;
XFontSet fontset;
char **missing_charsets;
int num_missing_charsets;
char *default_string;
int i;
GC gc;
XEvent xe;
char *p;
char locale[100];
char *program_name = argv[0];
p = setlocale (LC_CTYPE,"");
if ( !p ) {
//if ( setlocale (LC_ALL,"") == NULL ) {
fprintf (stderr, "%s: setlocale fail.\n",
program_name );
//exit (1);
}
else
{
strcpy(locale, p);
fprintf(stderr, "%s: locale is (%s)\n", program_name, locale);
}
if ( !XSupportsLocale() ) {
fprintf (stderr,"%s: X does not support locale %s.\n",
program_name, setlocale( LC_ALL, NULL ) );
exit (1);
}
if ( XSetLocaleModifiers("") == NULL ) {
fprintf (stderr,
"%s: Warning: setlocalemodifiers fail.\n",
program_name);
}
dpy = XOpenDisplay ( NULL);
w = XCreateSimpleWindow ( dpy, RootWindow( dpy, 0 ), 50, 50,
100, 50, 5, BlackPixel( dpy, 0 ),
WhitePixel( dpy, 0 ) );
gc = XCreateGC ( dpy, w, 0L, ( XGCValues * ) NULL );
fontset = XCreateFontSet (dpy, "-*-*-*-*-*-*-16-*-*-*-*-*-*-*",
&missing_charsets, &num_missing_charsets,
&default_string);
if ( num_missing_charsets > 0 ) {
(void) fprintf (stderr,
"%s: The following charsets are missing:\n",
program_name);
for ( i=0; i < num_missing_charsets; i++ )
(void)fprintf (stderr, "%s: %s\n", program_name,
missing_charsets);
(void) fprintf (stderr, "%s: The string is %s\n", program_name,
default_string);
(void) fprintf (stderr,
"%s: of any characters from those sets\n",
program_name);
XFreeStringList (missing_charsets);
}
XSetLineAttributes ( dpy, gc, 5, LineSolid, CapRound, JoinRound );
XSelectInput ( dpy, w, ExposureMask | ButtonPressMask
| EnterWindowMask | LeaveWindowMask );
XMapWindow ( dpy, w );
XFlush ( dpy );
while ( True )
{
XNextEvent ( dpy, &xe );
switch ( xe.type ) {
case Expose:
printf ("Expose 出现.\n");
XSetForeground ( dpy, gc, BlackPixel( dpy, 0 ) );
DrawCenteredMbString ( dpy, w, fontset, gc,
"abc 你好",
10, 0, 0, 100, 50 );
break;
case ButtonPress:
printf ("按下!\n");
exit (1);
break;
case EnterNotify:
printf ("进入.\n");
XSetForeground ( dpy, gc, BlackPixel( dpy, 0 ) );
XDrawRectangle ( dpy, w, gc, 0, 0, 100, 50 );
break;
case LeaveNotify:
printf ("离开.\n");
XSetForeground ( dpy, gc, WhitePixel( dpy, 0 ) );
XDrawRectangle ( dpy, w, gc, 0, 0, 100, 50 );
break;
default:
printf ("默认.\n");
break;
}
}
return 0;
}
void
DrawCenteredMbString (dpy, w, fontset, gc, str, num_bytes, x, y, width, height )
Display *dpy;
Window w;
XFontSet fontset;
GC gc;
char *str;
int num_bytes;
int x,y, width, height;
{
XRectangle boundingbox;
XRectangle dummy;
int originx, originy;
(void) XmbTextExtents (fontset, str, num_bytes, &dummy, &boundingbox);
originx = x + ( width - boundingbox.width )/2 - boundingbox.x;
originy = y + ( height - boundingbox.height)/2 - boundingbox.y;
XmbDrawString (dpy, w, fontset, gc, originx, originy, str, num_bytes);
} |
|
|