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
)
94 wassertrv(font
!=NULL
, NULL
);
103 WMReleaseFont(WMFont
*font
)
105 wassertr(font
!=NULL
);
108 if (font
->refCount
< 1) {
109 if (font
->notFontSet
)
110 XFreeFont(font
->screen
->display
, font
->font
.normal
);
112 XFreeFontSet(font
->screen
->display
, font
->font
.set
);
120 WMFontHeight(WMFont
*font
)
122 wassertrv(font
!=NULL
, 0);
131 WMSystemFontOfSize(WMScreen
*scrPtr
, int size
)
136 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.systemFont
, size
);
138 font
= WMCreateFont(scrPtr
, fontSpec
);
141 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
142 font
= WMCreateFont(scrPtr
, "fixed");
144 wwarning("could not load fixed font!");
156 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
161 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
163 font
= WMCreateFont(scrPtr
, fontSpec
);
166 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
167 font
= WMCreateFont(scrPtr
, "fixed");
169 wwarning("could not load fixed font!");
181 WMGetFontFontSet(WMFont
*font
)
183 wassertrv(font
!=NULL
, NULL
);
185 if (font
->notFontSet
)
188 return font
->font
.set
;
193 WMWidthOfString(WMFont
*font
, char *text
, int length
)
195 wassertrv(font
!=NULL
, 0);
196 wassertrv(text
!=NULL
, 0);
198 if (font
->notFontSet
)
199 return XTextWidth(font
->font
.normal
, text
, length
);
204 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
213 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
214 char *text
, int length
)
216 wassertr(font
!=NULL
);
218 if (font
->notFontSet
) {
219 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
220 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
222 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
229 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
230 char *text
, int length
)
232 wassertr(font
!= NULL
);
234 if (font
->notFontSet
) {
235 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
236 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
238 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
247 makeFontSetOfSize(char *fontset
, int size
)
257 ptr
= strchr(fontset
, ',');
262 if (strlen(fontset
)>255) {
263 wwarning("font description %s is too large.", fontset
);
265 sprintf(font
, fontset
, size
);
266 tmp
= wstrappend(newfs
, font
);