#ifndef lint static char sccsid[] = "@(#)shape.c 9.2 88/01/19 Copyright 1987 Sun Micro"; #endif /* * Copyright (c) 1987 by Sun Microsystems, Inc. */ /* * Shape Object Primitives * * shape.c, Thu Feb 20 11:19:25 PST 1986 * * David Rosenthal, Sun Microsystems */ #ifdef REF #include #include #endif #include "PostScript.h" getcanvasshape(ee) register struct execution_environment *ee; { register struct body *b; register struct shape *s; if ((s = cs_canvasshape(cs_currentcanvas(&ee->gontext))) != NULL) { if ((b = new_body(shape)) == 0) { ee->error_code = VMerror_error_code; return; } b->type = shape_type; set_typed_bodied_object(ee->optop, shape_type, b); b->body.shape = ee->optop[0].value.shape = s; sh_incref(ee->optop[0].value.shape); object_incref(ee->optop); } else { ee->optop[0].type = null_type; } ee->optop++; } currentpath(ee) register struct execution_environment *ee; { register struct body *b; register struct shape *s; if ((s = cs_currentpath(&ee->gontext)) != NULL) { if ((b = new_body(shape)) == 0) { ee->error_code = VMerror_error_code; return; } b->type = shape_type; set_typed_bodied_object(&(ee->optop[0]), shape_type, b); b->body.shape = ee->optop[0].value.shape = s; sh_incref(ee->optop[0].value.shape); object_incref(&(ee->optop[0])); } else { ee->optop[0].type = null_type; } ee->optop++; } eocurrentpath(ee) register struct execution_environment *ee; { register struct body *b; register struct shape *s; if ((s = cs_eocurrentpath(&ee->gontext)) != NULL) { if ((b = new_body(shape)) == 0) { ee->error_code = VMerror_error_code; return; } b->type = shape_type; set_typed_bodied_object(ee->optop, shape_type, b); b->body.shape = ee->optop[0].value.shape = s; sh_incref(ee->optop[0].value.shape); object_incref(ee->optop); } else { ee->optop[0].type = null_type; } ee->optop++; } setpath(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 1; switch (optop->type) { case shape_type: cs_setpath(&ee->gontext, optop->value.shape); ee->optop--; object_decref(ee->optop); break; case null_type: cs_newpath(&ee->gontext); ee->optop--; break; default: ee->error_code = typecheck_error_code; break; } return; } damagepath(ee) register struct execution_environment *ee; { register struct shape *sh; sh = cs_getdamageshape(cs_currentcanvas(&ee->gontext)); if (sh) { cs_setpath(&ee->gontext, sh); sh_decref(sh); cs_cleardamageshape(cs_currentcanvas(&ee->gontext)); } } emptypath(ee) register struct execution_environment *ee; { set_typed_object(ee->optop, boolean_type); ee->optop->value.fixed = fracti(cs_emptypath(&ee->gontext)); ee->optop++; } pointinpath(ee) register struct execution_environment *ee; { register struct shape *sh; register int ret = 0; struct fpoint pos; extern struct shape *cv_pathtoshape(); sh = cv_pathtoshape(&ee->gontext, ~1); switch (object_type_pair(ee->optop[-2], ee->optop[-1])) { case tp(fixed, fixed): cs_frtransform(&ee->gontext, ee->optop[-2].value.fixed, ee->optop[-1].value.fixed, &pos.x, &pos.y); break; default: ee->error_code = typecheck_error_code; return; } if (cs_pointinshape(sh, roundfr(pos.x), roundfr(pos.y))) ret = fracti(1); ee->optop -= 1; set_typed_object(&(ee->optop[-1]), boolean_type); ee->optop[-1].value.fixed = ret; if (sh) sh_decref(sh); } initialize_shape() { define_operator("getcanvasshape", getcanvasshape, 0, 0, 1); define_operator("currentpath", currentpath, 0, 0, 1); define_operator("eocurrentpath", eocurrentpath, 0, 0, 1); define_operator("setpath", setpath, 0, 1, 0); define_operator("damagepath", damagepath, 0, 0, 0); define_operator("emptypath", emptypath, 0, 0, 1); define_operator("pointinpath", pointinpath, 0, 2, 1); }