textextents_l.c (834B)
1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "../x11.h" 5 6 Rectangle 7 textextents_l(Font *font, const char *text, uint len, int *offset) { 8 Rectangle rect; 9 XRectangle r; 10 XGlyphInfo i; 11 int unused; 12 13 if(!offset) 14 offset = &unused; 15 16 switch(font->type) { 17 case FFontSet: 18 *offset = Xutf8TextExtents(font->font.set, text, len, &r, nil); 19 return Rect(r.x, -r.y - r.height, r.x + r.width, -r.y); 20 case FXft: 21 xft->textextents(display, font->font.xft, text, len, &i); 22 *offset = i.xOff; 23 return Rect(-i.x, i.y - i.height, -i.x + i.width, i.y); 24 case FX11: 25 rect = ZR; 26 rect.max.x = XTextWidth(font->font.x11, text, len); 27 rect.max.y = font->ascent; 28 *offset = rect.max.x; 29 return rect; 30 default: 31 die("Invalid font type"); 32 return ZR; /* shut up ken */ 33 } 34 }