[q-lang-cvs] q/modules/ggi ggi.c,1.8,1.9 ggi.q,1.4,1.5
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-20 19:09:37
|
Update of /cvsroot/q-lang/q/modules/ggi In directory sc8-pr-cvs1:/tmp/cvs-serv4723 Modified Files: ggi.c ggi.q Log Message: added ggi_get_string_bbox operation Index: ggi.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/ggi.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ggi.c 20 Dec 2003 17:34:36 -0000 1.8 --- ggi.c 20 Dec 2003 19:09:34 -0000 1.9 *************** *** 1505,1509 **** /* compute the bounding box of a rendered string */ ! static int bbox(visual_t *v, char *s, int *wd, int *ht) { ggi_visual_t vis = v->vis; --- 1505,1511 ---- /* compute the bounding box of a rendered string */ ! static int bbox(visual_t *v, char *s, ! int *xmin, int *xmax, ! int *ymin, int *ymax) { ggi_visual_t vis = v->vis; *************** *** 1516,1520 **** FT_BBox bbox; /* bounding box */ ! *wd = *ht = 0; if (!glyphs) return (l==0); --- 1518,1522 ---- FT_BBox bbox; /* bounding box */ ! *xmin = *xmax = *ymin = *ymax = 0; if (!glyphs) return (l==0); *************** *** 1567,1572 **** FT_Done_Glyph(glyphs[n].image); free(glyphs); ! *wd = bbox.xMax - bbox.xMin; ! *ht = bbox.yMax - bbox.yMin; return 1; } --- 1569,1576 ---- FT_Done_Glyph(glyphs[n].image); free(glyphs); ! *xmin = bbox.xMin; ! *xmax = bbox.xMax; ! *ymin = bbox.yMin; ! *ymax = bbox.yMax; return 1; } *************** *** 1574,1581 **** #endif ! FUNCTION(ggi,ggi_get_string_size,argc,argv) { visual_t *v; ! int w, h; char *s; if (init && argc == 2 && isobj(argv[0], type(GGIVisual), (void**)&v) && --- 1578,1585 ---- #endif ! FUNCTION(ggi,ggi_get_string_bbox,argc,argv) { visual_t *v; ! int xmin, xmax, ymin, ymax; char *s; if (init && argc == 2 && isobj(argv[0], type(GGIVisual), (void**)&v) && *************** *** 1583,1596 **** #ifdef HAVE_FT2 if (v->face) ! if (bbox(v, s, &w, &h)) ! return mktuplel(2, mkint(w), mkint(h)); else return __FAIL; else #endif ! if (ggiGetCharSize(v->vis, &w, &h)) return __FAIL; else ! return mktuplel(2, mkint(w*strlen(s)), mkint(h)); else return __FAIL; --- 1587,1601 ---- #ifdef HAVE_FT2 if (v->face) ! if (bbox(v, s, &xmin, &xmax, &ymin, &ymax)) ! return mktuplel(4, mkint(xmin), mkint(xmax), mkint(ymin), mkint(ymax)); else return __FAIL; else #endif ! if (ggiGetCharSize(v->vis, &xmax, &ymax)) return __FAIL; else ! return mktuplel(4, mkint(0), mkint(xmax*strlen(s)), mkint(0), ! mkint(ymax)); else return __FAIL; Index: ggi.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/ggi.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ggi.q 20 Dec 2003 18:09:39 -0000 1.4 --- ggi.q 20 Dec 2003 19:09:34 -0000 1.5 *************** *** 401,414 **** /* Drawing text on a visual. These operations use the current font (GGI's builtin font by default) and the current foreground and background colors ! to render text on a visual. Note that control characters in the text are ! *not* interpreted, and *no* word wrap is performed. So the correct layout ! of the text is up to you. To these ends, the ggi_get_string_size function ! allows you to calculate the width and height of the bounding box of a ! rendered string. Individual characters and character strings can be placed ! at the given position P = (X,Y) with the ggi_putc and ggi_puts operations, ! respectively. */ - public extern ggi_get_string_size VIS S; public extern ggi_putc VIS P C, ggi_puts VIS P S; /* Get and put operations. The get operations allow you to retrieve a pixel, --- 401,441 ---- /* Drawing text on a visual. These operations use the current font (GGI's builtin font by default) and the current foreground and background colors ! to render text on a visual. Individual characters and character strings can ! be placed at the given position P = (X,Y) with the ggi_putc and ggi_puts ! operations, respectively. Note that control characters in the text are ! *not* interpreted, and *no* word wrap is performed. So the entire layout of ! the text is up to you. Additional operations are provided to help with ! this, see below. */ public extern ggi_putc VIS P C, ggi_puts VIS P S; + + /* The following operations can be used to handle the layout of text in a + visual. Both operations take into account the current text transform set on + a visual. Thus, if the transform specifies a translation, rotation or + stretching of the text, the returned figures will change accordingly. + + The ggi_get_string_size function allows you to calculate the dimensions of + the bounding box of a rendered string, which is useful, e.g., for centering + text. It returns a pair (W,H), where W denotes the width and H the height + of the rendered text. + + The ggi_get_string_bbox function gives you finer control over the layout + process. It returns four values (XMIN,XMAX,YMIN,YMAX) which describe the + bounding box of the string in relationship to the baseline. For the default + font, the XMIN and YMIN values are always zero, and the XMAX and YMAX + values correspond to the width and height of the rendered string. For other + fonts, the XMIN value described the initial offset of the first character + in the string from adjacent characters. The YMIN value specifies the amount + of vertical space between the lowest pixel in the rendered string and the + baseline of the text; note that this value can be negative, indicating that + the string extends *below* the baseline. The YMIN value is useful, in + particular, if text is to be aligned properly w.r.t. the baseline. */ + + public extern ggi_get_string_bbox VIS S; + public ggi_get_string_size VIS S; + + ggi_get_string_size VIS:GGIVisual S:String + = (XMAX-XMIN,YMAX-YMIN) + where (XMIN,XMAX,YMIN,YMAX) = ggi_get_string_bbox VIS S; /* Get and put operations. The get operations allow you to retrieve a pixel, |