static void desktops(int start) { char buf[4]; XGlyphInfo extents; int x, i, curdesk, numdesk; int cellwidth = 14; curdesk = get_int_property("_NET_CURRENT_DESKTOP"); numdesk = get_int_property("_NET_NUMBER_OF_DESKTOPS"); if (curdesk < 0 || numdesk < 0) return; for (i=0, x=start; i<numdesk; i++, x+=cellwidth) { sprintf(buf, "%d", i+1); if (i == curdesk) { XftDrawRect(xftd, &white, x, 0, cellwidth, BARHEIGHT); XftTextExtentsUtf8(d, xftfont, (const FcChar8 *)buf, strlen(buf), &extents); XftDrawStringUtf8(xftd, &black, xftfont, x + (cellwidth - extents.xOff) / 2, 2 + xftfont->ascent, (const FcChar8 *)buf, strlen(buf)); } else { XftDrawRect(xftd, &black, x, 0, cellwidth, BARHEIGHT); XftTextExtentsUtf8(d, xftfont, (const FcChar8 *)buf, strlen(buf), &extents); XftDrawStringUtf8(xftd, &white, xftfont, x + (cellwidth - extents.xOff) / 2, 2 + xftfont->ascent, (const FcChar8 *)buf, strlen(buf)); } } }
/*----------------------------------------------------------------------------*/ void VKCreateFontDialog() { static char *max_fnt_string = "Alt Control Shift ISO_Left_Tab"; int i, j, fh, fa, fw; #ifdef USE_XFT XGlyphInfo fi; fw = 2 * vk_font->max_advance_width; XftTextExtentsUtf8(display, vk_font, max_fnt_string, strlen(max_fnt_string), &fi); #else XRectangle fi; fw = 2 * vk_font->perchar['W'].width; XmbTextExtents(vk_fontset, max_fnt_string, strlen(max_fnt_string), 0, &fi); #endif fnt.width = (fi.width<300 ? 300 : fi.width+fw); fa = vk_text_ascent; fh = vk_text_height; fnt.ty = (fa + 5) + fh + 4; VKFontControlInit(20, 2 * (fh + 4) + 6, fnt.width - 20, fh+4); fnt.ly = 0;//fnt.name.y + fnt.name.h + fh/2; for( i=0; i<2; i++ ) { VKButtonControl *b = fb_actions[i]; #ifdef USE_XFT XftTextExtentsUtf8(display, vk_font, "Cancel", 6, &fi); #else XmbTextExtents(vk_fontset, "Cancel", 6, 0, &fi); #endif fw = fi.width; b[0].w = b[1].w = fw + 24; b[0].x = (fnt.width - 2 * b[0].w - 24) / 2; b[1].x = fnt.width - b[0].x - b[0].w; for( j=0; j<2; j++ ) { b[j].y = fnt.ly + fh/2; b[j].h = fh + 4; } } fnt.height = fb_actions[0][0].y + fh + 4 + fh/2; fnt.window = XCreateWindow(display, root, 0, 0, fnt.width, fnt.height, 0, DefaultDepth(display, screen), InputOutput, visual, vk_attribmask, &vk_attrib); XSelectInput(display, fnt.window, MAIN_EVENT_MASKS); XDefineCursor(display, fnt.window, vk_cursor); fnt.gc = XCreateGC(display, fnt.window, 0, 0); #ifndef USE_XFT XSetFont(display, fnt.gc, vk_font->fid); #endif VKRegisterEvent(fnt.window, VKFontProcess); DUMP("create done\n"); }
static void calc_widget_size(Widget w, Dimension *width, Dimension *height ) { CtrlWidget cw = (CtrlWidget)w; CtrlPart *c = & cw->ctrl; Display *dpy = XtDisplay(w); clabel_t *cl,*cu,*ct; char *s; Dimension total_w=0, total_h=0, stretch=0; TF(); total_w = total_h = 0; // top-left cl = c->clabel+LABEL; s=cl->str; if( ! IsEmpty(s) && cl->font ) { XftTextExtentsUtf8(dpy, cl->font, (FcChar8*)s, strlen(s), & cl->extents ); total_h = cl->font->height; total_w = cl->extents.xOff; } total_w += c->hspace +1; // top-right cu = c->clabel+UNIT; s=cu->str; if(! IsEmpty(s) && cu->font ) { XftTextExtentsUtf8(dpy, cu->font, (FcChar8*)s, strlen(s), & cu->extents ); total_w += cu->extents.xOff; total_h = Max( cu->font->height, total_h ); } total_h += c->vspace; // center bottom ct = c->clabel+TEXT; s=ct->str; if(! IsEmpty(s) && ct->font ) { XftTextExtentsUtf8(dpy, ct->font, (FcChar8*)s, strlen(s), & ct->extents ); total_w = Max( total_w,ct->extents.xOff ); total_h += ct->font->height; } *width = total_w; *height = total_h; TRACE(2,"%s %u %u", cw->core.name, total_w, total_h ); }
void zwm_decor_init(void) { int i; XGlyphInfo info; cmap = DefaultColormap(dpy, scr); gc = XCreateGC(dpy, root, 0, NULL); memset(icons,0,64); xfont = XftFontOpenName (dpy, scr, "DejaVu Sans-9:bold"); if(!xfont)xfont = XftFontOpenXlfd(dpy, scr, config.font); ifont = XftFontOpenName (dpy, scr, "DejaVu Sans-16:bold"); if(!ifont)ifont = XftFontOpenXlfd(dpy, scr, config.icons); XftColorAllocValue(dpy, DefaultVisual(dpy, scr), cmap, &xcolor.color, &xcolor); config.xcolor_nborder = alloc_color(config.normal_border_color); config.xcolor_fborder = alloc_color(config.focus_border_color); config.xcolor_nbg = alloc_color(config.normal_bg_color); config.xcolor_fbg = alloc_color(config.focus_bg_color); config.xcolor_flbg = alloc_color(config.float_bg_color); config.xcolor_nshadow = alloc_color(config.normal_shadow_color); config.xcolor_fshadow = alloc_color(config.focus_shadow_color); config.xcolor_ntitle = alloc_color(config.normal_title_color); config.xcolor_ftitle = alloc_color(config.focus_title_color); config.xcolor_root = alloc_color(config.root_bg_color); get_status(icons, 64); XftTextExtentsUtf8(dpy, xfont, (FcChar8*)" [000] ", 7, &info); char_width = info.width; XftTextExtentsUtf8(dpy, xfont, (FcChar8*)icons, strlen(icons), &info); date_width = info.width; icons[0] = 0; for(i=0; i<32 && config.buttons[i].func; i++){ strcat(icons, config.buttons[i].c); config.button_count = i+1; } if(config.button_count){ XftTextExtentsUtf8(dpy, ifont, (FcChar8*)icons, strlen(icons), &info); config.button_width = info.width / config.button_count; config.icon_y = info.height + (config.title_height - info.height)/2 + 1; } config.title_y = config.title_height - xfont->descent - 2; }
/** Calculates the text's size relatively to the font * \param text Text string * \return final text width */ ushort textw(char *text) { XGlyphInfo gl; #ifdef HAVE_IMLIB char *ostr = NULL; ImageAttr im[128]; size_t textlen; #endif /* HAVE_IMLIB */ if(!text) return 0; #ifdef HAVE_IMLIB ostr = xstrdup(text); textlen = strlen(ostr); if(strstr(text, "i[")) parse_image_block(im, text); #endif /* HAVE_IMLIB */ XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl); #ifdef HAVE_IMLIB if(strstr(ostr, "i[")) strncpy(text, ostr, textlen); free(ostr); #endif /* HAVE_IMLIB */ return gl.width + font->descent; }
int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y, char *text, int len, int w) { int err, tw = 0; char *t, *next; uint32_t rune; XftFont *f; FcCharSet *fccharset; XGlyphInfo ext; for (t = text; t - text < len; t = next) { next = utf8_decode(t, &rune, &err); if (XftCharExists(win->env.dpy, font, rune)) { f = font; } else { /* fallback font */ fccharset = FcCharSetCreate(); FcCharSetAddChar(fccharset, rune); f = XftFontOpen(win->env.dpy, win->env.scr, FC_CHARSET, FcTypeCharSet, fccharset, FC_SCALABLE, FcTypeBool, FcTrue, FC_SIZE, FcTypeDouble, fontsize, NULL); FcCharSetDestroy(fccharset); } XftTextExtentsUtf8(win->env.dpy, f, (XftChar8*)t, next - t, &ext); tw += ext.xOff; if (tw <= w) { XftDrawStringUtf8(d, color, f, x, y, (XftChar8*)t, next - t); x += ext.xOff; } if (f != font) XftFontClose(win->env.dpy, f); } return tw; }
int text_width(struct font *font, char *str) { XGlyphInfo ext; XftTextExtentsUtf8(dpy, font->xfont, (XftChar8 *)str, strlen(str), &ext); return ext.xOff; }
struct gui_font * gui_font_load(const char *name, unsigned int size, int flags) { struct gui_font *result; XGlyphInfo extents; XftFont *xft_font; char *xft_font_desc; xft_font_desc = alloca(strlen(name) + 64); sprintf(xft_font_desc, "%s:pixelsize=%d", name, size); if(flags & GUI_FONT_BOLD) strcat(xft_font_desc, ":bold"); if(0 == (xft_font = XftFontOpenName(GUI_display, GUI_screenidx, xft_font_desc))) return 0; result = malloc(sizeof(*result)); result->xft_font = xft_font; XftTextExtentsUtf8(GUI_display, xft_font, (const unsigned char *) " ", 1, &extents); result->space_width = extents.xOff; return result; }
JSize JXFontManager::GetCharWidth ( const JFontID fontID, const JSize size, const JFontStyle& style, const JCharacter c ) const { #ifdef _J_USE_XFT XftFont* xftfont = GetXftFont(fontID); XGlyphInfo extents; //XftTextExtents8(*itsDisplay, xftfont, (XftChar8*)&c, 1, &extents); XftTextExtentsUtf8(*itsDisplay, xftfont, (XftChar8*)&c, 1, &extents); return extents.xOff; #else XFontStruct* xfont = GetXFontInfo(fontID); if (xfont->min_bounds.width == xfont->max_bounds.width) { return xfont->min_bounds.width; } else { return XTextWidth(xfont, &c, 1); } #endif }
//========================================= // setText //----------------------------------------- XImage* setText (Display* dpy,int screen,char* text, int* x, int* y) { Window root = RootWindow ( dpy,screen ); int DWidth = DisplayWidth ( dpy,screen ); int DHeight = DisplayHeight ( dpy,screen ); XftPattern *pattern = NULL; XftFont* FTfont = NULL; XftDraw* FTdraw = NULL; XftColor* FTcolor = NULL; XImage* Image = NULL; XGlyphInfo FTinfo; XColor color; XGCValues values; int XTwidth; int XTheight; int x1,y1; pattern = XftNameParse (XFTFONT); pattern = XftFontMatch (dpy,screen,pattern,NULL); FTfont = XftFontOpenPattern (dpy, pattern); XftTextExtentsUtf8 ( dpy,FTfont,text,strlen(text),&FTinfo ); XTwidth = FTinfo.xOff; XTheight= FTfont->height + 20; FTdraw = XftDrawCreate ( dpy, root, DefaultVisual(dpy,screen),DefaultColormap(dpy,screen) ); FTcolor = (XftColor*)malloc(sizeof(XftColor)); color.red = 255 << 8; color.green = 255 << 8; color.blue = 255 << 8; XAllocColor (dpy,DefaultColormap(dpy,screen),&color); XSetForeground(dpy,DefaultGC (dpy,screen),color.pixel); XGetGCValues ( dpy, DefaultGC (dpy,screen), GCForeground | GCBackground, &values ); FTcolor->color.red = color.red; FTcolor->color.green = color.green; FTcolor->color.blue = color.blue; FTcolor->color.alpha = 0xffff; x1 = (int)((DWidth / 2) - (XTwidth / 2)); y1 = (int)((DHeight / 2) - (XTheight / 2)); XftDrawStringUtf8 ( FTdraw, FTcolor,FTfont,x1,y1,text,strlen(text) ); XFlush (dpy); y1 = (int)((DHeight / 2) - XTheight); Image = XGetImage( dpy,root,x1,y1,XTwidth,XTheight,AllPlanes,XYPixmap ); *x = x1; *y = y1; return (Image); }
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex) { XGlyphInfo ext; XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); tex->h = font->h; tex->w = ext.xOff; }
static int xft_measure (Lisp_Font *f, char *string, size_t length) { XGlyphInfo info; XftTextExtentsUtf8 (dpy, f->font, (FcChar8 *)string, length, &info); return info.xOff; }
int xu_xft_width(XftFont *xftfont, const char *text, int len) { XGlyphInfo extents; XftTextExtentsUtf8(X_Dpy, xftfont, (const FcChar8*)text, len, &extents); return (extents.xOff); }
unsigned int gui_text_width (struct gui_font *font, const char *text, size_t length) { XGlyphInfo extents; XftTextExtentsUtf8(GUI_display, font->xft_font, (const unsigned char *) text, length, &extents); return extents.xOff; }
int Menu::getTextWidth(char *text, unsigned int len) { #ifdef CONFIG_USE_XFT XGlyphInfo extents; XftTextExtentsUtf8(display(), m_font, (FcChar8 *)text, len, &extents); return extents.width; #else return XmbTextEscapement(m_fontset, text, len); #endif }
static void ui_draw_coordinates() { for ( int y = 0; y < 8; ++y ) { XftChar8 c = '8' - y; XGlyphInfo extents; XftTextExtentsUtf8(ui_display, ui_coordfont, &c, 1, &extents); int xPos = ui_board_pos_x + (4 * UI_SIZE_SQUARE_WIDTH) / 100; int yPos = UI_POS_BOARD_Y + (UI_SIZE_SQUARE_HEIGHT * y) + extents.height + (4 * UI_SIZE_SQUARE_WIDTH) / 100; XftColor* color = NULL; if ( y % 2 == 0 ) { color = &ui_squarecolorblack; } else { color = &ui_squarecolorwhite; } XftDrawStringUtf8(ui_xftdraw, color, ui_coordfont, xPos, yPos, &c, 1); } for ( int x = 0; x < 8; ++x ) { XftChar8 c = 'a' + x; XGlyphInfo extents; XftTextExtentsUtf8(ui_display, ui_coordfont, &c, 1, &extents); int xPos = ui_board_pos_x + (UI_SIZE_SQUARE_WIDTH * (x + 1)) - extents.width;// - (4 * UI_SIZE_SQUARE_WIDTH) / 100; int yPos = UI_POS_BOARD_Y + (UI_SIZE_SQUARE_HEIGHT * 8) - (60 * extents.height) / 100; XftColor* color = NULL; if ( x % 2 == 0 ) { color = &ui_squarecolorwhite; } else { color = &ui_squarecolorblack; } XftDrawStringUtf8(ui_xftdraw, color, ui_coordfont, xPos, yPos, &c, 1); } }
static inline void draw_string(Display *xdisplay, XftDraw *draw, XftFont *font, XftColor *colour, const gchar *text, gint *pos_y) { XGlyphInfo extents; gint len = strlen(text); XftTextExtentsUtf8(xdisplay, font, (guchar *)text, len, &extents); XftDrawStringUtf8(draw, colour, font, 4, *pos_y + extents.y, (guchar *)text, len); *pos_y += extents.height + 4; }
int text_width(FcChar8 *s) { XGlyphInfo g; int i, len = strlen(s); /* XftTextExtentsUtf8 doesn't seem to know what a space is. */ char str[MAX_LEN]; strcpy(str, s); for (i = 0; i < len; i++) if (str[i] == ' ') str[i] = '-'; XftTextExtentsUtf8(display, font, str, len, &g); return g.width; }
void drw_font_getexts(Drw *drw, const char *text, unsigned int len, Extnts *tex) { if(!drw || !text) return; XGlyphInfo ext; XftTextExtentsUtf8(drw->dpy, drw->font->xfont, (XftChar8 *) text, len, &ext); tex->w = ext.xOff; tex->h = ext.yOff; }
void setfont(const char *fontstr) { #ifndef DZEN_XFT char *def, **missing; int i, n; missing = NULL; if(dzen.font.set) XFreeFontSet(dzen.dpy, dzen.font.set); dzen.font.set = XCreateFontSet(dzen.dpy, fontstr, &missing, &n, &def); if(missing) XFreeStringList(missing); if(dzen.font.set) { XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; dzen.font.ascent = dzen.font.descent = 0; font_extents = XExtentsOfFontSet(dzen.font.set); n = XFontsOfFontSet(dzen.font.set, &xfonts, &font_names); for(i = 0, dzen.font.ascent = 0, dzen.font.descent = 0; i < n; i++) { if(dzen.font.ascent < (*xfonts)->ascent) dzen.font.ascent = (*xfonts)->ascent; if(dzen.font.descent < (*xfonts)->descent) dzen.font.descent = (*xfonts)->descent; xfonts++; } } else { if(dzen.font.xfont) XFreeFont(dzen.dpy, dzen.font.xfont); dzen.font.xfont = NULL; if(!(dzen.font.xfont = XLoadQueryFont(dzen.dpy, fontstr))) eprint("dzen: error, cannot load font: '%s'\n", fontstr); dzen.font.ascent = dzen.font.xfont->ascent; dzen.font.descent = dzen.font.xfont->descent; } dzen.font.height = dzen.font.ascent + dzen.font.descent; #else if(dzen.font.xftfont) XftFontClose(dzen.dpy, dzen.font.xftfont); dzen.font.xftfont = XftFontOpenXlfd(dzen.dpy, dzen.screen, fontstr); if(!dzen.font.xftfont) dzen.font.xftfont = XftFontOpenName(dzen.dpy, dzen.screen, fontstr); if(!dzen.font.xftfont) eprint("error, cannot load font: '%s'\n", fontstr); dzen.font.extents = malloc(sizeof(XGlyphInfo)); XftTextExtentsUtf8(dzen.dpy, dzen.font.xftfont, (unsigned const char *) fontstr, strlen(fontstr), dzen.font.extents); dzen.font.height = dzen.font.xftfont->ascent + dzen.font.xftfont->descent; dzen.font.width = (dzen.font.extents->width)/strlen(fontstr); #endif }
int textnw(DC *dc, const char *text, size_t len) { if(dc->font.xft_font) { XGlyphInfo gi; XftTextExtentsUtf8(dc->dpy, dc->font.xft_font, (const FcChar8*)text, len, &gi); return gi.xOff; } else if(dc->font.set) { XRectangle r; XmbTextExtents(dc->font.set, text, len, NULL, &r); return r.width; } return XTextWidth(dc->font.xfont, text, len); }
static void ui_draw_string( const char* str, XftFont* font, XftColor* color, int x, int y, int maxwidth, int* width) { XftChar16 dotch = 0x2026; // unicode ... character /* get width of three dots */ XGlyphInfo extents; XftTextExtents16(ui_display, font, &dotch, 1, &extents); int sizepoints = extents.width; size_t cutlen = 0; XftTextExtentsUtf8(ui_display, font, (XftChar8*) str, strlen(str), &extents); int totlen = extents.width; while (totlen > maxwidth && cutlen < strlen(str)) { ++cutlen; XftTextExtentsUtf8(ui_display, font, (XftChar8*) str, strlen(str) - cutlen, &extents); totlen = extents.width + sizepoints; } if (NULL != width) { *width = 0; } if (totlen <= maxwidth) { XftDrawStringUtf8(ui_xftdraw, color, font, x, y, (XftChar8*) str, strlen(str) - cutlen); if (cutlen > 0) { XftDrawString16(ui_xftdraw, color, font, x + extents.width, y, &dotch, 1); } if (NULL != width) { *width = totlen; } } }
static void menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) { struct screen_ctx *sc = mc->sc; struct menu *mi; struct geom area; int n, xsave, ysave; XGlyphInfo extents; if (mc->list) { if (TAILQ_EMPTY(resultq)) { /* Copy them all over. */ TAILQ_FOREACH(mi, menuq, entry) TAILQ_INSERT_TAIL(resultq, mi, resultentry); mc->listing = 1; } else if (mc->changed) mc->listing = 0; } (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s", mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR); XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents); mc->geom.w = extents.xOff; mc->geom.h = sc->xftfont->height + 1; mc->num = 1; TAILQ_FOREACH(mi, resultq, resultentry) { (*mc->print)(mi, mc->listing); XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)mi->print, MIN(strlen(mi->print), MENU_MAXENTRY), &extents); mc->geom.w = MAX(mc->geom.w, extents.xOff); mc->geom.h += sc->xftfont->height + 1; mc->num++; }
/* render text position - 0 left, 1-center */ static void draw_str( Widget w, int clear_area, enum CLABEL n ) { CtrlWidget cw = (CtrlWidget)w; CtrlPart *c = & cw->ctrl; Display *dpy = XtDisplay(w); clabel_t *cl = c->clabel + n; char *s; Dimension x,y; TF(); if( ! cl->width || ! cl->height ) return; if( clear_area ) { TRACE(2, "%s %d", cw->core.name, c->msg.state ); XFillRectangle( XtDisplay(w), XtWindow(w), c->gc[c->msg.state], cl->x, cl->y, cl->width, cl->height ); } s = cl->str; if( IsEmpty(s) ) return; x = cl->x; y = cl->y + cl->font->ascent; if( cl->position == 1 ) // center label { XftTextExtentsUtf8(dpy, cl->font, (FcChar8*)s, strlen(s), & cl->extents ); x+=(cl->width - cl->extents.xOff) / 2; calc_str_position( cl ); TRACE(2, "%s (%u %u) (%u %u)", cw->core.name, cl->x, cl->y, cl->str_x, cl->str_y ); XftDrawStringUtf8(c->draw, c->col+c->msg.state, cl->font, cl->x + cl->str_x, cl->y + cl->str_y, (FcChar8*)s,strlen(s) ); return; } XftDrawStringUtf8(c->draw, c->col+c->msg.state, cl->font, x,y, (FcChar8*)s,strlen(s) ); }
static int drawstring(char *str, int x, int flushright) { XGlyphInfo extents; int erasemore = 10; XftTextExtentsUtf8(d, xftfont, (const FcChar8 *)str, strlen(str), &extents); if (flushright) { XftDrawRect(xftd, &black, x - extents.xOff - erasemore, 0, extents.xOff + erasemore, BARHEIGHT); XftDrawStringUtf8(xftd, &white, xftfont, x - extents.xOff, 1 + xftfont->ascent, (const FcChar8 *)str, strlen(str)); } else { XftDrawRect(xftd, &black, x, 0, extents.xOff + erasemore, BARHEIGHT); XftDrawStringUtf8(xftd, &white, xftfont, x, 1 + xftfont->ascent, (const FcChar8 *)str, strlen(str)); } return extents.xOff; }
static unsigned int textnw(Fnt *font, const char *text, unsigned int len) { #ifndef DZEN_XFT XRectangle r; if(font->set) { XmbTextExtents(font->set, text, len, NULL, &r); return r.width; } return XTextWidth(font->xfont, text, len); #else XftTextExtentsUtf8(dzen.dpy, dzen.font.xftfont, (unsigned const char *) text, strlen(text), dzen.font.extents); if(dzen.font.extents->height > dzen.font.height) dzen.font.height = dzen.font.extents->height; return dzen.font.extents->xOff; #endif }
void XImlib2Caption::createWindow() { XDesktopContainer * xContainer = dynamic_cast<XDesktopContainer *>(AbstractImage::container); DesktopConfig * dConfig = dynamic_cast<DesktopConfig *>(XImlib2Image::config); XSetWindowAttributes attr; attr.override_redirect = True; attr.cursor = XCreateFontCursor(xContainer->getDisplay(), dConfig->getCursorOver()); attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | PropertyChangeMask | ExposureMask; XftTextExtentsUtf8( xContainer->getDisplay(), font, (XftChar8*)text.c_str(), text.length(), &fontInfo ); // fix window extents so shadow text is not cut // TODO: fix window extents if shadow is negative: // Would have to edit x and y of the window width = fontInfo.width + FONTSHIFT; height = font->height; if (shadowOn) { width += shadowX > 0 ? shadowX : 0; height += shadowY > 0 ? shadowY : 0; } window = XCreateWindow( xContainer->getDisplay(), xContainer->getRootWindow(), 0, 0, width, height, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWOverrideRedirect|CWEventMask|CWCursor, &attr ); }
bool x11_blocks_resize(XRESOURCES* xres, CFG* config, TEXTBLOCK** blocks, XGlyphInfo* bounding_box, double size){ XftFont* font = NULL; unsigned bounding_width = 0, bounding_height = 0; unsigned i; //load font with at supplied size font=XftFontOpen(xres->display, xres->screen, XFT_FAMILY, XftTypeString, config->font_name, XFT_PIXEL_SIZE, XftTypeDouble, size, NULL ); if(!font){ fprintf(stderr, "Could not load font\n"); return false; } //fprintf(stderr, "Block \"%s\" extents: width %d, height %d, x %d, y %d, xOff %d, yOff %d\n", // block->text, block->extents.width, block->extents.height, block->extents.x, block->extents.y, // block->extents.xOff, block->extents.yOff); //bounds calculation for(i = 0; blocks[i] && blocks[i]->active; i++){ //update only not yet calculated blocks if(!(blocks[i]->calculated)){ XftTextExtentsUtf8(xres->display, font, (FcChar8*)blocks[i]->text, strlen(blocks[i]->text), &(blocks[i]->extents)); errlog(config, LOG_DEBUG, "Recalculated block %d (%s) extents: %dx%d\n", i, blocks[i]->text, blocks[i]->extents.width, blocks[i]->extents.height); blocks[i]->size = size; } //calculate bounding box over all bounding_height += blocks[i]->extents.height; if(blocks[i]->extents.width > bounding_width){ bounding_width = blocks[i]->extents.width; } } if(bounding_box){ bounding_box->width = bounding_width; bounding_box->height = bounding_height; } XftFontClose(xres->display, font); return true; }
uint defont_get_text_width(DEFont *font, const char *text, uint len) { #ifdef HAVE_X11_XFT if(font->font!=NULL){ XGlyphInfo extents; if(ioncore_g.enc_utf8) XftTextExtentsUtf8(ioncore_g.dpy, font->font, (XftChar8*)text, len, &extents); else XftTextExtents8(ioncore_g.dpy, font->font, (XftChar8*)text, len, &extents); return extents.xOff; } #endif /* HAVE_X11_XFT */ #ifdef HAVE_X11_BMF if(font->fontset!=NULL){ XRectangle lext; #ifdef CF_DE_USE_XUTF8 if(ioncore_g.enc_utf8) Xutf8TextExtents(font->fontset, text, len, NULL, &lext); else #endif XmbTextExtents(font->fontset, text, len, NULL, &lext); return lext.width; }else if(font->fontstruct!=NULL){ if(ioncore_g.enc_utf8){ XChar2b *str16; int len16=0; uint res; toucs(text, len, &str16, &len16); res=XTextWidth16(font->fontstruct, str16, len16); free(str16); return res; }else{ return XTextWidth(font->fontstruct, text, len); } } #endif /* HAVE_X11_BMF */ else{ return 0; } }
//========================================= // XFontSetup //----------------------------------------- XTFont XFontSetup (XInit xi,char *text) { // ... // Open the defined XFTFONT and calculate the // pixel width and height needed for text with the // given font // --- XftPattern *pattern; XGlyphInfo FTinfo; XTFont xt; pattern = XftNameParse (XFTFONT); pattern = XftFontMatch (xi.dpy,xi.DScreen,pattern,NULL); xt.FTfont = XftFontOpenPattern (xi.dpy, pattern); XftTextExtentsUtf8 ( xi.dpy,xt.FTfont,text,strlen(text),&FTinfo ); xt.XTheight = xt.FTfont->height; xt.XTwidth = FTinfo.xOff; return(xt); }