]>
Dogcows Code - chaz/openbox/blob - render/font.c
2 #include <X11/Xft/Xft.h>
3 #include "../kernel/openbox.h"
6 #include "../src/gettext.h"
7 #define _(str) gettext(str)
9 void font_startup(void)
15 g_warning(_("Couldn't initialize Xft.\n\n"));
19 version
= XftGetVersion();
20 g_message("Using Xft %d.%d.%d (Built against %d.%d.%d).\n",
21 version
/ 10000 % 100, version
/ 100 % 100, version
% 100,
22 XFT_MAJOR
, XFT_MINOR
, XFT_REVISION
);
26 ObFont
*font_open(char *fontstring
)
31 if ((xf
= XftFontOpenName(ob_display
, ob_screen
, fontstring
))) {
32 out
= malloc(sizeof(ObFont
));
36 g_warning(_("Unable to load font: %s\n"), fontstring
);
37 g_warning(_("Trying fallback font: %s\n"), "fixed");
39 if ((xf
= XftFontOpenName(ob_display
, ob_screen
, "fixed"))) {
40 out
= malloc(sizeof(ObFont
));
44 g_warning(_("Unable to load font: %s\n"), "fixed");
45 g_warning(_("Aborting!.\n"));
47 exit(3); // can't continue without a font
50 void font_close(ObFont
*f
)
52 XftFontClose(ob_display
, f
->xftfont
);
55 int font_measure_string(ObFont
*f
, const char *str
, int shadow
, int offset
)
59 XftTextExtentsUtf8(ob_display
, f
->xftfont
,
60 (FcChar8
*)str
, strlen(str
), &info
);
62 return (signed) info
.xOff
+ (shadow
? offset
: 0);
65 int font_height(ObFont
*f
, int shadow
, int offset
)
67 return (signed) f
->xftfont
->height
+ (shadow
? offset
: 0);
70 int font_max_char_width(ObFont
*f
)
72 return (signed) f
->xftfont
->max_advance_width
;
75 void font_draw(XftDraw
*d
, TextureText
*t
)
83 c
.color
.alpha
= t
->tint
| t
->tint
<< 8; // transparent shadow
84 c
.pixel
= BlackPixel(ob_display
, ob_screen
);
86 XftDrawStringUtf8(d
, &c
, t
->font
->xftfont
, x
+ t
->offset
,
87 t
->font
->xftfont
->ascent
+ y
+ t
->offset
,
88 (FcChar8
*)t
->string
, strlen(t
->string
));
90 c
.color
.red
= t
->color
->r
| t
->color
->r
<< 8;
91 c
.color
.green
= t
->color
->g
| t
->color
->g
<< 8;
92 c
.color
.blue
= t
->color
->b
| t
->color
->b
<< 8;
93 c
.pixel
= t
->color
->pixel
;
94 c
.color
.alpha
= 0xff | 0xff << 8; // no transparency in Color yet
96 XftDrawStringUtf8(d
, &c
, t
->font
->xftfont
, x
, t
->font
->xftfont
->ascent
+ y
,
97 (FcChar8
*)t
->string
, strlen(t
->string
));
This page took 0.04546 seconds and 4 git commands to generate.