Code

fix clipping with unfilled paths
[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 <libnr/n-art-bpath.h>
20 #include <libnr/nr-path.h>
21 #include <libnr/nr-pixops.h>
22 #include <libnr/nr-matrix-ops.h>
23 #include <libnr/nr-blit.h>
24 #include <livarot/Path.h>
25 #include <livarot/float-line.h>
26 #include <livarot/int-line.h>
27 #include <style.h>
29 //int  showRuns=0;
30 void nr_pixblock_render_shape_mask_or (NRPixBlock &m,Shape* theS);
32 static void nr_arena_shape_class_init (NRArenaShapeClass *klass);
33 static void nr_arena_shape_init (NRArenaShape *shape);
34 static void nr_arena_shape_finalize (NRObject *object);
36 static NRArenaItem *nr_arena_shape_children (NRArenaItem *item);
37 static void nr_arena_shape_add_child (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
38 static void nr_arena_shape_remove_child (NRArenaItem *item, NRArenaItem *child);
39 static void nr_arena_shape_set_child_position (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
41 static guint nr_arena_shape_update (NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
42 static unsigned int nr_arena_shape_render (NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
43 static guint nr_arena_shape_clip (NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
44 static NRArenaItem *nr_arena_shape_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
46 static NRArenaItemClass *shape_parent_class;
48 NRType
49 nr_arena_shape_get_type (void)
50 {
51     static NRType type = 0;
52     if (!type) {
53         type = nr_object_register_type (NR_TYPE_ARENA_ITEM,
54                                         "NRArenaShape",
55                                         sizeof (NRArenaShapeClass),
56                                         sizeof (NRArenaShape),
57                                         (void (*) (NRObjectClass *)) nr_arena_shape_class_init,
58                                         (void (*) (NRObject *)) nr_arena_shape_init);
59     }
60     return type;
61 }
63 static void
64 nr_arena_shape_class_init (NRArenaShapeClass *klass)
65 {
66     NRObjectClass *object_class;
67     NRArenaItemClass *item_class;
69     object_class = (NRObjectClass *) klass;
70     item_class = (NRArenaItemClass *) klass;
72     shape_parent_class = (NRArenaItemClass *)  ((NRObjectClass *) klass)->parent;
74     object_class->finalize = nr_arena_shape_finalize;
75     object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaShape>;
77     item_class->children = nr_arena_shape_children;
78     item_class->add_child = nr_arena_shape_add_child;
79     item_class->set_child_position = nr_arena_shape_set_child_position;
80     item_class->remove_child = nr_arena_shape_remove_child;
81     item_class->update = nr_arena_shape_update;
82     item_class->render = nr_arena_shape_render;
83     item_class->clip = nr_arena_shape_clip;
84     item_class->pick = nr_arena_shape_pick;
85 }
87 static void
88 nr_arena_shape_init (NRArenaShape *shape)
89 {
90     shape->curve = NULL;
91     shape->style = NULL;
92     shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
93     shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
95     nr_matrix_set_identity (&shape->ctm);
96     shape->fill_painter = NULL;
97     shape->stroke_painter = NULL;
98     shape->cached_fill = NULL;
99     shape->cached_stroke = NULL;
100     shape->fill_shp = NULL;
101     shape->stroke_shp = NULL;
103     shape->delayed_shp = false;
105     shape->approx_bbox.x0 = shape->approx_bbox.y0 = 0;
106     shape->approx_bbox.x1 = shape->approx_bbox.y1 = 0;
107     nr_matrix_set_identity(&shape->cached_fctm);
108     nr_matrix_set_identity(&shape->cached_sctm);
110     shape->markers = NULL;
113 static void
114 nr_arena_shape_finalize (NRObject *object)
116     NRArenaShape *shape = (NRArenaShape *) (object);
118     if (shape->fill_shp) delete shape->fill_shp;
119     if (shape->stroke_shp) delete shape->stroke_shp;
120     if (shape->cached_fill) delete shape->cached_fill;
121     if (shape->cached_stroke) delete shape->cached_stroke;
122     if (shape->fill_painter) sp_painter_free (shape->fill_painter);
123     if (shape->stroke_painter) sp_painter_free (shape->stroke_painter);
125     if (shape->style) sp_style_unref (shape->style);
126     if (shape->curve) sp_curve_unref (shape->curve);
128     ((NRObjectClass *) shape_parent_class)->finalize (object);
131 static NRArenaItem *
132 nr_arena_shape_children (NRArenaItem *item)
134     NRArenaShape *shape = (NRArenaShape *) item;
136     return shape->markers;
139 static void
140 nr_arena_shape_add_child (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
142     NRArenaShape *shape = (NRArenaShape *) item;
144     if (!ref) {
145         shape->markers = nr_arena_item_attach_ref (item, child, NULL, shape->markers);
146     } else {
147         ref->next = nr_arena_item_attach_ref (item, child, ref, ref->next);
148     }
150     nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE);
153 static void
154 nr_arena_shape_remove_child (NRArenaItem *item, NRArenaItem *child)
156     NRArenaShape *shape = (NRArenaShape *) item;
158     if (child->prev) {
159         nr_arena_item_detach_unref (item, child);
160     } else {
161         shape->markers = nr_arena_item_detach_unref (item, child);
162     }
164     nr_arena_item_request_update (item, NR_ARENA_ITEM_STATE_ALL, FALSE);
167 static void
168 nr_arena_shape_set_child_position (NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
170     NRArenaShape *shape = (NRArenaShape *) item;
172     if (child->prev) {
173         nr_arena_item_detach_unref (item, child);
174     } else {
175         shape->markers = nr_arena_item_detach_unref (item, child);
176     }
178     if (!ref) {
179         shape->markers = nr_arena_item_attach_ref (item, child, NULL, shape->markers);
180     } else {
181         ref->next = nr_arena_item_attach_ref (item, child, ref, ref->next);
182     }
184     nr_arena_item_request_render (child);
187 void nr_arena_shape_update_stroke(NRArenaShape *shape,NRGC* gc);
188 void nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, bool force_shape = false);
189 void nr_arena_shape_add_bboxes(NRArenaShape* shape,NRRect &bbox);
191 static guint
192 nr_arena_shape_update (NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
194     NRRect bbox;
196     NRArenaShape *shape = NR_ARENA_SHAPE (item);
198     unsigned int beststate = NR_ARENA_ITEM_STATE_ALL;
200     unsigned int newstate;
201     for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
202         newstate = nr_arena_item_invoke_update (child, area, gc, state, reset);
203         beststate = beststate & newstate;
204     }
206     if (!(state & NR_ARENA_ITEM_STATE_RENDER)) {
207         /* We do not have to create rendering structures */
208         shape->ctm = gc->transform;
209         if (state & NR_ARENA_ITEM_STATE_BBOX) {
210             if (shape->curve) {
211                 NRBPath bp;
212                 /* fixme: */
213                 bbox.x0 = bbox.y0 = NR_HUGE;
214                 bbox.x1 = bbox.y1 = -NR_HUGE;
215                 bp.path = shape->curve->bpath;
216                 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
217                 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
218                 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
219                 item->bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
220                 item->bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
221             }
222             if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
223                 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
224                     nr_rect_l_union (&item->bbox, &item->bbox, &child->bbox);
225                 }
226             }
227         }
228         return (state | item->state);
229     }
231     shape->delayed_shp=true;
232     shape->ctm = gc->transform;
233     bbox.x0 = bbox.y0 = NR_HUGE;
234     bbox.x1 = bbox.y1 = -NR_HUGE;
235   
236     if (shape->curve) {
237         NRBPath bp;
238         /* fixme: */
239         bbox.x0 = bbox.y0 = NR_HUGE;
240         bbox.x1 = bbox.y1 = -NR_HUGE;
241         bp.path = shape->curve->bpath;
242         nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
243         if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
244             float width, scale;
245             scale = NR_MATRIX_DF_EXPANSION (&gc->transform);
246             width = MAX (0.125, shape->_stroke.width * scale);
247             if ( fabs(shape->_stroke.width * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
248                 bbox.x0-=width;
249                 bbox.x1+=width;
250                 bbox.y0-=width;
251                 bbox.y1+=width;
252             }      
253             // those pesky miters, now
254             float miterMax=width*shape->_stroke.mitre_limit;
255             if ( miterMax > 0.01 ) {
256                 // grunt mode. we should compute the various miters instead (one for each point on the curve)
257                 bbox.x0-=miterMax;
258                 bbox.x1+=miterMax;
259                 bbox.y0-=miterMax;
260                 bbox.y1+=miterMax;        
261             }
262         }
263     } else {
264     }
265     shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
266     shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
267     shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
268     shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
269     if ( area && nr_rect_l_test_intersect (area, &shape->approx_bbox) ) shape->delayed_shp=false;
271     /* Release state data */
272     if (TRUE || !nr_matrix_test_transform_equal (&gc->transform, &shape->ctm, NR_EPSILON)) {
273         /* Concept test */
274         if (shape->fill_shp) {
275             delete shape->fill_shp;
276             shape->fill_shp = NULL;
277         }
278     }
279     if (shape->stroke_shp) {
280         delete shape->stroke_shp;
281         shape->stroke_shp = NULL;
282     }
283     if (shape->fill_painter) {
284         sp_painter_free (shape->fill_painter);
285         shape->fill_painter = NULL;
286     }
287     if (shape->stroke_painter) {
288         sp_painter_free (shape->stroke_painter);
289         shape->stroke_painter = NULL;
290     }
292     if (!shape->curve || !shape->style) return NR_ARENA_ITEM_STATE_ALL;
293     if (sp_curve_is_empty (shape->curve)) return NR_ARENA_ITEM_STATE_ALL;
294     if ( ( shape->_fill.paint.type() == NRArenaShape::Paint::NONE ) &&
295          ( shape->_stroke.paint.type() == NRArenaShape::Paint::NONE ) )
296     {
297         return NR_ARENA_ITEM_STATE_ALL;
298     }
300     /* Build state data */
301     if ( shape->delayed_shp ) {
302         item->bbox=shape->approx_bbox;
303     } else {
304         nr_arena_shape_update_stroke(shape,gc);
305         nr_arena_shape_update_fill(shape,gc);
307         bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
308         nr_arena_shape_add_bboxes(shape,bbox);
309     
310         shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
311         shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
312         shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
313         shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
314     } 
315         
316     if (nr_rect_d_test_empty (&bbox)) return NR_ARENA_ITEM_STATE_ALL;
318     item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
319     item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
320     item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
321     item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
322     nr_arena_request_render_rect (item->arena, &item->bbox);
324     item->render_opacity = TRUE;
325     if ( shape->_fill.paint.type() == NRArenaShape::Paint::SERVER ) {
326         if (gc && gc->parent) {
327             shape->fill_painter = sp_paint_server_painter_new (shape->_fill.paint.server(),
328                                                            NR::Matrix (&gc->transform), NR::Matrix (&gc->parent->transform), 
329                                                            &shape->paintbox);
330         }
331         item->render_opacity = FALSE;
332     }
333     if ( shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER ) {
334         if (gc && gc->parent) {
335             shape->stroke_painter = sp_paint_server_painter_new (shape->_stroke.paint.server(),
336                                                              NR::Matrix (&gc->transform), NR::Matrix (&gc->parent->transform), 
337                                                              &shape->paintbox);
338         }
339         item->render_opacity = FALSE;
340     }
341     if ( item->render_opacity == TRUE &&
342          shape->_fill.paint.type()   != NRArenaShape::Paint::NONE &&
343          shape->_stroke.paint.type() != NRArenaShape::Paint::NONE )
344     {
345         // don't merge item opacity with paint opacity if there is a stroke on the fill
346         item->render_opacity = FALSE;    
347     }
348         
349     if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
350         for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
351             nr_rect_l_union (&item->bbox, &item->bbox, &child->bbox);
352         }
353     }
355     return NR_ARENA_ITEM_STATE_ALL;
358 int matrix_is_isometry(NR::Matrix p) {
359     NR::Matrix   tp;
360     // transposition
361     tp[0]=p[0];
362     tp[1]=p[2];
363     tp[2]=p[1];
364     tp[3]=p[3];
365     for(int i = 4; i < 6; i++) // shut valgrind up :)
366         tp[i] = p[i] = 0;
367     NR::Matrix   isom = tp*p; // A^T * A = adjunct?
368     // Is the adjunct nearly an identity function?
369     if (isom.is_translation(0.01)) {
370         // the transformation is an isometry -> no need to recompute
371         // the uncrossed polygon
372         if ( p.det() < 0 )
373             return -1; 
374         else
375             return 1;
376     }
377     return 0;
380 /** force_shape is used for clipping paths, when we need the shape for clipping even if it's not filled */
381 void
382 nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, bool force_shape)
384     shape->delayed_shp = false;
385     if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) &&
386         ((shape->curve->end > 2) || (shape->curve->bpath[1].code == NR_CURVETO)) ) {
387             if (TRUE || !shape->fill_shp) {
388                 NR::Matrix  cached_to_new;
389                 int isometry = 0;
390                 if ( shape->cached_fill ) {
391                     cached_to_new = shape->cached_fctm.inverse()*gc->transform;
392                     isometry = matrix_is_isometry(cached_to_new);
393                 }
394                 if ( isometry == 0 ) {
395                     if ( shape->cached_fill == NULL ) shape->cached_fill=new Shape;
396                     shape->cached_fill->Reset();
397             
398                     Path*  thePath=new Path;
399                     Shape* theShape=new Shape;
400                     {
401                         NR::Matrix   tempMat(gc->transform);
402                         thePath->LoadArtBPath(shape->curve->bpath,tempMat,true);
403                     }
405                     thePath->Convert(1.0);
407                     thePath->Fill(theShape, 0);
409                     if ( shape->_fill.rule == NRArenaShape::EVEN_ODD ) {
410                     shape->cached_fill->ConvertToShape(theShape, fill_oddEven);
411                     // alternatively, this speeds up rendering of oddeven shapes but disables AA :(        
412                     //shape->cached_fill->Copy(theShape);
413                     } else {
414                     shape->cached_fill->ConvertToShape(theShape, fill_nonZero);
415                     }
416                     shape->cached_fctm=gc->transform;
417                     delete theShape;
418                     delete thePath;
419                     if ( shape->fill_shp == NULL )
420                    shape->fill_shp = new Shape;
422                     shape->fill_shp->Copy(shape->cached_fill);
424                 } else {
426                     if ( shape->fill_shp == NULL )
427                         shape->fill_shp=new Shape;
429                     shape->fill_shp->Reset(shape->cached_fill->numberOfPoints(),
430                                            shape->cached_fill->numberOfEdges());
431                     for (int i = 0; i < shape->cached_fill->numberOfPoints(); i++)
432                         shape->fill_shp->AddPoint(shape->cached_fill->getPoint(i).x * cached_to_new);
433                     if ( isometry == 1 ) {
434                         for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++) 
435                             shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).st,
436                                                      shape->cached_fill->getEdge(i).en);
437                     } else if ( isometry == -1 ) { // need to flip poly.
438                         for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
439                             shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).en,
440                                                      shape->cached_fill->getEdge(i).st);
441                     }
442                     shape->fill_shp->ForceToPolygon();
443                     shape->fill_shp->needPointsSorting();
444                     shape->fill_shp->needEdgesSorting();
445                 }
446             }
447         }
450 void
451 nr_arena_shape_update_stroke(NRArenaShape *shape,NRGC* gc)
453     SPStyle* style = shape->style;
454   
455     shape->delayed_shp = false;
457     const float scale = NR_MATRIX_DF_EXPANSION (&gc->transform);
459     if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE || 
460         ((shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) &&
461          ( fabs(shape->_stroke.width * scale) > 0.01 ))) { // sinon c'est 0=oon veut pas de bord
463         float width = MAX (0.125, shape->_stroke.width * scale);
464         if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE)
465             width = 0.5; // 1 pixel wide, independent of zoom
467         NR::Matrix cached_to_new;
469         int isometry = 0;
470         if ( shape->cached_stroke ) {
471             cached_to_new = shape->cached_sctm.inverse() * gc->transform;
472             isometry = matrix_is_isometry(cached_to_new);
473         }
475         if ( isometry == 0 ) {
476             if ( shape->cached_stroke == NULL ) shape->cached_stroke=new Shape;
477             shape->cached_stroke->Reset();
478             Path*  thePath = new Path;
479             Shape* theShape = new Shape;    
480             {
481                 NR::Matrix   tempMat(gc->transform);
482                 thePath->LoadArtBPath(shape->curve->bpath, tempMat, true);
483             }
485             if (NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE)
486                 thePath->Convert(1.0);
487             else 
488                 thePath->Convert(4.0); // slightly rougher & faster
490             if (style->stroke_dash.n_dash && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) {      
491                 double dlen = 0.0;
492                 for (int i = 0; i < style->stroke_dash.n_dash; i++) {
493                     dlen += style->stroke_dash.dash[i] * scale;
494                 }
495                 if (dlen >= 1.0) {
496                     NRVpathDash dash;
497                     dash.offset = style->stroke_dash.offset * scale;
498                     dash.n_dash = style->stroke_dash.n_dash;
499                     dash.dash = g_new (double, dash.n_dash);
500                     for (int i = 0; i < dash.n_dash; i++) {
501                         dash.dash[i] = style->stroke_dash.dash[i] * scale;
502                     }
503                     int    nbD=dash.n_dash;
504                     float  *dashs=(float*)malloc((nbD+1)*sizeof(float));
505                     while ( dash.offset >= dlen ) dash.offset-=dlen;
506                     dashs[0]=dash.dash[0];
507                     for (int i=1; i<nbD; i++) {
508                         dashs[i]=dashs[i-1]+dash.dash[i];
509                     }
510                     // modulo dlen
511                     thePath->DashPolyline(0.0,0.0,dlen,nbD,dashs,true,dash.offset);
512                     free(dashs);
513                     g_free (dash.dash);
514                 }
515             }
516             ButtType butt=butt_straight;
517             switch(shape->_stroke.cap) {
518             case NRArenaShape::BUTT_CAP:
519                 butt = butt_straight;
520                 break;
521             case NRArenaShape::ROUND_CAP:
522                 butt = butt_round;
523                 break;
524             case NRArenaShape::SQUARE_CAP:
525                 butt = butt_square;
526                 break;
527             }
528             JoinType join=join_straight;
529             switch(shape->_stroke.join) {
530             case NRArenaShape::MITRE_JOIN:
531                 join = join_pointy;
532                 break;
533             case NRArenaShape::ROUND_JOIN:
534                 join = join_round;
535                 break;
536             case NRArenaShape::BEVEL_JOIN:
537                 join = join_straight;
538                 break;
539             }
541             if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
542                 butt = butt_straight;
543                 join = join_straight;
544             }
546             thePath->Stroke(theShape, false, 0.5*width, join, butt, 
547                             0.5*width*shape->_stroke.mitre_limit);
548                 
550             if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
551                 // speeds it up, but uses evenodd for the stroke shape (which does not matter for 1-pixel wide outline)
552                 shape->cached_stroke->Copy(theShape); 
553             } else {
554                 shape->cached_stroke->ConvertToShape(theShape, fill_nonZero);
555             }
557             shape->cached_sctm=gc->transform;
558             delete thePath;
559             delete theShape;
560             if ( shape->stroke_shp == NULL ) shape->stroke_shp=new Shape;
562             shape->stroke_shp->Copy(shape->cached_stroke);
564         } else {
566             if ( shape->stroke_shp == NULL )
567                 shape->stroke_shp=new Shape;
568             shape->stroke_shp->Reset(shape->cached_stroke->numberOfPoints(), shape->cached_stroke->numberOfEdges());
569             for (int i = 0; i < shape->cached_stroke->numberOfPoints(); i++)
570                 shape->stroke_shp->AddPoint(shape->cached_stroke->getPoint(i).x * cached_to_new);
571             if ( isometry == 1 ) {
572                 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
573                     shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).st,
574                                                shape->cached_stroke->getEdge(i).en);
575             } else if ( isometry == -1 ) {
576                 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
577                     shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).en,
578                                                shape->cached_stroke->getEdge(i).st);
579             }
580             shape->stroke_shp->ForceToPolygon();
581             shape->stroke_shp->needPointsSorting();
582             shape->stroke_shp->needEdgesSorting();
583         }
584     }
588 void
589 nr_arena_shape_add_bboxes(NRArenaShape* shape, NRRect &bbox)
591     if ( shape->stroke_shp ) {
592         shape->stroke_shp->CalcBBox();
593         shape->stroke_shp->leftX=floor(shape->stroke_shp->leftX);
594         shape->stroke_shp->rightX=ceil(shape->stroke_shp->rightX);
595         shape->stroke_shp->topY=floor(shape->stroke_shp->topY);
596         shape->stroke_shp->bottomY=ceil(shape->stroke_shp->bottomY);
597         if ( bbox.x0 >= bbox.x1 ) {
598             if ( shape->stroke_shp->leftX < shape->stroke_shp->rightX ) {
599                 bbox.x0=shape->stroke_shp->leftX;
600                 bbox.x1=shape->stroke_shp->rightX;
601             }
602         } else {
603             if ( shape->stroke_shp->leftX < bbox.x0 )
604                 bbox.x0=shape->stroke_shp->leftX;
605             if ( shape->stroke_shp->rightX > bbox.x1 )
606                 bbox.x1=shape->stroke_shp->rightX;
607         }
608         if ( bbox.y0 >= bbox.y1 ) {
609             if ( shape->stroke_shp->topY < shape->stroke_shp->bottomY ) {
610                 bbox.y0=shape->stroke_shp->topY;
611                 bbox.y1=shape->stroke_shp->bottomY;
612             }
613         } else {
614             if ( shape->stroke_shp->topY < bbox.y0 )
615                 bbox.y0=shape->stroke_shp->topY;
616             if ( shape->stroke_shp->bottomY > bbox.y1 )
617                 bbox.y1=shape->stroke_shp->bottomY;
618         }
619     }
620     if ( shape->fill_shp ) {
621         shape->fill_shp->CalcBBox();
622         shape->fill_shp->leftX=floor(shape->fill_shp->leftX);
623         shape->fill_shp->rightX=ceil(shape->fill_shp->rightX);
624         shape->fill_shp->topY=floor(shape->fill_shp->topY);
625         shape->fill_shp->bottomY=ceil(shape->fill_shp->bottomY);
626         if ( bbox.x0 >= bbox.x1 ) {
627             if ( shape->fill_shp->leftX < shape->fill_shp->rightX ) {
628                 bbox.x0=shape->fill_shp->leftX;
629                 bbox.x1=shape->fill_shp->rightX;
630             }
631         } else {
632             if ( shape->fill_shp->leftX < bbox.x0 ) bbox.x0=shape->fill_shp->leftX;
633             if ( shape->fill_shp->rightX > bbox.x1 ) bbox.x1=shape->fill_shp->rightX;
634         }
635         if ( bbox.y0 >= bbox.y1 ) {
636             if ( shape->fill_shp->topY < shape->fill_shp->bottomY ) {
637                 bbox.y0=shape->fill_shp->topY;
638                 bbox.y1=shape->fill_shp->bottomY;
639             }
640         } else {
641             if ( shape->fill_shp->topY < bbox.y0 ) bbox.y0=shape->fill_shp->topY;
642             if ( shape->fill_shp->bottomY > bbox.y1 ) bbox.y1=shape->fill_shp->bottomY;
643         }
644     }
646 static unsigned int
647 nr_arena_shape_render (NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags)
649     NRArenaShape *shape = NR_ARENA_SHAPE (item);
651     if (!shape->curve) return item->state;
652     if (!shape->style) return item->state;
653   
654     if ( shape->delayed_shp ) {
655         if ( nr_rect_l_test_intersect (area, &item->bbox) ) {
656             NRGC   tempGC(NULL);
657             tempGC.transform=shape->ctm;
658             nr_arena_shape_update_stroke(shape,&tempGC);
659             nr_arena_shape_update_fill(shape,&tempGC);
660 /*      NRRect bbox;
661         bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
662         nr_arena_shape_add_bboxes(shape,bbox);
663         item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
664         item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
665         item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
666         item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
667         shape->approx_bbox=item->bbox;*/
668         }
669     }
671     SPStyle const *style = shape->style;
672     if ( shape->fill_shp && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) {
673         NRPixBlock m;
674         guint32 rgba;
676         nr_pixblock_setup_fast (&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
677         nr_pixblock_render_shape_mask_or (m,shape->fill_shp);
678         m.empty = FALSE;
680         if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) {
681         // do not render fill in any way
682       } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) {
683             if ( item->render_opacity ) {
684                 rgba = sp_color_get_rgba32_falpha (&shape->_fill.paint.color(),
685                                                    shape->_fill.opacity *
686                                                    SP_SCALE24_TO_FLOAT (style->opacity.value));
687             } else {
688                 rgba = sp_color_get_rgba32_falpha (&shape->_fill.paint.color(),
689                                                    shape->_fill.opacity);
690             }
691             nr_blit_pixblock_mask_rgba32 (pb, &m, rgba);
692             pb->empty = FALSE;
693       } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) {
694             if (shape->fill_painter) {
695               nr_arena_render_paintserver_fill (pb, area, shape->fill_painter, shape->_fill.opacity, &m);
696             }
697         }
699         nr_pixblock_release (&m);
700     }
701   
702     if ( shape->stroke_shp ) {
703         NRPixBlock m;
704         guint32 rgba;
706         nr_pixblock_setup_fast (&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
707         nr_pixblock_render_shape_mask_or (m, shape->stroke_shp);
708         m.empty = FALSE;
710         if (shape->_stroke.paint.type() == NRArenaShape::Paint::COLOR || 
711             NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
712             if ( NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
713                 rgba = NR_ARENA_ITEM(shape)->arena->outlinecolor;
714             } else if ( item->render_opacity ) {
715                 rgba = sp_color_get_rgba32_falpha (&shape->_stroke.paint.color(),
716                                                    shape->_stroke.opacity *
717                                                    SP_SCALE24_TO_FLOAT (style->opacity.value));
718             } else {
719                 rgba = sp_color_get_rgba32_falpha (&shape->_stroke.paint.color(),
720                                                    shape->_stroke.opacity);
721             }
722             nr_blit_pixblock_mask_rgba32 (pb, &m, rgba);
723             pb->empty = FALSE;
724         } else if (shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER) {
725             if (shape->stroke_painter) {
726                 nr_arena_render_paintserver_fill (pb, area, shape->stroke_painter, shape->_stroke.opacity, &m);
727             }
728         }
730         nr_pixblock_release (&m);
731     }
732   
733     /* Just compose children into parent buffer */
734     for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
735         unsigned int ret;
736         ret = nr_arena_item_invoke_render (child, area, pb, flags);
737         if (ret & NR_ARENA_ITEM_STATE_INVALID) return ret;
738     }
740     return item->state;
743 static guint
744 nr_arena_shape_clip (NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
746     NRArenaShape *shape = NR_ARENA_SHAPE (item);
747     if (!shape->curve) return item->state;
749     if ( shape->delayed_shp ) {
750         if ( nr_rect_l_test_intersect (area, &item->bbox) ) {
751             NRGC   tempGC(NULL);
752             tempGC.transform=shape->ctm;
753             //nr_arena_shape_update_stroke(shape,&tempGC); // we don't need stroke for clipping
754             nr_arena_shape_update_fill(shape, &tempGC, true);
755             /*      NRRect bbox;
756                     bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
757                     nr_arena_shape_add_bboxes(shape,bbox);
758                     item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
759                     item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
760                     item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
761                     item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
762                     shape->approx_bbox=item->bbox;*/
763         }
764     }
766     if ( shape->fill_shp ) {
767         NRPixBlock m;
769         /* fixme: We can OR in one step (Lauris) */
770         nr_pixblock_setup_fast (&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
771         nr_pixblock_render_shape_mask_or (m,shape->fill_shp);
772     
773         for (int y = area->y0; y < area->y1; y++) {
774             unsigned char *s, *d;
775             s = NR_PIXBLOCK_PX (&m) + (y - area->y0) * m.rs;
776             d = NR_PIXBLOCK_PX (pb) + (y - area->y0) * pb->rs;
777             for (int x = area->x0; x < area->x1; x++) {
778           *d = NR_A7_NORMALIZED(*s,*d); 
779                 d ++;
780                 s ++;
781             }
782         }
783         nr_pixblock_release (&m);
784         pb->empty = FALSE;
785     }
786   
787     return item->state;
790 static NRArenaItem *
791 nr_arena_shape_pick (NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/)
793     NRArenaShape *shape = NR_ARENA_SHAPE (item);
795     if (!shape->curve) return NULL;
796     if (!shape->style) return NULL;
797     if ( shape->delayed_shp ) {
798         NRRectL  area;
799         area.x0=(int)floor(p[NR::X]);
800         area.x1=(int)ceil(p[NR::X]);
801         area.y0=(int)floor(p[NR::Y]);
802         area.y1=(int)ceil(p[NR::Y]);
803         int idelta = (int)ceil(delta) + 1;
804         // njh: inset rect
805         area.x0-=idelta;
806         area.x1+=idelta;
807         area.y0-=idelta;
808         area.y1+=idelta;
809         if ( nr_rect_l_test_intersect (&area, &item->bbox) ) {
810             NRGC   tempGC(NULL);
811             tempGC.transform=shape->ctm;
812             nr_arena_shape_update_stroke(shape,&tempGC);
813             nr_arena_shape_update_fill(shape,&tempGC);
814             /*      NRRect bbox;
815                     bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
816                     nr_arena_shape_add_bboxes(shape,bbox);
817                     item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
818                     item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
819                     item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
820                     item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
821                     shape->approx_bbox=item->bbox;*/
822         }
823     }
825     if (item->state & NR_ARENA_ITEM_STATE_RENDER) {
826         if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
827             if (shape->fill_shp->PtWinding(p) > 0 ) return item;
828         }
829         if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
830             if (shape->stroke_shp->PtWinding(p) > 0 ) return item;
831         }
832         if (delta > 1e-3) {
833             if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
834                 if (distanceLessThanOrEqual(shape->fill_shp, p, delta)) return item;
835             }
836             if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
837                 if (distanceLessThanOrEqual(shape->stroke_shp, p, delta)) return item;
838             }
839         }
840     } else {
841         NRBPath bp;
842         bp.path = shape->curve->bpath;
843         double dist = NR_HUGE;
844         int wind = 0;
845         nr_path_matrix_point_bbox_wind_distance(&bp, shape->ctm, p, NULL, &wind, &dist, NR_EPSILON);
846         if (shape->_fill.paint.type() != NRArenaShape::Paint::NONE) {
847             if (!shape->style->fill_rule.computed) {
848                 if (wind != 0) return item;
849             } else {
850                 if (wind & 0x1) return item;
851             }
852         }
853         if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
854             /* fixme: We do not take stroke width into account here (Lauris) */
855             if (dist < delta) return item;
856         }
857     }
859     return NULL;
862 /** 
863  *
864  *  Requests a render of the shape, then if the shape is already a curve it
865  *  unrefs the old curve; if the new curve is valid it creates a copy of the
866  *  curve and adds it to the shape.  Finally, it requests an update of the
867  *  arena for the shape.
868  */
869 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve,bool justTrans)
871     g_return_if_fail (shape != NULL);
872     g_return_if_fail (NR_IS_ARENA_SHAPE (shape));
874     if ( justTrans == false ) {
875         // dirty cached versions
876         if ( shape->cached_fill ) {
877             delete shape->cached_fill;
878             shape->cached_fill=NULL;
879         }
880         if ( shape->cached_stroke ) {
881             delete shape->cached_stroke;
882             shape->cached_stroke=NULL;
883         }
884     }
886     nr_arena_item_request_render (NR_ARENA_ITEM (shape));
888     if (shape->curve) {
889         sp_curve_unref (shape->curve);
890         shape->curve = NULL;
891     }
893     if (curve) {
894         shape->curve = curve;
895         sp_curve_ref (curve);
896     }
898     nr_arena_item_request_update (NR_ARENA_ITEM (shape), NR_ARENA_ITEM_STATE_ALL, FALSE);
901 void NRArenaShape::setFill(SPPaintServer *server) {
902     _fill.paint.set(server);
903     _invalidateCachedFill();
906 void NRArenaShape::setFill(SPColor const &color) {
907     _fill.paint.set(color);
908     _invalidateCachedFill();
911 void NRArenaShape::setFillOpacity(double opacity) {
912     _fill.opacity = opacity;
913     _invalidateCachedFill();
916 void NRArenaShape::setFillRule(NRArenaShape::FillRule rule) {
917     _fill.rule = rule;
918     _invalidateCachedFill();
921 void NRArenaShape::setStroke(SPPaintServer *server) {
922     _stroke.paint.set(server);
923     _invalidateCachedStroke();
926 void NRArenaShape::setStroke(SPColor const &color) {
927     _stroke.paint.set(color);
928     _invalidateCachedStroke();
931 void NRArenaShape::setStrokeOpacity(double opacity) {
932     _stroke.opacity = opacity;
933     _invalidateCachedStroke();
936 void NRArenaShape::setStrokeWidth(double width) {
937     _stroke.width = width;
938     _invalidateCachedStroke();
941 void NRArenaShape::setMitreLimit(double limit) {
942     _stroke.mitre_limit = limit;
943     _invalidateCachedStroke();
946 void NRArenaShape::setLineCap(NRArenaShape::CapType cap) {
947     _stroke.cap = cap;
948     _invalidateCachedStroke();
951 void NRArenaShape::setLineJoin(NRArenaShape::JoinType join) {
952     _stroke.join = join;
953     _invalidateCachedStroke();
956 /** nr_arena_shape_set_style
957  *
958  * Unrefs any existing style and ref's to the given one, then requests an update of the arena
959  */
960 void
961 nr_arena_shape_set_style (NRArenaShape *shape, SPStyle *style)
963     g_return_if_fail (shape != NULL);
964     g_return_if_fail (NR_IS_ARENA_SHAPE (shape));
966     if (style) sp_style_ref (style);
967     if (shape->style) sp_style_unref (shape->style);
968     shape->style = style;
970     switch (style->fill.type) {
971         case SP_PAINT_TYPE_NONE: {
972             shape->setFill(NULL);
973             break;
974         }
975         case SP_PAINT_TYPE_COLOR: {
976             shape->setFill(style->fill.value.color);
977             break;
978         }
979         case SP_PAINT_TYPE_PAINTSERVER: {
980             shape->setFill(style->fill.value.paint.server);
981             break;
982         }
983         default: {
984             g_assert_not_reached();
985         }
986     }
987     shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
988     switch (style->fill_rule.computed) {
989         case SP_WIND_RULE_EVENODD: {
990             shape->setFillRule(NRArenaShape::EVEN_ODD);
991             break;
992         }
993         case SP_WIND_RULE_NONZERO: {
994             shape->setFillRule(NRArenaShape::NONZERO);
995             break;
996         }
997         default: {
998             g_assert_not_reached();
999         }
1000     }
1002     switch (style->stroke.type) {
1003         case SP_PAINT_TYPE_NONE: {
1004             shape->setStroke(NULL);
1005             break;
1006         }
1007         case SP_PAINT_TYPE_COLOR: {
1008             shape->setStroke(style->stroke.value.color);
1009             break;
1010         }
1011         case SP_PAINT_TYPE_PAINTSERVER: {
1012             shape->setStroke(style->stroke.value.paint.server);
1013             break;
1014         }
1015         default: {
1016             g_assert_not_reached();
1017         }
1018     }
1019     shape->setStrokeWidth(style->stroke_width.computed);
1020     shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
1021     switch (style->stroke_linecap.computed) {
1022         case SP_STROKE_LINECAP_ROUND: {
1023             shape->setLineCap(NRArenaShape::ROUND_CAP);
1024             break;
1025         }
1026         case SP_STROKE_LINECAP_SQUARE: {
1027             shape->setLineCap(NRArenaShape::SQUARE_CAP);
1028             break;
1029         }
1030         case SP_STROKE_LINECAP_BUTT: {
1031             shape->setLineCap(NRArenaShape::BUTT_CAP);
1032             break;
1033         }
1034         default: {
1035             g_assert_not_reached();
1036         }
1037     }
1038     switch (style->stroke_linejoin.computed) {
1039         case SP_STROKE_LINEJOIN_ROUND: {
1040             shape->setLineJoin(NRArenaShape::ROUND_JOIN);
1041             break;
1042         }
1043         case SP_STROKE_LINEJOIN_BEVEL: {
1044             shape->setLineJoin(NRArenaShape::BEVEL_JOIN);
1045             break;
1046         }
1047         case SP_STROKE_LINEJOIN_MITER: {
1048             shape->setLineJoin(NRArenaShape::MITRE_JOIN);
1049             break;
1050         }
1051         default: {
1052             g_assert_not_reached();
1053         }
1054     }
1055     shape->setMitreLimit(style->stroke_miterlimit.value);
1057     nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1060 void
1061 nr_arena_shape_set_paintbox (NRArenaShape *shape, const NRRect *pbox)
1063     g_return_if_fail (shape != NULL);
1064     g_return_if_fail (NR_IS_ARENA_SHAPE (shape));
1065     g_return_if_fail (pbox != NULL);
1067     if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
1068         shape->paintbox = *pbox;
1069     } else {
1070         /* fixme: We kill warning, although not sure what to do here (Lauris) */
1071         shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
1072         shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
1073     }
1075     nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1078 void NRArenaShape::setPaintBox(NR::Rect const &pbox)
1080     paintbox.x0 = pbox.min()[NR::X];
1081     paintbox.y0 = pbox.min()[NR::Y];
1082     paintbox.x1 = pbox.max()[NR::X];
1083     paintbox.y1 = pbox.max()[NR::Y];
1085     nr_arena_item_request_update(this, NR_ARENA_ITEM_STATE_ALL, FALSE);
1088 static void
1089 shape_run_A8_OR (raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
1091     if ( st >= en ) return;
1092     if ( vst < 0 ) vst=0;
1093     if ( vst > 1 ) vst=1;
1094     if ( ven < 0 ) ven=0;
1095     if ( ven > 1 ) ven=1;
1096     float   sv=vst;
1097     float   dv=ven-vst;
1098     int     len=en-st;
1099     unsigned char*   d=(unsigned char*)dest.buffer;
1100     d+=(st-dest.startPix);
1101     if ( fabs(dv) < 0.001 ) {
1102         if ( vst > 0.999 ) {
1103             /* Simple copy */
1104             while (len > 0) {
1105                 d[0] = 255;
1106                 d += 1;
1107                 len -= 1;
1108             }
1109         } else {
1110             sv*=256;
1111             unsigned int c0_24=(int)sv;
1112             c0_24&=0xFF;
1113             while (len > 0) {
1114                 unsigned int da;
1115                 /* Draw */
1116                 da = NR_A7(c0_24,d[0]);
1117                 d[0] = NR_PREMUL_SINGLE(da);
1118                 d += 1;
1119                 len -= 1;
1120             }
1121         }
1122     } else {
1123         if ( en <= st+1 ) {
1124             sv=0.5*(vst+ven);
1125             sv*=256;
1126             unsigned int c0_24=(int)sv;
1127             c0_24&=0xFF;
1128             unsigned int da;
1129             /* Draw */
1130             da = NR_A7(c0_24,d[0]);
1131             d[0] = NR_PREMUL_SINGLE(da);
1132         } else {
1133             dv/=len;
1134             sv+=0.5*dv; // correction trapezoidale
1135             sv*=16777216;
1136             dv*=16777216;
1137             int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
1138             int s0_24 = static_cast<int>(dv);
1139             while (len > 0) {
1140                 unsigned int ca, da;
1141                 /* Draw */
1142                 ca = c0_24 >> 16;
1143                 if ( ca > 255 ) ca=255;
1144                 da = NR_A7(ca,d[0]);
1145                 d[0] = NR_PREMUL_SINGLE(da);
1146                 d += 1;
1147                 c0_24 += s0_24;
1148                 c0_24 = CLAMP (c0_24, 0, 16777216);
1149                 len -= 1;
1150             }
1151         }
1152     }
1155 void nr_pixblock_render_shape_mask_or (NRPixBlock &m,Shape* theS)
1158     theS->CalcBBox();
1159     float  l=theS->leftX,r=theS->rightX,t=theS->topY,b=theS->bottomY;
1160     int    il,ir,it,ib;
1161     il=(int)floor(l);
1162     ir=(int)ceil(r);
1163     it=(int)floor(t);
1164     ib=(int)ceil(b);
1166     if ( il >= m.area.x1 || ir <= m.area.x0 || it >= m.area.y1 || ib <= m.area.y0 ) return;
1167     if ( il < m.area.x0 ) il=m.area.x0;
1168     if ( it < m.area.y0 ) it=m.area.y0;
1169     if ( ir > m.area.x1 ) ir=m.area.x1;
1170     if ( ib > m.area.y1 ) ib=m.area.y1;
1171   
1172     // version par FloatLigne
1173     int    curPt;
1174     float  curY;
1175     theS->BeginQuickRaster(curY, curPt);
1176   
1177     FloatLigne* theI=new FloatLigne();
1178     IntLigne*   theIL=new IntLigne();
1179   
1180     theS->DirectQuickScan(curY,curPt,(float)(it),true,1.0);
1181   
1182     char* mdata=(char*)m.data.px;
1183     if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1184     uint32_t* ligStart=((uint32_t*)(mdata+((il-m.area.x0)+m.rs*(it-m.area.y0))));
1185     for (int y=it;y<ib;y++) {
1186         theI->Reset();
1187         theS->QuickScan(curY,curPt,((float)(y+1)),theI,1.0);
1188         theI->Flatten();
1189         theIL->Copy(theI);
1190     
1191         raster_info  dest;
1192         dest.startPix=il;
1193         dest.endPix=ir;
1194         dest.sth=il;
1195         dest.stv=y;
1196         dest.buffer=ligStart;
1197         theIL->Raster(dest,NULL,shape_run_A8_OR);
1198         ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1199     }
1200     theS->EndQuickRaster();
1201     delete theI;
1202     delete theIL;
1203   
1204     /*  // version par BitLigne
1205         int    curPt;
1206         float  curY;
1207         theS->BeginRaster(curY,curPt,1.0);
1208   
1209         BitLigne*   theI[4];
1210         for (int i=0;i<4;i++) theI[i]=new BitLigne(il,ir);
1211         IntLigne*   theIL=new IntLigne();
1212   
1213         theS->Scan(curY,curPt,(float)(it),0.25);
1214   
1215         char* mdata=(char*)m.data.px;
1216         if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1217         uint32_t* ligStart=((uint32_t*)(mdata+((il-m.area.x0)+m.rs*(it-m.area.y0))));
1218         for (int y=it;y<ib;y++) {
1219         for (int i=0;i<4;i++) theI[i]->Reset();
1220         if ( y&0x00000003 ) {
1221         theS->Scan(curY,curPt,((float)(y+0.25)),fill_oddEven,theI[0],false,0.25);
1222         theS->Scan(curY,curPt,((float)(y+0.5)),fill_oddEven,theI[1],false,0.25);
1223         theS->Scan(curY,curPt,((float)(y+0.75)),fill_oddEven,theI[2],false,0.25);
1224         theS->Scan(curY,curPt,((float)(y+1.0)),fill_oddEven,theI[3],false,0.25);
1225         } else {
1226         theS->Scan(curY,curPt,((float)(y+0.25)),fill_oddEven,theI[0],true,0.25);
1227         theS->Scan(curY,curPt,((float)(y+0.5)),fill_oddEven,theI[1],true,0.25);
1228         theS->Scan(curY,curPt,((float)(y+0.75)),fill_oddEven,theI[2],true,0.25);
1229         theS->Scan(curY,curPt,((float)(y+1.0)),fill_oddEven,theI[3],true,0.25);
1230         }
1231         theIL->Copy(4,theI);
1232     
1233         raster_info  dest;
1234         dest.startPix=il;
1235         dest.endPix=ir;
1236         dest.sth=il;
1237         dest.stv=y;
1238         dest.buffer=ligStart;
1239         theIL->Raster(dest,NULL,shape_run_A8_OR);
1240         ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1241         }
1242         theS->EndRaster();
1243         for (int i=0;i<4;i++) delete theI[i];
1244         delete theIL;*/
1245   
1246 /*  // version par BitLigne directe
1247     int    curPt;
1248     float  curY;
1249     theS->BeginQuickRaster(curY,curPt,1.0);
1250   
1251     BitLigne*   theI[4];
1252     for (int i=0;i<4;i++) theI[i]=new BitLigne(il,ir);
1253     IntLigne*   theIL=new IntLigne();
1254   
1255     theS->DirectQuickScan(curY,curPt,(float)(it),true,0.25);
1256   
1257     char* mdata=(char*)m.data.px;
1258     if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1259     uint32_t* ligStart=((uint32_t*)(mdata+((il-m.area.x0)+m.rs*(it-m.area.y0))));
1260     for (int y=it;y<ib;y++) {
1261     for (int i=0;i<4;i++) theI[i]->Reset();
1262     if ( y&0x00000003 ) {
1263     theS->QuickScan(curY,curPt,((float)(y+0.25)),fill_oddEven,theI[0],false,0.25);
1264     theS->QuickScan(curY,curPt,((float)(y+0.5)),fill_oddEven,theI[1],false,0.25);
1265     theS->QuickScan(curY,curPt,((float)(y+0.75)),fill_oddEven,theI[2],false,0.25);
1266     theS->QuickScan(curY,curPt,((float)(y+1.0)),fill_oddEven,theI[3],false,0.25);
1267     } else {
1268     theS->QuickScan(curY,curPt,((float)(y+0.25)),fill_oddEven,theI[0],true,0.25);
1269     theS->QuickScan(curY,curPt,((float)(y+0.5)),fill_oddEven,theI[1],true,0.25);
1270     theS->QuickScan(curY,curPt,((float)(y+0.75)),fill_oddEven,theI[2],true,0.25);
1271     theS->QuickScan(curY,curPt,((float)(y+1.0)),fill_oddEven,theI[3],true,0.25);
1272     }
1273     theIL->Copy(4,theI);
1274     
1275     raster_info  dest;
1276     dest.startPix=il;
1277     dest.endPix=ir;
1278     dest.sth=il;
1279     dest.stv=y;
1280     dest.buffer=ligStart;
1281     theIL->Raster(dest,NULL,shape_run_A8_OR);
1282     ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1283     }
1284     theS->EndQuickRaster();
1285     for (int i=0;i<4;i++) delete theI[i];
1286     delete theIL;*/
1290 /*
1291   Local Variables:
1292   mode:c++
1293   c-file-style:"stroustrup"
1294   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1295   indent-tabs-mode:nil
1296   fill-column:99
1297   End:
1298 */
1299 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :