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
stringwidth (String str) typedict.Graphics
 
Returns the distance the current point would move horizontally in user space if the string str were printed by show on drawable using the current font. The number returned by stringwidth matches the horizontal advance returned by stringadvance.
 
 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);
            moveto(0, 0);
            rlineto(72*3, 0);
            moveto(0, 0);
            rlineto(0, 72*3);
            setrgbcolor(1, 1, 1);
            stroke();
            moveto(-stringwidth(text)/2, 0);
            setrgbcolor(1, 0, 0);
            show(text);
            grestore();
        }
    }
};

f.visible = TRUE;
defines a paint function in a frame that draws coordinate axes and then uses stringwidth to figure out how to print a string so its center end up near the origin.
 
 Return:   double
 
 See Also:   ashow, awidthshow, charpath, imagepath, kshow, show, showimage, stringadvance, stringbounds, widthshow

 

Yoix is a registered trademark of AT&T Inc.