以下面的範例來說,如果指定字體裡沒有全部的「龍龙竜」三字,就會顯示成空白或方格…(例如顯示成「龍龙 」或「龍 竜」)
請問有沒有不複雜的方法做到「自動尋字」呢?
- 代碼: 選擇全部
/*
With parts from lysavis.c by
Heine Larsen
With parts from HelloX.C by
(c) Copyright Paul Griffiths 1999
Email: paulgriffiths@cwcom.net
"Hello, World!", X Window System style.
Other parts about doublebuffering from
Linux/X11 Game Writers Page
Maintained by Paul Coates at
http://game.ncl.ac.uk/00104/
*/
#include <X11/Xft/Xft.h>
int main()
{
Display *display;
display = XOpenDisplay(NULL);
int screen_num = DefaultScreen(display);
Window win;
int x = 0;
int y = 0;
int msg_x_pos = 0;
int width = 500;
int height = 70;
int border_width = 0;
unsigned int depth = DefaultDepth(display, screen_num);
Colormap cmap = DefaultColormap(display, screen_num);
XGCValues values;
GC gc;
GC copygc;
Pixmap buffer;
Window rootwin = RootWindow(display, screen_num);
XftFont *xftfont;
Status retval;
XftColor color_fg;
XColor dummyc;
XColor fg;
XftDraw *xftdraw;
char *msg = "龍龙竜";
win = XCreateSimpleWindow(display, rootwin, x, y, width, height, border_width, BlackPixel(display, screen_num), BlackPixel(display, screen_num));
buffer = XCreatePixmap(display, win, width, height, depth);
xftfont = XftFontOpen(display, screen_num, XFT_FAMILY, XftTypeString, "Sazanami Mincho", XFT_SIZE, XftTypeInteger, 40, 0, NULL);
gc = XCreateGC(display, win, 0, &values);
copygc = XCreateGC(display, win, 0, &values);
retval = XAllocNamedColor(display, cmap, "white", &fg, &dummyc);
color_fg.color.red = dummyc.red;
color_fg.color.green = dummyc.green;
color_fg.color.blue = dummyc.blue;
xftdraw = XftDrawCreate(display, (Drawable) buffer, DefaultVisual(display, screen_num), cmap);
XMapWindow(display, win);
while (1) {
XFillRectangle(display, buffer, gc, 0, 0, width, height);
XftDrawStringUtf8(xftdraw, &color_fg, xftfont, msg_x_pos, xftfont->ascent, (unsigned char *) msg, strlen(msg));
XSetFillStyle(display, copygc, FillTiled);
XSetTile(display, copygc, buffer);
XFillRectangle(display, win, copygc, 0, 0, width, height);
XFlush(display);
usleep(1000);
}
return 0;
}