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