Ejemplo n.º 1
0
int GCgettextsize(Gwidget_t * widget, Gtextline_t * tlp, int n, char *fn,
		  double fs, Gsize_t * gsp)
{

    Gsize_t gs;
    PIXsize_t ps;
    GdkFont *font;
    int i, dir, asc, des, rbearing, lbearing, width;

    gs.x = 0, gs.y = fs;
    ps = sdrawtopix(widget, gs);
    if (!(font = findfont(fn, ps.y))) {
	gsp->x = 1, gsp->y = 1;
	return 0;
    }
    SETFONT(font);
    for (ps.x = ps.y = 0, i = 0; i < n; i++) {
	gdk_text_extents(font, tlp[i].p, tlp[i].n, &lbearing, &rbearing,
			 &width, &asc, &des);
	ps.x = max(ps.x, width), ps.y += asc + des;
    }

    *gsp = spixtodraw(widget, ps);
    return 0;
}
Ejemplo n.º 2
0
/* Returns the metrics of a string.

	 font : a GdkFont
	 text : the text to measure
  text_length : the length of the text in bytes. (If the font is a
		16-bit font, this is twice the length of the text in characters.)
     lbearing : the left bearing of the string.
     rbearing : the right bearing of the string.
	width : the width of the string.
       ascent : the ascent of the string.
      descent : the descent of the string. */
int
clip_GDK_TEXTEXTENTS(ClipMachine * cm)
{
	C_object      *cfont = _fetch_co_opt(cm);
	gchar * string = _clip_parc(cm,2);
	gint     text_length = _clip_parni(cm,3);
	gint lbearing, rbearing, width, ascent, descent;
	CHECKCOBJOPT(cfont,GDK_IS_FONT(cfont));
	CHECKARG(2,CHARACTER_t); CHECKOPT(3,NUMERIC_t);
	if (_clip_parinfo(cm,3)==UNDEF_t) text_length = strlen(string);
	LOCALE_TO_UTF(string);
	gdk_text_extents(GDK_FONT(cfont->object), string, text_length,
		&lbearing, &rbearing, &width, &ascent, &descent);
	FREE_TEXT(string);
	_clip_storni(cm,lbearing,4,0);
	_clip_storni(cm,rbearing,5,0);
	_clip_storni(cm,width,6,0);
	_clip_storni(cm,ascent,7,0);
	_clip_storni(cm,descent,8,0);
	return 0;
err:
	return 1;
}
Ejemplo n.º 3
0
int GCtext(Gwidget_t * widget, Gtextline_t * tlp, int n, Gpoint_t go,
	   char *fn, double fs, char *justs, Ggattr_t * ap)
{

    Gsize_t gs;
    PIXpoint_t po;
    PIXsize_t ps;
    PIXrect_t pr;
    Grect_t gr;
    GdkFont *font;
    int dir, asc, des, x = 0, y, w, h, i;
    int lbearing, rbearing, width;

    po = pdrawtopix(widget, go);
    gs.x = 0, gs.y = fs;
    ps = sdrawtopix(widget, gs);
    if (!(font = findfont(fn, ps.y))) {
	printf("NO FONT\n");
	gdk_draw_rectangle(widget->w, GC, FALSE, po.x, po.y, 1, 1);
	return 0;
    }

    setgattr(widget, ap);
    SETFONT(font);

    for (w = h = 0, i = 0; i < n; i++) {
	gdk_text_extents(font, tlp[i].p, tlp[i].n, &lbearing, &rbearing,
			 &width, &asc, &des);

	tlp[i].w = width, tlp[i].h = asc + des;
	w = max(w, width), h += asc + des;

    }

    switch (justs[0]) {
    case 'l':
	po.x += w / 2;
	break;
    case 'r':
	po.x -= w / 2;
	break;
    }
    switch (justs[1]) {
    case 'd':
	po.y -= h;
	break;
    case 'c':
	po.y -= h / 2;
	break;
    }
    pr.o.x = po.x - w / 2, pr.o.y = po.y;
    pr.c.x = po.x + w / 2, pr.c.y = po.y + h;
    gr = rpixtodraw(widget, pr);

/*	if(!ISVISIBLE(gr))
		return 1;
*/

    for (i = 0; i < n; i++) {
	switch (tlp[i].j) {
	case 'l':
	    x = po.x - w / 2;
	    break;
	case 'n':
	    x = po.x - tlp[i].w / 2;
	    break;
	case 'r':
	    x = po.x - (tlp[i].w - w / 2);
	    break;
	}
	y = po.y + (i + 1) * tlp[i].h - des;

	gdk_draw_text(widget->w->window, font, GC, x, y, tlp[i].p,
		      tlp[i].n);
    }

    return 0;
}