void calcTextObjectExtents(TextObject *t, XFontStruct *font) { if ((!t) || (!(t->text))) { return; } t->textLength = strlen(t->text); XTextExtents(font, t->text, t->textLength, &(t->direction), &(t->ascent), &(t->descent), &(t->overall)); }
static int font_width(XFontStruct * font, char ch) { int dummy; XCharStruct xcs; (void) XTextExtents(font, &ch, 1, &dummy, &dummy, &dummy, &xcs); return xcs.width; }
void button_dimensions(char *string, int *width, int *height) { XCharStruct overall; int dir, asc, desc; XTextExtents(font_struct, string, strlen(string), &dir, &asc, &desc, &overall); *width = overall.width + 4 + 2 * margin; *height = overall.ascent + overall.descent + 1 + 4 + 2*margin; }
int x_wglasi(char *string, int stringLength) { int ascent, descent; int direction; XCharStruct fonteInfo; XTextExtents(fonte, string, stringLength, &direction, &ascent, &descent, &fonteInfo); return (ascent); }
void HelloWorld::_drawStringCentered(const GC& gc, const char* str, int x, int y, int w, int h) { int direction, ascent, descent; XCharStruct strDimensions; XTextExtents(XQueryFont(_display, XGContextFromGC(gc)), str, strlen(str), &direction, &ascent, &descent, &strDimensions); int newX = x + (w - strDimensions.width) / 2; int newY = y + (h + strDimensions.ascent - strDimensions.descent) / 2; _drawString(gc, str, newX, newY); }
static void text_extent (XFontStruct* fontStruct, const char* text, int len, int* width, int* height) { XCharStruct extent; int dummy; XTextExtents (fontStruct, text, len, &dummy, &dummy, &dummy, &extent); *width = extent.width; *height = fontStruct->ascent + fontStruct->descent; }
void NSString::fontWindowHeight(unsigned int arg) { int direction, ascent, descent; XCharStruct charStruct; XTextExtents(fontStruct, _label.c_str(), _label.length(), &direction, &ascent, &descent, &charStruct); if (_resizable) { _fontWindowHeight = arg; //_vGap = (_fontWindowHeight - charStruct.ascent - charStruct.descent) / 2; } }
void NSString::fontWindowWidth(unsigned int arg) { int direction, ascent, descent; XCharStruct charStruct; XTextExtents(fontStruct, _label.c_str(), _label.length(), &direction, &ascent, &descent, &charStruct); if (_resizable) { _fontWindowWidth = arg; //_hGap = (_fontWindowWidth - charStruct.rbearing + charStruct.lbearing) / 2; } }
static void Resize (XtcwpAxesWidget w) { XtcwpAxesCallbackStruct cb; XFontStruct *fa,*ft; XCharStruct cs; int labelch,labelcw,titlech,bl,bt,br,bb,ticsize,dummy; /* get fonts and determine character dimensions */ fa = XQueryFont(XtDisplay(w),w->axes.labelfont); XTextExtents(fa,"2",1,&dummy,&dummy,&dummy,&cs); labelch = cs.ascent+cs.descent; labelcw = cs.width; ft = XQueryFont(XtDisplay(w),w->axes.titlefont); titlech = ft->max_bounds.ascent+ft->max_bounds.descent; /* determine axes rectangle position and dimensions */ ticsize = labelcw; bl = labelch+7*labelcw; br = w->core.width-5*labelcw; while (br<bl) { br += labelcw; bl -= labelcw; } if (bl<0) bl = 0; if (br>((int) w->core.width)) br = w->core.width; if (w->axes.style==XtcwpNORMAL) { bt = labelch+labelch/2+titlech; bb = w->core.height-3*ticsize/2-2*labelch; } else { bt = 3*ticsize/2+2*labelch; bb = w->core.height-labelch-labelch/2-titlech; } while (bb<bt) { bb += labelch; bt -= labelch; } if (bt<0) bt = 0; if (bb>((int) w->core.height)) bb = w->core.height; w->axes.x = bl; w->axes.y = bt; w->axes.width = br-bl; w->axes.height = bb-bt; /* Free font info */ XFreeFontInfo(NULL,fa,1); XFreeFontInfo(NULL,ft,1); /* call callbacks */ fillCallbackStruct(w,XtcwpCR_RESIZE,NULL,NULL,&cb); XtCallCallbacks ((Widget) w,XtNresizeCallback,&cb); }
void InitHScrollBar(struct XObj *xobj) { unsigned long mask; XSetWindowAttributes Attr; int i; int asc,desc,dir; XCharStruct struc; char str[20]; /* Enregistrement des couleurs et de la police */ MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->forecolor,&xobj->TabColor[fore]); MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->backcolor,&xobj->TabColor[back]); MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->licolor,&xobj->TabColor[li]); MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->shadcolor,&xobj->TabColor[shad]); MyAllocNamedColor(xobj->display,*xobj->colormap,"#000000",&xobj->TabColor[black]); MyAllocNamedColor(xobj->display,*xobj->colormap,"#FFFFFF",&xobj->TabColor[white]); mask=0; Attr.background_pixel=xobj->TabColor[back].pixel; mask|=CWBackPixel; Attr.cursor=XCreateFontCursor(xobj->display,XC_hand2); mask|=CWCursor; /* Curseur pour la fenetre */ xobj->win=XCreateWindow(xobj->display,*xobj->ParentWin, xobj->x,xobj->y,xobj->width,xobj->height,0, CopyFromParent,InputOutput,CopyFromParent, mask,&Attr); xobj->gc=XCreateGC(xobj->display,xobj->win,0,NULL); XSetForeground(xobj->display,xobj->gc,xobj->TabColor[fore].pixel); XSetBackground(xobj->display,xobj->gc,xobj->TabColor[back].pixel); if ((xobj->xfont=XLoadQueryFont(xobj->display,xobj->font))==NULL) fprintf(stderr,"Can't load font %s\n",xobj->font); else XSetFont(xobj->display,xobj->gc,xobj->xfont->fid); XSetLineAttributes(xobj->display,xobj->gc,1,LineSolid,CapRound,JoinMiter); if ((xobj->value3-xobj->value2)<=0) xobj->value3=xobj->value2+10; if (!((xobj->value>=xobj->value2)&&(xobj->value<=xobj->value3))) xobj->value=xobj->value2; XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); xobj->height=(asc+desc)*2+30; sprintf(str,"%d",xobj->value2); i=XTextWidth(xobj->xfont,str,strlen(str)); sprintf(str,"%d",xobj->value3); i=XTextWidth(xobj->xfont,str,strlen(str))+i+20; if (xobj->width<i) xobj->width=i; XResizeWindow(xobj->display,xobj->win,xobj->width,xobj->height); }
void HideThumbH(struct XObj *xobj) { int x,y; int asc,desc,dir; XCharStruct struc; x=4+(xobj->width-36)*(xobj->value-xobj->value2)/(xobj->value3-xobj->value2); y=xobj->height/2-8; XSetForeground(xobj->display,xobj->gc,xobj->TabColor[back].pixel); XFillRectangle(xobj->display,xobj->win,xobj->gc,x,y,28,16); XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); XFillRectangle(xobj->display,xobj->win,xobj->gc,x-asc -desc,y-asc-10,90,asc+desc+2); }
static int query_font_geometry (Display *dpy, GC gc, const char *txt, int *w, int *h, int *a, int *d) { XCharStruct text_structure; int font_direction, font_ascent, font_descent; XFontStruct *fontinfo = XQueryFont (dpy, XGContextFromGC (gc)); if (!fontinfo) { return -1; } XTextExtents (fontinfo, txt, strlen (txt), &font_direction, &font_ascent, &font_descent, &text_structure); if (w) *w = XTextWidth (fontinfo, txt, strlen (txt)); if (h) *h = text_structure.ascent + text_structure.descent; if (a) *a = text_structure.ascent; if (d) *d = text_structure.descent; XFreeFontInfo (NULL, fontinfo, 1); return 0; }
void GraphicWindow::text(const char t[], double x, double y) { int direction, ascent, descent; XCharStruct overall; XTextExtents(_fontinfo_ptr, t, strlen(t), &direction, &ascent, &descent, &overall); int disp_x = user_to_disp_x(x); int disp_y = user_to_disp_y(y) + ascent; XSetForeground(display, xgc, BlackPixel(display, screen_num)); XDrawString(display, win, xgc, disp_x, disp_y, t, strlen(t)); XDrawString(display, _ppm, xgc, disp_x, disp_y, t, strlen(t)); }
/********************************************************************** * XG_JUSTIFY * - figures out the dimensions of a string when drawn **********************************************************************/ void xg_justify(void *xgid, char *string, int *width, int *ascent, int *descent) { struct xg_graphic *graphic; int string_length; XCharStruct string_info; int direction; int lascent; int ldescent; graphic = (struct xg_graphic *)xgid; string_length = strlen(string); XTextExtents(graphic->font_info, string, string_length, &direction, &lascent, &ldescent, &string_info); *width = string_info.width; *ascent = string_info.ascent; *descent = string_info.descent; }
/* R4 and below code */ static void computeFontInfo(BALLOON) { int dir, ascent, descent; XCharStruct sw; if(ATTR(font) == NULL) return; XTextExtents(ATTR(font), "1", 1, &dir, &ascent, &descent, &sw); /* collect font dimensions */ ATTR(baseline) = sw.ascent; ATTR(font_width) = sw.width; ATTR(font_height) = sw.ascent + sw.descent; }
void Font::string_bbox(const char* s, int len, FontBoundingBox& b) const { FontRep* f = impl_->default_rep(); float scale = f->scale_; XFontStruct* xf = f->font_; Display* d = f->display_; XCharStruct c; int dir, asc, des; XTextExtents(xf, s, len, &dir, &asc, &des, &c); b.left_bearing_ = scale * d->to_coord(-c.lbearing); b.right_bearing_ = scale * d->to_coord(c.rbearing); b.width_ = width(s, len); b.ascent_ = scale * d->to_coord(c.ascent); b.descent_ = scale * d->to_coord(c.descent); b.font_ascent_ = scale * d->to_coord(xf->ascent); b.font_descent_ = scale * d->to_coord(xf->descent); }
static void set_ruler_text(int row, int col, int *h, int *w, int *asc) { int dir, des; XCharStruct over; /* format the data */ sprintf( text, "%9.d,%-9.d", row+1, col+1 ); /* how big will it be? */ XTextExtents( ruler_font, text, strlen(text), &dir, asc, &des, &over ); /* how big a window will we need? */ *h = 2*ruler_border + over.ascent + over.descent; *w = 2*ruler_border + over.width; }
void NSString::label(const char* str) { _label = str; int direction, ascent, descent; XCharStruct charStruct; XTextExtents(fontStruct, _label.c_str(), _label.length(), &direction, &ascent, &descent, &charStruct); if (_resizable) { _hGap = (_fontWindowWidth - charStruct.rbearing + charStruct.lbearing) / 2; _vGap = (_fontWindowHeight - charStruct.ascent - charStruct.descent) / 2; } else { _fontWindowWidth = charStruct.rbearing - charStruct.lbearing + fontGap * 2; _vGap = (_fontWindowHeight - (charStruct.ascent + charStruct.descent)) / 2; } }
static void clear_cursorline(InputItem *sym) { XCharStruct extents; int dir, asc, des; int cursor_y; XTextExtents(gInputFont, sym->curr_line->buffer, sym->curr_line->buff_pntr, &dir, &asc, &des, &extents); cursor_y = (sym->curr_line->line_number - 1) * line_height; sym->cursor_x = start_x + extents.width; XClearArea(gXDisplay, sym->win, sym->cursor_x, cursor_y, gWindow->width, line_height, False); XDrawString(gXDisplay, sym->win, gWindow->fInputGC, start_x, cursor_y + start_y, sym->curr_line->buffer, sym->curr_line->len); }
void HideThumbV(struct XObj *xobj) { int x,y; char str[20]; int asc,desc,dir; XCharStruct struc; x = xobj->width/2 - 10; y = 2 + (xobj->height - 36) * (xobj->value - xobj->value3) / (xobj->value2 - xobj->value3); XClearArea(dpy, xobj->win, x, y, 20, 32, False); sprintf(str, "%d", xobj->value); x = x - XTextWidth(xobj->xfont, str, strlen(str)) - 6; XTextExtents(xobj->xfont, "lp", strlen("lp"), &dir, &asc, &desc, &struc); XClearArea(dpy, xobj->win, x, y, XTextWidth(xobj->xfont, str, strlen(str)), asc+desc+8, False); }
void update_inputsymbol(InputItem *sym) { int y_spot = start_y; LineStruct *cline; XCharStruct extents; int dir, asc, des; /*int cleared = 0;*/ int clear_y; int clear_width; int clear_height; #if 0 int cursor_y; cursor_y = (sym->curr_line->line_number - 1) * line_height; #endif clear_width = (sym->size + 1) * gInputFont->max_bounds.width + 10; clear_height = line_height; clear_y = 0; XTextExtents(gInputFont, sym->curr_line->buffer, sym->curr_line->buff_pntr, &dir, &asc, &des, &extents); sym->cursor_x = start_x + extents.width; /* * While the list of input strings is not NULL, I should just keep * drawing them */ for (cline = sym->lines; cline != NULL; cline = cline->next, y_spot += line_height, clear_y += line_height) /* Now I should draw the initial string ** */ if (cline->changed) { cline->changed = 0; XClearArea(gXDisplay, sym->win, 0, clear_y, clear_width, clear_height, False); XDrawString(gXDisplay, sym->win, gWindow->fInputGC, start_x, y_spot, cline->buffer, cline->len); } draw_cursor(sym); }
static void draw_screen () { int x; int y; int direction; int ascent; int descent; XCharStruct overall; /* Centre the text in the middle of the box. */ XTextExtents (text_box.font, text_box.text, text_box.text_len, & direction, & ascent, & descent, & overall); x = (text_box.width - overall.width) / 2; y = text_box.height / 2 + (ascent - descent) / 2; XClearWindow (text_box.display, text_box.window); XDrawString (text_box.display, text_box.window, text_box.gc, x, y, text_box.text, text_box.text_len); }
void DrawList(struct XObj *xobj) { int asc,desc,dir,HeightCell; XCharStruct struc; int NbVisCell,NbCell; XRectangle r; /* Dessin du contour */ DrawReliefRect(0,0,xobj->width,xobj->height,xobj, xobj->TabColor[li].pixel,xobj->TabColor[shad].pixel,xobj->TabColor[fore].pixel,-1); /* Dessin du contour de la liste */ r.x=2+BdWidth; r.y=r.x; r.width=xobj->width-r.x-4-2*BdWidth-SbWidth; r.height=xobj->height-r.y-2*BdWidth; DrawReliefRect(r.x,r.y,r.width,r.height,xobj,xobj->TabColor[shad].pixel, xobj->TabColor[li].pixel,xobj->TabColor[fore].pixel,-1); /* Calcul du nombre de cellules visibles */ XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); HeightCell=asc+desc+3; NbVisCell=r.height/HeightCell; NbCell=CountOption(xobj->title); if (NbCell>NbVisCell) { if (xobj->value2>(NbCell-NbVisCell+1)) xobj->value2=NbCell-NbVisCell+1; if ((xobj->value2<1)||(xobj->value2<0)) xobj->value2=1; } else xobj->value2=1; /* Dessin des cellules */ DrawCellule(xobj,NbCell,NbVisCell,HeightCell,asc); /* Dessin de l'ascenseur vertical */ DrawVSbList(xobj,NbCell,NbVisCell,0); }
int GraphicWindow::put_string(const char instr[], int str_x, int curr_x) { int direction, ascent, descent; XCharStruct overall; XTextExtents(_fontinfo_ptr, instr, strlen(instr), &direction, &ascent, &descent, &overall); XClearArea(display, win, str_x - 1, 0, /*clear from top*/ curr_x + 1, /*clear to right edge of screen*/ ascent + descent + 1, 0 /* generate exposure events */); XSetForeground(display, xgc, BlackPixel(display, screen_num)); XDrawImageString(display, win, xgc, str_x, ascent, instr, strlen(instr)); curr_x = str_x + overall.width; /* redraw cursor */ XDrawLine(display, win, xgc, curr_x, 0, curr_x, ascent + descent); return curr_x; }
void GraphicWindow::statusline_prompt(string s) { int direction, ascent, descent; XCharStruct overall; const char* t = s.c_str(); XTextExtents(_fontinfo_ptr, t, strlen(t), &direction, &ascent, &descent, &overall); XSetBackground(display, xgc, WhitePixel(display, screen_num)); XClearArea(display, win, 0, 0, /*clear from top*/ 0 /*clear to right edge of screen*/, ascent + descent, 0 /* generate exposure events */); XDrawImageString(display, win, xgc, 0, ascent, t, strlen(t)); XDrawImageString(display, _ppm, xgc, 0, ascent, t, strlen(t)); }
static PyObject * TextExtents(PaxFontObject *self, PyObject *args) { char *string; int nchars; int direction, font_ascent, font_descent; XCharStruct overall; if (!PyArg_ParseTuple(args, "s#", &string, &nchars)) return NULL; XTextExtents(self->font_struct, string, nchars, &direction, &font_ascent, &font_descent, &overall); return Py_BuildValue("(iii(iiiiii))", direction, font_ascent, font_descent, overall.lbearing, overall.rbearing, overall.width, overall.ascent, overall.descent, overall.attributes); }
int XMessageBox::loadFont() { // load the font mFS = XLoadQueryFont(mDisplay, "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"); if (mFS == NULL) mFS = XLoadQueryFont(mDisplay, "fixed"); if (mFS == NULL) return -1; // dummy call to XTextExtents to get the font specs XCharStruct strInfo; XTextExtents(mFS, "foo", 1, &mFontDirection, &mFontAscent, &mFontDescent, &strInfo); mFontHeight = mFontAscent + mFontDescent; return 0; }
/* * Given a font or fontset, return the extents of the text. */ void CalTextExtents( Cal_Font *font, char *string, int nbytes, int *x_return, int *y_return, int *width_return, int *height_return) { if (!font) return; if (font->cf_type == XmFONT_IS_FONT) { int direction, ascent, descent; XCharStruct overall; XTextExtents(font->f.cf_font, string, nbytes, &direction, &ascent, &descent, &overall); *x_return = overall.lbearing; *y_return = overall.ascent; *width_return = overall.width; *height_return = overall.ascent + overall.descent; } else { XRectangle ink, logical; XmbTextExtents(font->f.cf_fontset, string, nbytes, &ink, &logical); *x_return = logical.x; *y_return = logical.y; *width_return = logical.width; *height_return = logical.height; } }
void fl_set_font( int numb, int size ) { int dh; XCharStruct overall; XFontStruct *fs; fs = fl_get_font_struct( numb, size ); /* cur_font is always the one in current GC */ if ( fl_state[ fl_vmode ].cur_fnt == fs ) { #if FL_DEBUG >= ML_DEBUG M_debug( "fl_set_font", "current", fli_curfnt ); #endif return; } fl_state[ fl_vmode ].cur_fnt = flx->fs = fs; /* Basic font info (no need to send a string, we just want the maximum ascent and descent) */ XTextExtents( flx->fs, "", 0, &dh, &flx->fasc, &flx->fdesc, &overall ); flx->fheight = flx->fasc + flx->fdesc; XSetFont( flx->display, flx->textgc, flx->fs->fid ); if ( fli_cntl.debug > 1 ) { unsigned long res = 0; if ( XGetFontProperty( flx->fs, XA_RESOLUTION, &res ) ) M_info2( "fl_set_font", "FontResolution: %lu", res ); } }
void DrawThumbH(struct XObj *xobj) { int x,y,w,h; XSegment segm; char str[20]; int asc,desc,dir; XCharStruct struc; x=3+(xobj->width-36)*(xobj->value-xobj->value2)/(xobj->value3-xobj->value2); y=xobj->height/2-9; w=30; h=18; DrawReliefRect(x,y,w,h,xobj,xobj->TabColor[li].pixel,xobj->TabColor[shad].pixel, xobj->TabColor[black].pixel,-1); segm.x1=x+15; segm.y1=y+3; segm.x2=x+15; segm.y2=y+h-3; XSetForeground(xobj->display,xobj->gc,xobj->TabColor[shad].pixel); XDrawSegments(xobj->display,xobj->win,xobj->gc,&segm,1); segm.x1=x+16; segm.y1=y+3; segm.x2=x+16; segm.y2=y+h-3; XSetForeground(xobj->display,xobj->gc,xobj->TabColor[li].pixel); XDrawSegments(xobj->display,xobj->win,xobj->gc,&segm,1); XSetForeground(xobj->display,xobj->gc,xobj->TabColor[fore].pixel); sprintf(str,"%d",xobj->value); x=x+15-(XTextWidth(xobj->xfont,str,strlen(str))/2); XTextExtents(xobj->xfont,"lp",strlen("lp"),&dir,&asc,&desc,&struc); y=y-desc-4; DrawString(xobj->display,xobj->gc,xobj->win,x,y,str, strlen(str),xobj->TabColor[fore].pixel, xobj->TabColor[li].pixel,xobj->TabColor[back].pixel, !xobj->flags[1]); }