#ifndef lint static char sccsid[] = "@(#)pathtoarc.c 9.2 88/01/19 Copyright 1985 Sun Micro"; #endif /* * Copyright (c) 1985 by Sun Microsystems, Inc. */ /*- Convert a PostScript style path to an arclist pathtoarc.c, Thu Sep 19 15:45:44 1985 */ #ifdef REF #include #include #endif #include "shape.h" #include "qalloc.h" struct shape_arc * path_to_arc(path, closed) register struct path *path; { register struct path_element *p = path->element + path->startpos; register struct shape_arc *ret = 0, *tail, *pathstart = 0, *new; register n = path->used - path->startpos; register laststate = MOVE_TO_FLAG; while (--n >= 0) { switch (p->variation) { case MOVE_TO_FLAG: switch (laststate) { case MOVE_TO_FLAG: if (ret == 0) { qtalloc(ret, (struct shape_arc *)); tail = ret; } break; default: if (closed) tail->C = pathstart->A; else { tail->C = tail->B; tail->sh = 0; } qtalloc(new, (struct shape_arc *)); tail->next = new; tail = new; break; case 0: if (closed) { qtalloc(new, (struct shape_arc *)); tail->next = new; new->A = tail->C; new->C = pathstart->A; new->B = new->C; new->sh = 0; tail = new; } case CLOSEPATH_FLAG: qtalloc(new, (struct shape_arc *)); tail->next = new; tail = new; break; } tail->A = p->pos; pathstart = tail; break; case CLOSEPATH_FLAG: switch (laststate) { case MOVE_TO_FLAG: case CLOSEPATH_FLAG: break; case 0: qtalloc(new, (struct shape_arc *)); tail->next = new; new->A = tail->C; new->B = new->A; tail = new; tail->sh = 0; default: tail->C = pathstart->A; break; } pathstart = 0; break; case 0: switch (laststate) { case MOVE_TO_FLAG: if (ret) { tail->sh = 0; tail->C = p->pos; tail->B = tail->C; break; } case CLOSEPATH_FLAG: qtalloc(new, (struct shape_arc *)); if (ret) tail->next = new; else ret = new; new->A = p->pos; tail = new; p->variation = MOVE_TO_FLAG; pathstart = new; break; case 0: qtalloc(new, (struct shape_arc *)); tail->next = new; new->A = tail->C; tail = new; tail->sh = 0; tail->C = p->pos; tail->B = tail->C; break; default: tail->C = p->pos; break; } break; default: switch (laststate) { case MOVE_TO_FLAG: if (ret) { tail->B = p->pos; tail->sh = p->variation; break; } case CLOSEPATH_FLAG: qtalloc(new, (struct shape_arc *)); if (ret) tail->next = new; else ret = new; new->A = p->pos; tail = new; p->variation = MOVE_TO_FLAG; pathstart = new; break; case 0: qtalloc(new, (struct shape_arc *)); tail->next = new; new->A = tail->C; tail = new; tail->B = p->pos; tail->sh = p->variation; break; default: qtalloc(new, (struct shape_arc *)); tail->next = new; tail->C.x = (tail->B.x + p->pos.x) >> 1; tail->C.y = (tail->B.y + p->pos.y) >> 1; new->A = tail->C; tail = new; tail->B = p->pos; tail->sh = p->variation; break; } break; } laststate = p->variation; p++; } switch (laststate) { case CLOSEPATH_FLAG: break; case MOVE_TO_FLAG: if (ret) { tail->C = tail->A; tail->B = tail->A; tail->sh = 0; } break; case 0: if (closed) { qtalloc(new, (struct shape_arc *)); tail->next = new; new->A = tail->C; new->B = new->A; new->C = pathstart->A; tail = new; tail->sh = 0; } break; default: if (closed) tail->C = pathstart->A; else { tail->C = tail->B; tail->sh = 0; } break; } if (ret) tail->next = ret; return ret; } freearc(l) register struct shape_arc *l; { register struct shape_arc *p, *n; p = l; do { n = p->next; qtfree(p); p = n; } while (p != l); }