diff options
| author | Eric Pruitt <eric.pruitt@gmail.com> | 2015-03-05 20:26:11 -0800 |
|---|---|---|
| committer | Anselm R Garbe <garbeam@gmail.com> | 2015-03-13 21:44:22 +0100 |
| commit | 14343e69cc596b847f71f1e825d3019ab1a29aa8 (patch) | |
| tree | bf7b0bede9b451f7f8e78e0d47fda511201622d8 /drw.c | |
| parent | removed .hgtags, thanks Dimitris for spotting (diff) | |
| download | dwm-14343e69cc596b847f71f1e825d3019ab1a29aa8.tar.gz dwm-14343e69cc596b847f71f1e825d3019ab1a29aa8.zip | |
Add Xft and follback-fonts support to graphics lib
Diffstat (limited to '')
| -rw-r--r-- | drw.c | 349 |
1 files changed, 267 insertions, 82 deletions
| @@ -3,10 +3,59 @@ | |||
| 3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
| 4 | #include <string.h> | 4 | #include <string.h> |
| 5 | #include <X11/Xlib.h> | 5 | #include <X11/Xlib.h> |
| 6 | #include <X11/Xft/Xft.h> | ||
| 6 | 7 | ||
| 7 | #include "drw.h" | 8 | #include "drw.h" |
| 8 | #include "util.h" | 9 | #include "util.h" |
| 9 | 10 | ||
| 11 | #define UTF_INVALID 0xFFFD | ||
| 12 | #define UTF_SIZ 4 | ||
| 13 | |||
| 14 | static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; | ||
| 15 | static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; | ||
| 16 | static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; | ||
| 17 | static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; | ||
| 18 | |||
| 19 | static long | ||
| 20 | utf8decodebyte(const char c, size_t *i) { | ||
| 21 | for(*i = 0; *i < (UTF_SIZ + 1); ++(*i)) | ||
| 22 | if(((unsigned char)c & utfmask[*i]) == utfbyte[*i]) | ||
| 23 | return (unsigned char)c & ~utfmask[*i]; | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | static size_t | ||
| 28 | utf8validate(long *u, size_t i) { | ||
| 29 | if(!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) | ||
| 30 | *u = UTF_INVALID; | ||
| 31 | for(i = 1; *u > utfmax[i]; ++i) | ||
| 32 | ; | ||
| 33 | return i; | ||
| 34 | } | ||
| 35 | |||
| 36 | static size_t | ||
| 37 | utf8decode(const char *c, long *u, size_t clen) { | ||
| 38 | size_t i, j, len, type; | ||
| 39 | long udecoded; | ||
| 40 | |||
| 41 | *u = UTF_INVALID; | ||
| 42 | if(!clen) | ||
| 43 | return 0; | ||
| 44 | udecoded = utf8decodebyte(c[0], &len); | ||
| 45 | if(!BETWEEN(len, 1, UTF_SIZ)) | ||
| 46 | return 1; | ||
| 47 | for(i = 1, j = 1; i < clen && j < len; ++i, ++j) { | ||
| 48 | udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); | ||
| 49 | if(type != 0) | ||
| 50 | return j; | ||
| 51 | } | ||
| 52 | if(j < len) | ||
| 53 | return 0; | ||
| 54 | *u = udecoded; | ||
| 55 | utf8validate(u, len); | ||
| 56 | return len; | ||
| 57 | } | ||
| 58 | |||
| 10 | Drw * | 59 | Drw * |
| 11 | drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) { | 60 | drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) { |
| 12 | Drw *drw = (Drw *)calloc(1, sizeof(Drw)); | 61 | Drw *drw = (Drw *)calloc(1, sizeof(Drw)); |
| @@ -19,6 +68,7 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h | |||
| 19 | drw->h = h; | 68 | drw->h = h; |
| 20 | drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); | 69 | drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); |
| 21 | drw->gc = XCreateGC(dpy, root, 0, NULL); | 70 | drw->gc = XCreateGC(dpy, root, 0, NULL); |
| 71 | drw->fontcount = 0; | ||
| 22 | XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); | 72 | XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); |
| 23 | return drw; | 73 | return drw; |
| 24 | } | 74 | } |
| @@ -36,56 +86,88 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h) { | |||
| 36 | 86 | ||
| 37 | void | 87 | void |
| 38 | drw_free(Drw *drw) { | 88 | drw_free(Drw *drw) { |
| 89 | size_t i; | ||
| 90 | for (i = 0; i < drw->fontcount; i++) { | ||
| 91 | drw_font_free(drw->fonts[i]); | ||
| 92 | } | ||
| 39 | XFreePixmap(drw->dpy, drw->drawable); | 93 | XFreePixmap(drw->dpy, drw->drawable); |
| 40 | XFreeGC(drw->dpy, drw->gc); | 94 | XFreeGC(drw->dpy, drw->gc); |
| 41 | free(drw); | 95 | free(drw); |
| 42 | } | 96 | } |
| 43 | 97 | ||
| 44 | Fnt * | 98 | /* This function is an implementation detail. Library users should use |
| 45 | drw_font_create(Display *dpy, const char *fontname) { | 99 | * drw_font_create instead. |
| 100 | */ | ||
| 101 | static Fnt * | ||
| 102 | drw_font_xcreate(Drw *drw, const char *fontname, FcPattern *fontpattern) { | ||
| 46 | Fnt *font; | 103 | Fnt *font; |
| 47 | char *def, **missing; | ||
| 48 | int n; | ||
| 49 | 104 | ||
| 50 | font = (Fnt *)calloc(1, sizeof(Fnt)); | 105 | if (!(fontname || fontpattern)) |
| 51 | if(!font) | 106 | die("No font specified.\n"); |
| 107 | |||
| 108 | if (!(font = (Fnt *)calloc(1, sizeof(Fnt)))) | ||
| 52 | return NULL; | 109 | return NULL; |
| 53 | font->set = XCreateFontSet(dpy, fontname, &missing, &n, &def); | 110 | |
| 54 | if(missing) { | 111 | if (fontname) { |
| 55 | while(n--) | 112 | /* Using the pattern found at font->xfont->pattern does not yield same |
| 56 | fprintf(stderr, "drw: missing fontset: %s\n", missing[n]); | 113 | * the same substitution results as using the pattern returned by |
| 57 | XFreeStringList(missing); | 114 | * FcNameParse; using the latter results in the desired fallback |
| 58 | } | 115 | * behaviour whereas the former just results in |
| 59 | if(font->set) { | 116 | * missing-character-rectangles being drawn, at least with some fonts. |
| 60 | XFontStruct **xfonts; | 117 | */ |
| 61 | char **font_names; | 118 | if (!(font->xfont = XftFontOpenName(drw->dpy, drw->screen, fontname)) || |
| 62 | XExtentsOfFontSet(font->set); | 119 | !(font->pattern = FcNameParse((FcChar8 *) fontname))) { |
| 63 | n = XFontsOfFontSet(font->set, &xfonts, &font_names); | 120 | if (font->xfont) { |
| 64 | while(n--) { | 121 | XftFontClose(drw->dpy, font->xfont); |
| 65 | font->ascent = MAX(font->ascent, (*xfonts)->ascent); | 122 | font->xfont = NULL; |
| 66 | font->descent = MAX(font->descent,(*xfonts)->descent); | 123 | } |
| 67 | xfonts++; | 124 | fprintf(stderr, "error, cannot load font: '%s'\n", fontname); |
| 125 | } | ||
| 126 | } else if (fontpattern) { | ||
| 127 | if (!(font->xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { | ||
| 128 | fprintf(stderr, "error, cannot load font pattern.\n"); | ||
| 129 | } else { | ||
| 130 | font->pattern = NULL; | ||
| 68 | } | 131 | } |
| 69 | } | 132 | } |
| 70 | else { | 133 | |
| 71 | if(!(font->xfont = XLoadQueryFont(dpy, fontname)) | 134 | if (!font->xfont) { |
| 72 | && !(font->xfont = XLoadQueryFont(dpy, "fixed"))) | 135 | free(font); |
| 73 | die("error, cannot load font: '%s'\n", fontname); | 136 | return NULL; |
| 74 | font->ascent = font->xfont->ascent; | ||
| 75 | font->descent = font->xfont->descent; | ||
| 76 | } | 137 | } |
| 138 | |||
| 139 | font->ascent = font->xfont->ascent; | ||
| 140 | font->descent = font->xfont->descent; | ||
| 77 | font->h = font->ascent + font->descent; | 141 | font->h = font->ascent + font->descent; |
| 142 | font->dpy = drw->dpy; | ||
| 78 | return font; | 143 | return font; |
| 79 | } | 144 | } |
| 80 | 145 | ||
| 146 | Fnt* | ||
| 147 | drw_font_create(Drw *drw, const char *fontname) { | ||
| 148 | return drw_font_xcreate(drw, fontname, NULL); | ||
| 149 | } | ||
| 150 | |||
| 151 | void | ||
| 152 | drw_load_fonts(Drw* drw, const char *fonts[], size_t fontcount) { | ||
| 153 | size_t i; | ||
| 154 | Fnt *font; | ||
| 155 | for (i = 0; i < fontcount; i++) { | ||
| 156 | if (drw->fontcount >= DRW_FONT_CACHE_SIZE) { | ||
| 157 | die("Font cache exhausted.\n"); | ||
| 158 | } else if ((font = drw_font_xcreate(drw, fonts[i], NULL))) { | ||
| 159 | drw->fonts[drw->fontcount++] = font; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 81 | void | 164 | void |
| 82 | drw_font_free(Display *dpy, Fnt *font) { | 165 | drw_font_free(Fnt *font) { |
| 83 | if(!font) | 166 | if(!font) |
| 84 | return; | 167 | return; |
| 85 | if(font->set) | 168 | if(font->pattern) |
| 86 | XFreeFontSet(dpy, font->set); | 169 | FcPatternDestroy(font->pattern); |
| 87 | else | 170 | XftFontClose(font->dpy, font->xfont); |
| 88 | XFreeFont(dpy, font->xfont); | ||
| 89 | free(font); | 171 | free(font); |
| 90 | } | 172 | } |
| 91 | 173 | ||
| @@ -93,7 +175,7 @@ Clr * | |||
| 93 | drw_clr_create(Drw *drw, const char *clrname) { | 175 | drw_clr_create(Drw *drw, const char *clrname) { |
| 94 | Clr *clr; | 176 | Clr *clr; |
| 95 | Colormap cmap; | 177 | Colormap cmap; |
| 96 | XColor color; | 178 | Visual *vis; |
| 97 | 179 | ||
| 98 | if(!drw) | 180 | if(!drw) |
| 99 | return NULL; | 181 | return NULL; |
| @@ -101,9 +183,10 @@ drw_clr_create(Drw *drw, const char *clrname) { | |||
| 101 | if(!clr) | 183 | if(!clr) |
| 102 | return NULL; | 184 | return NULL; |
| 103 | cmap = DefaultColormap(drw->dpy, drw->screen); | 185 | cmap = DefaultColormap(drw->dpy, drw->screen); |
| 104 | if(!XAllocNamedColor(drw->dpy, cmap, clrname, &color, &color)) | 186 | vis = DefaultVisual(drw->dpy, drw->screen); |
| 187 | if(!XftColorAllocName(drw->dpy, vis, cmap, clrname, &clr->rgb)) | ||
| 105 | die("error, cannot allocate color '%s'\n", clrname); | 188 | die("error, cannot allocate color '%s'\n", clrname); |
| 106 | clr->rgb = color.pixel; | 189 | clr->pix = clr->rgb.pixel; |
| 107 | return clr; | 190 | return clr; |
| 108 | } | 191 | } |
| 109 | 192 | ||
| @@ -114,14 +197,8 @@ drw_clr_free(Clr *clr) { | |||
| 114 | } | 197 | } |
| 115 | 198 | ||
| 116 | void | 199 | void |
| 117 | drw_setfont(Drw *drw, Fnt *font) { | ||
| 118 | if(drw) | ||
| 119 | drw->font = font; | ||
| 120 | } | ||
| 121 | |||
| 122 | void | ||
| 123 | drw_setscheme(Drw *drw, ClrScheme *scheme) { | 200 | drw_setscheme(Drw *drw, ClrScheme *scheme) { |
| 124 | if(drw && scheme) | 201 | if(drw && scheme) |
| 125 | drw->scheme = scheme; | 202 | drw->scheme = scheme; |
| 126 | } | 203 | } |
| 127 | 204 | ||
| @@ -129,46 +206,160 @@ void | |||
| 129 | drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) { | 206 | drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) { |
| 130 | int dx; | 207 | int dx; |
| 131 | 208 | ||
| 132 | if(!drw || !drw->font || !drw->scheme) | 209 | if(!drw || !drw->fontcount || !drw->scheme) |
| 133 | return; | 210 | return; |
| 134 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb); | 211 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->pix : drw->scheme->fg->pix); |
| 135 | dx = (drw->font->ascent + drw->font->descent + 2) / 4; | 212 | dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4; |
| 136 | if(filled) | 213 | if(filled) |
| 137 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1); | 214 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1); |
| 138 | else if(empty) | 215 | else if(empty) |
| 139 | XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx, dx); | 216 | XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx, dx); |
| 140 | } | 217 | } |
| 141 | 218 | ||
| 142 | void | 219 | int |
| 143 | drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) { | 220 | drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert) { |
| 144 | char buf[256]; | 221 | char buf[1024]; |
| 145 | int i, tx, ty, th, len, olen; | 222 | int tx, ty, th; |
| 146 | Extnts tex; | 223 | Extnts tex; |
| 224 | Colormap cmap; | ||
| 225 | Visual *vis; | ||
| 226 | XftDraw *d; | ||
| 227 | Fnt *curfont, *nextfont; | ||
| 228 | size_t i, len; | ||
| 229 | int utf8strlen, utf8charlen, render; | ||
| 230 | long utf8codepoint = 0; | ||
| 231 | const char *utf8str; | ||
| 232 | FcCharSet *fccharset; | ||
| 233 | FcPattern *fcpattern; | ||
| 234 | FcPattern *match; | ||
| 235 | XftResult result; | ||
| 236 | int charexists = 0; | ||
| 147 | 237 | ||
| 148 | if(!drw || !drw->scheme) | 238 | if (!(render = x || y || w || h)) { |
| 149 | return; | 239 | w = ~w; |
| 150 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->rgb : drw->scheme->bg->rgb); | 240 | } |
| 151 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); | 241 | |
| 152 | if(!text || !drw->font) | 242 | if (!drw || !drw->scheme) { |
| 153 | return; | 243 | return 0; |
| 154 | olen = strlen(text); | 244 | } else if (render) { |
| 155 | drw_font_getexts(drw->font, text, olen, &tex); | 245 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->pix : drw->scheme->bg->pix); |
| 156 | th = drw->font->ascent + drw->font->descent; | 246 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); |
| 157 | ty = y + (h / 2) - (th / 2) + drw->font->ascent; | 247 | } |
| 158 | tx = x + (h / 2); | 248 | |
| 159 | /* shorten text if necessary */ | 249 | if (!text || !drw->fontcount) { |
| 160 | for(len = MIN(olen, sizeof buf); len && (tex.w > w - tex.h || w < tex.h); len--) | 250 | return 0; |
| 161 | drw_font_getexts(drw->font, text, len, &tex); | 251 | } else if (render) { |
| 162 | if(!len) | 252 | cmap = DefaultColormap(drw->dpy, drw->screen); |
| 163 | return; | 253 | vis = DefaultVisual(drw->dpy, drw->screen); |
| 164 | memcpy(buf, text, len); | 254 | d = XftDrawCreate(drw->dpy, drw->drawable, vis, cmap); |
| 165 | if(len < olen) | 255 | } |
| 166 | for(i = len; i && i > len - 3; buf[--i] = '.'); | 256 | |
| 167 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb); | 257 | curfont = drw->fonts[0]; |
| 168 | if(drw->font->set) | 258 | while (1) { |
| 169 | XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len); | 259 | utf8strlen = 0; |
| 170 | else | 260 | utf8str = text; |
| 171 | XDrawString(drw->dpy, drw->drawable, drw->gc, tx, ty, buf, len); | 261 | nextfont = NULL; |
| 262 | while (*text) { | ||
| 263 | utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); | ||
| 264 | for (i = 0; i < drw->fontcount; i++) { | ||
| 265 | charexists = charexists || XftCharExists(drw->dpy, drw->fonts[i]->xfont, utf8codepoint); | ||
| 266 | if (charexists) { | ||
| 267 | if (drw->fonts[i] == curfont) { | ||
| 268 | utf8strlen += utf8charlen; | ||
| 269 | text += utf8charlen; | ||
| 270 | } else { | ||
| 271 | nextfont = drw->fonts[i]; | ||
| 272 | } | ||
| 273 | break; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | if (!charexists || (nextfont && nextfont != curfont)) { | ||
| 278 | break; | ||
| 279 | } else { | ||
| 280 | charexists = 0; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | if (utf8strlen) { | ||
| 285 | drw_font_getexts(curfont, utf8str, utf8strlen, &tex); | ||
| 286 | /* shorten text if necessary */ | ||
| 287 | for(len = MIN(utf8strlen, (sizeof buf) - 1); len && (tex.w > w - drw->fonts[0]->h || w < drw->fonts[0]->h); len--) | ||
| 288 | drw_font_getexts(curfont, utf8str, len, &tex); | ||
| 289 | |||
| 290 | if (len) { | ||
| 291 | memcpy(buf, utf8str, len); | ||
| 292 | buf[len] = '\0'; | ||
| 293 | if(len < utf8strlen) | ||
| 294 | for(i = len; i && i > len - 3; buf[--i] = '.'); | ||
| 295 | |||
| 296 | if (render) { | ||
| 297 | th = curfont->ascent + curfont->descent; | ||
| 298 | ty = y + (h / 2) - (th / 2) + curfont->ascent; | ||
| 299 | tx = x + (h / 2); | ||
| 300 | XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); | ||
| 301 | } | ||
| 302 | |||
| 303 | x += tex.w; | ||
| 304 | w -= tex.w; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | if (!*text) { | ||
| 309 | break; | ||
| 310 | } else if (nextfont) { | ||
| 311 | charexists = 0; | ||
| 312 | curfont = nextfont; | ||
| 313 | } else { | ||
| 314 | /* Regardless of whether or not a fallback font is found, the | ||
| 315 | * character must be drawn. | ||
| 316 | */ | ||
| 317 | charexists = 1; | ||
| 318 | |||
| 319 | if (drw->fontcount >= DRW_FONT_CACHE_SIZE) { | ||
| 320 | continue; | ||
| 321 | } | ||
| 322 | |||
| 323 | fccharset = FcCharSetCreate(); | ||
| 324 | FcCharSetAddChar(fccharset, utf8codepoint); | ||
| 325 | |||
| 326 | if (!drw->fonts[0]->pattern) { | ||
| 327 | /* Refer to the comment in drw_font_xcreate for more | ||
| 328 | * information. | ||
| 329 | */ | ||
| 330 | die("The first font in the cache must be loaded from a font string.\n"); | ||
| 331 | } | ||
| 332 | |||
| 333 | fcpattern = FcPatternDuplicate(drw->fonts[0]->pattern); | ||
| 334 | FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); | ||
| 335 | FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); | ||
| 336 | |||
| 337 | FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); | ||
| 338 | FcDefaultSubstitute(fcpattern); | ||
| 339 | match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); | ||
| 340 | |||
| 341 | FcCharSetDestroy(fccharset); | ||
| 342 | FcPatternDestroy(fcpattern); | ||
| 343 | |||
| 344 | if (match) { | ||
| 345 | curfont = drw_font_xcreate(drw, NULL, match); | ||
| 346 | if (curfont && XftCharExists(drw->dpy, curfont->xfont, utf8codepoint)) { | ||
| 347 | drw->fonts[drw->fontcount++] = curfont; | ||
| 348 | } else { | ||
| 349 | if (curfont) { | ||
| 350 | drw_font_free(curfont); | ||
| 351 | } | ||
| 352 | curfont = drw->fonts[0]; | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 358 | if (render) { | ||
| 359 | XftDrawDestroy(d); | ||
| 360 | } | ||
| 361 | |||
| 362 | return x; | ||
| 172 | } | 363 | } |
| 173 | 364 | ||
| 174 | void | 365 | void |
| @@ -182,19 +373,13 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) { | |||
| 182 | 373 | ||
| 183 | void | 374 | void |
| 184 | drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) { | 375 | drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) { |
| 185 | XRectangle r; | 376 | XGlyphInfo ext; |
| 186 | 377 | ||
| 187 | if(!font || !text) | 378 | if(!font || !text) |
| 188 | return; | 379 | return; |
| 189 | if(font->set) { | 380 | XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); |
| 190 | XmbTextExtents(font->set, text, len, NULL, &r); | 381 | tex->h = font->h; |
| 191 | tex->w = r.width; | 382 | tex->w = ext.xOff; |
| 192 | tex->h = r.height; | ||
| 193 | } | ||
| 194 | else { | ||
| 195 | tex->h = font->ascent + font->descent; | ||
| 196 | tex->w = XTextWidth(font->xfont, text, len); | ||
| 197 | } | ||
| 198 | } | 383 | } |
| 199 | 384 | ||
| 200 | unsigned int | 385 | unsigned int |
