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
= malloc(sizeof(WMFont
));
81 memset(font
, 0, sizeof(WMFont
));
85 font
->screen
= scrPtr
;
87 font
->font
.normal
= XLoadQueryFont(display
, fontName
);
88 if (!font
->font
.normal
) {
93 font
->height
= font
->font
.normal
->ascent
+font
->font
.normal
->descent
;
94 font
->y
= font
->font
.normal
->ascent
;
104 WMRetainFont(WMFont
*font
)
106 wassertrv(font
!=NULL
, NULL
);
115 WMReleaseFont(WMFont
*font
)
117 wassertr(font
!=NULL
);
120 if (font
->refCount
< 1) {
121 if (font
->notFontSet
)
122 XFreeFont(font
->screen
->display
, font
->font
.normal
);
124 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
127 WMHashRemove(font
->screen
->fontCache
, font
->name
);
137 WMFontHeight(WMFont
*font
)
139 wassertrv(font
!=NULL
, 0);
148 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
153 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.systemFont
, size
);
155 font
= WMCreateFont(scrPtr
, fontSpec
);
158 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
159 font
= WMCreateFont(scrPtr
, "fixed");
161 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
164 wwarning("could not load fixed font!");
176 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
181 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
183 font
= WMCreateFont(scrPtr
, fontSpec
);
186 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
187 font
= WMCreateFont(scrPtr
, "fixed");
189 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
192 wwarning("could not load fixed font!");
204 WMGetFontFontSet(WMFont
*font
)
206 wassertrv(font
!=NULL
, NULL
);
208 if (font
->notFontSet
)
211 return font
->font
.set
;
216 WMWidthOfString(WMFont
*font
, char *text
, int length
)
218 wassertrv(font
!=NULL
, 0);
219 wassertrv(text
!=NULL
, 0);
221 if (font
->notFontSet
)
222 return XTextWidth(font
->font
.normal
, text
, length
);
227 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
236 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
237 char *text
, int length
)
239 wassertr(font
!=NULL
);
241 if (font
->notFontSet
) {
242 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
243 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
245 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
252 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
253 char *text
, int length
)
255 wassertr(font
!= NULL
);
257 if (font
->notFontSet
) {
258 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
259 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
261 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
270 makeFontSetOfSize(char *fontset
, int size
)
280 ptr
= strchr(fontset
, ',');
285 if (strlen(fontset
)>255) {
286 wwarning("font description %s is too large.", fontset
);
288 sprintf(font
, fontset
, size
);
289 tmp
= wstrappend(newfs
, font
);