static int fontset_measure (Lisp_Font *f, char *string, size_t length) { #ifdef X_HAVE_UTF8_STRING return Xutf8TextEscapement (f->font, string, length); #else return XmbTextEscapement (f->font, string, length); #endif }
int main_loop(Display *dpy, XFontSet font, GC pen, int width, int height, char *text){ int text_width; int textx, texty; XEvent ev; int font_ascent; XFontStruct **fonts; char **font_names; int nfonts; int j; printf("%s:%d\n", text, strlen(text)); text_width = Xutf8TextEscapement(font, text, strlen(text)); font_ascent = 0; nfonts = XFontsOfFontSet(font, &fonts, &font_names); for(j = 0; j < nfonts; j += 1){ if (font_ascent < fonts[j]->ascent) font_ascent = fonts[j]->ascent; printf("Font: %s\n", font_names[j]); } /* as each event that we asked about occurs, we respond. */ while(1){ XNextEvent(dpy, &ev); switch(ev.type){ case Expose: if (ev.xexpose.count > 0) break; XDrawLine(dpy, ev.xany.window, pen, 0, 0, width/2-text_width/2, height/2); XDrawLine(dpy, ev.xany.window, pen, width, 0, width/2+text_width/2, height/2); XDrawLine(dpy, ev.xany.window, pen, 0, height, width/2-text_width/2, height/2); XDrawLine(dpy, ev.xany.window, pen, width, height, width/2+text_width/2, height/2); textx = (width - text_width)/2; texty = (height + font_ascent)/2; Xutf8DrawString(dpy, ev.xany.window, font, pen, textx, texty, text, strlen(text)); break; case ConfigureNotify: if (width != ev.xconfigure.width || height != ev.xconfigure.height) { width = ev.xconfigure.width; height = ev.xconfigure.height; XClearWindow(dpy, ev.xany.window); } break; case ButtonRelease: XCloseDisplay(dpy); return 0; } } }