#ifndef lint static char sccsid[] = "@(#)gr_misc.c 9.2 88/01/19 Copyright 1987 Sun Micro"; #endif /* * Copyright (c) 1987 by Sun Microsystems, Inc. */ /* Miscellaneous PostScript graphics primitives gr_misc.c, Thu Mar 14 18:08:59 1985 James Gosling, Sun Microsystems */ #ifdef REF #include #include #endif #include "PostScript.h" #include "input.h" #include "qalloc.h" #include "cursor.h" static kill_everything() { restore_keyboard(); exit(0); } static currentcursorlocation(ee) register struct execution_environment *ee; { short x, y; set_typed_object(ee->optop, fixed_type); set_typed_object(ee->optop + 1, fixed_type); #ifdef OLDCURSORLOCATION cs_screentocanvas(cs_currentcanvas(&ee->gontext), cfloorfr(cv_cursor.ri.pos.x), cfloorfr(cv_cursor.ri.pos.y), &x, &y); #else cs_screentocanvas(cs_currentcanvas(&ee->gontext), cfloorfr(last_event_x), cfloorfr(last_event_y), &x, &y); #endif cs_fritransform(&ee->gontext, fracti(x), fracti(y), &ee->optop[0].value.fixed, &ee->optop[1].value.fixed); ee->optop += 2; } static screentransform(ee) register struct execution_environment *ee; { #ifdef undef struct fpoint pos; if (ee->optop[-2].type != fixed_type || ee->optop[-1].type != fixed_type) { ee->error_code = typecheck_error_code; return; } transform(&ee->transform, ee->optop - 2, &pos); idtransform(&ee->transform, pos.x + fracti(lpr_d(ee->gontext.canvas.value.pixrect)->loc.x), pos.y + fracti(cursor.display->pr_size.y - lpr_d(ee->gontext.canvas.value.pixrect)->loc.y), &ee->optop[-2].value.fixed, &ee->optop[-1].value.fixed); #endif } static currentcanvas(ee) register struct execution_environment *ee; { register struct object *o = ee->optop++; set_typed_object(o, canvas_type); (struct canvas *) o->value.canvas = cs_currentcanvas(&ee->gontext); if (cv_is_canvas(o->value.canvas)) set_body_of(o, cs_currentcanvasspare((struct canvas *) o->value.canvas)); } /* path deltax deltay COPYAREA */ static copyarea(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop; if (optop[-2].type != fixed_type || optop[-1].type != fixed_type) { ee->error_code = typecheck_error_code; return; } ee->optop -= 2; if (ee->execee.value.def->index) cs_eofrcopyarea(&ee->gontext, optop[-2].value.fixed, optop[-1].value.fixed); else cs_frcopyarea(&ee->gontext, optop[-2].value.fixed, optop[-1].value.fixed); } static extenddamage(ee) register struct execution_environment *ee; { if (ee->execee.value.def->index) cs_eoextenddamage(&ee->gontext); else cs_extenddamage(&ee->gontext); } static setdash(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop; fract hold[30]; register fract *d; register struct object *o; register n; if (optop[-1].type != fixed_type || optop[-2].type != array_type) { typecheck_error: ee->error_code = typecheck_error_code; return; } n = optop[-2].value.substring.length; if (n >= sizeof hold / sizeof hold[0]) { ee->error_code = rangecheck_error_code; return; } for (d = hold, o = &body_of(optop - 2)->body.array.objects[optop[-2].value.substring.start]; --n >= 0;) { if (o->type == fixed_type) *d++ = o->value.fixed; else if (o->type == real_type) *d++ = fractf(o->value.real); else goto typecheck_error; } *d++ = 0; cs_frsetdash(&ee->gontext, hold, optop[-1].value.fixed); object_decref(optop - 2); ee->optop -= 2; } static makefont(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop; register struct body *b; register struct psfont *f; FMATRIX m; register i, j; if (optop[-2].type != font_id_type || optop[-1].type != array_type || optop[-1].value.substring.length < 6) { typecheck_error: ee->error_code = typecheck_error_code; return; } b = body_of(optop - 1); for (i = 0; i < 3; i++) for (j = 0; j < 2; j++) { register struct object *el = &b->body.array.objects[optop[-1].value.substring.start + i * 2 + j]; if (el->type == real_type) m[i][j] = fractf(el->value.real); else if (el->type == fixed_type) m[i][j] = el->value.fixed; else goto typecheck_error; } decref(b); b = body_of(optop - 2); f = cs_frmakefont(b->body.font, m); decref(b); b = new_body(font); set_typed_bodied_object(optop - 2, font_id_type, b); b->type = font_id_type; b->body.font = f; ee->optop--; } #define F(n) optop[-n].type == fixed_type #define FV(n) optop[-n].value.fixed #define E(v,n) if(optop[-n].type == real_type) v = optop[-n].value.real; \ else if(optop[-n].type == fixed_type) v = floatfr(optop[-n].value.fixed); \ else goto typecheck_error; static curveto(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop; if (F(1) && F(2) && F(3) && F(4) && F(5) && F(6)) { cs_frcurveto(&ee->gontext, FV(6), FV(5), FV(4), FV(3), FV(2), FV(1)); } else { double x1, y1, x2, y2, x3, y3; E(x1, 6); E(y1, 5); E(x2, 4); E(y2, 3); E(x3, 2); E(y3, 1); cs_flcurveto(&ee->gontext, x1, y1, x2, y2, x3, y3); } ee->optop -= 6; return; typecheck_error: ee->error_code == typecheck_error_code; } static rcurveto(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop; if (F(1) && F(2) && F(3) && F(4) && F(5) && F(6)) { cs_frrcurveto(&ee->gontext, FV(6), FV(5), FV(4), FV(3), FV(2), FV(1)); } else { double x1, y1, x2, y2, x3, y3; E(x1, 6); E(y1, 5); E(x2, 4); E(y2, 3); E(x3, 2); E(y3, 1); cs_flrcurveto(&ee->gontext, x1, y1, x2, y2, x3, y3); } ee->optop -= 6; return; typecheck_error: ee->error_code == typecheck_error_code; } #undef E #undef FV #undef F static /* This is a hack that is likely to last a very long time... */ charpath(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop; register struct shape *sh; if (optop[-1].type != boolean_type || optop[-2].type != string_type) { ee->error_code = typecheck_error_code; return; } sh = cs_cstringbbox(&ee->gontext, body_of(optop-2)->body.string.chars+optop[-2].value.substring.start, optop[-2].value.substring.length); object_decref(optop-2); ee->optop -= 2; cs_setpath(&ee->gontext,sh); sh_decref(sh); } static currentstate(ee) register struct execution_environment *ee; { register struct body *b = new_body(graphicsstate); b->type = graphicsstate_type; set_typed_bodied_object(ee->optop, graphicsstate_type, b); ee->optop++; cs_copy_context_to_empty(&ee->gontext, &b->body.graphicsstate); } static setstate(ee) register struct execution_environment *ee; { register struct body *b; if (ee->optop[-1].type != graphicsstate_type) { ee->error_code = typecheck_error_code; return; } ee->optop--; b = body_of(ee->optop); cs_copy_context_into(&b->body.graphicsstate, &ee->gontext); decref(b); } static currentlinequality(ee) register struct execution_environment *ee; { register n = cs_currentstrokequality(&ee->gontext); if (n < 0) n = -n; set_fixed_object(ee->optop, fraction(n, 64)); ee->optop++; } static setlinequality(ee) register struct execution_environment *ee; { register n; if (ee->optop[-1].type != fixed_type) { ee->error_code = typecheck_error_code; return; } n = roundfr(ee->optop[-1].value.fixed * 64); if (n > 64) n = 64; if (n < 0) n = 0; cs_setstrokequality(&ee->gontext, n); ee->optop--; } static currentflat(ee) register struct execution_environment *ee; { set_fixed_object(ee->optop, fracti(cs_currentflat(&ee->gontext))); ee->optop++; } static setflat(ee) register struct execution_environment *ee; { register n; if (ee->optop[-1].type != fixed_type) { ee->error_code = typecheck_error_code; return; } n = roundfr(ee->optop[-1].value.fixed); cs_setflat(&ee->gontext, n); ee->optop--; } static flattenpath(ee) register struct execution_environment *ee; { cs_flattenpath(&ee->gontext); } struct object slow_stroke_handler_proc; initialize_gr_misc() { define_operator ("currentcursorlocation", currentcursorlocation, 0, 0, 2); define_operator("setdash", setdash, 0, 2, 0); define_operator("makefont", makefont, 0, 2, 1); define_operator("extenddamage", extenddamage, 0, 0, 0); define_operator("eoextenddamage", extenddamage, 1, 0, 0); define_operator("copyarea", copyarea, 0, 2, 0); define_operator("eocopyarea", copyarea, 1, 2, 0); define_operator("curveto", curveto, 0, 6, 0); define_operator("rcurveto", rcurveto, 0, 6, 0); define_operator("charpath", charpath, 0, 2, 0); define_operator("^C", kill_everything, 0, 0, 0); define_operator("currentstate", currentstate, 0, 0, 1); define_operator("setstate", setstate, 0, 1, 0); define_operator("setlinequality", setlinequality, 0, 1, 0); define_operator("currentlinequality", currentlinequality, 0, 0, 1); define_operator("setflat", setflat, 0, 1, 0); define_operator("currentflat", currentflat, 0, 0, 1); define_operator("flattenpath", flattenpath, 0, 0, 0); set_executable_typed_bodied_object(&slow_stroke_handler_proc, keyword_type, get_name("&slow_stroke_handler_proc", -1)); }