8 static char *makeFontSetOfSize(char *fontset
, int size
);
12 WMCreateFontSet(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 WMCreateNormalFont(WMScreen
*scrPtr
, char *fontName
)
76 Display
*display
= scrPtr
->display
;
79 if ((ptr
= strchr(fontName
, ','))) {
80 fname
= wmalloc(ptr
- fontName
+ 1);
81 strncpy(fname
, fontName
, ptr
- fontName
);
82 fname
[ptr
- fontName
] = 0;
84 fname
= wstrdup(fontName
);
87 font
= WMHashGet(scrPtr
->fontCache
, fname
);
94 font
= malloc(sizeof(WMFont
));
99 memset(font
, 0, sizeof(WMFont
));
101 font
->notFontSet
= 1;
103 font
->screen
= scrPtr
;
105 font
->font
.normal
= XLoadQueryFont(display
, fname
);
106 if (!font
->font
.normal
) {
111 font
->height
= font
->font
.normal
->ascent
+font
->font
.normal
->descent
;
112 font
->y
= font
->font
.normal
->ascent
;
118 assert(WMHashInsert(scrPtr
->fontCache
, font
->name
, font
)==NULL
);
126 WMCreateFont(WMScreen
*scrPtr
, char *fontName
)
128 if (scrPtr
->useMultiByte
)
129 return WMCreateFontSet(scrPtr
, fontName
);
131 return WMCreateNormalFont(scrPtr
, fontName
);
137 WMRetainFont(WMFont
*font
)
139 wassertrv(font
!=NULL
, NULL
);
148 WMReleaseFont(WMFont
*font
)
150 wassertr(font
!=NULL
);
153 if (font
->refCount
< 1) {
154 if (font
->notFontSet
)
155 XFreeFont(font
->screen
->display
, font
->font
.normal
);
157 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
160 WMHashRemove(font
->screen
->fontCache
, font
->name
);
170 WMFontHeight(WMFont
*font
)
172 wassertrv(font
!=NULL
, 0);
180 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
185 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.systemFont
, size
);
187 if (scrPtr
->useMultiByte
)
188 font
= WMCreateFontSet(scrPtr
, fontSpec
);
190 font
= WMCreateNormalFont(scrPtr
, fontSpec
);
193 if (scrPtr
->useMultiByte
) {
194 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
195 font
= WMCreateFontSet(scrPtr
, "fixed");
197 font
= WMCreateFontSet(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
200 wwarning("could not load font %s. Trying fixed.", fontSpec
);
201 font
= WMCreateNormalFont(scrPtr
, "fixed");
204 wwarning("could not load fixed font!");
216 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
221 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
223 if (scrPtr
->useMultiByte
)
224 font
= WMCreateFontSet(scrPtr
, fontSpec
);
226 font
= WMCreateNormalFont(scrPtr
, fontSpec
);
229 if (scrPtr
->useMultiByte
) {
230 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
231 font
= WMCreateFontSet(scrPtr
, "fixed");
233 font
= WMCreateFontSet(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
236 wwarning("could not load font %s. Trying fixed.", fontSpec
);
237 font
= WMCreateNormalFont(scrPtr
, "fixed");
240 wwarning("could not load fixed font!");
252 WMGetFontFontSet(WMFont
*font
)
254 wassertrv(font
!=NULL
, NULL
);
256 if (font
->notFontSet
)
259 return font
->font
.set
;
264 WMWidthOfString(WMFont
*font
, char *text
, int length
)
266 wassertrv(font
!=NULL
, 0);
267 wassertrv(text
!=NULL
, 0);
269 if (font
->notFontSet
)
270 return XTextWidth(font
->font
.normal
, text
, length
);
275 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
284 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
285 char *text
, int length
)
287 wassertr(font
!=NULL
);
289 if (font
->notFontSet
) {
290 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
291 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
293 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
300 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
301 char *text
, int length
)
303 wassertr(font
!= NULL
);
305 if (font
->notFontSet
) {
306 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
307 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
309 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
318 makeFontSetOfSize(char *fontset
, int size
)
328 ptr
= strchr(fontset
, ',');
333 if (strlen(fontset
)>255) {
334 wwarning("font description %s is too large.", fontset
);
336 sprintf(font
, fontset
, size
);
337 tmp
= wstrappend(newfs
, font
);