d26d1bc2792fb73c7b314dd70a9e3f732ffbaf84
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-matrix-fns.h>
24 #include <libnr/nr-blit.h>
25 #include <livarot/Path.h>
26 #include <livarot/float-line.h>
27 #include <livarot/int-line.h>
28 #include <style.h>
30 //int showRuns=0;
31 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS);
33 static void nr_arena_shape_class_init(NRArenaShapeClass *klass);
34 static void nr_arena_shape_init(NRArenaShape *shape);
35 static void nr_arena_shape_finalize(NRObject *object);
37 static NRArenaItem *nr_arena_shape_children(NRArenaItem *item);
38 static void nr_arena_shape_add_child(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
39 static void nr_arena_shape_remove_child(NRArenaItem *item, NRArenaItem *child);
40 static void nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
42 static guint nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
43 static unsigned int nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
44 static guint nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
45 static NRArenaItem *nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
47 static NRArenaItemClass *shape_parent_class;
49 NRType
50 nr_arena_shape_get_type(void)
51 {
52 static NRType type = 0;
53 if (!type) {
54 type = nr_object_register_type(NR_TYPE_ARENA_ITEM,
55 "NRArenaShape",
56 sizeof(NRArenaShapeClass),
57 sizeof(NRArenaShape),
58 (void (*)(NRObjectClass *)) nr_arena_shape_class_init,
59 (void (*)(NRObject *)) nr_arena_shape_init);
60 }
61 return type;
62 }
64 static void
65 nr_arena_shape_class_init(NRArenaShapeClass *klass)
66 {
67 NRObjectClass *object_class;
68 NRArenaItemClass *item_class;
70 object_class = (NRObjectClass *) klass;
71 item_class = (NRArenaItemClass *) klass;
73 shape_parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent;
75 object_class->finalize = nr_arena_shape_finalize;
76 object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaShape>;
78 item_class->children = nr_arena_shape_children;
79 item_class->add_child = nr_arena_shape_add_child;
80 item_class->set_child_position = nr_arena_shape_set_child_position;
81 item_class->remove_child = nr_arena_shape_remove_child;
82 item_class->update = nr_arena_shape_update;
83 item_class->render = nr_arena_shape_render;
84 item_class->clip = nr_arena_shape_clip;
85 item_class->pick = nr_arena_shape_pick;
86 }
88 static void
89 nr_arena_shape_init(NRArenaShape *shape)
90 {
91 shape->curve = NULL;
92 shape->style = NULL;
93 shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
94 shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
96 nr_matrix_set_identity(&shape->ctm);
97 shape->fill_painter = NULL;
98 shape->stroke_painter = NULL;
99 shape->cached_fill = NULL;
100 shape->cached_stroke = NULL;
101 shape->cached_fpartialy = false;
102 shape->cached_spartialy = false;
103 shape->fill_shp = NULL;
104 shape->stroke_shp = NULL;
106 shape->delayed_shp = false;
108 shape->approx_bbox.x0 = shape->approx_bbox.y0 = 0;
109 shape->approx_bbox.x1 = shape->approx_bbox.y1 = 0;
110 nr_matrix_set_identity(&shape->cached_fctm);
111 nr_matrix_set_identity(&shape->cached_sctm);
113 shape->markers = NULL;
114 }
116 static void
117 nr_arena_shape_finalize(NRObject *object)
118 {
119 NRArenaShape *shape = (NRArenaShape *) object;
121 if (shape->fill_shp) delete shape->fill_shp;
122 if (shape->stroke_shp) delete shape->stroke_shp;
123 if (shape->cached_fill) delete shape->cached_fill;
124 if (shape->cached_stroke) delete shape->cached_stroke;
125 if (shape->fill_painter) sp_painter_free(shape->fill_painter);
126 if (shape->stroke_painter) sp_painter_free(shape->stroke_painter);
128 if (shape->style) sp_style_unref(shape->style);
129 if (shape->curve) sp_curve_unref(shape->curve);
131 ((NRObjectClass *) shape_parent_class)->finalize(object);
132 }
134 static NRArenaItem *
135 nr_arena_shape_children(NRArenaItem *item)
136 {
137 NRArenaShape *shape = (NRArenaShape *) item;
139 return shape->markers;
140 }
142 static void
143 nr_arena_shape_add_child(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
144 {
145 NRArenaShape *shape = (NRArenaShape *) item;
147 if (!ref) {
148 shape->markers = nr_arena_item_attach(item, child, NULL, shape->markers);
149 } else {
150 ref->next = nr_arena_item_attach(item, child, ref, ref->next);
151 }
153 nr_arena_item_request_update(item, NR_ARENA_ITEM_STATE_ALL, FALSE);
154 }
156 static void
157 nr_arena_shape_remove_child(NRArenaItem *item, NRArenaItem *child)
158 {
159 NRArenaShape *shape = (NRArenaShape *) item;
161 if (child->prev) {
162 nr_arena_item_detach(item, child);
163 } else {
164 shape->markers = nr_arena_item_detach(item, child);
165 }
167 nr_arena_item_request_update(item, NR_ARENA_ITEM_STATE_ALL, FALSE);
168 }
170 static void
171 nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
172 {
173 NRArenaShape *shape = (NRArenaShape *) item;
175 if (child->prev) {
176 nr_arena_item_detach(item, child);
177 } else {
178 shape->markers = nr_arena_item_detach(item, child);
179 }
181 if (!ref) {
182 shape->markers = nr_arena_item_attach(item, child, NULL, shape->markers);
183 } else {
184 ref->next = nr_arena_item_attach(item, child, ref, ref->next);
185 }
187 nr_arena_item_request_render(child);
188 }
190 void nr_arena_shape_update_stroke(NRArenaShape *shape, NRGC* gc, NRRectL *area);
191 void nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape = false);
192 void nr_arena_shape_add_bboxes(NRArenaShape* shape,NRRect &bbox);
194 static guint
195 nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
196 {
197 NRRect bbox;
199 NRArenaShape *shape = NR_ARENA_SHAPE(item);
201 unsigned int beststate = NR_ARENA_ITEM_STATE_ALL;
203 unsigned int newstate;
204 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
205 newstate = nr_arena_item_invoke_update(child, area, gc, state, reset);
206 beststate = beststate & newstate;
207 }
209 if (!(state & NR_ARENA_ITEM_STATE_RENDER)) {
210 /* We do not have to create rendering structures */
211 shape->ctm = gc->transform;
212 if (state & NR_ARENA_ITEM_STATE_BBOX) {
213 if (shape->curve) {
214 NRBPath bp;
215 /* fixme: */
216 bbox.x0 = bbox.y0 = NR_HUGE;
217 bbox.x1 = bbox.y1 = -NR_HUGE;
218 bp.path = SP_CURVE_BPATH(shape->curve);
219 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
220 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
221 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
222 item->bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
223 item->bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
224 }
225 if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
226 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
227 nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
228 }
229 }
230 }
231 return (state | item->state);
232 }
234 shape->delayed_shp=true;
235 shape->ctm = gc->transform;
236 bbox.x0 = bbox.y0 = NR_HUGE;
237 bbox.x1 = bbox.y1 = -NR_HUGE;
239 if (shape->curve) {
240 NRBPath bp;
241 /* fixme: */
242 bbox.x0 = bbox.y0 = NR_HUGE;
243 bbox.x1 = bbox.y1 = -NR_HUGE;
244 bp.path = SP_CURVE_BPATH(shape->curve);
245 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
246 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
247 float width, scale;
248 scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
249 width = MAX(0.125, shape->_stroke.width * scale);
250 if ( fabs(shape->_stroke.width * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
251 bbox.x0-=width;
252 bbox.x1+=width;
253 bbox.y0-=width;
254 bbox.y1+=width;
255 }
256 // those pesky miters, now
257 float miterMax=width*shape->_stroke.mitre_limit;
258 if ( miterMax > 0.01 ) {
259 // grunt mode. we should compute the various miters instead (one for each point on the curve)
260 bbox.x0-=miterMax;
261 bbox.x1+=miterMax;
262 bbox.y0-=miterMax;
263 bbox.y1+=miterMax;
264 }
265 }
266 } else {
267 }
268 shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
269 shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
270 shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
271 shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
272 if ( area && nr_rect_l_test_intersect(area, &shape->approx_bbox) ) shape->delayed_shp=false;
274 /* Release state data */
275 if (TRUE || !nr_matrix_test_transform_equal(&gc->transform, &shape->ctm, NR_EPSILON)) {
276 /* Concept test */
277 if (shape->fill_shp) {
278 delete shape->fill_shp;
279 shape->fill_shp = NULL;
280 }
281 }
282 if (shape->stroke_shp) {
283 delete shape->stroke_shp;
284 shape->stroke_shp = NULL;
285 }
286 if (shape->fill_painter) {
287 sp_painter_free(shape->fill_painter);
288 shape->fill_painter = NULL;
289 }
290 if (shape->stroke_painter) {
291 sp_painter_free(shape->stroke_painter);
292 shape->stroke_painter = NULL;
293 }
295 if (!shape->curve || !shape->style) return NR_ARENA_ITEM_STATE_ALL;
296 if (sp_curve_is_empty(shape->curve)) return NR_ARENA_ITEM_STATE_ALL;
297 if ( ( shape->_fill.paint.type() == NRArenaShape::Paint::NONE ) &&
298 ( shape->_stroke.paint.type() == NRArenaShape::Paint::NONE ) )
299 {
300 return NR_ARENA_ITEM_STATE_ALL;
301 }
303 /* Build state data */
304 if ( shape->delayed_shp ) {
305 item->bbox=shape->approx_bbox;
306 } else {
307 nr_arena_shape_update_stroke(shape, gc, area);
308 nr_arena_shape_update_fill(shape, gc, area);
310 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
311 nr_arena_shape_add_bboxes(shape,bbox);
313 shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
314 shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
315 shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
316 shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
317 }
319 if (nr_rect_d_test_empty(&bbox)) return NR_ARENA_ITEM_STATE_ALL;
321 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
322 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
323 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
324 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
325 nr_arena_request_render_rect(item->arena, &item->bbox);
327 item->render_opacity = TRUE;
328 if ( shape->_fill.paint.type() == NRArenaShape::Paint::SERVER ) {
329 if (gc && gc->parent) {
330 shape->fill_painter = sp_paint_server_painter_new(shape->_fill.paint.server(),
331 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
332 &shape->paintbox);
333 }
334 item->render_opacity = FALSE;
335 }
336 if ( shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER ) {
337 if (gc && gc->parent) {
338 shape->stroke_painter = sp_paint_server_painter_new(shape->_stroke.paint.server(),
339 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
340 &shape->paintbox);
341 }
342 item->render_opacity = FALSE;
343 }
344 if ( item->render_opacity == TRUE
345 && shape->_fill.paint.type() != NRArenaShape::Paint::NONE
346 && shape->_stroke.paint.type() != NRArenaShape::Paint::NONE )
347 {
348 // don't merge item opacity with paint opacity if there is a stroke on the fill
349 item->render_opacity = FALSE;
350 }
352 if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
353 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
354 nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
355 }
356 }
358 return NR_ARENA_ITEM_STATE_ALL;
359 }
361 int matrix_is_isometry(NR::Matrix p) {
362 NR::Matrix tp;
363 // transposition
364 tp[0]=p[0];
365 tp[1]=p[2];
366 tp[2]=p[1];
367 tp[3]=p[3];
368 for (int i = 4; i < 6; i++) // shut valgrind up :)
369 tp[i] = p[i] = 0;
370 NR::Matrix isom = tp*p; // A^T * A = adjunct?
371 // Is the adjunct nearly an identity function?
372 if (isom.is_translation(0.01)) {
373 // the transformation is an isometry -> no need to recompute
374 // the uncrossed polygon
375 if ( p.det() < 0 )
376 return -1;
377 else
378 return 1;
379 }
380 return 0;
381 }
383 static bool is_inner_area(NRRectL const &outer, NRRectL const &inner) {
384 return (outer.x0 <= inner.x0 && outer.y0 <= inner.y0 && outer.x1 >= inner.x1 && outer.y1 >= inner.y1);
385 }
387 /** force_shape is used for clipping paths, when we need the shape for clipping even if it's not filled */
388 void
389 nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape)
390 {
391 if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) &&
392 ((shape->curve->end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) {
393 if (TRUE || !shape->fill_shp) {
394 NR::Matrix cached_to_new = NR::identity();
395 int isometry = 0;
396 if ( shape->cached_fill ) {
397 if (shape->cached_fctm == gc->transform) {
398 isometry = 2; // identity
399 } else {
400 cached_to_new = shape->cached_fctm.inverse() * gc->transform;
401 isometry = matrix_is_isometry(cached_to_new);
402 }
403 if (0 != isometry && !is_inner_area(shape->cached_farea, *area))
404 isometry = 0;
405 }
406 if ( isometry == 0 ) {
407 if ( shape->cached_fill == NULL ) shape->cached_fill=new Shape;
408 shape->cached_fill->Reset();
410 Path* thePath=new Path;
411 Shape* theShape=new Shape;
412 {
413 NR::Matrix tempMat(gc->transform);
414 thePath->LoadArtBPath(SP_CURVE_BPATH(shape->curve),tempMat,true);
415 }
417 if (is_inner_area(*area, NR_ARENA_ITEM(shape)->bbox)) {
418 thePath->Convert(1.0);
419 shape->cached_fpartialy = false;
420 } else {
421 thePath->Convert(area, 1.0);
422 shape->cached_fpartialy = true;
423 }
425 thePath->Fill(theShape, 0);
427 if ( shape->_fill.rule == NRArenaShape::EVEN_ODD ) {
428 shape->cached_fill->ConvertToShape(theShape, fill_oddEven);
429 // alternatively, this speeds up rendering of oddeven shapes but disables AA :(
430 //shape->cached_fill->Copy(theShape);
431 } else {
432 shape->cached_fill->ConvertToShape(theShape, fill_nonZero);
433 }
434 shape->cached_fctm=gc->transform;
435 shape->cached_farea = *area;
436 delete theShape;
437 delete thePath;
438 if ( shape->fill_shp == NULL )
439 shape->fill_shp = new Shape;
441 shape->fill_shp->Copy(shape->cached_fill);
443 } else if ( 2 == isometry ) {
444 if ( shape->fill_shp == NULL ) {
445 shape->fill_shp = new Shape;
446 shape->fill_shp->Copy(shape->cached_fill);
447 }
448 } else {
450 if ( shape->fill_shp == NULL )
451 shape->fill_shp = new Shape;
453 shape->fill_shp->Reset(shape->cached_fill->numberOfPoints(),
454 shape->cached_fill->numberOfEdges());
455 for (int i = 0; i < shape->cached_fill->numberOfPoints(); i++)
456 shape->fill_shp->AddPoint(shape->cached_fill->getPoint(i).x * cached_to_new);
457 if ( isometry == 1 ) {
458 for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
459 shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).st,
460 shape->cached_fill->getEdge(i).en);
461 } else if ( isometry == -1 ) { // need to flip poly.
462 for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
463 shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).en,
464 shape->cached_fill->getEdge(i).st);
465 }
466 shape->fill_shp->ForceToPolygon();
467 shape->fill_shp->needPointsSorting();
468 shape->fill_shp->needEdgesSorting();
469 }
470 shape->delayed_shp |= shape->cached_fpartialy;
471 }
472 }
473 }
475 void
476 nr_arena_shape_update_stroke(NRArenaShape *shape,NRGC* gc, NRRectL *area)
477 {
478 SPStyle* style = shape->style;
480 float const scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
482 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE ||
483 ((shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) &&
484 ( fabs(shape->_stroke.width * scale) > 0.01 ))) { // sinon c'est 0=oon veut pas de bord
486 float width = MAX(0.125, shape->_stroke.width * scale);
487 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE)
488 width = 0.5; // 1 pixel wide, independent of zoom
490 NR::Matrix cached_to_new = NR::identity();
492 int isometry = 0;
493 if ( shape->cached_stroke ) {
494 if (shape->cached_sctm == gc->transform) {
495 isometry = 2; // identity
496 } else {
497 cached_to_new = shape->cached_sctm.inverse() * gc->transform;
498 isometry = matrix_is_isometry(cached_to_new);
499 }
500 if (0 != isometry && !is_inner_area(shape->cached_sarea, *area))
501 isometry = 0;
502 }
504 if ( isometry == 0 ) {
505 if ( shape->cached_stroke == NULL ) shape->cached_stroke=new Shape;
506 shape->cached_stroke->Reset();
507 Path* thePath = new Path;
508 Shape* theShape = new Shape;
509 {
510 NR::Matrix tempMat(gc->transform);
511 thePath->LoadArtBPath(SP_CURVE_BPATH(shape->curve), tempMat, true);
512 }
514 // add some padding to the rendering area, so clipped path does not go into a render area
515 NRRectL padded_area = *area;
516 padded_area.x0 -= (NR::ICoord)width;
517 padded_area.x1 += (NR::ICoord)width;
518 padded_area.y0 -= (NR::ICoord)width;
519 padded_area.y1 += (NR::ICoord)width;
520 if ((style->stroke_dash.n_dash && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) || is_inner_area(padded_area, NR_ARENA_ITEM(shape)->bbox)) {
521 thePath->Convert((NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) ? 1.0 : 4.0);
522 shape->cached_spartialy = false;
523 }
524 else {
525 thePath->Convert(&padded_area, (NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) ? 1.0 : 4.0);
526 shape->cached_spartialy = true;
527 }
529 if (style->stroke_dash.n_dash && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) {
530 thePath->DashPolylineFromStyle(style, scale, 1.0);
531 }
533 ButtType butt=butt_straight;
534 switch (shape->_stroke.cap) {
535 case NRArenaShape::BUTT_CAP:
536 butt = butt_straight;
537 break;
538 case NRArenaShape::ROUND_CAP:
539 butt = butt_round;
540 break;
541 case NRArenaShape::SQUARE_CAP:
542 butt = butt_square;
543 break;
544 }
545 JoinType join=join_straight;
546 switch (shape->_stroke.join) {
547 case NRArenaShape::MITRE_JOIN:
548 join = join_pointy;
549 break;
550 case NRArenaShape::ROUND_JOIN:
551 join = join_round;
552 break;
553 case NRArenaShape::BEVEL_JOIN:
554 join = join_straight;
555 break;
556 }
558 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
559 butt = butt_straight;
560 join = join_straight;
561 }
563 thePath->Stroke(theShape, false, 0.5*width, join, butt,
564 0.5*width*shape->_stroke.mitre_limit);
567 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
568 // speeds it up, but uses evenodd for the stroke shape (which does not matter for 1-pixel wide outline)
569 shape->cached_stroke->Copy(theShape);
570 } else {
571 shape->cached_stroke->ConvertToShape(theShape, fill_nonZero);
572 }
574 shape->cached_sctm=gc->transform;
575 shape->cached_sarea = *area;
576 delete thePath;
577 delete theShape;
578 if ( shape->stroke_shp == NULL ) shape->stroke_shp=new Shape;
580 shape->stroke_shp->Copy(shape->cached_stroke);
582 } else if ( 2 == isometry ) {
583 if ( shape->stroke_shp == NULL ) {
584 shape->stroke_shp=new Shape;
585 shape->stroke_shp->Copy(shape->cached_stroke);
586 }
587 } else {
588 if ( shape->stroke_shp == NULL )
589 shape->stroke_shp=new Shape;
590 shape->stroke_shp->Reset(shape->cached_stroke->numberOfPoints(), shape->cached_stroke->numberOfEdges());
591 for (int i = 0; i < shape->cached_stroke->numberOfPoints(); i++)
592 shape->stroke_shp->AddPoint(shape->cached_stroke->getPoint(i).x * cached_to_new);
593 if ( isometry == 1 ) {
594 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
595 shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).st,
596 shape->cached_stroke->getEdge(i).en);
597 } else if ( isometry == -1 ) {
598 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
599 shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).en,
600 shape->cached_stroke->getEdge(i).st);
601 }
602 shape->stroke_shp->ForceToPolygon();
603 shape->stroke_shp->needPointsSorting();
604 shape->stroke_shp->needEdgesSorting();
605 }
606 shape->delayed_shp |= shape->cached_spartialy;
607 }
608 }
611 void
612 nr_arena_shape_add_bboxes(NRArenaShape* shape, NRRect &bbox)
613 {
614 if ( shape->stroke_shp ) {
615 shape->stroke_shp->CalcBBox();
616 shape->stroke_shp->leftX=floor(shape->stroke_shp->leftX);
617 shape->stroke_shp->rightX=ceil(shape->stroke_shp->rightX);
618 shape->stroke_shp->topY=floor(shape->stroke_shp->topY);
619 shape->stroke_shp->bottomY=ceil(shape->stroke_shp->bottomY);
620 if ( bbox.x0 >= bbox.x1 ) {
621 if ( shape->stroke_shp->leftX < shape->stroke_shp->rightX ) {
622 bbox.x0=shape->stroke_shp->leftX;
623 bbox.x1=shape->stroke_shp->rightX;
624 }
625 } else {
626 if ( shape->stroke_shp->leftX < bbox.x0 )
627 bbox.x0=shape->stroke_shp->leftX;
628 if ( shape->stroke_shp->rightX > bbox.x1 )
629 bbox.x1=shape->stroke_shp->rightX;
630 }
631 if ( bbox.y0 >= bbox.y1 ) {
632 if ( shape->stroke_shp->topY < shape->stroke_shp->bottomY ) {
633 bbox.y0=shape->stroke_shp->topY;
634 bbox.y1=shape->stroke_shp->bottomY;
635 }
636 } else {
637 if ( shape->stroke_shp->topY < bbox.y0 )
638 bbox.y0=shape->stroke_shp->topY;
639 if ( shape->stroke_shp->bottomY > bbox.y1 )
640 bbox.y1=shape->stroke_shp->bottomY;
641 }
642 }
643 if ( shape->fill_shp ) {
644 shape->fill_shp->CalcBBox();
645 shape->fill_shp->leftX=floor(shape->fill_shp->leftX);
646 shape->fill_shp->rightX=ceil(shape->fill_shp->rightX);
647 shape->fill_shp->topY=floor(shape->fill_shp->topY);
648 shape->fill_shp->bottomY=ceil(shape->fill_shp->bottomY);
649 if ( bbox.x0 >= bbox.x1 ) {
650 if ( shape->fill_shp->leftX < shape->fill_shp->rightX ) {
651 bbox.x0=shape->fill_shp->leftX;
652 bbox.x1=shape->fill_shp->rightX;
653 }
654 } else {
655 if ( shape->fill_shp->leftX < bbox.x0 ) bbox.x0=shape->fill_shp->leftX;
656 if ( shape->fill_shp->rightX > bbox.x1 ) bbox.x1=shape->fill_shp->rightX;
657 }
658 if ( bbox.y0 >= bbox.y1 ) {
659 if ( shape->fill_shp->topY < shape->fill_shp->bottomY ) {
660 bbox.y0=shape->fill_shp->topY;
661 bbox.y1=shape->fill_shp->bottomY;
662 }
663 } else {
664 if ( shape->fill_shp->topY < bbox.y0 ) bbox.y0=shape->fill_shp->topY;
665 if ( shape->fill_shp->bottomY > bbox.y1 ) bbox.y1=shape->fill_shp->bottomY;
666 }
667 }
668 }
669 static unsigned int
670 nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags)
671 {
672 NRArenaShape *shape = NR_ARENA_SHAPE(item);
674 if (!shape->curve) return item->state;
675 if (!shape->style) return item->state;
677 if ( shape->delayed_shp ) {
678 if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
679 NRGC tempGC(NULL);
680 tempGC.transform=shape->ctm;
681 shape->delayed_shp = false;
682 nr_arena_shape_update_stroke(shape,&tempGC,&pb->visible_area);
683 nr_arena_shape_update_fill(shape,&tempGC,&pb->visible_area);
684 /* NRRect bbox;
685 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
686 nr_arena_shape_add_bboxes(shape,bbox);
687 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
688 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
689 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
690 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
691 shape->approx_bbox=item->bbox;*/
692 } else {
693 return item->state;
694 }
695 }
697 SPStyle const *style = shape->style;
698 if ( shape->fill_shp && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) {
699 NRPixBlock m;
700 guint32 rgba;
702 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
703 m.visible_area = pb->visible_area;
704 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
705 m.empty = FALSE;
707 if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) {
708 // do not render fill in any way
709 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) {
710 if ( item->render_opacity ) {
711 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
712 shape->_fill.opacity *
713 SP_SCALE24_TO_FLOAT(style->opacity.value));
714 } else {
715 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
716 shape->_fill.opacity);
717 }
718 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
719 pb->empty = FALSE;
720 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) {
721 if (shape->fill_painter) {
722 nr_arena_render_paintserver_fill(pb, area, shape->fill_painter, shape->_fill.opacity, &m);
723 }
724 }
726 nr_pixblock_release(&m);
727 }
729 if ( shape->stroke_shp ) {
730 NRPixBlock m;
731 guint32 rgba;
733 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
734 m.visible_area = pb->visible_area;
735 nr_pixblock_render_shape_mask_or(m, shape->stroke_shp);
736 m.empty = FALSE;
738 if (shape->_stroke.paint.type() == NRArenaShape::Paint::COLOR ||
739 NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
740 if ( NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
741 rgba = NR_ARENA_ITEM(shape)->arena->outlinecolor;
742 } else if ( item->render_opacity ) {
743 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
744 shape->_stroke.opacity *
745 SP_SCALE24_TO_FLOAT(style->opacity.value));
746 } else {
747 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
748 shape->_stroke.opacity);
749 }
750 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
751 pb->empty = FALSE;
752 } else if (shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER) {
753 if (shape->stroke_painter) {
754 nr_arena_render_paintserver_fill(pb, area, shape->stroke_painter, shape->_stroke.opacity, &m);
755 }
756 }
758 nr_pixblock_release(&m);
759 }
761 /* Just compose children into parent buffer */
762 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
763 unsigned int ret;
764 ret = nr_arena_item_invoke_render(child, area, pb, flags);
765 if (ret & NR_ARENA_ITEM_STATE_INVALID) return ret;
766 }
768 return item->state;
769 }
771 static guint
772 nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
773 {
774 NRArenaShape *shape = NR_ARENA_SHAPE(item);
775 if (!shape->curve) return item->state;
777 if ( shape->delayed_shp || shape->fill_shp == NULL) { // we need a fill shape no matter what
778 if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
779 NRGC tempGC(NULL);
780 tempGC.transform=shape->ctm;
781 shape->delayed_shp = false;
782 nr_arena_shape_update_fill(shape, &tempGC, &pb->visible_area, true);
783 } else {
784 return item->state;
785 }
786 }
788 if ( shape->fill_shp ) {
789 NRPixBlock m;
791 /* fixme: We can OR in one step (Lauris) */
792 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
793 m.visible_area = pb->visible_area;
794 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
796 for (int y = area->y0; y < area->y1; y++) {
797 unsigned char *s, *d;
798 s = NR_PIXBLOCK_PX(&m) + (y - area->y0) * m.rs;
799 d = NR_PIXBLOCK_PX(pb) + (y - area->y0) * pb->rs;
800 for (int x = area->x0; x < area->x1; x++) {
801 *d = NR_A7_NORMALIZED(*s,*d);
802 d ++;
803 s ++;
804 }
805 }
806 nr_pixblock_release(&m);
807 pb->empty = FALSE;
808 }
810 return item->state;
811 }
813 static NRArenaItem *
814 nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/)
815 {
816 NRArenaShape *shape = NR_ARENA_SHAPE(item);
818 if (!shape->curve) return NULL;
819 if (!shape->style) return NULL;
820 if ( shape->delayed_shp ) {
821 NRRectL area, updateArea;
822 area.x0=(int)floor(p[NR::X]);
823 area.x1=(int)ceil(p[NR::X]);
824 area.y0=(int)floor(p[NR::Y]);
825 area.y1=(int)ceil(p[NR::Y]);
826 int idelta = (int)ceil(delta) + 1;
827 // njh: inset rect
828 area.x0-=idelta;
829 area.x1+=idelta;
830 area.y0-=idelta;
831 area.y1+=idelta;
832 if ( nr_rect_l_test_intersect(&area, &item->bbox) ) {
833 NRGC tempGC(NULL);
834 tempGC.transform=shape->ctm;
835 updateArea = item->bbox;
836 if (shape->cached_stroke)
837 nr_rect_l_intersect (&updateArea, &updateArea, &shape->cached_sarea);
839 shape->delayed_shp = false;
840 nr_arena_shape_update_stroke(shape, &tempGC, &updateArea);
841 nr_arena_shape_update_fill(shape, &tempGC, &updateArea);
842 /* NRRect bbox;
843 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
844 nr_arena_shape_add_bboxes(shape,bbox);
845 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
846 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
847 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
848 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
849 shape->approx_bbox=item->bbox;*/
850 }
851 }
853 if (item->state & NR_ARENA_ITEM_STATE_RENDER) {
854 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
855 if (shape->fill_shp->PtWinding(p) > 0 ) return item;
856 }
857 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
858 if (shape->stroke_shp->PtWinding(p) > 0 ) return item;
859 }
860 if (delta > 1e-3) {
861 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
862 if (distanceLessThanOrEqual(shape->fill_shp, p, delta)) return item;
863 }
864 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
865 if (distanceLessThanOrEqual(shape->stroke_shp, p, delta)) return item;
866 }
867 }
868 } else {
869 NRBPath bp;
870 bp.path = SP_CURVE_BPATH(shape->curve);
871 double dist = NR_HUGE;
872 int wind = 0;
873 nr_path_matrix_point_bbox_wind_distance(&bp, shape->ctm, p, NULL, &wind, &dist, NR_EPSILON);
874 if (shape->_fill.paint.type() != NRArenaShape::Paint::NONE) {
875 if (!shape->style->fill_rule.computed) {
876 if (wind != 0) return item;
877 } else {
878 if (wind & 0x1) return item;
879 }
880 }
881 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
882 /* fixme: We do not take stroke width into account here (Lauris) */
883 if (dist < delta) return item;
884 }
885 }
887 return NULL;
888 }
890 /**
891 *
892 * Requests a render of the shape, then if the shape is already a curve it
893 * unrefs the old curve; if the new curve is valid it creates a copy of the
894 * curve and adds it to the shape. Finally, it requests an update of the
895 * arena for the shape.
896 */
897 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve,bool justTrans)
898 {
899 g_return_if_fail(shape != NULL);
900 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
902 if ( justTrans == false ) {
903 // dirty cached versions
904 if ( shape->cached_fill ) {
905 delete shape->cached_fill;
906 shape->cached_fill=NULL;
907 }
908 if ( shape->cached_stroke ) {
909 delete shape->cached_stroke;
910 shape->cached_stroke=NULL;
911 }
912 }
914 nr_arena_item_request_render(NR_ARENA_ITEM(shape));
916 if (shape->curve) {
917 sp_curve_unref(shape->curve);
918 shape->curve = NULL;
919 }
921 if (curve) {
922 shape->curve = curve;
923 sp_curve_ref(curve);
924 }
926 nr_arena_item_request_update(NR_ARENA_ITEM(shape), NR_ARENA_ITEM_STATE_ALL, FALSE);
927 }
929 void NRArenaShape::setFill(SPPaintServer *server) {
930 _fill.paint.set(server);
931 _invalidateCachedFill();
932 }
934 void NRArenaShape::setFill(SPColor const &color) {
935 _fill.paint.set(color);
936 _invalidateCachedFill();
937 }
939 void NRArenaShape::setFillOpacity(double opacity) {
940 _fill.opacity = opacity;
941 _invalidateCachedFill();
942 }
944 void NRArenaShape::setFillRule(NRArenaShape::FillRule rule) {
945 _fill.rule = rule;
946 _invalidateCachedFill();
947 }
949 void NRArenaShape::setStroke(SPPaintServer *server) {
950 _stroke.paint.set(server);
951 _invalidateCachedStroke();
952 }
954 void NRArenaShape::setStroke(SPColor const &color) {
955 _stroke.paint.set(color);
956 _invalidateCachedStroke();
957 }
959 void NRArenaShape::setStrokeOpacity(double opacity) {
960 _stroke.opacity = opacity;
961 _invalidateCachedStroke();
962 }
964 void NRArenaShape::setStrokeWidth(double width) {
965 _stroke.width = width;
966 _invalidateCachedStroke();
967 }
969 void NRArenaShape::setMitreLimit(double limit) {
970 _stroke.mitre_limit = limit;
971 _invalidateCachedStroke();
972 }
974 void NRArenaShape::setLineCap(NRArenaShape::CapType cap) {
975 _stroke.cap = cap;
976 _invalidateCachedStroke();
977 }
979 void NRArenaShape::setLineJoin(NRArenaShape::JoinType join) {
980 _stroke.join = join;
981 _invalidateCachedStroke();
982 }
984 /** nr_arena_shape_set_style
985 *
986 * Unrefs any existing style and ref's to the given one, then requests an update of the arena
987 */
988 void
989 nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style)
990 {
991 g_return_if_fail(shape != NULL);
992 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
994 if (style) sp_style_ref(style);
995 if (shape->style) sp_style_unref(shape->style);
996 shape->style = style;
998 switch (style->fill.type) {
999 case SP_PAINT_TYPE_NONE: {
1000 shape->setFill(NULL);
1001 break;
1002 }
1003 case SP_PAINT_TYPE_COLOR: {
1004 shape->setFill(style->fill.value.color);
1005 break;
1006 }
1007 case SP_PAINT_TYPE_PAINTSERVER: {
1008 shape->setFill(style->fill.value.paint.server);
1009 break;
1010 }
1011 default: {
1012 g_assert_not_reached();
1013 }
1014 }
1015 shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
1016 switch (style->fill_rule.computed) {
1017 case SP_WIND_RULE_EVENODD: {
1018 shape->setFillRule(NRArenaShape::EVEN_ODD);
1019 break;
1020 }
1021 case SP_WIND_RULE_NONZERO: {
1022 shape->setFillRule(NRArenaShape::NONZERO);
1023 break;
1024 }
1025 default: {
1026 g_assert_not_reached();
1027 }
1028 }
1030 switch (style->stroke.type) {
1031 case SP_PAINT_TYPE_NONE: {
1032 shape->setStroke(NULL);
1033 break;
1034 }
1035 case SP_PAINT_TYPE_COLOR: {
1036 shape->setStroke(style->stroke.value.color);
1037 break;
1038 }
1039 case SP_PAINT_TYPE_PAINTSERVER: {
1040 shape->setStroke(style->stroke.value.paint.server);
1041 break;
1042 }
1043 default: {
1044 g_assert_not_reached();
1045 }
1046 }
1047 shape->setStrokeWidth(style->stroke_width.computed);
1048 shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
1049 switch (style->stroke_linecap.computed) {
1050 case SP_STROKE_LINECAP_ROUND: {
1051 shape->setLineCap(NRArenaShape::ROUND_CAP);
1052 break;
1053 }
1054 case SP_STROKE_LINECAP_SQUARE: {
1055 shape->setLineCap(NRArenaShape::SQUARE_CAP);
1056 break;
1057 }
1058 case SP_STROKE_LINECAP_BUTT: {
1059 shape->setLineCap(NRArenaShape::BUTT_CAP);
1060 break;
1061 }
1062 default: {
1063 g_assert_not_reached();
1064 }
1065 }
1066 switch (style->stroke_linejoin.computed) {
1067 case SP_STROKE_LINEJOIN_ROUND: {
1068 shape->setLineJoin(NRArenaShape::ROUND_JOIN);
1069 break;
1070 }
1071 case SP_STROKE_LINEJOIN_BEVEL: {
1072 shape->setLineJoin(NRArenaShape::BEVEL_JOIN);
1073 break;
1074 }
1075 case SP_STROKE_LINEJOIN_MITER: {
1076 shape->setLineJoin(NRArenaShape::MITRE_JOIN);
1077 break;
1078 }
1079 default: {
1080 g_assert_not_reached();
1081 }
1082 }
1083 shape->setMitreLimit(style->stroke_miterlimit.value);
1085 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1086 }
1088 void
1089 nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox)
1090 {
1091 g_return_if_fail(shape != NULL);
1092 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1093 g_return_if_fail(pbox != NULL);
1095 if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
1096 shape->paintbox = *pbox;
1097 } else {
1098 /* fixme: We kill warning, although not sure what to do here (Lauris) */
1099 shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
1100 shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
1101 }
1103 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1104 }
1106 void NRArenaShape::setPaintBox(NR::Rect const &pbox)
1107 {
1108 paintbox.x0 = pbox.min()[NR::X];
1109 paintbox.y0 = pbox.min()[NR::Y];
1110 paintbox.x1 = pbox.max()[NR::X];
1111 paintbox.y1 = pbox.max()[NR::Y];
1113 nr_arena_item_request_update(this, NR_ARENA_ITEM_STATE_ALL, FALSE);
1114 }
1116 static void
1117 shape_run_A8_OR(raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
1118 {
1119 if ( st >= en ) return;
1120 if ( vst < 0 ) vst=0;
1121 if ( vst > 1 ) vst=1;
1122 if ( ven < 0 ) ven=0;
1123 if ( ven > 1 ) ven=1;
1124 float sv=vst;
1125 float dv=ven-vst;
1126 int len=en-st;
1127 unsigned char* d=(unsigned char*)dest.buffer;
1128 d+=(st-dest.startPix);
1129 if ( fabs(dv) < 0.001 ) {
1130 if ( vst > 0.999 ) {
1131 /* Simple copy */
1132 while (len > 0) {
1133 d[0] = 255;
1134 d += 1;
1135 len -= 1;
1136 }
1137 } else {
1138 sv*=256;
1139 unsigned int c0_24=(int)sv;
1140 c0_24&=0xFF;
1141 while (len > 0) {
1142 unsigned int da;
1143 /* Draw */
1144 da = NR_A7(c0_24,d[0]);
1145 d[0] = NR_PREMUL_SINGLE(da);
1146 d += 1;
1147 len -= 1;
1148 }
1149 }
1150 } else {
1151 if ( en <= st+1 ) {
1152 sv=0.5*(vst+ven);
1153 sv*=256;
1154 unsigned int c0_24=(int)sv;
1155 c0_24&=0xFF;
1156 unsigned int da;
1157 /* Draw */
1158 da = NR_A7(c0_24,d[0]);
1159 d[0] = NR_PREMUL_SINGLE(da);
1160 } else {
1161 dv/=len;
1162 sv+=0.5*dv; // correction trapezoidale
1163 sv*=16777216;
1164 dv*=16777216;
1165 int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
1166 int s0_24 = static_cast<int>(dv);
1167 while (len > 0) {
1168 unsigned int ca, da;
1169 /* Draw */
1170 ca = c0_24 >> 16;
1171 if ( ca > 255 ) ca=255;
1172 da = NR_A7(ca,d[0]);
1173 d[0] = NR_PREMUL_SINGLE(da);
1174 d += 1;
1175 c0_24 += s0_24;
1176 c0_24 = CLAMP(c0_24, 0, 16777216);
1177 len -= 1;
1178 }
1179 }
1180 }
1181 }
1183 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS)
1184 {
1185 theS->CalcBBox();
1186 float l = theS->leftX, r = theS->rightX, t = theS->topY, b = theS->bottomY;
1187 int il,ir,it,ib;
1188 il=(int)floor(l);
1189 ir=(int)ceil(r);
1190 it=(int)floor(t);
1191 ib=(int)ceil(b);
1193 if ( il >= m.area.x1 || ir <= m.area.x0 || it >= m.area.y1 || ib <= m.area.y0 ) return;
1194 if ( il < m.area.x0 ) il=m.area.x0;
1195 if ( it < m.area.y0 ) it=m.area.y0;
1196 if ( ir > m.area.x1 ) ir=m.area.x1;
1197 if ( ib > m.area.y1 ) ib=m.area.y1;
1199 /* This is the FloatLigne version. See svn (prior to Apr 2006) for versions using BitLigne or direct BitLigne. */
1200 int curPt;
1201 float curY;
1202 theS->BeginQuickRaster(curY, curPt);
1204 FloatLigne *theI = new FloatLigne();
1205 IntLigne *theIL = new IntLigne();
1207 theS->DirectQuickScan(curY, curPt, (float) it, true, 1.0);
1209 char *mdata = (char*)m.data.px;
1210 if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1211 uint32_t *ligStart = ((uint32_t*)(mdata + ((il - m.area.x0) + m.rs * (it - m.area.y0))));
1212 for (int y = it; y < ib; y++) {
1213 theI->Reset();
1214 theS->QuickScan(curY, curPt, ((float)(y+1)), theI, 1.0);
1215 theI->Flatten();
1216 theIL->Copy(theI);
1218 raster_info dest;
1219 dest.startPix=il;
1220 dest.endPix=ir;
1221 dest.sth=il;
1222 dest.stv=y;
1223 dest.buffer=ligStart;
1224 theIL->Raster(dest, NULL, shape_run_A8_OR);
1225 ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1226 }
1227 theS->EndQuickRaster();
1228 delete theI;
1229 delete theIL;
1230 }
1233 /*
1234 Local Variables:
1235 mode:c++
1236 c-file-style:"stroustrup"
1237 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1238 indent-tabs-mode:nil
1239 fill-column:99
1240 End:
1241 */
1242 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :