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