#ifndef lint static char sccsid[] = "@(#)fill.c 9.2 88/01/19 Copyright 1985 Sun Micro"; #endif /* * Copyright (c) 1985 by Sun Microsystems, Inc. */ /*- Region filling top level fill.c, Wed Sep 25 10:18:33 1985 */ #ifdef REF #include #include #endif #include "shape.h" #include "canvas.h" #include "qalloc.h" #include "cursor.h" shape_fill(gc, mask) register struct graphics_context *gc; { register struct shape *outline = cv_pathtoshape(gc, mask); if (outline) { extern struct pixrect *grey_patterns[256]; if (gc->clip != ((struct canvas *) gc->canvas)->lastclip && cv_is_canvas(gc->canvas)) cv_validate_clip(gc->canvas, gc->clip); cs_checkcursorshape(gc->canvas, outline); if (gc->canvas->pr_depth == 1) pr_shaperop(gc->canvas, outline, gc->func, grey_patterns[gc->color.hint], 0, 0); else pr_shaperop(gc->canvas, outline, gc->func, 0, 0, 0); sh_decref(outline); } cs_newpath(gc); } struct shape * cv_pathtoshape(gc, mask) register struct graphics_context *gc; { register struct shape *outline; if (gc->path.used == gc->path.startpos) if (gc->shape) { outline = gc->shape; sh_incref(gc->shape); } else outline = 0; else { extern struct shape_trapezon *looptotrap(); register struct path *path; register struct path_element *pe; qtalloc(outline, (struct shape *)); outline->refcnt = 1; path = &gc->path; pe = path->element + path->startpos; if ((path->used - path->startpos == 4 || path->used - path->startpos == 5 && pe[4].variation == CLOSEPATH_FLAG) && path->straight && ((pe[0].pos.x == pe[1].pos.x && pe[2].pos.x == pe[3].pos.x && pe[0].pos.y == pe[3].pos.y && pe[1].pos.y == pe[2].pos.y) || (pe[0].pos.y == pe[1].pos.y && pe[2].pos.y == pe[3].pos.y && pe[0].pos.x == pe[3].pos.x && pe[1].pos.x == pe[2].pos.x))) { outline->pos.x = roundfr(pe[0].pos.x); outline->size.x = roundfr(pe[2].pos.x - pe[0].pos.x); if (outline->size.x < 0) { outline->pos.x += outline->size.x; outline->size.x = -outline->size.x; } outline->pos.y = roundfr(pe[0].pos.y); outline->size.y = roundfr(pe[2].pos.y - pe[0].pos.y); if (outline->size.y < 0) { outline->pos.y += outline->size.y; outline->size.y = -outline->size.y; } outline->is_rect = 1; outline->trapset = 0; } else { register struct shape_trapezon *tr; outline->is_rect = 0; tr = looptotrap(path_to_arc(&gc->path, 1), mask); if ((outline->trapset = tr) == 0) { qtfree(outline); outline = 0; } else { register top, bottom, left, right; top = tr->top; bottom = tr->bottom; left = tr->left; right = tr->right; while (tr = tr->next) { if (tr->left < left) left = tr->left; if (tr->top < top) top = tr->top; if (tr->right > right) right = tr->right; if (tr->bottom > bottom) bottom - tr->bottom; } outline->pos.x = left; outline->pos.y = top; outline->size.x = right - left + 1; outline->size.y = bottom - top + 1; } } } return outline; }