1 /*
2    text.c
3 
4    Mike Hufnagel & Bill Kendrick
5    Last modified: 11/18/95 (clean up)
6 */
7 
8 #include <X11/Xlib.h>
9 #include "text.h"
10 #include <string.h>
11 
FontHeight(XFontStruct * font_struct)12 int FontHeight(XFontStruct *font_struct)
13 {
14   return(font_struct->ascent + font_struct->descent);
15 }
16 
LoadFont(Display * display,char * font_name,char * fallback_font_name)17 XFontStruct *LoadFont(Display *display, char* font_name,
18 		      char* fallback_font_name)
19 {
20   XFontStruct *font_struct;
21 
22   font_struct = XLoadQueryFont(display, font_name);
23   if (font_struct == (XFontStruct*)NULL)
24     {
25       /* try to load the fallbacck font */
26       font_struct = XLoadQueryFont(display,fallback_font_name);
27     }
28 
29   return(font_struct);
30 }
31 
32 
drawtext(Display * display,Window window,GC gc,int x,int y,char * s)33 void drawtext(Display *display, Window window, GC gc, int x, int y, char *s)
34 {
35   XDrawImageString(display, window, gc, x, y, s, strlen(s));
36 }
37 
drawcenteredtext(Display * display,Window window,GC gc,int x1,int x2,int y,char * s,XFontStruct * font)38 void drawcenteredtext(Display *display, Window window, GC gc, int x1, int x2,
39 		      int y, char *s, XFontStruct *font)
40 {
41   int x;
42 
43   x = ((x2 - x1) / 2) + x1;
44   x = x - (XTextWidth(font, s, strlen(s))) / 2;
45 
46   drawtext(display, window, gc, x, y, s);
47 }
48