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 (Object font, String str) yoix.graphics
stringWidth (Object dest, String str)  
 
Returns the advance width of the text string str when printed in font, which can be given as a Font or String, or when printed on the drawable object dest, which must be an Image or a drawable component (i.e., a Swing or AWT component, like a JCanvas, JFrame, or Canvas, that supports a paint function).
 
 Example:   The program,
import yoix.*.*;

JFrame frame = {
    Array layout = {
        new JCanvas {
            String text = "hello, world";
            Color  background = Color.black;

            Graphics graphics = {
                String font = "Helvetica-bold-12";
                Color  foreground = Color.yellow;
            };

            paint(clip) {
                double x;
                double y;

                x = size.width - stringWidth(this, text) - 72./4;
                y = size.height - graphics.font.descent - 72./4;
                drawString(this, text, x, y);
            }
        },
    };
};

frame.visible = TRUE;
sleep(5);
exit(0);
prints a string near the lower right corner of a canvas. stringWidth and font metric information is used to figure out where to place the string so it all shows up properly.
 
 See Also:   clearRect, copyArea, drawArc, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, pointInPolygon, pointInRect, rectContainsRect, rectIntersectionRect, rectIntersectsRect, rectUnionRect, stringBounds

 

Yoix is a registered trademark of AT&T Inc.