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);
710 m.visible_area = pb->visible_area;
711 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
712 m.empty = FALSE;
714 if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) {
715 // do not render fill in any way
716 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) {
717 if ( item->render_opacity ) {
718 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
719 shape->_fill.opacity *
720 SP_SCALE24_TO_FLOAT(style->opacity.value));
721 } else {
722 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
723 shape->_fill.opacity);
724 }
725 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
726 pb->empty = FALSE;
727 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) {
728 if (shape->fill_painter) {
729 nr_arena_render_paintserver_fill(pb, area, shape->fill_painter, shape->_fill.opacity, &m);
730 }
731 }
733 nr_pixblock_release(&m);
734 }
736 if ( shape->stroke_shp ) {
737 NRPixBlock m;
738 guint32 rgba;
740 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
741 m.visible_area = pb->visible_area;
742 nr_pixblock_render_shape_mask_or(m, shape->stroke_shp);
743 m.empty = FALSE;
745 if (shape->_stroke.paint.type() == NRArenaShape::Paint::COLOR ||
746 NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
747 if ( NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
748 rgba = NR_ARENA_ITEM(shape)->arena->outlinecolor;
749 } else if ( item->render_opacity ) {
750 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
751 shape->_stroke.opacity *
752 SP_SCALE24_TO_FLOAT(style->opacity.value));
753 } else {
754 rgba = sp_color_get_rgba32_falpha(&shape->_stroke.paint.color(),
755 shape->_stroke.opacity);
756 }
757 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
758 pb->empty = FALSE;
759 } else if (shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER) {
760 if (shape->stroke_painter) {
761 nr_arena_render_paintserver_fill(pb, area, shape->stroke_painter, shape->_stroke.opacity, &m);
762 }
763 }
765 nr_pixblock_release(&m);
766 }
768 /* Just compose children into parent buffer */
769 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
770 unsigned int ret;
771 ret = nr_arena_item_invoke_render(child, area, pb, flags);
772 if (ret & NR_ARENA_ITEM_STATE_INVALID) return ret;
773 }
775 return item->state;
776 }
778 static guint
779 nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb)
780 {
781 NRArenaShape *shape = NR_ARENA_SHAPE(item);
782 if (!shape->curve) return item->state;
784 if ( shape->delayed_shp || shape->fill_shp == NULL) { // we need a fill shape no matter what
785 if ( nr_rect_l_test_intersect(area, &item->bbox) ) {
786 NRGC tempGC(NULL);
787 tempGC.transform=shape->ctm;
788 shape->delayed_shp = false;
789 nr_arena_shape_update_fill(shape, &tempGC, &pb->visible_area, true);
790 } else {
791 return item->state;
792 }
793 }
795 if ( shape->fill_shp ) {
796 NRPixBlock m;
798 /* fixme: We can OR in one step (Lauris) */
799 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
800 m.visible_area = pb->visible_area;
801 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
803 for (int y = area->y0; y < area->y1; y++) {
804 unsigned char *s, *d;
805 s = NR_PIXBLOCK_PX(&m) + (y - area->y0) * m.rs;
806 d = NR_PIXBLOCK_PX(pb) + (y - area->y0) * pb->rs;
807 for (int x = area->x0; x < area->x1; x++) {
808 *d = NR_COMPOSEA_111(*s, *d);
809 d ++;
810 s ++;
811 }
812 }
813 nr_pixblock_release(&m);
814 pb->empty = FALSE;
815 }
817 return item->state;
818 }
820 static NRArenaItem *
821 nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/)
822 {
823 NRArenaShape *shape = NR_ARENA_SHAPE(item);
825 if (!shape->curve) return NULL;
826 if (!shape->style) return NULL;
827 if ( shape->delayed_shp ) {
828 NRRectL area, updateArea;
829 area.x0=(int)floor(p[NR::X]);
830 area.x1=(int)ceil(p[NR::X]);
831 area.y0=(int)floor(p[NR::Y]);
832 area.y1=(int)ceil(p[NR::Y]);
833 int idelta = (int)ceil(delta) + 1;
834 // njh: inset rect
835 area.x0-=idelta;
836 area.x1+=idelta;
837 area.y0-=idelta;
838 area.y1+=idelta;
839 if ( nr_rect_l_test_intersect(&area, &item->bbox) ) {
840 NRGC tempGC(NULL);
841 tempGC.transform=shape->ctm;
842 updateArea = item->bbox;
843 if (shape->cached_stroke)
844 nr_rect_l_intersect (&updateArea, &updateArea, &shape->cached_sarea);
846 shape->delayed_shp = false;
847 nr_arena_shape_update_stroke(shape, &tempGC, &updateArea);
848 nr_arena_shape_update_fill(shape, &tempGC, &updateArea);
849 /* NRRect bbox;
850 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
851 nr_arena_shape_add_bboxes(shape,bbox);
852 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
853 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
854 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
855 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
856 shape->approx_bbox=item->bbox;*/
857 }
858 }
860 if (item->state & NR_ARENA_ITEM_STATE_RENDER) {
861 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
862 if (shape->fill_shp->PtWinding(p) > 0 ) return item;
863 }
864 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
865 if (shape->stroke_shp->PtWinding(p) > 0 ) return item;
866 }
867 if (delta > 1e-3) {
868 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
869 if (distanceLessThanOrEqual(shape->fill_shp, p, delta)) return item;
870 }
871 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
872 if (distanceLessThanOrEqual(shape->stroke_shp, p, delta)) return item;
873 }
874 }
875 } else {
876 NRBPath bp;
877 bp.path = SP_CURVE_BPATH(shape->curve);
878 double dist = NR_HUGE;
879 int wind = 0;
880 nr_path_matrix_point_bbox_wind_distance(&bp, shape->ctm, p, NULL, &wind, &dist, NR_EPSILON);
881 if (shape->_fill.paint.type() != NRArenaShape::Paint::NONE) {
882 if (!shape->style->fill_rule.computed) {
883 if (wind != 0) return item;
884 } else {
885 if (wind & 0x1) return item;
886 }
887 }
888 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
889 /* fixme: We do not take stroke width into account here (Lauris) */
890 if (dist < delta) return item;
891 }
892 }
894 return NULL;
895 }
897 /**
898 *
899 * Requests a render of the shape, then if the shape is already a curve it
900 * unrefs the old curve; if the new curve is valid it creates a copy of the
901 * curve and adds it to the shape. Finally, it requests an update of the
902 * arena for the shape.
903 */
904 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve,bool justTrans)
905 {
906 g_return_if_fail(shape != NULL);
907 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
909 if ( justTrans == false ) {
910 // dirty cached versions
911 if ( shape->cached_fill ) {
912 delete shape->cached_fill;
913 shape->cached_fill=NULL;
914 }
915 if ( shape->cached_stroke ) {
916 delete shape->cached_stroke;
917 shape->cached_stroke=NULL;
918 }
919 }
921 nr_arena_item_request_render(NR_ARENA_ITEM(shape));
923 if (shape->curve) {
924 sp_curve_unref(shape->curve);
925 shape->curve = NULL;
926 }
928 if (curve) {
929 shape->curve = curve;
930 sp_curve_ref(curve);
931 }
933 nr_arena_item_request_update(NR_ARENA_ITEM(shape), NR_ARENA_ITEM_STATE_ALL, FALSE);
934 }
936 void NRArenaShape::setFill(SPPaintServer *server) {
937 _fill.paint.set(server);
938 _invalidateCachedFill();
939 }
941 void NRArenaShape::setFill(SPColor const &color) {
942 _fill.paint.set(color);
943 _invalidateCachedFill();
944 }
946 void NRArenaShape::setFillOpacity(double opacity) {
947 _fill.opacity = opacity;
948 _invalidateCachedFill();
949 }
951 void NRArenaShape::setFillRule(NRArenaShape::FillRule rule) {
952 _fill.rule = rule;
953 _invalidateCachedFill();
954 }
956 void NRArenaShape::setStroke(SPPaintServer *server) {
957 _stroke.paint.set(server);
958 _invalidateCachedStroke();
959 }
961 void NRArenaShape::setStroke(SPColor const &color) {
962 _stroke.paint.set(color);
963 _invalidateCachedStroke();
964 }
966 void NRArenaShape::setStrokeOpacity(double opacity) {
967 _stroke.opacity = opacity;
968 _invalidateCachedStroke();
969 }
971 void NRArenaShape::setStrokeWidth(double width) {
972 _stroke.width = width;
973 _invalidateCachedStroke();
974 }
976 void NRArenaShape::setMitreLimit(double limit) {
977 _stroke.mitre_limit = limit;
978 _invalidateCachedStroke();
979 }
981 void NRArenaShape::setLineCap(NRArenaShape::CapType cap) {
982 _stroke.cap = cap;
983 _invalidateCachedStroke();
984 }
986 void NRArenaShape::setLineJoin(NRArenaShape::JoinType join) {
987 _stroke.join = join;
988 _invalidateCachedStroke();
989 }
991 /** nr_arena_shape_set_style
992 *
993 * Unrefs any existing style and ref's to the given one, then requests an update of the arena
994 */
995 void
996 nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style)
997 {
998 g_return_if_fail(shape != NULL);
999 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1001 if (style) sp_style_ref(style);
1002 if (shape->style) sp_style_unref(shape->style);
1003 shape->style = style;
1005 switch (style->fill.type) {
1006 case SP_PAINT_TYPE_NONE: {
1007 shape->setFill(NULL);
1008 break;
1009 }
1010 case SP_PAINT_TYPE_COLOR: {
1011 shape->setFill(style->fill.value.color);
1012 break;
1013 }
1014 case SP_PAINT_TYPE_PAINTSERVER: {
1015 shape->setFill(style->fill.value.paint.server);
1016 break;
1017 }
1018 default: {
1019 g_assert_not_reached();
1020 }
1021 }
1022 shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
1023 switch (style->fill_rule.computed) {
1024 case SP_WIND_RULE_EVENODD: {
1025 shape->setFillRule(NRArenaShape::EVEN_ODD);
1026 break;
1027 }
1028 case SP_WIND_RULE_NONZERO: {
1029 shape->setFillRule(NRArenaShape::NONZERO);
1030 break;
1031 }
1032 default: {
1033 g_assert_not_reached();
1034 }
1035 }
1037 switch (style->stroke.type) {
1038 case SP_PAINT_TYPE_NONE: {
1039 shape->setStroke(NULL);
1040 break;
1041 }
1042 case SP_PAINT_TYPE_COLOR: {
1043 shape->setStroke(style->stroke.value.color);
1044 break;
1045 }
1046 case SP_PAINT_TYPE_PAINTSERVER: {
1047 shape->setStroke(style->stroke.value.paint.server);
1048 break;
1049 }
1050 default: {
1051 g_assert_not_reached();
1052 }
1053 }
1054 shape->setStrokeWidth(style->stroke_width.computed);
1055 shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
1056 switch (style->stroke_linecap.computed) {
1057 case SP_STROKE_LINECAP_ROUND: {
1058 shape->setLineCap(NRArenaShape::ROUND_CAP);
1059 break;
1060 }
1061 case SP_STROKE_LINECAP_SQUARE: {
1062 shape->setLineCap(NRArenaShape::SQUARE_CAP);
1063 break;
1064 }
1065 case SP_STROKE_LINECAP_BUTT: {
1066 shape->setLineCap(NRArenaShape::BUTT_CAP);
1067 break;
1068 }
1069 default: {
1070 g_assert_not_reached();
1071 }
1072 }
1073 switch (style->stroke_linejoin.computed) {
1074 case SP_STROKE_LINEJOIN_ROUND: {
1075 shape->setLineJoin(NRArenaShape::ROUND_JOIN);
1076 break;
1077 }
1078 case SP_STROKE_LINEJOIN_BEVEL: {
1079 shape->setLineJoin(NRArenaShape::BEVEL_JOIN);
1080 break;
1081 }
1082 case SP_STROKE_LINEJOIN_MITER: {
1083 shape->setLineJoin(NRArenaShape::MITRE_JOIN);
1084 break;
1085 }
1086 default: {
1087 g_assert_not_reached();
1088 }
1089 }
1090 shape->setMitreLimit(style->stroke_miterlimit.value);
1092 //if shape has a filter
1093 if (style->filter.set && style->filter.filter)
1094 {
1095 shape->filter = new NR::Filter();
1096 shape->filter->set_x(style->filter.filter->x);
1097 shape->filter->set_y(style->filter.filter->y);
1098 shape->filter->set_width(style->filter.filter->width);
1099 shape->filter->set_height(style->filter.filter->height);
1101 //go through all SP filter primitives
1102 for(int i=0; i<style->filter.filter->_primitive_count; i++)
1103 {
1104 SPFilterPrimitive *primitive = style->filter.filter->_primitives[i];
1105 //if primitive is gaussianblur
1106 // if(SP_IS_GAUSSIANBLUR(primitive))
1107 {
1108 NR::FilterGaussian * gaussian = (NR::FilterGaussian *) shape->filter->add_primitive(NR::NR_FILTER_GAUSSIANBLUR);
1109 SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
1110 float num = spblur->stdDeviation.getNumber();
1111 if( num>=0.0 )
1112 {
1113 float optnum = spblur->stdDeviation.getOptNumber();
1114 if( optnum>=0.0 )
1115 gaussian->set_deviation((double) num, (double) optnum);
1116 else
1117 gaussian->set_deviation((double) num);
1118 }
1119 }
1120 }
1121 }
1122 else
1123 {
1124 //no filter set for this shape
1125 shape->filter = NULL;
1126 }
1128 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1129 }
1131 void
1132 nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox)
1133 {
1134 g_return_if_fail(shape != NULL);
1135 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1136 g_return_if_fail(pbox != NULL);
1138 if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
1139 shape->paintbox = *pbox;
1140 } else {
1141 /* fixme: We kill warning, although not sure what to do here (Lauris) */
1142 shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
1143 shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
1144 }
1146 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1147 }
1149 void NRArenaShape::setPaintBox(NR::Rect const &pbox)
1150 {
1151 paintbox.x0 = pbox.min()[NR::X];
1152 paintbox.y0 = pbox.min()[NR::Y];
1153 paintbox.x1 = pbox.max()[NR::X];
1154 paintbox.y1 = pbox.max()[NR::Y];
1156 nr_arena_item_request_update(this, NR_ARENA_ITEM_STATE_ALL, FALSE);
1157 }
1159 static void
1160 shape_run_A8_OR(raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
1161 {
1162 if ( st >= en ) return;
1163 if ( vst < 0 ) vst=0;
1164 if ( vst > 1 ) vst=1;
1165 if ( ven < 0 ) ven=0;
1166 if ( ven > 1 ) ven=1;
1167 float sv=vst;
1168 float dv=ven-vst;
1169 int len=en-st;
1170 unsigned char* d=(unsigned char*)dest.buffer;
1171 d+=(st-dest.startPix);
1172 if ( fabs(dv) < 0.001 ) {
1173 if ( vst > 0.999 ) {
1174 /* Simple copy */
1175 while (len > 0) {
1176 d[0] = 255;
1177 d += 1;
1178 len -= 1;
1179 }
1180 } else {
1181 sv*=256;
1182 unsigned int c0_24=(int)sv;
1183 c0_24&=0xFF;
1184 while (len > 0) {
1185 /* Draw */
1186 d[0] = NR_COMPOSEA_111(c0_24,d[0]);
1187 d += 1;
1188 len -= 1;
1189 }
1190 }
1191 } else {
1192 if ( en <= st+1 ) {
1193 sv=0.5*(vst+ven);
1194 sv*=256;
1195 unsigned int c0_24=(int)sv;
1196 c0_24&=0xFF;
1197 /* Draw */
1198 d[0] = NR_COMPOSEA_111(c0_24,d[0]);
1199 } else {
1200 dv/=len;
1201 sv+=0.5*dv; // correction trapezoidale
1202 sv*=16777216;
1203 dv*=16777216;
1204 int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
1205 int s0_24 = static_cast<int>(dv);
1206 while (len > 0) {
1207 unsigned int ca;
1208 /* Draw */
1209 ca = c0_24 >> 16;
1210 if ( ca > 255 ) ca=255;
1211 d[0] = NR_COMPOSEA_111(ca,d[0]);
1212 d += 1;
1213 c0_24 += s0_24;
1214 c0_24 = CLAMP(c0_24, 0, 16777216);
1215 len -= 1;
1216 }
1217 }
1218 }
1219 }
1221 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS)
1222 {
1223 theS->CalcBBox();
1224 float l = theS->leftX, r = theS->rightX, t = theS->topY, b = theS->bottomY;
1225 int il,ir,it,ib;
1226 il=(int)floor(l);
1227 ir=(int)ceil(r);
1228 it=(int)floor(t);
1229 ib=(int)ceil(b);
1231 if ( il >= m.area.x1 || ir <= m.area.x0 || it >= m.area.y1 || ib <= m.area.y0 ) return;
1232 if ( il < m.area.x0 ) il=m.area.x0;
1233 if ( it < m.area.y0 ) it=m.area.y0;
1234 if ( ir > m.area.x1 ) ir=m.area.x1;
1235 if ( ib > m.area.y1 ) ib=m.area.y1;
1237 /* This is the FloatLigne version. See svn (prior to Apr 2006) for versions using BitLigne or direct BitLigne. */
1238 int curPt;
1239 float curY;
1240 theS->BeginQuickRaster(curY, curPt);
1242 FloatLigne *theI = new FloatLigne();
1243 IntLigne *theIL = new IntLigne();
1245 theS->DirectQuickScan(curY, curPt, (float) it, true, 1.0);
1247 char *mdata = (char*)m.data.px;
1248 if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1249 uint32_t *ligStart = ((uint32_t*)(mdata + ((il - m.area.x0) + m.rs * (it - m.area.y0))));
1250 for (int y = it; y < ib; y++) {
1251 theI->Reset();
1252 theS->QuickScan(curY, curPt, ((float)(y+1)), theI, 1.0);
1253 theI->Flatten();
1254 theIL->Copy(theI);
1256 raster_info dest;
1257 dest.startPix=il;
1258 dest.endPix=ir;
1259 dest.sth=il;
1260 dest.stv=y;
1261 dest.buffer=ligStart;
1262 theIL->Raster(dest, NULL, shape_run_A8_OR);
1263 ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1264 }
1265 theS->EndQuickRaster();
1266 delete theI;
1267 delete theIL;
1268 }
1271 /*
1272 Local Variables:
1273 mode:c++
1274 c-file-style:"stroustrup"
1275 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1276 indent-tabs-mode:nil
1277 fill-column:99
1278 End:
1279 */
1280 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :