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 assert(WMHashInsert(scrPtr
->fontCache
, font
->name
, font
)==NULL
);
112 WMRetainFont(WMFont
*font
)
114 wassertrv(font
!=NULL
, NULL
);
123 WMReleaseFont(WMFont
*font
)
125 wassertr(font
!=NULL
);
128 if (font
->refCount
< 1) {
129 if (font
->notFontSet
)
130 XFreeFont(font
->screen
->display
, font
->font
.normal
);
132 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
135 WMHashRemove(font
->screen
->fontCache
, font
->name
);
145 WMFontHeight(WMFont
*font
)
147 wassertrv(font
!=NULL
, 0);
155 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
160 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.systemFont
, size
);
162 font
= WMCreateFont(scrPtr
, fontSpec
);
165 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
166 font
= WMCreateFont(scrPtr
, "fixed");
168 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
171 wwarning("could not load fixed font!");
183 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
188 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
190 font
= WMCreateFont(scrPtr
, fontSpec
);
193 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
194 font
= WMCreateFont(scrPtr
, "fixed");
196 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
199 wwarning("could not load fixed font!");
211 WMGetFontFontSet(WMFont
*font
)
213 wassertrv(font
!=NULL
, NULL
);
215 if (font
->notFontSet
)
218 return font
->font
.set
;
223 WMWidthOfString(WMFont
*font
, char *text
, int length
)
225 wassertrv(font
!=NULL
, 0);
226 wassertrv(text
!=NULL
, 0);
228 if (font
->notFontSet
)
229 return XTextWidth(font
->font
.normal
, text
, length
);
234 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
243 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
244 char *text
, int length
)
246 wassertr(font
!=NULL
);
248 if (font
->notFontSet
) {
249 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
250 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
252 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
259 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
260 char *text
, int length
)
262 wassertr(font
!= NULL
);
264 if (font
->notFontSet
) {
265 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
266 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
268 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
277 makeFontSetOfSize(char *fontset
, int size
)
287 ptr
= strchr(fontset
, ',');
292 if (strlen(fontset
)>255) {
293 wwarning("font description %s is too large.", fontset
);
295 sprintf(font
, fontset
, size
);
296 tmp
= wstrappend(newfs
, font
);