Code

fix visibility and pickability of nofill/nostroke objects in outline mode; optimize...
[inkscape.git] / src / display / nr-arena-shape.cpp
1 #define __NR_ARENA_SHAPE_C__
3 /*
4  * RGBA display list system for inkscape
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 2001-2002 Lauris Kaplinski
10  * Copyright (C) 2001 Ximian, Inc.
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
17 #include <display/nr-arena.h>
18 #include <display/nr-arena-shape.h>
19 #include "display/nr-filter.h"
20 #include "display/nr-filter-gaussian.h"
21 #include "display/nr-filter-types.h"
22 #include <libnr/n-art-bpath.h>
23 #include <libnr/nr-path.h>
24 #include <libnr/nr-pixops.h>
25 #include <libnr/nr-matrix-ops.h>
26 #include <libnr/nr-matrix-fns.h>
27 #include <libnr/nr-blit.h>
28 #include <livarot/Path.h>
29 #include <livarot/float-line.h>
30 #include <livarot/int-line.h>
31 #include <style.h>
32 /* prefs-utils used for deciding, whether to run filtering test or not */
33 #include "prefs-utils.h"
34 #include "sp-filter.h"
35 #include "sp-gaussian-blur.h"
37 //int  showRuns=0;
38 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS);
40 static void nr_arena_shape_class_init(NRArenaShapeClass *klass);
41 static void nr_arena_shape_init(NRArenaShape *shape);
42 static void nr_arena_shape_finalize(NRObject *object);
44 static NRArenaItem *nr_arena_shape_children(NRArenaItem *item);
45 static void nr_arena_shape_add_child(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
46 static void nr_arena_shape_remove_child(NRArenaItem *item, NRArenaItem *child);
47 static void nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
49 static guint nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
50 static unsigned int nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
51 static guint nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
52 static NRArenaItem *nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
54 static NRArenaItemClass *shape_parent_class;
56 NRType
57 nr_arena_shape_get_type(void)
58 {
59     static NRType type = 0;
60     if (!type) {
61         type = nr_object_register_type(NR_TYPE_ARENA_ITEM,
62                                        "NRArenaShape",
63                                        sizeof(NRArenaShapeClass),
64                                        sizeof(NRArenaShape),
65                                        (void (*)(NRObjectClass *)) nr_arena_shape_class_init,
66                                        (void (*)(NRObject *)) nr_arena_shape_init);
67     }
68     return type;
69 }
71 static void
72 nr_arena_shape_class_init(NRArenaShapeClass *klass)
73 {
74     NRObjectClass *object_class;
75     NRArenaItemClass *item_class;
77     object_class = (NRObjectClass *) klass;
78     item_class = (NRArenaItemClass *) klass;
80     shape_parent_class = (NRArenaItemClass *)  ((NRObjectClass *) klass)->parent;
82     object_class->finalize = nr_arena_shape_finalize;
83     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaShape>;
85     item_class->children = nr_arena_shape_children;
86     item_class->add_child = nr_arena_shape_add_child;
87     item_class->set_child_position = nr_arena_shape_set_child_position;
88     item_class->remove_child = nr_arena_shape_remove_child;
89     item_class->update = nr_arena_shape_update;
90     item_class->render = nr_arena_shape_render;
91     item_class->clip = nr_arena_shape_clip;
92     item_class->pick = nr_arena_shape_pick;
93 }
95 static void
96 nr_arena_shape_init(NRArenaShape *shape)
97 {
98     shape->curve = NULL;
99     shape->style = NULL;
100     shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
101     shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
103     nr_matrix_set_identity(&shape->ctm);
104     shape->fill_painter = NULL;
105     shape->stroke_painter = NULL;
106     shape->cached_fill = NULL;
107     shape->cached_stroke = NULL;
108     shape->cached_fpartialy = false;
109     shape->cached_spartialy = false;
110     shape->fill_shp = NULL;
111     shape->stroke_shp = NULL;
113     shape->delayed_shp = false;
115     shape->approx_bbox.x0 = shape->approx_bbox.y0 = 0;
116     shape->approx_bbox.x1 = shape->approx_bbox.y1 = 0;
117     nr_matrix_set_identity(&shape->cached_fctm);
118     nr_matrix_set_identity(&shape->cached_sctm);
120     shape->markers = NULL;
123 static void
124 nr_arena_shape_finalize(NRObject *object)
126     NRArenaShape *shape = (NRArenaShape *) object;
128     if (shape->fill_shp) delete shape->fill_shp;
129     if (shape->stroke_shp) delete shape->stroke_shp;
130     if (shape->cached_fill) delete shape->cached_fill;
131     if (shape->cached_stroke) delete shape->cached_stroke;
132     if (shape->fill_painter) sp_painter_free(shape->fill_painter);
133     if (shape->stroke_painter) sp_painter_free(shape->stroke_painter);
135     if (shape->style) sp_style_unref(shape->style);
136     if (shape->curve) sp_curve_unref(shape->curve);
138     ((NRObjectClass *) shape_parent_class)->finalize(object);
141 static NRArenaItem *
142 nr_arena_shape_children(NRArenaItem *item)
144     NRArenaShape *shape = (NRArenaShape *) item;
146     return shape->markers;
149 static void
150 nr_arena_shape_add_child(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
152     NRArenaShape *shape = (NRArenaShape *) item;
154     if (!ref) {
155         shape->markers = nr_arena_item_attach(item, child, NULL, shape->markers);
156     } else {
157         ref->next = nr_arena_item_attach(item, child, ref, ref->next);
158     }
160     nr_arena_item_request_update(item, NR_ARENA_ITEM_STATE_ALL, FALSE);
163 static void
164 nr_arena_shape_remove_child(NRArenaItem *item, NRArenaItem *child)
166     NRArenaShape *shape = (NRArenaShape *) item;
168     if (child->prev) {
169         nr_arena_item_detach(item, child);
170     } else {
171         shape->markers = nr_arena_item_detach(item, child);
172     }
174     nr_arena_item_request_update(item, NR_ARENA_ITEM_STATE_ALL, FALSE);
177 static void
178 nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
180     NRArenaShape *shape = (NRArenaShape *) item;
182     if (child->prev) {
183         nr_arena_item_detach(item, child);
184     } else {
185         shape->markers = nr_arena_item_detach(item, child);
186     }
188     if (!ref) {
189         shape->markers = nr_arena_item_attach(item, child, NULL, shape->markers);
190     } else {
191         ref->next = nr_arena_item_attach(item, child, ref, ref->next);
192     }
194     nr_arena_item_request_render(child);
197 void nr_arena_shape_update_stroke(NRArenaShape *shape, NRGC* gc, NRRectL *area);
198 void nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape = false);
199 void nr_arena_shape_add_bboxes(NRArenaShape* shape,NRRect &bbox);
201 static guint
202 nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
204     NRRect bbox;
206     NRArenaShape *shape = NR_ARENA_SHAPE(item);
208     unsigned int beststate = NR_ARENA_ITEM_STATE_ALL;
210     unsigned int newstate;
211     for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
212         newstate = nr_arena_item_invoke_update(child, area, gc, state, reset);
213         beststate = beststate & newstate;
214     }
216     if (!(state & NR_ARENA_ITEM_STATE_RENDER)) {
217         /* We do not have to create rendering structures */
218         shape->ctm = gc->transform;
219         if (state & NR_ARENA_ITEM_STATE_BBOX) {
220             if (shape->curve) {
221                 NRBPath bp;
222                 /* fixme: */
223                 bbox.x0 = bbox.y0 = NR_HUGE;
224                 bbox.x1 = bbox.y1 = -NR_HUGE;
225                 bp.path = SP_CURVE_BPATH(shape->curve);
226                 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
227                 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
228                 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
229                 item->bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
230                 item->bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
231             }
232             if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
233                 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
234                     nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
235                 }
236             }
237         }
238         return (state | item->state);
239     }
241     shape->delayed_shp=true;
242     shape->ctm = gc->transform;
243     bbox.x0 = bbox.y0 = NR_HUGE;
244     bbox.x1 = bbox.y1 = -NR_HUGE;
246     bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
248     if (shape->curve) {
249         NRBPath bp;
250         /* fixme: */
251         bbox.x0 = bbox.y0 = NR_HUGE;
252         bbox.x1 = bbox.y1 = -NR_HUGE;
253         bp.path = SP_CURVE_BPATH(shape->curve);
254         nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
255         if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline) {
256             float width, scale;
257             scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
258             width = MAX(0.125, shape->_stroke.width * scale);
259             if ( fabs(shape->_stroke.width * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
260                 bbox.x0-=width;
261                 bbox.x1+=width;
262                 bbox.y0-=width;
263                 bbox.y1+=width;
264             }
265             // those pesky miters, now
266             float miterMax=width*shape->_stroke.mitre_limit;
267             if ( miterMax > 0.01 ) {
268                 // grunt mode. we should compute the various miters instead (one for each point on the curve)
269                 bbox.x0-=miterMax;
270                 bbox.x1+=miterMax;
271                 bbox.y0-=miterMax;
272                 bbox.y1+=miterMax;
273             }
274         }
275     } else {
276     }
277     shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
278     shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
279     shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
280     shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
281     if ( area && nr_rect_l_test_intersect(area, &shape->approx_bbox) ) shape->delayed_shp=false;
283     /* Release state data */
284     if (TRUE || !nr_matrix_test_transform_equal(&gc->transform, &shape->ctm, NR_EPSILON)) {
285         /* Concept test */
286         if (shape->fill_shp) {
287             delete shape->fill_shp;
288             shape->fill_shp = NULL;
289         }
290     }
291     if (shape->stroke_shp) {
292         delete shape->stroke_shp;
293         shape->stroke_shp = NULL;
294     }
295     if (shape->fill_painter) {
296         sp_painter_free(shape->fill_painter);
297         shape->fill_painter = NULL;
298     }
299     if (shape->stroke_painter) {
300         sp_painter_free(shape->stroke_painter);
301         shape->stroke_painter = NULL;
302     }
304     if (!shape->curve || !shape->style) return NR_ARENA_ITEM_STATE_ALL;
305     if (sp_curve_is_empty(shape->curve)) return NR_ARENA_ITEM_STATE_ALL;
306     if ( ( shape->_fill.paint.type() == NRArenaShape::Paint::NONE ) &&
307          ( shape->_stroke.paint.type() == NRArenaShape::Paint::NONE && !outline) )
308     {
309         return NR_ARENA_ITEM_STATE_ALL;
310     }
312     /* Build state data */
313     if ( shape->delayed_shp ) {
314         item->bbox=shape->approx_bbox;
315     } else {
316         nr_arena_shape_update_stroke(shape, gc, area);
317         nr_arena_shape_update_fill(shape, gc, area);
319         bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
320         nr_arena_shape_add_bboxes(shape,bbox);
322         shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
323         shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
324         shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
325         shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
326     }
328     if (nr_rect_d_test_empty(&bbox)) return NR_ARENA_ITEM_STATE_ALL;
330     item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
331     item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
332     item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
333     item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
334     nr_arena_request_render_rect(item->arena, &item->bbox);
336     item->render_opacity = TRUE;
337     if ( shape->_fill.paint.type() == NRArenaShape::Paint::SERVER ) {
338         if (gc && gc->parent) {
339             shape->fill_painter = sp_paint_server_painter_new(shape->_fill.paint.server(),
340                                                               NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
341                                                               &shape->paintbox);
342         }
343         item->render_opacity = FALSE;
344     }
345     if ( shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER ) {
346         if (gc && gc->parent) {
347             shape->stroke_painter = sp_paint_server_painter_new(shape->_stroke.paint.server(),
348                                                                 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
349                                                                 &shape->paintbox);
350         }
351         item->render_opacity = FALSE;
352     }
353     if ( item->render_opacity == TRUE
354          && shape->_fill.paint.type()   != NRArenaShape::Paint::NONE
355          && shape->_stroke.paint.type() != NRArenaShape::Paint::NONE )
356     {
357         // don't merge item opacity with paint opacity if there is a stroke on the fill
358         item->render_opacity = FALSE;
359     }
361     if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
362         for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
363             nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
364         }
365     }
367     return NR_ARENA_ITEM_STATE_ALL;
370 int matrix_is_isometry(NR::Matrix p) {
371     NR::Matrix   tp;
372     // transposition
373     tp[0]=p[0];
374     tp[1]=p[2];
375     tp[2]=p[1];
376     tp[3]=p[3];
377     for (int i = 4; i < 6; i++) // shut valgrind up :)
378         tp[i] = p[i] = 0;
379     NR::Matrix   isom = tp*p; // A^T * A = adjunct?
380     // Is the adjunct nearly an identity function?
381     if (isom.is_translation(0.01)) {
382         // the transformation is an isometry -> no need to recompute
383         // the uncrossed polygon
384         if ( p.det() < 0 )
385             return -1;
386         else
387             return 1;
388     }
389     return 0;
392 static bool is_inner_area(NRRectL const &outer, NRRectL const &inner) {
393     return (outer.x0 <= inner.x0 && outer.y0 <= inner.y0 && outer.x1 >= inner.x1 && outer.y1 >= inner.y1);
396 /** force_shape is used for clipping paths, when we need the shape for clipping even if it's not filled */
397 void
398 nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape)
400     if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) &&
401         ((shape->curve->end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) {
402         if (TRUE || !shape->fill_shp) {
403             NR::Matrix  cached_to_new = NR::identity();
404             int isometry = 0;
405             if ( shape->cached_fill ) {
406                 if (shape->cached_fctm == gc->transform) {
407                     isometry = 2; // identity
408                 } else {
409                     cached_to_new = shape->cached_fctm.inverse() * gc->transform;
410                     isometry = matrix_is_isometry(cached_to_new);
411                 }
412                 if (0 != isometry && !is_inner_area(shape->cached_farea, *area))
413                     isometry = 0;
414             }
415             if ( isometry == 0 ) {
416                 if ( shape->cached_fill == NULL ) shape->cached_fill=new Shape;
417                 shape->cached_fill->Reset();
419                 Path*  thePath=new Path;
420                 Shape* theShape=new Shape;
421                 {
422                     NR::Matrix   tempMat(gc->transform);
423                     thePath->LoadArtBPath(SP_CURVE_BPATH(shape->curve),tempMat,true);
424                 }
426                 if (is_inner_area(*area, NR_ARENA_ITEM(shape)->bbox)) {
427                     thePath->Convert(1.0);
428                     shape->cached_fpartialy = false;
429                 } else {
430                     thePath->Convert(area, 1.0);
431                     shape->cached_fpartialy = true;
432                 }
434                 thePath->Fill(theShape, 0);
436                 if ( shape->_fill.rule == NRArenaShape::EVEN_ODD ) {
437                     shape->cached_fill->ConvertToShape(theShape, fill_oddEven);
438                     // alternatively, this speeds up rendering of oddeven shapes but disables AA :(
439                     //shape->cached_fill->Copy(theShape);
440                 } else {
441                     shape->cached_fill->ConvertToShape(theShape, fill_nonZero);
442                 }
443                 shape->cached_fctm=gc->transform;
444                 shape->cached_farea = *area;
445                 delete theShape;
446                 delete thePath;
447                 if ( shape->fill_shp == NULL )
448                     shape->fill_shp = new Shape;
450                 shape->fill_shp->Copy(shape->cached_fill);
452             } else if ( 2 == isometry ) {
453                 if ( shape->fill_shp == NULL ) {
454                     shape->fill_shp = new Shape;
455                     shape->fill_shp->Copy(shape->cached_fill);
456                 }
457             } else {
459                 if ( shape->fill_shp == NULL )
460                     shape->fill_shp = new Shape;
462                 shape->fill_shp->Reset(shape->cached_fill->numberOfPoints(),
463                                        shape->cached_fill->numberOfEdges());
464                 for (int i = 0; i < shape->cached_fill->numberOfPoints(); i++)
465                     shape->fill_shp->AddPoint(shape->cached_fill->getPoint(i).x * cached_to_new);
466                 if ( isometry == 1 ) {
467                     for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
468                         shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).st,
469                                                  shape->cached_fill->getEdge(i).en);
470                 } else if ( isometry == -1 ) { // need to flip poly.
471                     for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
472                         shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).en,
473                                                  shape->cached_fill->getEdge(i).st);
474                 }
475                 shape->fill_shp->ForceToPolygon();
476                 shape->fill_shp->needPointsSorting();
477                 shape->fill_shp->needEdgesSorting();
478             }
479             shape->delayed_shp |= shape->cached_fpartialy;
480         }
481     }
484 void
485 nr_arena_shape_update_stroke(NRArenaShape *shape,NRGC* gc, NRRectL *area)
487     SPStyle* style = shape->style;
489     float const scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
491     bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
493     if (outline ||
494         ((shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) &&
495          ( fabs(shape->_stroke.width * scale) > 0.01 ))) { // sinon c'est 0=oon veut pas de bord
497         float width = MAX(0.125, shape->_stroke.width * scale);
498         if (outline)
499             width = 0.5; // 1 pixel wide, independent of zoom
501         NR::Matrix  cached_to_new = NR::identity();
503         int isometry = 0;
504         if ( shape->cached_stroke ) {
505             if (shape->cached_sctm == gc->transform) {
506                 isometry = 2; // identity
507             } else {
508                 cached_to_new = shape->cached_sctm.inverse() * gc->transform;
509                 isometry = matrix_is_isometry(cached_to_new);
510             }
511             if (0 != isometry && !is_inner_area(shape->cached_sarea, *area))
512                 isometry = 0;
513         }
515         if ( isometry == 0 ) {
516             if ( shape->cached_stroke == NULL ) shape->cached_stroke=new Shape;
517             shape->cached_stroke->Reset();
518             Path*  thePath = new Path;
519             Shape* theShape = new Shape;
520             {
521                 NR::Matrix   tempMat(gc->transform);
522                 thePath->LoadArtBPath(SP_CURVE_BPATH(shape->curve), tempMat, true);
523             }
525             // add some padding to the rendering area, so clipped path does not go into a render area
526             NRRectL padded_area = *area;
527             padded_area.x0 -= (NR::ICoord)width;
528             padded_area.x1 += (NR::ICoord)width;
529             padded_area.y0 -= (NR::ICoord)width;
530             padded_area.y1 += (NR::ICoord)width;
531             if ((style->stroke_dash.n_dash && !outline) || is_inner_area(padded_area, NR_ARENA_ITEM(shape)->bbox)) {
532                 thePath->Convert((outline) ? 4.0 : 1.0);
533                 shape->cached_spartialy = false;
534             }
535             else {
536                 thePath->Convert(&padded_area, (outline) ? 4.0 : 1.0);
537                 shape->cached_spartialy = true;
538             }
540             if (style->stroke_dash.n_dash && !outline) {
541                 thePath->DashPolylineFromStyle(style, scale, 1.0);
542             }
544             ButtType butt=butt_straight;
545             switch (shape->_stroke.cap) {
546                 case NRArenaShape::BUTT_CAP:
547                     butt = butt_straight;
548                     break;
549                 case NRArenaShape::ROUND_CAP:
550                     butt = butt_round;
551                     break;
552                 case NRArenaShape::SQUARE_CAP:
553                     butt = butt_square;
554                     break;
555             }
556             JoinType join=join_straight;
557             switch (shape->_stroke.join) {
558                 case NRArenaShape::MITRE_JOIN:
559                     join = join_pointy;
560                     break;
561                 case NRArenaShape::ROUND_JOIN:
562                     join = join_round;
563                     break;
564                 case NRArenaShape::BEVEL_JOIN:
565                     join = join_straight;
566                     break;
567             }
569             if (outline) {
570                 butt = butt_straight;
571                 join = join_straight;
572             }
574             thePath->Stroke(theShape, false, 0.5*width, join, butt,
575                             0.5*width*shape->_stroke.mitre_limit);
578             if (outline) {
579                 // speeds it up, but uses evenodd for the stroke shape (which does not matter for 1-pixel wide outline)
580                 shape->cached_stroke->Copy(theShape);
581             } else {
582                 shape->cached_stroke->ConvertToShape(theShape, fill_nonZero);
583             }
585             shape->cached_sctm=gc->transform;
586             shape->cached_sarea = *area;
587             delete thePath;
588             delete theShape;
589             if ( shape->stroke_shp == NULL ) shape->stroke_shp=new Shape;
591             shape->stroke_shp->Copy(shape->cached_stroke);
593         } else if ( 2 == isometry ) {
594             if ( shape->stroke_shp == NULL ) {
595                 shape->stroke_shp=new Shape;
596                 shape->stroke_shp->Copy(shape->cached_stroke);
597             }
598         } else {
599             if ( shape->stroke_shp == NULL )
600                 shape->stroke_shp=new Shape;
601             shape->stroke_shp->Reset(shape->cached_stroke->numberOfPoints(), shape->cached_stroke->numberOfEdges());
602             for (int i = 0; i < shape->cached_stroke->numberOfPoints(); i++)
603                 shape->stroke_shp->AddPoint(shape->cached_stroke->getPoint(i).x * cached_to_new);
604             if ( isometry == 1 ) {
605                 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
606                     shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).st,
607                                                shape->cached_stroke->getEdge(i).en);
608             } else if ( isometry == -1 ) {
609                 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
610                     shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).en,
611                                                shape->cached_stroke->getEdge(i).st);
612             }
613             shape->stroke_shp->ForceToPolygon();
614             shape->stroke_shp->needPointsSorting();
615             shape->stroke_shp->needEdgesSorting();
616         }
617         shape->delayed_shp |= shape->cached_spartialy;
618     }
622 void
623 nr_arena_shape_add_bboxes(NRArenaShape* shape, NRRect &bbox)
625     if ( shape->stroke_shp ) {
626         shape->stroke_shp->CalcBBox();
627         shape->stroke_shp->leftX=floor(shape->stroke_shp->leftX);
628         shape->stroke_shp->rightX=ceil(shape->stroke_shp->rightX);
629         shape->stroke_shp->topY=floor(shape->stroke_shp->topY);
630         shape->stroke_shp->bottomY=ceil(shape->stroke_shp->bottomY);
631         if ( bbox.x0 >= bbox.x1 ) {
632             if ( shape->stroke_shp->leftX < shape->stroke_shp->rightX ) {
633                 bbox.x0=shape->stroke_shp->leftX;
634                 bbox.x1=shape->stroke_shp->rightX;
635             }
636         } else {
637             if ( shape->stroke_shp->leftX < bbox.x0 )
638                 bbox.x0=shape->stroke_shp->leftX;
639             if ( shape->stroke_shp->rightX > bbox.x1 )
640                 bbox.x1=shape->stroke_shp->rightX;
641         }
642         if ( bbox.y0 >= bbox.y1 ) {
643             if ( shape->stroke_shp->topY < shape->stroke_shp->bottomY ) {
644                 bbox.y0=shape->stroke_shp->topY;
645                 bbox.y1=shape->stroke_shp->bottomY;
646             }
647         } else {
648             if ( shape->stroke_shp->topY < bbox.y0 )
649                 bbox.y0=shape->stroke_shp->topY;
650             if ( shape->stroke_shp->bottomY > bbox.y1 )
651                 bbox.y1=shape->stroke_shp->bottomY;
652         }
653     }
654     if ( shape->fill_shp ) {
655         shape->fill_shp->CalcBBox();
656         shape->fill_shp->leftX=floor(shape->fill_shp->leftX);
657         shape->fill_shp->rightX=ceil(shape->fill_shp->rightX);
658         shape->fill_shp->topY=floor(shape->fill_shp->topY);
659         shape->fill_shp->bottomY=ceil(shape->fill_shp->bottomY);
660         if ( bbox.x0 >= bbox.x1 ) {
661             if ( shape->fill_shp->leftX < shape->fill_shp->rightX ) {
662                 bbox.x0=shape->fill_shp->leftX;
663                 bbox.x1=shape->fill_shp->rightX;
664             }
665         } else {
666             if ( shape->fill_shp->leftX < bbox.x0 ) bbox.x0=shape->fill_shp->leftX;
667             if ( shape->fill_shp->rightX > bbox.x1 ) bbox.x1=shape->fill_shp->rightX;
668         }
669         if ( bbox.y0 >= bbox.y1 ) {
670             if ( shape->fill_shp->topY < shape->fill_shp->bottomY ) {
671                 bbox.y0=shape->fill_shp->topY;
672                 bbox.y1=shape->fill_shp->bottomY;
673             }
674         } else {
675             if ( shape->fill_shp->topY < bbox.y0 ) bbox.y0=shape->fill_shp->topY;
676             if ( shape->fill_shp->bottomY > bbox.y1 ) bbox.y1=shape->fill_shp->bottomY;
677         }
678     }
680 static unsigned int
681 nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags)
683     NRArenaShape *shape = NR_ARENA_SHAPE(item);
685     if (!shape->curve) return item->state;
686     if (!shape->style) return item->state;
688     if ( shape->delayed_shp ) {
689         if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
690             NRGC   tempGC(NULL);
691             tempGC.transform=shape->ctm;
692             shape->delayed_shp = false;
693             nr_arena_shape_update_stroke(shape,&tempGC,&pb->visible_area);
694             nr_arena_shape_update_fill(shape,&tempGC,&pb->visible_area);
695 /*      NRRect bbox;
696         bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
697         nr_arena_shape_add_bboxes(shape,bbox);
698         item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
699         item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
700         item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
701         item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
702         shape->approx_bbox=item->bbox;*/
703         } else {
704             return item->state;
705         }
706     }
708     bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
710     SPStyle const *style = shape->style;
711     if ( shape->fill_shp && !outline) {
712         NRPixBlock m;
713         guint32 rgba;
715         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
717         // if memory allocation failed, abort render
718         if (m.data.px == NULL) {
719             nr_pixblock_release (&m);
720             return (item->state);
721         }
723         m.visible_area = pb->visible_area; 
724         nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
725         m.empty = FALSE;
727         if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) {
728             // do not render fill in any way
729         } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) {
730             if ( item->render_opacity ) {
731                 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
732                                                   shape->_fill.opacity *
733                                                   SP_SCALE24_TO_FLOAT(style->opacity.value));
734             } else {
735                 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
736                                                   shape->_fill.opacity);
737             }
738             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
739             pb->empty = FALSE;
740         } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) {
741             if (shape->fill_painter) {
742                 nr_arena_render_paintserver_fill(pb, area, shape->fill_painter, shape->_fill.opacity, &m);
743             }
744         }
746         nr_pixblock_release(&m);
747     }
749     if ( shape->stroke_shp ) {
750         NRPixBlock m;
751         guint32 rgba;
753         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
755         // if memory allocation failed, abort render
756         if (m.data.px == NULL) {
757             nr_pixblock_release (&m);
758             return (item->state);
759         }
761         m.visible_area = pb->visible_area; 
762         nr_pixblock_render_shape_mask_or(m, shape->stroke_shp);
763         m.empty = FALSE;
765         if (shape->_stroke.paint.type() == NRArenaShape::Paint::COLOR || outline) {
766             if (outline) {
767                 rgba = NR_ARENA_ITEM(shape)->arena->outlinecolor;
768             } else if ( item->render_opacity ) {
769                 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
770                                                   shape->_stroke.opacity *
771                                                   SP_SCALE24_TO_FLOAT(style->opacity.value));
772             } else {
773                 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
774                                                   shape->_stroke.opacity);
775             }
776             nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
777             pb->empty = FALSE;
778         } else if (shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER) {
779             if (shape->stroke_painter) {
780                 nr_arena_render_paintserver_fill(pb, area, shape->stroke_painter, shape->_stroke.opacity, &m);
781             }
782         }
784         nr_pixblock_release(&m);
785     }
787     /* Just compose children into parent buffer */
788     for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
789         unsigned int ret;
790         ret = nr_arena_item_invoke_render(child, area, pb, flags);
791         if (ret & NR_ARENA_ITEM_STATE_INVALID) return ret;
792     }
794     return item->state;
797 static guint
798 nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
800     NRArenaShape *shape = NR_ARENA_SHAPE(item);
801     if (!shape->curve) return item->state;
803     if ( shape->delayed_shp || shape->fill_shp == NULL) { // we need a fill shape no matter what
804         if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
805             NRGC   tempGC(NULL);
806             tempGC.transform=shape->ctm;
807             shape->delayed_shp = false;
808             nr_arena_shape_update_fill(shape, &tempGC, &pb->visible_area, true);
809         } else {
810             return item->state;
811         }
812     }
814     if ( shape->fill_shp ) {
815         NRPixBlock m;
817         /* fixme: We can OR in one step (Lauris) */
818         nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
820         // if memory allocation failed, abort 
821         if (m.data.px == NULL) {
822             nr_pixblock_release (&m);
823             return (item->state);
824         }
826         m.visible_area = pb->visible_area; 
827         nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
829         for (int y = area->y0; y < area->y1; y++) {
830             unsigned char *s, *d;
831             s = NR_PIXBLOCK_PX(&m) + (y - area->y0) * m.rs;
832             d = NR_PIXBLOCK_PX(pb) + (y - area->y0) * pb->rs;
833             for (int x = area->x0; x < area->x1; x++) {
834                 *d = NR_COMPOSEA_111(*s, *d);
835                 d ++;
836                 s ++;
837             }
838         }
839         nr_pixblock_release(&m);
840         pb->empty = FALSE;
841     }
843     return item->state;
846 static NRArenaItem *
847 nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/)
849     NRArenaShape *shape = NR_ARENA_SHAPE(item);
851     if (!shape->curve) return NULL;
852     if (!shape->style) return NULL;
853     if ( shape->delayed_shp ) {
854         NRRectL  area, updateArea;
855         area.x0=(int)floor(p[NR::X]);
856         area.x1=(int)ceil(p[NR::X]);
857         area.y0=(int)floor(p[NR::Y]);
858         area.y1=(int)ceil(p[NR::Y]);
859         int idelta = (int)ceil(delta) + 1;
860         // njh: inset rect
861         area.x0-=idelta;
862         area.x1+=idelta;
863         area.y0-=idelta;
864         area.y1+=idelta;
865         if ( nr_rect_l_test_intersect(&area, &item->bbox) ) {
866             NRGC   tempGC(NULL);
867             tempGC.transform=shape->ctm;
868             updateArea = item->bbox;
869             if (shape->cached_stroke)
870                 nr_rect_l_intersect (&updateArea, &updateArea, &shape->cached_sarea);
872             shape->delayed_shp = false;
873             nr_arena_shape_update_stroke(shape, &tempGC, &updateArea);
874             nr_arena_shape_update_fill(shape, &tempGC, &updateArea);
875             /*      NRRect bbox;
876                     bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
877                     nr_arena_shape_add_bboxes(shape,bbox);
878                     item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
879                     item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
880                     item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
881                     item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
882                     shape->approx_bbox=item->bbox;*/
883         }
884     }
886     bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
888     if (item->state & NR_ARENA_ITEM_STATE_RENDER) {
889         if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
890             if (shape->fill_shp->PtWinding(p) > 0 ) return item;
891         }
892         if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline)) {
893             if (shape->stroke_shp->PtWinding(p) > 0 ) return item;
894         }
895         if (delta > 1e-3) {
896             if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
897                 if (distanceLessThanOrEqual(shape->fill_shp, p, delta)) return item;
898             }
899             if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline)) {
900                 if (distanceLessThanOrEqual(shape->stroke_shp, p, delta)) return item;
901             }
902         }
903     } else {
904         NRBPath bp;
905         bp.path = SP_CURVE_BPATH(shape->curve);
906         double dist = NR_HUGE;
907         int wind = 0;
908         nr_path_matrix_point_bbox_wind_distance(&bp, shape->ctm, p, NULL, &wind, &dist, NR_EPSILON);
909         if (shape->_fill.paint.type() != NRArenaShape::Paint::NONE) {
910             if (!shape->style->fill_rule.computed) {
911                 if (wind != 0) return item;
912             } else {
913                 if (wind & 0x1) return item;
914             }
915         }
916         if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline) {
917             /* fixme: We do not take stroke width into account here (Lauris) */
918             if (dist < delta) return item;
919         }
920     }
922     return NULL;
925 /**
926  *
927  *  Requests a render of the shape, then if the shape is already a curve it
928  *  unrefs the old curve; if the new curve is valid it creates a copy of the
929  *  curve and adds it to the shape.  Finally, it requests an update of the
930  *  arena for the shape.
931  */
932 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve,bool justTrans)
934     g_return_if_fail(shape != NULL);
935     g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
937     if ( justTrans == false ) {
938         // dirty cached versions
939         if ( shape->cached_fill ) {
940             delete shape->cached_fill;
941             shape->cached_fill=NULL;
942         }
943         if ( shape->cached_stroke ) {
944             delete shape->cached_stroke;
945             shape->cached_stroke=NULL;
946         }
947     }
949     nr_arena_item_request_render(NR_ARENA_ITEM(shape));
951     if (shape->curve) {
952         sp_curve_unref(shape->curve);
953         shape->curve = NULL;
954     }
956     if (curve) {
957         shape->curve = curve;
958         sp_curve_ref(curve);
959     }
961     nr_arena_item_request_update(NR_ARENA_ITEM(shape), NR_ARENA_ITEM_STATE_ALL, FALSE);
964 void NRArenaShape::setFill(SPPaintServer *server) {
965     _fill.paint.set(server);
966     _invalidateCachedFill();
969 void NRArenaShape::setFill(SPColor const &color) {
970     _fill.paint.set(color);
971     _invalidateCachedFill();
974 void NRArenaShape::setFillOpacity(double opacity) {
975     _fill.opacity = opacity;
976     _invalidateCachedFill();
979 void NRArenaShape::setFillRule(NRArenaShape::FillRule rule) {
980     _fill.rule = rule;
981     _invalidateCachedFill();
984 void NRArenaShape::setStroke(SPPaintServer *server) {
985     _stroke.paint.set(server);
986     _invalidateCachedStroke();
989 void NRArenaShape::setStroke(SPColor const &color) {
990     _stroke.paint.set(color);
991     _invalidateCachedStroke();
994 void NRArenaShape::setStrokeOpacity(double opacity) {
995     _stroke.opacity = opacity;
996     _invalidateCachedStroke();
999 void NRArenaShape::setStrokeWidth(double width) {
1000     _stroke.width = width;
1001     _invalidateCachedStroke();
1004 void NRArenaShape::setMitreLimit(double limit) {
1005     _stroke.mitre_limit = limit;
1006     _invalidateCachedStroke();
1009 void NRArenaShape::setLineCap(NRArenaShape::CapType cap) {
1010     _stroke.cap = cap;
1011     _invalidateCachedStroke();
1014 void NRArenaShape::setLineJoin(NRArenaShape::JoinType join) {
1015     _stroke.join = join;
1016     _invalidateCachedStroke();
1019 /** nr_arena_shape_set_style
1020  *
1021  * Unrefs any existing style and ref's to the given one, then requests an update of the arena
1022  */
1023 void
1024 nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style)
1026     g_return_if_fail(shape != NULL);
1027     g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1029     if (style) sp_style_ref(style);
1030     if (shape->style) sp_style_unref(shape->style);
1031     shape->style = style;
1033     switch (style->fill.type) {
1034         case SP_PAINT_TYPE_NONE: {
1035             shape->setFill(NULL);
1036             break;
1037         }
1038         case SP_PAINT_TYPE_COLOR: {
1039             shape->setFill(style->fill.value.color);
1040             break;
1041         }
1042         case SP_PAINT_TYPE_PAINTSERVER: {
1043             shape->setFill(style->fill.value.paint.server);
1044             break;
1045         }
1046         default: {
1047             g_assert_not_reached();
1048         }
1049     }
1050     shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
1051     switch (style->fill_rule.computed) {
1052         case SP_WIND_RULE_EVENODD: {
1053             shape->setFillRule(NRArenaShape::EVEN_ODD);
1054             break;
1055         }
1056         case SP_WIND_RULE_NONZERO: {
1057             shape->setFillRule(NRArenaShape::NONZERO);
1058             break;
1059         }
1060         default: {
1061             g_assert_not_reached();
1062         }
1063     }
1065     switch (style->stroke.type) {
1066         case SP_PAINT_TYPE_NONE: {
1067             shape->setStroke(NULL);
1068             break;
1069         }
1070         case SP_PAINT_TYPE_COLOR: {
1071             shape->setStroke(style->stroke.value.color);
1072             break;
1073         }
1074         case SP_PAINT_TYPE_PAINTSERVER: {
1075             shape->setStroke(style->stroke.value.paint.server);
1076             break;
1077         }
1078         default: {
1079             g_assert_not_reached();
1080         }
1081     }
1082     shape->setStrokeWidth(style->stroke_width.computed);
1083     shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
1084     switch (style->stroke_linecap.computed) {
1085         case SP_STROKE_LINECAP_ROUND: {
1086             shape->setLineCap(NRArenaShape::ROUND_CAP);
1087             break;
1088         }
1089         case SP_STROKE_LINECAP_SQUARE: {
1090             shape->setLineCap(NRArenaShape::SQUARE_CAP);
1091             break;
1092         }
1093         case SP_STROKE_LINECAP_BUTT: {
1094             shape->setLineCap(NRArenaShape::BUTT_CAP);
1095             break;
1096         }
1097         default: {
1098             g_assert_not_reached();
1099         }
1100     }
1101     switch (style->stroke_linejoin.computed) {
1102         case SP_STROKE_LINEJOIN_ROUND: {
1103             shape->setLineJoin(NRArenaShape::ROUND_JOIN);
1104             break;
1105         }
1106         case SP_STROKE_LINEJOIN_BEVEL: {
1107             shape->setLineJoin(NRArenaShape::BEVEL_JOIN);
1108             break;
1109         }
1110         case SP_STROKE_LINEJOIN_MITER: {
1111             shape->setLineJoin(NRArenaShape::MITRE_JOIN);
1112             break;
1113         }
1114         default: {
1115             g_assert_not_reached();
1116         }
1117     }
1118     shape->setMitreLimit(style->stroke_miterlimit.value);
1120     //if shape has a filter
1121     if (style->filter.set && style->filter.filter) 
1122     {
1123         shape->filter = new NR::Filter();
1124         shape->filter->set_x(style->filter.filter->x);
1125         shape->filter->set_y(style->filter.filter->y);
1126         shape->filter->set_width(style->filter.filter->width);
1127         shape->filter->set_height(style->filter.filter->height);
1128         
1129         //go through all SP filter primitives
1130         for(int i=0; i<style->filter.filter->_primitive_count; i++)
1131         {
1132             SPFilterPrimitive *primitive = style->filter.filter->_primitives[i];
1133             //if primitive is gaussianblur
1134 //            if(SP_IS_GAUSSIANBLUR(primitive))
1135             {
1136                 NR::FilterGaussian * gaussian = (NR::FilterGaussian *) shape->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR);
1137                 SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
1138                 float num = spblur->stdDeviation.getNumber();
1139                 if( num>=0.0 )
1140                 {
1141                     float optnum = spblur->stdDeviation.getOptNumber();
1142                     if( optnum>=0.0 )
1143                         gaussian->set_deviation((double) num, (double) optnum);
1144                     else
1145                         gaussian->set_deviation((double) num);
1146                 }
1147             }
1148         }
1149     }
1150     else
1151     {
1152         //no filter set for this shape
1153         shape->filter = NULL;
1154     }
1156     nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1159 void
1160 nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox)
1162     g_return_if_fail(shape != NULL);
1163     g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1164     g_return_if_fail(pbox != NULL);
1166     if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
1167         shape->paintbox = *pbox;
1168     } else {
1169         /* fixme: We kill warning, although not sure what to do here (Lauris) */
1170         shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
1171         shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
1172     }
1174     nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1177 void NRArenaShape::setPaintBox(NR::Rect const &pbox)
1179     paintbox.x0 = pbox.min()[NR::X];
1180     paintbox.y0 = pbox.min()[NR::Y];
1181     paintbox.x1 = pbox.max()[NR::X];
1182     paintbox.y1 = pbox.max()[NR::Y];
1184     nr_arena_item_request_update(this, NR_ARENA_ITEM_STATE_ALL, FALSE);
1187 static void
1188 shape_run_A8_OR(raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
1190     if ( st >= en ) return;
1191     if ( vst < 0 ) vst=0;
1192     if ( vst > 1 ) vst=1;
1193     if ( ven < 0 ) ven=0;
1194     if ( ven > 1 ) ven=1;
1195     float   sv=vst;
1196     float   dv=ven-vst;
1197     int     len=en-st;
1198     unsigned char*   d=(unsigned char*)dest.buffer;
1199     d+=(st-dest.startPix);
1200     if ( fabs(dv) < 0.001 ) {
1201         if ( vst > 0.999 ) {
1202             /* Simple copy */
1203             while (len > 0) {
1204                 d[0] = 255;
1205                 d += 1;
1206                 len -= 1;
1207             }
1208         } else {
1209             sv*=256;
1210             unsigned int c0_24=(int)sv;
1211             c0_24&=0xFF;
1212             while (len > 0) {
1213                 /* Draw */
1214                 d[0] = NR_COMPOSEA_111(c0_24,d[0]);
1215                 d += 1;
1216                 len -= 1;
1217             }
1218         }
1219     } else {
1220         if ( en <= st+1 ) {
1221             sv=0.5*(vst+ven);
1222             sv*=256;
1223             unsigned int c0_24=(int)sv;
1224             c0_24&=0xFF;
1225             /* Draw */
1226             d[0] = NR_COMPOSEA_111(c0_24,d[0]);
1227         } else {
1228             dv/=len;
1229             sv+=0.5*dv; // correction trapezoidale
1230             sv*=16777216;
1231             dv*=16777216;
1232             int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
1233             int s0_24 = static_cast<int>(dv);
1234             while (len > 0) {
1235                 unsigned int ca;
1236                 /* Draw */
1237                 ca = c0_24 >> 16;
1238                 if ( ca > 255 ) ca=255;
1239                 d[0] = NR_COMPOSEA_111(ca,d[0]);
1240                 d += 1;
1241                 c0_24 += s0_24;
1242                 c0_24 = CLAMP(c0_24, 0, 16777216);
1243                 len -= 1;
1244             }
1245         }
1246     }
1249 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS)
1251     theS->CalcBBox();
1252     float l = theS->leftX, r = theS->rightX, t = theS->topY, b = theS->bottomY;
1253     int    il,ir,it,ib;
1254     il=(int)floor(l);
1255     ir=(int)ceil(r);
1256     it=(int)floor(t);
1257     ib=(int)ceil(b);
1259     if ( il >= m.area.x1 || ir <= m.area.x0 || it >= m.area.y1 || ib <= m.area.y0 ) return;
1260     if ( il < m.area.x0 ) il=m.area.x0;
1261     if ( it < m.area.y0 ) it=m.area.y0;
1262     if ( ir > m.area.x1 ) ir=m.area.x1;
1263     if ( ib > m.area.y1 ) ib=m.area.y1;
1265     /* This is the FloatLigne version.  See svn (prior to Apr 2006) for versions using BitLigne or direct BitLigne. */
1266     int    curPt;
1267     float  curY;
1268     theS->BeginQuickRaster(curY, curPt);
1270     FloatLigne *theI = new FloatLigne();
1271     IntLigne *theIL = new IntLigne();
1273     theS->DirectQuickScan(curY, curPt, (float) it, true, 1.0);
1275     char *mdata = (char*)m.data.px;
1276     if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1277     uint32_t *ligStart = ((uint32_t*)(mdata + ((il - m.area.x0) + m.rs * (it - m.area.y0))));
1278     for (int y = it; y < ib; y++) {
1279         theI->Reset();
1280         theS->QuickScan(curY, curPt, ((float)(y+1)), theI, 1.0);
1281         theI->Flatten();
1282         theIL->Copy(theI);
1284         raster_info  dest;
1285         dest.startPix=il;
1286         dest.endPix=ir;
1287         dest.sth=il;
1288         dest.stv=y;
1289         dest.buffer=ligStart;
1290         theIL->Raster(dest, NULL, shape_run_A8_OR);
1291         ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1292     }
1293     theS->EndQuickRaster();
1294     delete theI;
1295     delete theIL;
1299 /*
1300   Local Variables:
1301   mode:c++
1302   c-file-style:"stroustrup"
1303   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1304   indent-tabs-mode:nil
1305   fill-column:99
1306   End:
1307 */
1308 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :