34 |
int |
int |
35 |
getFont (Display * dpy, MyFont * font, char *name) |
getFont (Display * dpy, MyFont * font, char *name) |
36 |
{ |
{ |
37 |
char **missing_list; |
char **missing_list; |
38 |
int missing_count; |
int missing_count; |
39 |
char *def_string; |
char *def_string; |
40 |
XFontStruct **fonts; |
XFontStruct **fonts; |
41 |
char **font_names; |
char **font_names; |
42 |
int i, ascent, descent, fnum; |
int i, ascent, descent, fnum; |
43 |
char *basename; |
char *basename; |
44 |
|
|
45 |
#ifdef DEBUG |
#ifdef DEBUG |
46 |
printf ("entering getFont\n"); |
printf ("entering getFont\n"); |
47 |
printf ("font=%s\n", name); |
printf ("font=%s\n", name); |
48 |
#endif |
#endif |
49 |
|
|
50 |
font->font = NULL; |
font->font = NULL; |
51 |
font->fontset = NULL; |
font->fontset = NULL; |
52 |
|
|
53 |
if (use_fontset) |
if (use_fontset) |
54 |
{ |
{ |
55 |
basename = xmalloc (strlen (name) + 3); |
basename = xmalloc (strlen (name) + 3); |
56 |
if (basename) |
if (basename) |
57 |
sprintf (basename, "%s,*", name); |
sprintf (basename, "%s,*", name); |
58 |
else |
else |
59 |
basename = name; |
basename = name; |
60 |
|
|
61 |
font->fontset = |
font->fontset = |
62 |
XCreateFontSet (dpy, basename, &missing_list, &missing_count, |
XCreateFontSet (dpy, basename, &missing_list, &missing_count, |
63 |
&def_string); |
&def_string); |
64 |
if (!font->fontset) |
if (!font->fontset) |
65 |
{ |
{ |
66 |
if (basename != name) |
if (basename != name) |
67 |
free (basename); |
free (basename); |
68 |
return False; |
return False; |
69 |
} |
} |
70 |
|
|
71 |
if (basename != name) |
if (basename != name) |
72 |
free (basename); |
free (basename); |
73 |
|
|
74 |
for (i = 0; i < missing_count; i++) |
for (i = 0; i < missing_count; i++) |
75 |
fprintf (stderr, "Warning! Missing charset %s\n", missing_list[i]); |
fprintf (stderr, "Warning! Missing charset %s\n", missing_list[i]); |
76 |
|
|
77 |
fnum = XFontsOfFontSet (font->fontset, &fonts, &font_names); |
fnum = XFontsOfFontSet (font->fontset, &fonts, &font_names); |
78 |
for (i = 0, ascent = 0, descent = 0; i < fnum; i++) |
for (i = 0, ascent = 0, descent = 0; i < fnum; i++) |
79 |
{ |
{ |
80 |
if (ascent < fonts[i]->ascent) |
if (ascent < fonts[i]->ascent) |
81 |
ascent = fonts[i]->ascent; |
ascent = fonts[i]->ascent; |
82 |
if (descent < fonts[i]->descent) |
if (descent < fonts[i]->descent) |
83 |
descent = fonts[i]->descent; |
descent = fonts[i]->descent; |
84 |
} |
} |
85 |
|
|
86 |
font->height = ascent + descent; |
font->height = ascent + descent; |
87 |
font->ascent = ascent; |
font->ascent = ascent; |
88 |
font->descent = descent; |
font->descent = descent; |
89 |
} |
} |
90 |
else |
else |
91 |
{ |
{ |
92 |
font->font = XLoadQueryFont (dpy, name); |
font->font = XLoadQueryFont (dpy, name); |
93 |
if (!font->font) |
if (!font->font) |
94 |
{ |
{ |
95 |
font->font = XLoadQueryFont (dpy, "fixed"); |
font->font = XLoadQueryFont (dpy, "fixed"); |
96 |
if (!font->font) |
if (!font->font) |
97 |
return False; |
return False; |
98 |
} |
} |
99 |
|
|
100 |
font->height = font->font->ascent + font->font->descent; |
font->height = font->font->ascent + font->font->descent; |
101 |
font->ascent = font->font->ascent; |
font->ascent = font->font->ascent; |
102 |
font->descent = font->font->descent; |
font->descent = font->font->descent; |
103 |
} |
} |
104 |
|
|
105 |
return True; |
return True; |
106 |
} |
} |
107 |
|
|
108 |
void |
void |
109 |
freeFont (Display * dpy, MyFont * font) |
freeFont (Display * dpy, MyFont * font) |
110 |
{ |
{ |
111 |
#ifdef DEBUG |
#ifdef DEBUG |
112 |
printf ("entering freeFont\n"); |
printf ("entering freeFont\n"); |
113 |
#endif |
#endif |
114 |
|
|
115 |
if (use_fontset) |
if (use_fontset) |
116 |
XFreeFontSet (dpy, font->fontset); |
XFreeFontSet (dpy, font->fontset); |
117 |
else |
else |
118 |
XFreeFont (dpy, font->font); |
XFreeFont (dpy, font->font); |
119 |
} |
} |
120 |
|
|
121 |
void |
void |
122 |
drawString (Display * dpy, Drawable d, MyFont * font, GC gc, int x, int y, |
drawString (Display * dpy, Drawable d, MyFont * font, GC gc, int x, int y, |
123 |
char *str) |
char *str) |
124 |
{ |
{ |
125 |
#ifdef DEBUG |
#ifdef DEBUG |
126 |
printf ("entering drawString\n"); |
printf ("entering drawString\n"); |
127 |
#endif |
#endif |
128 |
|
|
129 |
if (!str) |
if (!str) |
130 |
return; |
return; |
131 |
|
|
132 |
if (use_fontset) |
if (use_fontset) |
133 |
XmbDrawString (dpy, d, font->fontset, gc, x, y, str, strlen (str)); |
XmbDrawString (dpy, d, font->fontset, gc, x, y, str, strlen (str)); |
134 |
else |
else |
135 |
XDrawString (dpy, d, gc, x, y, str, strlen (str)); |
XDrawString (dpy, d, gc, x, y, str, strlen (str)); |
136 |
} |
} |
137 |
|
|
138 |
int |
int |
139 |
getTextWidth (char *str, MyFont * font) |
getTextWidth (char *str, MyFont * font) |
140 |
{ |
{ |
141 |
int width; |
int width; |
142 |
XRectangle ink, logical; |
XRectangle ink, logical; |
143 |
|
|
144 |
#ifdef DEBUG |
#ifdef DEBUG |
145 |
printf ("entering getTextWidth\n"); |
printf ("entering getTextWidth\n"); |
146 |
#endif |
#endif |
147 |
|
|
148 |
if (!str) |
if (!str) |
149 |
return 0; |
return 0; |
150 |
|
|
151 |
if (use_fontset) |
if (use_fontset) |
152 |
{ |
{ |
153 |
XmbTextExtents (font->fontset, str, strlen (str), &ink, &logical); |
XmbTextExtents (font->fontset, str, strlen (str), &ink, &logical); |
154 |
width = logical.width; |
width = logical.width; |
155 |
} |
} |
156 |
else |
else |
157 |
width = XTextWidth (font->font, str, strlen (str)); |
width = XTextWidth (font->font, str, strlen (str)); |
158 |
|
|
159 |
return width; |
return width; |
160 |
} |
} |
161 |
|
|
162 |
void |
void |
163 |
getWindowName (Display * dpy, Window w, char **name) |
getWindowName (Display * dpy, Window w, char **name) |
164 |
{ |
{ |
165 |
int status, num; |
int status, num; |
166 |
char **list; |
char **list; |
167 |
XTextProperty text_prop; |
XTextProperty text_prop; |
168 |
|
|
169 |
#ifdef DEBUG |
#ifdef DEBUG |
170 |
printf ("entering getWindowName\n"); |
printf ("entering getWindowName\n"); |
171 |
#endif |
#endif |
172 |
|
|
173 |
*name = NULL; |
*name = NULL; |
174 |
status = XGetWMName (dpy, w, &text_prop); |
status = XGetWMName (dpy, w, &text_prop); |
175 |
if (!status || !text_prop.value || !text_prop.nitems) |
if (!status || !text_prop.value || !text_prop.nitems) |
176 |
return; |
return; |
177 |
if (text_prop.encoding == XA_STRING) |
if (text_prop.encoding == XA_STRING) |
178 |
{ |
{ |
179 |
if (text_prop.value) |
if (text_prop.value) |
180 |
{ |
{ |
181 |
*name = strdup (text_prop.value); |
*name = strdup (text_prop.value); |
182 |
XFree (text_prop.value); |
XFree (text_prop.value); |
183 |
} |
} |
184 |
} |
} |
185 |
else |
else |
186 |
{ |
{ |
187 |
XmbTextPropertyToTextList (dpy, &text_prop, &list, &num); |
XmbTextPropertyToTextList (dpy, &text_prop, &list, &num); |
188 |
if (num && *list) |
if (num && *list) |
189 |
{ |
{ |
190 |
XFree (text_prop.value); |
XFree (text_prop.value); |
191 |
*name = strdup (*list); |
*name = strdup (*list); |
192 |
XFreeStringList (list); |
XFreeStringList (list); |
193 |
} |
} |
194 |
} |
} |
195 |
return; |
return; |
196 |
} |
} |
197 |
|
|
198 |
/**This must remain at the end of the file.********** |
/**This must remain at the end of the file.********** |
199 |
* vim600:set sw=2 ts=8: * |
* vim600:set sw=2 ts=2: * |
200 |
* vim600:set cindent cinoptions={1s,>2s,^-1s,n-1s: * |
* vim600:set cindent cinoptions={1s,>2s,^-1s,n-1s: * |
201 |
* vim600:set foldmethod=marker: * |
* vim600:set foldmethod=marker: * |
202 |
****************************************************/ |
****************************************************/ |