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