8 static char *makeFontSetOfSize(char *fontset
, int size
);
12 WMCreateFont(WMScreen
*scrPtr
, char *fontName
)
15 Display
*display
= scrPtr
->display
;
19 XFontSetExtents
*extents
;
21 font
= malloc(sizeof(WMFont
));
27 font
->screen
= scrPtr
;
29 font
->font
.set
= XCreateFontSet(display
, fontName
, &missing
, &nmissing
,
31 if (nmissing
> 0 && font
->font
.set
) {
34 wwarning("the following character sets are missing in %s:",
36 for (i
= 0; i
< nmissing
; i
++) {
39 XFreeStringList(missing
);
41 wwarning("the string \"%s\" will be used in place of any characters from those sets.",
44 if (!font
->font
.set
) {
49 extents
= XExtentsOfFontSet(font
->font
.set
);
51 font
->height
= extents
->max_logical_extent
.height
;
52 font
->y
= font
->height
- (font
->height
+ extents
->max_logical_extent
.y
);
62 WMCreateFontInDefaultEncoding(WMScreen
*scrPtr
, char *fontName
)
65 Display
*display
= scrPtr
->display
;
67 font
= malloc(sizeof(WMFont
));
73 font
->screen
= scrPtr
;
75 font
->font
.normal
= XLoadQueryFont(display
, fontName
);
76 if (!font
->font
.normal
) {
81 font
->height
= font
->font
.normal
->ascent
+font
->font
.normal
->descent
;
82 font
->y
= font
->font
.normal
->ascent
;
92 WMRetainFont(WMFont
*font
)
103 WMReleaseFont(WMFont
*font
)
107 if (font
->refCount
< 1) {
108 if (font
->notFontSet
)
109 XFreeFont(font
->screen
->display
, font
->font
.normal
);
111 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
119 WMFontHeight(WMFont
*font
)
130 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
135 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.systemFont
, size
);
137 font
= WMCreateFont(scrPtr
, fontSpec
);
140 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
141 font
= WMCreateFont(scrPtr
, "fixed");
143 wwarning("could not load fixed font!");
155 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
160 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
162 font
= WMCreateFont(scrPtr
, fontSpec
);
165 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
166 font
= WMCreateFont(scrPtr
, "fixed");
168 wwarning("could not load fixed font!");
180 WMGetFontFontSet(WMFont
*font
)
182 if (font
->notFontSet
)
185 return font
->font
.set
;
190 WMWidthOfString(WMFont
*font
, char *text
, int length
)
195 if (font
->notFontSet
)
196 return XTextWidth(font
->font
.normal
, text
, length
);
201 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
210 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
211 char *text
, int length
)
213 if (font
->notFontSet
) {
214 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
215 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
217 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
224 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
225 char *text
, int length
)
227 if (font
->notFontSet
) {
228 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
229 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
231 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
240 makeFontSetOfSize(char *fontset
, int size
)
250 ptr
= strchr(fontset
, ',');
255 if (strlen(fontset
)>255) {
256 wwarning("font description %s is too large.", fontset
);
258 sprintf(font
, fontset
, size
);
259 tmp
= wstrappend(newfs
, font
);