AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
stringbounds (String str [, int tight]) typedict.Graphics
 
Returns a Rectangle that represents the bounds of the string str in user space if it were printed at the origin by show on drawable using the current font. The optional tight argument, which is 0 by default, controls the fit of the Rectangle to the str and often closely matches the results that would be obtained using charpath and pathbbox, however in a rotated coordinate system stringbounds usually gives a better fit.

By default the result is a "loose fitting" Rectangle that contains the origin and the advance point, which is the where the current point (i.e., the origin) moves after str is printed by show, and extends ascent units above and descent units below the baseline, which is the line that connects the origin to the advance point. If the optional tight argument is supplied and is non-zero then the result will be a "tight fitting" Rectangle that just covers the characters in str.
 
 Example:   The program,
import yoix.*.*;

JFrame f = {
    Color background = Color.black;

    Graphics graphics = {
        String font = "Lucida-bold-24";
    };

    paint(Rectangle r) {
        String text = "hello, world";

        graphics {        // "named block"
            gsave();
            rectclip(r);
            translate(144, 144);
            rotate(15);
            setrgbcolor(1, 1, 1);
            rectfill(stringbounds(text));
            moveto(0, 0);
            setrgbcolor(1, 0, 0);
            ashow(0, 0, text);
            grestore();
        }
    }
};

f.visible = TRUE;
defines a paint function in a frame that fills the rectangle returned by stringbounds and then prints string in that rectangle.
 
 Return:   Rectangle
 
 See Also:   ashow, awidthshow, charpath, imagepath, kshow, show, showimage, stringadvance, stringwidth, widthshow

 

Yoix is a registered trademark of AT&T Inc.