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 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
147 wwarning("could not load fixed font!");
159 WMBoldSystemFontOfSize(WMScreen
*scrPtr
, int size
)
164 fontSpec
= makeFontSetOfSize(WINGsConfiguration
.boldSystemFont
, size
);
166 font
= WMCreateFont(scrPtr
, fontSpec
);
169 wwarning("could not load font set %s. Trying fixed.", fontSpec
);
170 font
= WMCreateFont(scrPtr
, "fixed");
172 font
= WMCreateFont(scrPtr
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*");
175 wwarning("could not load fixed font!");
187 WMGetFontFontSet(WMFont
*font
)
189 wassertrv(font
!=NULL
, NULL
);
191 if (font
->notFontSet
)
194 return font
->font
.set
;
199 WMWidthOfString(WMFont
*font
, char *text
, int length
)
201 wassertrv(font
!=NULL
, 0);
202 wassertrv(text
!=NULL
, 0);
204 if (font
->notFontSet
)
205 return XTextWidth(font
->font
.normal
, text
, length
);
210 XmbTextExtents(font
->font
.set
, text
, length
, &AIXsucks
, &rect
);
219 WMDrawString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
220 char *text
, int length
)
222 wassertr(font
!=NULL
);
224 if (font
->notFontSet
) {
225 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
226 XDrawString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
228 XmbDrawString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
235 WMDrawImageString(WMScreen
*scr
, Drawable d
, GC gc
, WMFont
*font
, int x
, int y
,
236 char *text
, int length
)
238 wassertr(font
!= NULL
);
240 if (font
->notFontSet
) {
241 XSetFont(scr
->display
, gc
, font
->font
.normal
->fid
);
242 XDrawImageString(scr
->display
, d
, gc
, x
, y
+ font
->y
, text
, length
);
244 XmbDrawImageString(scr
->display
, d
, font
->font
.set
, gc
, x
, y
+ font
->y
,
253 makeFontSetOfSize(char *fontset
, int size
)
263 ptr
= strchr(fontset
, ',');
268 if (strlen(fontset
)>255) {
269 wwarning("font description %s is too large.", fontset
);
271 sprintf(font
, fontset
, size
);
272 tmp
= wstrappend(newfs
, font
);