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 bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
248 if (shape->curve) {
249 NRBPath bp;
250 /* fixme: */
251 bbox.x0 = bbox.y0 = NR_HUGE;
252 bbox.x1 = bbox.y1 = -NR_HUGE;
253 bp.path = SP_CURVE_BPATH(shape->curve);
254 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
255 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline) {
256 float width, scale;
257 scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
258 width = MAX(0.125, shape->_stroke.width * scale);
259 if ( fabs(shape->_stroke.width * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
260 bbox.x0-=width;
261 bbox.x1+=width;
262 bbox.y0-=width;
263 bbox.y1+=width;
264 }
265 // those pesky miters, now
266 float miterMax=width*shape->_stroke.mitre_limit;
267 if ( miterMax > 0.01 ) {
268 // grunt mode. we should compute the various miters instead (one for each point on the curve)
269 bbox.x0-=miterMax;
270 bbox.x1+=miterMax;
271 bbox.y0-=miterMax;
272 bbox.y1+=miterMax;
273 }
274 }
275 } else {
276 }
277 shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
278 shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
279 shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
280 shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
281 if ( area && nr_rect_l_test_intersect(area, &shape->approx_bbox) ) shape->delayed_shp=false;
283 /* Release state data */
284 if (TRUE || !nr_matrix_test_transform_equal(&gc->transform, &shape->ctm, NR_EPSILON)) {
285 /* Concept test */
286 if (shape->fill_shp) {
287 delete shape->fill_shp;
288 shape->fill_shp = NULL;
289 }
290 }
291 if (shape->stroke_shp) {
292 delete shape->stroke_shp;
293 shape->stroke_shp = NULL;
294 }
295 if (shape->fill_painter) {
296 sp_painter_free(shape->fill_painter);
297 shape->fill_painter = NULL;
298 }
299 if (shape->stroke_painter) {
300 sp_painter_free(shape->stroke_painter);
301 shape->stroke_painter = NULL;
302 }
304 if (!shape->curve || !shape->style) return NR_ARENA_ITEM_STATE_ALL;
305 if (sp_curve_is_empty(shape->curve)) return NR_ARENA_ITEM_STATE_ALL;
306 if ( ( shape->_fill.paint.type() == NRArenaShape::Paint::NONE ) &&
307 ( shape->_stroke.paint.type() == NRArenaShape::Paint::NONE && !outline) )
308 {
309 return NR_ARENA_ITEM_STATE_ALL;
310 }
312 /* Build state data */
313 if ( shape->delayed_shp ) {
314 item->bbox=shape->approx_bbox;
315 } else {
316 nr_arena_shape_update_stroke(shape, gc, area);
317 nr_arena_shape_update_fill(shape, gc, area);
319 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
320 nr_arena_shape_add_bboxes(shape,bbox);
322 shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
323 shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
324 shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
325 shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
326 }
328 if (nr_rect_d_test_empty(&bbox)) return NR_ARENA_ITEM_STATE_ALL;
330 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
331 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
332 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
333 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
334 nr_arena_request_render_rect(item->arena, &item->bbox);
336 item->render_opacity = TRUE;
337 if ( shape->_fill.paint.type() == NRArenaShape::Paint::SERVER ) {
338 if (gc && gc->parent) {
339 shape->fill_painter = sp_paint_server_painter_new(shape->_fill.paint.server(),
340 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
341 &shape->paintbox);
342 }
343 item->render_opacity = FALSE;
344 }
345 if ( shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER ) {
346 if (gc && gc->parent) {
347 shape->stroke_painter = sp_paint_server_painter_new(shape->_stroke.paint.server(),
348 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
349 &shape->paintbox);
350 }
351 item->render_opacity = FALSE;
352 }
353 if ( item->render_opacity == TRUE
354 && shape->_fill.paint.type() != NRArenaShape::Paint::NONE
355 && shape->_stroke.paint.type() != NRArenaShape::Paint::NONE )
356 {
357 // don't merge item opacity with paint opacity if there is a stroke on the fill
358 item->render_opacity = FALSE;
359 }
361 if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
362 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
363 nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
364 }
365 }
367 return NR_ARENA_ITEM_STATE_ALL;
368 }
370 int matrix_is_isometry(NR::Matrix p) {
371 NR::Matrix tp;
372 // transposition
373 tp[0]=p[0];
374 tp[1]=p[2];
375 tp[2]=p[1];
376 tp[3]=p[3];
377 for (int i = 4; i < 6; i++) // shut valgrind up :)
378 tp[i] = p[i] = 0;
379 NR::Matrix isom = tp*p; // A^T * A = adjunct?
380 // Is the adjunct nearly an identity function?
381 if (isom.is_translation(0.01)) {
382 // the transformation is an isometry -> no need to recompute
383 // the uncrossed polygon
384 if ( p.det() < 0 )
385 return -1;
386 else
387 return 1;
388 }
389 return 0;
390 }
392 static bool is_inner_area(NRRectL const &outer, NRRectL const &inner) {
393 return (outer.x0 <= inner.x0 && outer.y0 <= inner.y0 && outer.x1 >= inner.x1 && outer.y1 >= inner.y1);
394 }
396 /** force_shape is used for clipping paths, when we need the shape for clipping even if it's not filled */
397 void
398 nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape)
399 {
400 if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) &&
401 ((shape->curve->end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) {
402 if (TRUE || !shape->fill_shp) {
403 NR::Matrix cached_to_new = NR::identity();
404 int isometry = 0;
405 if ( shape->cached_fill ) {
406 if (shape->cached_fctm == gc->transform) {
407 isometry = 2; // identity
408 } else {
409 cached_to_new = shape->cached_fctm.inverse() * gc->transform;
410 isometry = matrix_is_isometry(cached_to_new);
411 }
412 if (0 != isometry && !is_inner_area(shape->cached_farea, *area))
413 isometry = 0;
414 }
415 if ( isometry == 0 ) {
416 if ( shape->cached_fill == NULL ) shape->cached_fill=new Shape;
417 shape->cached_fill->Reset();
419 Path* thePath=new Path;
420 Shape* theShape=new Shape;
421 {
422 NR::Matrix tempMat(gc->transform);
423 thePath->LoadArtBPath(SP_CURVE_BPATH(shape->curve),tempMat,true);
424 }
426 if (is_inner_area(*area, NR_ARENA_ITEM(shape)->bbox)) {
427 thePath->Convert(1.0);
428 shape->cached_fpartialy = false;
429 } else {
430 thePath->Convert(area, 1.0);
431 shape->cached_fpartialy = true;
432 }
434 thePath->Fill(theShape, 0);
436 if ( shape->_fill.rule == NRArenaShape::EVEN_ODD ) {
437 shape->cached_fill->ConvertToShape(theShape, fill_oddEven);
438 // alternatively, this speeds up rendering of oddeven shapes but disables AA :(
439 //shape->cached_fill->Copy(theShape);
440 } else {
441 shape->cached_fill->ConvertToShape(theShape, fill_nonZero);
442 }
443 shape->cached_fctm=gc->transform;
444 shape->cached_farea = *area;
445 delete theShape;
446 delete thePath;
447 if ( shape->fill_shp == NULL )
448 shape->fill_shp = new Shape;
450 shape->fill_shp->Copy(shape->cached_fill);
452 } else if ( 2 == isometry ) {
453 if ( shape->fill_shp == NULL ) {
454 shape->fill_shp = new Shape;
455 shape->fill_shp->Copy(shape->cached_fill);
456 }
457 } else {
459 if ( shape->fill_shp == NULL )
460 shape->fill_shp = new Shape;
462 shape->fill_shp->Reset(shape->cached_fill->numberOfPoints(),
463 shape->cached_fill->numberOfEdges());
464 for (int i = 0; i < shape->cached_fill->numberOfPoints(); i++)
465 shape->fill_shp->AddPoint(shape->cached_fill->getPoint(i).x * cached_to_new);
466 if ( isometry == 1 ) {
467 for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
468 shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).st,
469 shape->cached_fill->getEdge(i).en);
470 } else if ( isometry == -1 ) { // need to flip poly.
471 for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
472 shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).en,
473 shape->cached_fill->getEdge(i).st);
474 }
475 shape->fill_shp->ForceToPolygon();
476 shape->fill_shp->needPointsSorting();
477 shape->fill_shp->needEdgesSorting();
478 }
479 shape->delayed_shp |= shape->cached_fpartialy;
480 }
481 }
482 }
484 void
485 nr_arena_shape_update_stroke(NRArenaShape *shape,NRGC* gc, NRRectL *area)
486 {
487 SPStyle* style = shape->style;
489 float const scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
491 bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
493 if (outline ||
494 ((shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) &&
495 ( fabs(shape->_stroke.width * scale) > 0.01 ))) { // sinon c'est 0=oon veut pas de bord
497 float style_width = MAX(0.125, shape->_stroke.width * scale);
498 float width;
499 if (outline) {
500 width = 0.5; // 1 pixel wide, independent of zoom
501 } else {
502 width = style_width;
503 }
505 NR::Matrix cached_to_new = NR::identity();
507 int isometry = 0;
508 if ( shape->cached_stroke ) {
509 if (shape->cached_sctm == gc->transform) {
510 isometry = 2; // identity
511 } else {
512 cached_to_new = shape->cached_sctm.inverse() * gc->transform;
513 isometry = matrix_is_isometry(cached_to_new);
514 }
515 if (0 != isometry && !is_inner_area(shape->cached_sarea, *area))
516 isometry = 0;
517 if (0 != isometry && width != shape->cached_width) {
518 // if this happens without setting style, we have just switched to outline or back
519 isometry = 0;
520 }
521 }
523 if ( isometry == 0 ) {
524 if ( shape->cached_stroke == NULL ) shape->cached_stroke=new Shape;
525 shape->cached_stroke->Reset();
526 Path* thePath = new Path;
527 Shape* theShape = new Shape;
528 {
529 NR::Matrix tempMat(gc->transform);
530 thePath->LoadArtBPath(SP_CURVE_BPATH(shape->curve), tempMat, true);
531 }
533 // add some padding to the rendering area, so clipped path does not go into a render area
534 NRRectL padded_area = *area;
535 padded_area.x0 -= (NR::ICoord)width;
536 padded_area.x1 += (NR::ICoord)width;
537 padded_area.y0 -= (NR::ICoord)width;
538 padded_area.y1 += (NR::ICoord)width;
539 if ((style->stroke_dash.n_dash && !outline) || is_inner_area(padded_area, NR_ARENA_ITEM(shape)->bbox)) {
540 thePath->Convert((outline) ? 4.0 : 1.0);
541 shape->cached_spartialy = false;
542 }
543 else {
544 thePath->Convert(&padded_area, (outline) ? 4.0 : 1.0);
545 shape->cached_spartialy = true;
546 }
548 if (style->stroke_dash.n_dash && !outline) {
549 thePath->DashPolylineFromStyle(style, scale, 1.0);
550 }
552 ButtType butt=butt_straight;
553 switch (shape->_stroke.cap) {
554 case NRArenaShape::BUTT_CAP:
555 butt = butt_straight;
556 break;
557 case NRArenaShape::ROUND_CAP:
558 butt = butt_round;
559 break;
560 case NRArenaShape::SQUARE_CAP:
561 butt = butt_square;
562 break;
563 }
564 JoinType join=join_straight;
565 switch (shape->_stroke.join) {
566 case NRArenaShape::MITRE_JOIN:
567 join = join_pointy;
568 break;
569 case NRArenaShape::ROUND_JOIN:
570 join = join_round;
571 break;
572 case NRArenaShape::BEVEL_JOIN:
573 join = join_straight;
574 break;
575 }
577 if (outline) {
578 butt = butt_straight;
579 join = join_straight;
580 }
582 thePath->Stroke(theShape, false, 0.5*width, join, butt,
583 0.5*width*shape->_stroke.mitre_limit);
586 if (outline) {
587 // speeds it up, but uses evenodd for the stroke shape (which does not matter for 1-pixel wide outline)
588 shape->cached_stroke->Copy(theShape);
589 } else {
590 shape->cached_stroke->ConvertToShape(theShape, fill_nonZero);
591 }
593 shape->cached_width = width;
595 shape->cached_sctm=gc->transform;
596 shape->cached_sarea = *area;
597 delete thePath;
598 delete theShape;
599 if ( shape->stroke_shp == NULL ) shape->stroke_shp=new Shape;
601 shape->stroke_shp->Copy(shape->cached_stroke);
603 } else if ( 2 == isometry ) {
604 if ( shape->stroke_shp == NULL ) {
605 shape->stroke_shp=new Shape;
606 shape->stroke_shp->Copy(shape->cached_stroke);
607 }
608 } else {
609 if ( shape->stroke_shp == NULL )
610 shape->stroke_shp=new Shape;
611 shape->stroke_shp->Reset(shape->cached_stroke->numberOfPoints(), shape->cached_stroke->numberOfEdges());
612 for (int i = 0; i < shape->cached_stroke->numberOfPoints(); i++)
613 shape->stroke_shp->AddPoint(shape->cached_stroke->getPoint(i).x * cached_to_new);
614 if ( isometry == 1 ) {
615 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
616 shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).st,
617 shape->cached_stroke->getEdge(i).en);
618 } else if ( isometry == -1 ) {
619 for (int i = 0; i < shape->cached_stroke->numberOfEdges(); i++)
620 shape->stroke_shp->AddEdge(shape->cached_stroke->getEdge(i).en,
621 shape->cached_stroke->getEdge(i).st);
622 }
623 shape->stroke_shp->ForceToPolygon();
624 shape->stroke_shp->needPointsSorting();
625 shape->stroke_shp->needEdgesSorting();
626 }
627 shape->delayed_shp |= shape->cached_spartialy;
628 }
629 }
632 void
633 nr_arena_shape_add_bboxes(NRArenaShape* shape, NRRect &bbox)
634 {
635 if ( shape->stroke_shp ) {
636 shape->stroke_shp->CalcBBox();
637 shape->stroke_shp->leftX=floor(shape->stroke_shp->leftX);
638 shape->stroke_shp->rightX=ceil(shape->stroke_shp->rightX);
639 shape->stroke_shp->topY=floor(shape->stroke_shp->topY);
640 shape->stroke_shp->bottomY=ceil(shape->stroke_shp->bottomY);
641 if ( bbox.x0 >= bbox.x1 ) {
642 if ( shape->stroke_shp->leftX < shape->stroke_shp->rightX ) {
643 bbox.x0=shape->stroke_shp->leftX;
644 bbox.x1=shape->stroke_shp->rightX;
645 }
646 } else {
647 if ( shape->stroke_shp->leftX < bbox.x0 )
648 bbox.x0=shape->stroke_shp->leftX;
649 if ( shape->stroke_shp->rightX > bbox.x1 )
650 bbox.x1=shape->stroke_shp->rightX;
651 }
652 if ( bbox.y0 >= bbox.y1 ) {
653 if ( shape->stroke_shp->topY < shape->stroke_shp->bottomY ) {
654 bbox.y0=shape->stroke_shp->topY;
655 bbox.y1=shape->stroke_shp->bottomY;
656 }
657 } else {
658 if ( shape->stroke_shp->topY < bbox.y0 )
659 bbox.y0=shape->stroke_shp->topY;
660 if ( shape->stroke_shp->bottomY > bbox.y1 )
661 bbox.y1=shape->stroke_shp->bottomY;
662 }
663 }
664 if ( shape->fill_shp ) {
665 shape->fill_shp->CalcBBox();
666 shape->fill_shp->leftX=floor(shape->fill_shp->leftX);
667 shape->fill_shp->rightX=ceil(shape->fill_shp->rightX);
668 shape->fill_shp->topY=floor(shape->fill_shp->topY);
669 shape->fill_shp->bottomY=ceil(shape->fill_shp->bottomY);
670 if ( bbox.x0 >= bbox.x1 ) {
671 if ( shape->fill_shp->leftX < shape->fill_shp->rightX ) {
672 bbox.x0=shape->fill_shp->leftX;
673 bbox.x1=shape->fill_shp->rightX;
674 }
675 } else {
676 if ( shape->fill_shp->leftX < bbox.x0 ) bbox.x0=shape->fill_shp->leftX;
677 if ( shape->fill_shp->rightX > bbox.x1 ) bbox.x1=shape->fill_shp->rightX;
678 }
679 if ( bbox.y0 >= bbox.y1 ) {
680 if ( shape->fill_shp->topY < shape->fill_shp->bottomY ) {
681 bbox.y0=shape->fill_shp->topY;
682 bbox.y1=shape->fill_shp->bottomY;
683 }
684 } else {
685 if ( shape->fill_shp->topY < bbox.y0 ) bbox.y0=shape->fill_shp->topY;
686 if ( shape->fill_shp->bottomY > bbox.y1 ) bbox.y1=shape->fill_shp->bottomY;
687 }
688 }
689 }
690 static unsigned int
691 nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags)
692 {
693 NRArenaShape *shape = NR_ARENA_SHAPE(item);
695 if (!shape->curve) return item->state;
696 if (!shape->style) return item->state;
698 if ( shape->delayed_shp ) {
699 if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
700 NRGC tempGC(NULL);
701 tempGC.transform=shape->ctm;
702 shape->delayed_shp = false;
703 nr_arena_shape_update_stroke(shape,&tempGC,&pb->visible_area);
704 nr_arena_shape_update_fill(shape,&tempGC,&pb->visible_area);
705 /* NRRect bbox;
706 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
707 nr_arena_shape_add_bboxes(shape,bbox);
708 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
709 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
710 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
711 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
712 shape->approx_bbox=item->bbox;*/
713 } else {
714 return item->state;
715 }
716 }
718 bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
720 SPStyle const *style = shape->style;
721 if ( shape->fill_shp && !outline) {
722 NRPixBlock m;
723 guint32 rgba;
725 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
727 // if memory allocation failed, abort render
728 if (m.data.px == NULL) {
729 nr_pixblock_release (&m);
730 return (item->state);
731 }
733 m.visible_area = pb->visible_area;
734 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
735 m.empty = FALSE;
737 if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) {
738 // do not render fill in any way
739 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) {
740 if ( item->render_opacity ) {
741 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
742 shape->_fill.opacity *
743 SP_SCALE24_TO_FLOAT(style->opacity.value));
744 } else {
745 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
746 shape->_fill.opacity);
747 }
748 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
749 pb->empty = FALSE;
750 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) {
751 if (shape->fill_painter) {
752 nr_arena_render_paintserver_fill(pb, area, shape->fill_painter, shape->_fill.opacity, &m);
753 }
754 }
756 nr_pixblock_release(&m);
757 }
759 if ( shape->stroke_shp ) {
760 NRPixBlock m;
761 guint32 rgba;
763 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
765 // if memory allocation failed, abort render
766 if (m.data.px == NULL) {
767 nr_pixblock_release (&m);
768 return (item->state);
769 }
771 m.visible_area = pb->visible_area;
772 nr_pixblock_render_shape_mask_or(m, shape->stroke_shp);
773 m.empty = FALSE;
775 if (shape->_stroke.paint.type() == NRArenaShape::Paint::COLOR || outline) {
776 if (outline) {
777 rgba = NR_ARENA_ITEM(shape)->arena->outlinecolor;
778 } else if ( item->render_opacity ) {
779 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
780 shape->_stroke.opacity *
781 SP_SCALE24_TO_FLOAT(style->opacity.value));
782 } else {
783 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
784 shape->_stroke.opacity);
785 }
786 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
787 pb->empty = FALSE;
788 } else if (shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER) {
789 if (shape->stroke_painter) {
790 nr_arena_render_paintserver_fill(pb, area, shape->stroke_painter, shape->_stroke.opacity, &m);
791 }
792 }
794 nr_pixblock_release(&m);
795 }
797 /* Just compose children into parent buffer */
798 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
799 unsigned int ret;
800 ret = nr_arena_item_invoke_render(child, area, pb, flags);
801 if (ret & NR_ARENA_ITEM_STATE_INVALID) return ret;
802 }
804 return item->state;
805 }
807 static guint
808 nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
809 {
810 NRArenaShape *shape = NR_ARENA_SHAPE(item);
811 if (!shape->curve) return item->state;
813 if ( shape->delayed_shp || shape->fill_shp == NULL) { // we need a fill shape no matter what
814 if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
815 NRGC tempGC(NULL);
816 tempGC.transform=shape->ctm;
817 shape->delayed_shp = false;
818 nr_arena_shape_update_fill(shape, &tempGC, &pb->visible_area, true);
819 } else {
820 return item->state;
821 }
822 }
824 if ( shape->fill_shp ) {
825 NRPixBlock m;
827 /* fixme: We can OR in one step (Lauris) */
828 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
830 // if memory allocation failed, abort
831 if (m.data.px == NULL) {
832 nr_pixblock_release (&m);
833 return (item->state);
834 }
836 m.visible_area = pb->visible_area;
837 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
839 for (int y = area->y0; y < area->y1; y++) {
840 unsigned char *s, *d;
841 s = NR_PIXBLOCK_PX(&m) + (y - area->y0) * m.rs;
842 d = NR_PIXBLOCK_PX(pb) + (y - area->y0) * pb->rs;
843 for (int x = area->x0; x < area->x1; x++) {
844 *d = NR_COMPOSEA_111(*s, *d);
845 d ++;
846 s ++;
847 }
848 }
849 nr_pixblock_release(&m);
850 pb->empty = FALSE;
851 }
853 return item->state;
854 }
856 static NRArenaItem *
857 nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/)
858 {
859 NRArenaShape *shape = NR_ARENA_SHAPE(item);
861 if (!shape->curve) return NULL;
862 if (!shape->style) return NULL;
863 if ( shape->delayed_shp ) {
864 NRRectL area, updateArea;
865 area.x0=(int)floor(p[NR::X]);
866 area.x1=(int)ceil(p[NR::X]);
867 area.y0=(int)floor(p[NR::Y]);
868 area.y1=(int)ceil(p[NR::Y]);
869 int idelta = (int)ceil(delta) + 1;
870 // njh: inset rect
871 area.x0-=idelta;
872 area.x1+=idelta;
873 area.y0-=idelta;
874 area.y1+=idelta;
875 if ( nr_rect_l_test_intersect(&area, &item->bbox) ) {
876 NRGC tempGC(NULL);
877 tempGC.transform=shape->ctm;
878 updateArea = item->bbox;
879 if (shape->cached_stroke)
880 nr_rect_l_intersect (&updateArea, &updateArea, &shape->cached_sarea);
882 shape->delayed_shp = false;
883 nr_arena_shape_update_stroke(shape, &tempGC, &updateArea);
884 nr_arena_shape_update_fill(shape, &tempGC, &updateArea);
885 /* NRRect bbox;
886 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
887 nr_arena_shape_add_bboxes(shape,bbox);
888 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
889 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
890 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
891 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
892 shape->approx_bbox=item->bbox;*/
893 }
894 }
896 bool outline = (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE);
898 if (item->state & NR_ARENA_ITEM_STATE_RENDER) {
899 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
900 if (shape->fill_shp->PtWinding(p) > 0 ) return item;
901 }
902 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline)) {
903 if (shape->stroke_shp->PtWinding(p) > 0 ) return item;
904 }
905 if (delta > 1e-3) {
906 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
907 if (distanceLessThanOrEqual(shape->fill_shp, p, delta)) return item;
908 }
909 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline)) {
910 if (distanceLessThanOrEqual(shape->stroke_shp, p, delta)) return item;
911 }
912 }
913 } else {
914 NRBPath bp;
915 bp.path = SP_CURVE_BPATH(shape->curve);
916 double dist = NR_HUGE;
917 int wind = 0;
918 nr_path_matrix_point_bbox_wind_distance(&bp, shape->ctm, p, NULL, &wind, &dist, NR_EPSILON);
919 if (shape->_fill.paint.type() != NRArenaShape::Paint::NONE) {
920 if (!shape->style->fill_rule.computed) {
921 if (wind != 0) return item;
922 } else {
923 if (wind & 0x1) return item;
924 }
925 }
926 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE || outline) {
927 /* fixme: We do not take stroke width into account here (Lauris) */
928 if (dist < delta) return item;
929 }
930 }
932 return NULL;
933 }
935 /**
936 *
937 * Requests a render of the shape, then if the shape is already a curve it
938 * unrefs the old curve; if the new curve is valid it creates a copy of the
939 * curve and adds it to the shape. Finally, it requests an update of the
940 * arena for the shape.
941 */
942 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve,bool justTrans)
943 {
944 g_return_if_fail(shape != NULL);
945 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
947 if ( justTrans == false ) {
948 // dirty cached versions
949 if ( shape->cached_fill ) {
950 delete shape->cached_fill;
951 shape->cached_fill=NULL;
952 }
953 if ( shape->cached_stroke ) {
954 delete shape->cached_stroke;
955 shape->cached_stroke=NULL;
956 }
957 }
959 nr_arena_item_request_render(NR_ARENA_ITEM(shape));
961 if (shape->curve) {
962 sp_curve_unref(shape->curve);
963 shape->curve = NULL;
964 }
966 if (curve) {
967 shape->curve = curve;
968 sp_curve_ref(curve);
969 }
971 nr_arena_item_request_update(NR_ARENA_ITEM(shape), NR_ARENA_ITEM_STATE_ALL, FALSE);
972 }
974 void NRArenaShape::setFill(SPPaintServer *server) {
975 _fill.paint.set(server);
976 _invalidateCachedFill();
977 }
979 void NRArenaShape::setFill(SPColor const &color) {
980 _fill.paint.set(color);
981 _invalidateCachedFill();
982 }
984 void NRArenaShape::setFillOpacity(double opacity) {
985 _fill.opacity = opacity;
986 _invalidateCachedFill();
987 }
989 void NRArenaShape::setFillRule(NRArenaShape::FillRule rule) {
990 _fill.rule = rule;
991 _invalidateCachedFill();
992 }
994 void NRArenaShape::setStroke(SPPaintServer *server) {
995 _stroke.paint.set(server);
996 _invalidateCachedStroke();
997 }
999 void NRArenaShape::setStroke(SPColor const &color) {
1000 _stroke.paint.set(color);
1001 _invalidateCachedStroke();
1002 }
1004 void NRArenaShape::setStrokeOpacity(double opacity) {
1005 _stroke.opacity = opacity;
1006 _invalidateCachedStroke();
1007 }
1009 void NRArenaShape::setStrokeWidth(double width) {
1010 _stroke.width = width;
1011 _invalidateCachedStroke();
1012 }
1014 void NRArenaShape::setMitreLimit(double limit) {
1015 _stroke.mitre_limit = limit;
1016 _invalidateCachedStroke();
1017 }
1019 void NRArenaShape::setLineCap(NRArenaShape::CapType cap) {
1020 _stroke.cap = cap;
1021 _invalidateCachedStroke();
1022 }
1024 void NRArenaShape::setLineJoin(NRArenaShape::JoinType join) {
1025 _stroke.join = join;
1026 _invalidateCachedStroke();
1027 }
1029 /** nr_arena_shape_set_style
1030 *
1031 * Unrefs any existing style and ref's to the given one, then requests an update of the arena
1032 */
1033 void
1034 nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style)
1035 {
1036 g_return_if_fail(shape != NULL);
1037 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1039 if (style) sp_style_ref(style);
1040 if (shape->style) sp_style_unref(shape->style);
1041 shape->style = style;
1043 switch (style->fill.type) {
1044 case SP_PAINT_TYPE_NONE: {
1045 shape->setFill(NULL);
1046 break;
1047 }
1048 case SP_PAINT_TYPE_COLOR: {
1049 shape->setFill(style->fill.value.color);
1050 break;
1051 }
1052 case SP_PAINT_TYPE_PAINTSERVER: {
1053 shape->setFill(style->fill.value.paint.server);
1054 break;
1055 }
1056 default: {
1057 g_assert_not_reached();
1058 }
1059 }
1060 shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
1061 switch (style->fill_rule.computed) {
1062 case SP_WIND_RULE_EVENODD: {
1063 shape->setFillRule(NRArenaShape::EVEN_ODD);
1064 break;
1065 }
1066 case SP_WIND_RULE_NONZERO: {
1067 shape->setFillRule(NRArenaShape::NONZERO);
1068 break;
1069 }
1070 default: {
1071 g_assert_not_reached();
1072 }
1073 }
1075 switch (style->stroke.type) {
1076 case SP_PAINT_TYPE_NONE: {
1077 shape->setStroke(NULL);
1078 break;
1079 }
1080 case SP_PAINT_TYPE_COLOR: {
1081 shape->setStroke(style->stroke.value.color);
1082 break;
1083 }
1084 case SP_PAINT_TYPE_PAINTSERVER: {
1085 shape->setStroke(style->stroke.value.paint.server);
1086 break;
1087 }
1088 default: {
1089 g_assert_not_reached();
1090 }
1091 }
1092 shape->setStrokeWidth(style->stroke_width.computed);
1093 shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
1094 switch (style->stroke_linecap.computed) {
1095 case SP_STROKE_LINECAP_ROUND: {
1096 shape->setLineCap(NRArenaShape::ROUND_CAP);
1097 break;
1098 }
1099 case SP_STROKE_LINECAP_SQUARE: {
1100 shape->setLineCap(NRArenaShape::SQUARE_CAP);
1101 break;
1102 }
1103 case SP_STROKE_LINECAP_BUTT: {
1104 shape->setLineCap(NRArenaShape::BUTT_CAP);
1105 break;
1106 }
1107 default: {
1108 g_assert_not_reached();
1109 }
1110 }
1111 switch (style->stroke_linejoin.computed) {
1112 case SP_STROKE_LINEJOIN_ROUND: {
1113 shape->setLineJoin(NRArenaShape::ROUND_JOIN);
1114 break;
1115 }
1116 case SP_STROKE_LINEJOIN_BEVEL: {
1117 shape->setLineJoin(NRArenaShape::BEVEL_JOIN);
1118 break;
1119 }
1120 case SP_STROKE_LINEJOIN_MITER: {
1121 shape->setLineJoin(NRArenaShape::MITRE_JOIN);
1122 break;
1123 }
1124 default: {
1125 g_assert_not_reached();
1126 }
1127 }
1128 shape->setMitreLimit(style->stroke_miterlimit.value);
1130 //if shape has a filter
1131 if (style->filter.set && style->filter.filter)
1132 {
1133 shape->filter = new NR::Filter();
1134 shape->filter->set_x(style->filter.filter->x);
1135 shape->filter->set_y(style->filter.filter->y);
1136 shape->filter->set_width(style->filter.filter->width);
1137 shape->filter->set_height(style->filter.filter->height);
1139 //go through all SP filter primitives
1140 for(int i=0; i<style->filter.filter->_primitive_count; i++)
1141 {
1142 SPFilterPrimitive *primitive = style->filter.filter->_primitives[i];
1143 //if primitive is gaussianblur
1144 // if(SP_IS_GAUSSIANBLUR(primitive))
1145 {
1146 NR::FilterGaussian * gaussian = (NR::FilterGaussian *) shape->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR);
1147 SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
1148 float num = spblur->stdDeviation.getNumber();
1149 if( num>=0.0 )
1150 {
1151 float optnum = spblur->stdDeviation.getOptNumber();
1152 if( optnum>=0.0 )
1153 gaussian->set_deviation((double) num, (double) optnum);
1154 else
1155 gaussian->set_deviation((double) num);
1156 }
1157 }
1158 }
1159 }
1160 else
1161 {
1162 //no filter set for this shape
1163 shape->filter = NULL;
1164 }
1166 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1167 }
1169 void
1170 nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox)
1171 {
1172 g_return_if_fail(shape != NULL);
1173 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1174 g_return_if_fail(pbox != NULL);
1176 if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
1177 shape->paintbox = *pbox;
1178 } else {
1179 /* fixme: We kill warning, although not sure what to do here (Lauris) */
1180 shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
1181 shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
1182 }
1184 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1185 }
1187 void NRArenaShape::setPaintBox(NR::Rect const &pbox)
1188 {
1189 paintbox.x0 = pbox.min()[NR::X];
1190 paintbox.y0 = pbox.min()[NR::Y];
1191 paintbox.x1 = pbox.max()[NR::X];
1192 paintbox.y1 = pbox.max()[NR::Y];
1194 nr_arena_item_request_update(this, NR_ARENA_ITEM_STATE_ALL, FALSE);
1195 }
1197 static void
1198 shape_run_A8_OR(raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
1199 {
1200 if ( st >= en ) return;
1201 if ( vst < 0 ) vst=0;
1202 if ( vst > 1 ) vst=1;
1203 if ( ven < 0 ) ven=0;
1204 if ( ven > 1 ) ven=1;
1205 float sv=vst;
1206 float dv=ven-vst;
1207 int len=en-st;
1208 unsigned char* d=(unsigned char*)dest.buffer;
1209 d+=(st-dest.startPix);
1210 if ( fabs(dv) < 0.001 ) {
1211 if ( vst > 0.999 ) {
1212 /* Simple copy */
1213 while (len > 0) {
1214 d[0] = 255;
1215 d += 1;
1216 len -= 1;
1217 }
1218 } else {
1219 sv*=256;
1220 unsigned int c0_24=(int)sv;
1221 c0_24&=0xFF;
1222 while (len > 0) {
1223 /* Draw */
1224 d[0] = NR_COMPOSEA_111(c0_24,d[0]);
1225 d += 1;
1226 len -= 1;
1227 }
1228 }
1229 } else {
1230 if ( en <= st+1 ) {
1231 sv=0.5*(vst+ven);
1232 sv*=256;
1233 unsigned int c0_24=(int)sv;
1234 c0_24&=0xFF;
1235 /* Draw */
1236 d[0] = NR_COMPOSEA_111(c0_24,d[0]);
1237 } else {
1238 dv/=len;
1239 sv+=0.5*dv; // correction trapezoidale
1240 sv*=16777216;
1241 dv*=16777216;
1242 int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
1243 int s0_24 = static_cast<int>(dv);
1244 while (len > 0) {
1245 unsigned int ca;
1246 /* Draw */
1247 ca = c0_24 >> 16;
1248 if ( ca > 255 ) ca=255;
1249 d[0] = NR_COMPOSEA_111(ca,d[0]);
1250 d += 1;
1251 c0_24 += s0_24;
1252 c0_24 = CLAMP(c0_24, 0, 16777216);
1253 len -= 1;
1254 }
1255 }
1256 }
1257 }
1259 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS)
1260 {
1261 theS->CalcBBox();
1262 float l = theS->leftX, r = theS->rightX, t = theS->topY, b = theS->bottomY;
1263 int il,ir,it,ib;
1264 il=(int)floor(l);
1265 ir=(int)ceil(r);
1266 it=(int)floor(t);
1267 ib=(int)ceil(b);
1269 if ( il >= m.area.x1 || ir <= m.area.x0 || it >= m.area.y1 || ib <= m.area.y0 ) return;
1270 if ( il < m.area.x0 ) il=m.area.x0;
1271 if ( it < m.area.y0 ) it=m.area.y0;
1272 if ( ir > m.area.x1 ) ir=m.area.x1;
1273 if ( ib > m.area.y1 ) ib=m.area.y1;
1275 /* This is the FloatLigne version. See svn (prior to Apr 2006) for versions using BitLigne or direct BitLigne. */
1276 int curPt;
1277 float curY;
1278 theS->BeginQuickRaster(curY, curPt);
1280 FloatLigne *theI = new FloatLigne();
1281 IntLigne *theIL = new IntLigne();
1283 theS->DirectQuickScan(curY, curPt, (float) it, true, 1.0);
1285 char *mdata = (char*)m.data.px;
1286 if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1287 uint32_t *ligStart = ((uint32_t*)(mdata + ((il - m.area.x0) + m.rs * (it - m.area.y0))));
1288 for (int y = it; y < ib; y++) {
1289 theI->Reset();
1290 theS->QuickScan(curY, curPt, ((float)(y+1)), theI, 1.0);
1291 theI->Flatten();
1292 theIL->Copy(theI);
1294 raster_info dest;
1295 dest.startPix=il;
1296 dest.endPix=ir;
1297 dest.sth=il;
1298 dest.stv=y;
1299 dest.buffer=ligStart;
1300 theIL->Raster(dest, NULL, shape_run_A8_OR);
1301 ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1302 }
1303 theS->EndQuickRaster();
1304 delete theI;
1305 delete theIL;
1306 }
1309 /*
1310 Local Variables:
1311 mode:c++
1312 c-file-style:"stroustrup"
1313 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1314 indent-tabs-mode:nil
1315 fill-column:99
1316 End:
1317 */
1318 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :