From 022119cc3148d63f6504ca340dca2eb115033d3a Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 26 Nov 2001 10:27:20 +0000 Subject: Traitement du clipping non rectangulaire. Factorisation du calcul des gradients. --- generic/Rectangle.c | 81 ++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 53 deletions(-) (limited to 'generic/Rectangle.c') diff --git a/generic/Rectangle.c b/generic/Rectangle.c index 1c78971..536303a 100644 --- a/generic/Rectangle.c +++ b/generic/Rectangle.c @@ -433,66 +433,36 @@ ComputeCoordinates(Item item, * by the gradient axis. */ if (!ZnGradientFlat(rect->fill_color)) { - if (rect->fill_color->type == ZN_AXIAL_GRADIENT) { - int angle = rect->fill_color->g.angle; - ZnTransfo *transfo1, *transfo2; - ZnPoint p1[4]; - ZnBBox bbox; - + ZnPoly shape; + + if (rect->fill_color->type == ZN_AXIAL_GRADIENT) { + int angle = rect->fill_color->g.angle; + if ((angle != 0) && (angle != 90) && (angle != 180) && (angle != 270)) { if (!rect->grad_geo) { rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); } - transfo1 = ZnTransfoNew(); - transfo2 = ZnTransfoNew(); - ZnRotateDeg(transfo1, angle); - ZnRotateDeg(transfo2, -angle); - ZnTransformPoints(transfo1, p, p1, 4); - ResetBBox(&bbox); - AddPointsToBBox(&bbox, p1, 4); - p1[0] = bbox.orig; - p1[2] = bbox.corner; - p1[1].x = p1[2].x; - p1[1].y = p1[0].y; - p1[3].x = p1[0].x; - p1[3].y = p1[2].y; - ZnTransfoSetIdentity(transfo1); - ZnTransfoCompose(transfo1, transfo2, wi->current_transfo); - ZnTransformPoints(transfo1, p1, rect->grad_geo, 4); - ZnTransfoFree(transfo1); - ZnTransfoFree(transfo2); + POLY_CONTOUR1(&shape, p, 4); + ComputeAxialGradient(wi, &shape, angle, rect->grad_geo); } else { goto free_ggeo; } + } else if (rect->fill_color->type == ZN_RADIAL_GRADIENT) { - ZnReal dist, new, x, y, fact; - ZnPoint p1[4]; - ZnBBox *bbox = &item->item_bounding_box; - ZnTransfo *transfo1; - if (!rect->grad_geo) { - rect->grad_geo = ZnMalloc(2*sizeof(ZnPoint)); + rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); } - ZnTransformPoint(wi->current_transfo, &rect->fill_color->g.p, &rect->grad_geo[0]); - transfo1 = ZnTransfoNew(); - ZnTranslate(transfo1, -rect->grad_geo[0].x, -rect->grad_geo[0].y); - fact = (bbox->corner.x-bbox->orig.x)/(bbox->corner.y-bbox->orig.y); - ZnScale(transfo1, 1.0, fact); - ZnTransformPoints(transfo1, rect->dev, p1, 4); - dist = 0.0; - for (i = 0; i < 4; i++) { - x = p1[i].x; - y = p1[i].y; - new = x*x+y*y; - if (new > dist) { - dist = new; - } + POLY_CONTOUR1(&shape, rect->dev, 4); + ComputeRadialGradient(wi, &shape, &item->item_bounding_box, + &rect->fill_color->g.p, rect->grad_geo); + } + else if (rect->fill_color->type == ZN_PATH_GRADIENT) { + if (!rect->grad_geo) { + rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); } - rect->grad_geo[1].x = sqrt(dist); - rect->grad_geo[1].y = rect->grad_geo[1].x / fact; - ZnTransfoFree(transfo1); + ZnTransformPoint(wi->current_transfo, &rect->fill_color->g.p, &rect->grad_geo[0]); } } else { @@ -722,9 +692,12 @@ Render(Item item) if (!ZnGradientFlat(rect->fill_color)) { ZnBool fast = (rect->fill_color->type == ZN_AXIAL_GRADIENT) && !rect->grad_geo; + ZnPoly poly; + + POLY_CONTOUR1(&poly, rect->dev, 4); RenderGradient(wi, rect->fill_color, - fast ? NULL : RectRenderCB, - rect, fast ? rect->dev : rect->grad_geo); + fast ? NULL: RectRenderCB, rect, + fast ? rect->dev : rect->grad_geo, &poly); } else { if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ @@ -881,12 +854,13 @@ PostScript(Item item, * * GetClipVertices -- * Get the clipping shape. + * Never ever call TRI_FREE on the tristrip returned by GetClipVertices. * ********************************************************************************** */ static ZnBool -GetClipVertices(Item item, - ZnPoly *poly) +GetClipVertices(Item item, + ZnTriStrip *tristrip) { RectangleItem rect = (RectangleItem) item; ZnPoint *points; @@ -894,7 +868,7 @@ GetClipVertices(Item item, if (ISSET(rect->flags, ALIGNED_BIT)) { ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); - POLY_CONTOUR1(poly, points, 2); + TRI_STRIP1(tristrip, points, 2); if (rect->dev[0].x < rect->dev[2].x) { points[0].x = rect->dev[0].x; @@ -914,7 +888,7 @@ GetClipVertices(Item item, } } else { - POLY_CONTOUR1(poly, rect->dev, 4); + TRI_STRIP1(tristrip, rect->dev, 4); } return ISSET(rect->flags, ALIGNED_BIT); @@ -1013,6 +987,7 @@ static ItemClassStruct RECTANGLE_ITEM_CLASS = { NULL, /* GetFieldSet */ NULL, /* GetAnchor */ GetClipVertices, + NULL, /* GetContours */ Coords, NULL, /* InsertChars */ NULL, /* DeleteChars */ -- cgit v1.1