8 static char *makeFontSetOfSize(char *fontset
, int size
);
12 WMCreateFont(WMScreen
*scrPtr
, char *fontName
)
15 Display
*display
= scrPtr
->display
;
19 XFontSetExtents
*extents
;
21 font
= WMHashGet(scrPtr
->fontCache
, fontName
);
27 font
= malloc(sizeof(WMFont
));
30 memset(font
, 0, sizeof(WMFont
));
34 font
->screen
= scrPtr
;
36 font
->font
.set
= XCreateFontSet(display
, fontName
, &missing
, &nmissing
,
38 if (nmissing
> 0 && font
->font
.set
) {
41 wwarning("the following character sets are missing in %s:",
43 for (i
= 0; i
< nmissing
; i
++) {
46 XFreeStringList(missing
);
48 wwarning("the string \"%s\" will be used in place of any characters from those sets.",
51 if (!font
->font
.set
) {
56 extents
= XExtentsOfFontSet(font
->font
.set
);
58 font
->height
= extents
->max_logical_extent
.height
;
59 font
->y
= font
->height
- (font
->height
+ extents
->max_logical_extent
.y
);
63 font
->name
= wstrdup(fontName
);
65 assert(WMHashInsert(scrPtr
->fontCache
, font
->name
, font
)==NULL
);
73 WMCreateFontInDefaultEncoding(WMScreen
*scrPtr
, char *fontName
)
76 Display
*display
= scrPtr
->display
;
78 font
= WMHashGet(scrPtr
->fontCache
, fontName
);
84 font
= malloc(sizeof(WMFont
));
87 memset(font
, 0, sizeof(WMFont
));
91 font
->screen
= scrPtr
;
93 font
->font
.normal
= XLoadQueryFont(display
, fontName
);
94 if (!font
->font
.normal
) {
99 font
->height
= font
->font
.normal
->ascent
+font
->font
.normal
->descent
;
100 font
->y
= font
->font
.normal
->ascent
;
104 font
->name
= wstrdup(fontName
);
106 assert(WMHashInsert(scrPtr
->fontCache
, font
->name
, font
)==NULL
);
114 WMRetainFont(WMFont
*font
)
116 wassertrv(font
!=NULL
, NULL
);
125 WMReleaseFont(WMFont
*font
)
127 wassertr(font
!=NULL
);
130 if (font
->refCount
< 1) {
131 if (font
->notFontSet
)
132 XFreeFont(font
->screen
->display
, font
->font
.normal
);
134 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
137 WMHashRemove(font
->screen
->fontCache
, font
->name
);
147 WMFontHeight(WMFont
*font
)
149 wassertrv(font
!=NULL
, 0);
157 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
162 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.systemFont
, size
);
164 if (WINGsConfiguration
.useMultiByte
)
165 font
= WMCreateFont(scrPtr
, fontSpec
);
167 font
= WMCreateFontInDefaultEncoding(scrPtr
, fontSpec
);
170 if (WINGsConfiguration
.useMultiByte
) {
171 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
172 font
= WMCreateFont(scrPtr
, "fixed");
174 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
177 wwarning("could not load font %s. Trying fixed.", fontSpec
);
178 font
= WMCreateFontInDefaultEncoding(scrPtr
, "fixed");
181 wwarning("could not load fixed font!");
193 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
198 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
200 if (WINGsConfiguration
.useMultiByte
)
201 font
= WMCreateFont(scrPtr
, fontSpec
);
203 font
= WMCreateFontInDefaultEncoding(scrPtr
, fontSpec
);
206 if (WINGsConfiguration
.useMultiByte
) {
207 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
208 font
= WMCreateFont(scrPtr
, "fixed");
210 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
213 wwarning("could not load font %s. Trying fixed.", fontSpec
);
214 font
= WMCreateFontInDefaultEncoding(scrPtr
, "fixed");
217 wwarning("could not load fixed font!");
229 WMGetFontFontSet(WMFont
*font
)
231 wassertrv(font
!=NULL
, NULL
);
233 if (font
->notFontSet
)
236 return font
->font
.set
;
241 WMWidthOfString(WMFont
*font
, char *text
, int length
)
243 wassertrv(font
!=NULL
, 0);
244 wassertrv(text
!=NULL
, 0);
246 if (font
->notFontSet
)
247 return XTextWidth(font
->font
.normal
, text
, length
);
252 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
261 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
262 char *text
, int length
)
264 wassertr(font
!=NULL
);
266 if (font
->notFontSet
) {
267 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
268 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
270 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
277 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
278 char *text
, int length
)
280 wassertr(font
!= NULL
);
282 if (font
->notFontSet
) {
283 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
284 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
286 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
295 makeFontSetOfSize(char *fontset
, int size
)
305 ptr
= strchr(fontset
, ',');
310 if (strlen(fontset
)>255) {
311 wwarning("font description %s is too large.", fontset
);
313 sprintf(font
, fontset
, size
);
314 tmp
= wstrappend(newfs
, font
);