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
pathforall (Function moveto, Function lineto, Function quadto, Function curveto, Function closepath) typedict.Path
pathforall (Function handler [, Object extra])  
 
In all cases pathforall walks through this path and calls a function for each path element that is encountered. In the first case the arguments are the functions named moveto, lineto, quadto, curveto, and closepath that are called, when they are not NULL, to handle the five corresponding path elements. Each function is called with the exact arguments that the corresponding moveto, lineto, quadto, curveto, or closepath built-in would use to duplicate the existing path, which means numbers are in the user space described by the CTM associated with this path when pathforall is called.

In the second case the single function named handler, which should accept a variable number of arguments, is called for every path element. The first argument in each call of handler is one of the integer constants SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CURVETO, or SEG_CLOSE defined in yoix.graphics that identifies the type of the path element. Immediately following the path element type are the arguments that the corresponding builtin would use to duplicate the existing path. The optional extra argument is an Object that, if supplied, will be passed as the last argument in each handler call.
 
 Example:   The program,
import yoix.stdio.*;

Path p;

moveto(x, y) = printf(" moveto(%.1f, %.1f);\n", x, y);
lineto(x, y) = printf(" lineto(%.1f, %.1f);\n", x, y);
closepath() = printf(" closepath();\n");

p.moveto(100, 200);
p.rlineto(100, 0);
p.rlineto(0, 200);
p.closepath();

printf("Output before CTM change:\n");
p.pathforall(moveto, lineto, NULL, NULL, closepath);
p.CTM.scale(2, 2);
printf("\nOutput after CTM change:\n");
p.pathforall(moveto, lineto, NULL, NULL, closepath);
prints something like
Output before CTM change:
 moveto(100.0, 200.0);
 lineto(200.0, 200.0);
 lineto(200.0, 400.0);
 closepath();

Output after CTM change:
 moveto(50.0, 100.0);
 lineto(100.0, 100.0);
 lineto(100.0, 200.0);
 closepath();
on standard output. Notice how the coordinates changed after we scaled the CTM associated with the path. Exactly the same output is produced by the program,
import yoix.*.*;

Path p;

Handler(int type, ...) {
    switch (type) {
	case SEG_MOVETO:
	    printf(" moveto(%.1f, %.1f);\n", argv[2], argv[3]);
	    break;

	case SEG_LINETO:
	    printf(" lineto(%.1f, %.1f);\n", argv[2], argv[3]);
	    break;

	case SEG_CLOSE:
	    printf(" closepath();\n\n");
	    break;
    }
}

p.moveto(100, 200);
p.rlineto(100, 0);
p.rlineto(0, 200);
p.closepath();

printf("Output before CTM change:\n");
p.pathforall(Handler);
p.CTM.scale(2, 2);
printf("\nOutput after CTM change:\n");
p.pathforall(Handler);
which uses a single function named Handler to process the individual path elements. The last program,
import yoix.*.*;

String dump;
Path   p;

Handler(int type, ...) {
    Object ptr = argv[argc-1];
    String str;

    switch (type) {
	case SEG_MOVETO:
	    str = strfmt(" moveto(%.1f, %.1f);\n", argv[2], argv[3]);
	    break;

	case SEG_LINETO:
	    str = strfmt(" lineto(%.1f, %.1f);\n", argv[2], argv[3]);
	    break;

	case SEG_CLOSE:
	    str = strfmt(" closepath();\n");
	    break;
    }

    *ptr = *ptr + str;
}

p.moveto(100, 200);
p.rlineto(100, 0);
p.rlineto(0, 200);
p.closepath();

dump += "Output before CTM change:\n";
p.pathforall(Handler, &dump);
p.CTM.scale(2, 2);
dump += "\nOutput after CTM change:\n";
p.pathforall(Handler, &dump);

printf("%s", dump);
writes the same dump to standard output using a single function named Handler to process the individual path elements, but in this case it arranges to pass the address of the output string as the optional second in each of the pathforall calls.
 
 Return:   none
 
 See Also:   arc, arcn, closepath, currentpath, currentpoint, curveto, flattenpath, Graphics, lineto, moveto, newpath, pathbbox, quadto, rcurveto, rlineto, rmoveto, rquadto

 

Yoix is a registered trademark of AT&T Inc.