]>
Dogcows Code - chaz/openbox/blob - render/font.c
1 #include "../kernel/openbox.h"
4 #include "../kernel/gettext.h"
5 #define _(str) gettext(str)
7 #include <X11/Xft/Xft.h>
9 #include "../kernel/geom.h"
11 void font_startup(void)
17 g_warning(_("Couldn't initialize Xft.\n"));
21 version
= XftGetVersion();
22 g_message("Using Xft %d.%d.%d (Built against %d.%d.%d).",
23 version
/ 10000 % 100, version
/ 100 % 100, version
% 100,
24 XFT_MAJOR
, XFT_MINOR
, XFT_REVISION
);
28 static void measure_height(ObFont
*f
)
33 /* XXX add some extended UTF8 characters in here? */
34 str
= "12345678900-qwertyuiopasdfghjklzxcvbnm"
35 "!@#$%^&*()_+QWERTYUIOPASDFGHJKLZXCVBNM"
36 "`~[]\\;',./{}|:\"<>?";
38 XftTextExtentsUtf8(ob_display
, f
->xftfont
,
39 (FcChar8
*)str
, strlen(str
), &info
);
40 f
->height
= (signed) info
.height
;
43 ObFont
*font_open(char *fontstring
)
48 if ((xf
= XftFontOpenName(ob_display
, ob_screen
, fontstring
))) {
49 out
= g_new(ObFont
, 1);
54 g_warning(_("Unable to load font: %s\n"), fontstring
);
55 g_warning(_("Trying fallback font: %s\n"), "sans");
57 if ((xf
= XftFontOpenName(ob_display
, ob_screen
, "sans"))) {
58 out
= g_new(ObFont
, 1);
63 g_warning(_("Unable to load font: %s\n"), "sans");
64 g_warning(_("Aborting!.\n"));
66 exit(3); /* can't continue without a font */
69 void font_close(ObFont
*f
)
71 XftFontClose(ob_display
, f
->xftfont
);
75 int font_measure_string(ObFont
*f
, char *str
, int shadow
, int offset
)
79 XftTextExtentsUtf8(ob_display
, f
->xftfont
,
80 (FcChar8
*)str
, strlen(str
), &info
);
82 return (signed) info
.xOff
+ (shadow
? offset
: 0);
85 int font_height(ObFont
*f
, int shadow
, int offset
)
87 return f
->height
+ (shadow
? offset
: 0);
90 int font_max_char_width(ObFont
*f
)
92 return (signed) f
->xftfont
->max_advance_width
;
95 void font_draw(XftDraw
*d
, TextureText
*t
, Rect
*position
)
103 h
= position
->height
;
105 /* accomidate for areas bigger/smaller than Xft thinks the font is tall */
106 y
-= (2 * (t
->font
->xftfont
->ascent
+ t
->font
->xftfont
->descent
) -
107 (t
->font
->height
+ h
) - 1) / 2;
109 x
+= 3; /* XXX figure out X with justification */
116 c
.color
.alpha
= 0xffff * t
->tint
/ 100; /* transparent shadow */
117 c
.pixel
= BlackPixel(ob_display
, ob_screen
);
119 c
.color
.red
= 0xffff * -t
->tint
/ 100;
120 c
.color
.green
= 0xffff * -t
->tint
/ 100;
121 c
.color
.blue
= 0xffff * -t
->tint
/ 100;
122 c
.color
.alpha
= 0xffff * -t
->tint
/ 100; /* transparent shadow */
123 c
.pixel
= WhitePixel(ob_display
, ob_screen
);
125 XftDrawStringUtf8(d
, &c
, t
->font
->xftfont
, x
+ t
->offset
,
126 t
->font
->xftfont
->ascent
+ y
+ t
->offset
,
127 (FcChar8
*)t
->string
, strlen(t
->string
));
129 c
.color
.red
= t
->color
->r
| t
->color
->r
<< 8;
130 c
.color
.green
= t
->color
->g
| t
->color
->g
<< 8;
131 c
.color
.blue
= t
->color
->b
| t
->color
->b
<< 8;
132 c
.color
.alpha
= 0xff | 0xff << 8; /* fully opaque text */
133 c
.pixel
= t
->color
->pixel
;
135 XftDrawStringUtf8(d
, &c
, t
->font
->xftfont
, x
,
136 t
->font
->xftfont
->ascent
+ y
,
137 (FcChar8
*)t
->string
, strlen(t
->string
));
This page took 0.038384 seconds and 4 git commands to generate.