1 /*  This file contains routines that manipulate fonts.
2  *
3  *                     This code is under the GNU Copyleft.
4  *
5  *  Dominic Giampaolo
6  *  dbg@sgi.com
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "xstuff.h"
11 #include "libsx.h"
12 #include "libsx_private.h"
13 
14 
15 
16 
GetFont(char * fontname)17 XFont  GetFont(char *fontname)
18 {
19   XFontStruct *xfs;
20 
21   if (lsx_curwin->display == NULL || fontname == NULL)
22     return NULL;
23 
24   xfs = XLoadQueryFont(lsx_curwin->display, fontname);
25 
26   return xfs;
27 }
28 
29 
30 
SetWidgetFont(Widget w,XFont f)31 void  SetWidgetFont(Widget w, XFont f)
32 {
33   int    n = 0;
34   Arg    wargs[1];		/* Used to set widget resources */
35   DrawInfo *di;
36 
37   if (lsx_curwin->toplevel == NULL || w == NULL || f == NULL)
38     return;
39 
40   if ((di=libsx_find_draw_info(w)) != NULL)
41    {
42      XSetFont(lsx_curwin->display, di->drawgc, f->fid);
43      di->font = f;
44      return;
45    }
46 
47   n = 0;
48   XtSetArg(wargs[n], XtNfont, f);	 	     n++;
49   XtSetValues(w, wargs, n);
50 
51   return;
52 }
53 
54 
55 
GetWidgetFont(Widget w)56 XFont  GetWidgetFont(Widget w)
57 {
58   int    n = 0;
59   Arg    wargs[1];		/* Used to set widget resources */
60   XFont  f=NULL;
61   DrawInfo *di;
62 
63   if (lsx_curwin->toplevel == NULL || w == NULL)
64     return NULL;
65 
66 
67   if ((di=libsx_find_draw_info(w)) != NULL)
68    {
69      return di->font;
70    }
71 
72   n = 0;
73   XtSetArg(wargs[n], XtNfont, &f);	 	     n++;
74   XtGetValues(w, wargs, n);
75 
76   return f;
77 }
78 
79 
80 
FreeFont(XFont f)81 void FreeFont(XFont f)
82 {
83   if (lsx_curwin->display && f)
84     XFreeFont(lsx_curwin->display, f);
85 }
86 
87 
88 
FontHeight(XFont f)89 int FontHeight(XFont f)
90 {
91   if (f)
92     return (f->ascent+f->descent);
93   else
94     return -1;
95 }
96 
97 
98 
TextWidth(XFont f,char * txt)99 int TextWidth(XFont f, char *txt)
100 {
101   if (f && txt)
102     return XTextWidth(f, txt, strlen(txt));
103   else
104     return -1;
105 }
106 
107