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 <libnr/n-art-bpath.h>
20 #include <libnr/nr-path.h>
21 #include <libnr/nr-pixops.h>
22 #include <libnr/nr-matrix-ops.h>
23 #include <libnr/nr-blit.h>
24 #include <livarot/Path.h>
25 #include <livarot/float-line.h>
26 #include <livarot/int-line.h>
27 #include <style.h>
29 //int showRuns=0;
30 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS);
32 static void nr_arena_shape_class_init(NRArenaShapeClass *klass);
33 static void nr_arena_shape_init(NRArenaShape *shape);
34 static void nr_arena_shape_finalize(NRObject *object);
36 static NRArenaItem *nr_arena_shape_children(NRArenaItem *item);
37 static void nr_arena_shape_add_child(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
38 static void nr_arena_shape_remove_child(NRArenaItem *item, NRArenaItem *child);
39 static void nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref);
41 static guint nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset);
42 static unsigned int nr_arena_shape_render(NRArenaItem *item, NRRectL *area, NRPixBlock *pb, unsigned int flags);
43 static guint nr_arena_shape_clip(NRArenaItem *item, NRRectL *area, NRPixBlock *pb);
44 static NRArenaItem *nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int sticky);
46 static NRArenaItemClass *shape_parent_class;
48 NRType
49 nr_arena_shape_get_type(void)
50 {
51 static NRType type = 0;
52 if (!type) {
53 type = nr_object_register_type(NR_TYPE_ARENA_ITEM,
54 "NRArenaShape",
55 sizeof(NRArenaShapeClass),
56 sizeof(NRArenaShape),
57 (void (*)(NRObjectClass *)) nr_arena_shape_class_init,
58 (void (*)(NRObject *)) nr_arena_shape_init);
59 }
60 return type;
61 }
63 static void
64 nr_arena_shape_class_init(NRArenaShapeClass *klass)
65 {
66 NRObjectClass *object_class;
67 NRArenaItemClass *item_class;
69 object_class = (NRObjectClass *) klass;
70 item_class = (NRArenaItemClass *) klass;
72 shape_parent_class = (NRArenaItemClass *) ((NRObjectClass *) klass)->parent;
74 object_class->finalize = nr_arena_shape_finalize;
75 object_class->cpp_ctor = NRObject::invoke_ctor<NRArenaShape>;
77 item_class->children = nr_arena_shape_children;
78 item_class->add_child = nr_arena_shape_add_child;
79 item_class->set_child_position = nr_arena_shape_set_child_position;
80 item_class->remove_child = nr_arena_shape_remove_child;
81 item_class->update = nr_arena_shape_update;
82 item_class->render = nr_arena_shape_render;
83 item_class->clip = nr_arena_shape_clip;
84 item_class->pick = nr_arena_shape_pick;
85 }
87 static void
88 nr_arena_shape_init(NRArenaShape *shape)
89 {
90 shape->curve = NULL;
91 shape->style = NULL;
92 shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
93 shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
95 nr_matrix_set_identity(&shape->ctm);
96 shape->fill_painter = NULL;
97 shape->stroke_painter = NULL;
98 shape->cached_fill = NULL;
99 shape->cached_stroke = NULL;
100 shape->cached_fpartialy = false;
101 shape->cached_spartialy = false;
102 shape->fill_shp = NULL;
103 shape->stroke_shp = NULL;
105 shape->delayed_shp = false;
107 shape->approx_bbox.x0 = shape->approx_bbox.y0 = 0;
108 shape->approx_bbox.x1 = shape->approx_bbox.y1 = 0;
109 nr_matrix_set_identity(&shape->cached_fctm);
110 nr_matrix_set_identity(&shape->cached_sctm);
112 shape->markers = NULL;
113 }
115 static void
116 nr_arena_shape_finalize(NRObject *object)
117 {
118 NRArenaShape *shape = (NRArenaShape *) object;
120 if (shape->fill_shp) delete shape->fill_shp;
121 if (shape->stroke_shp) delete shape->stroke_shp;
122 if (shape->cached_fill) delete shape->cached_fill;
123 if (shape->cached_stroke) delete shape->cached_stroke;
124 if (shape->fill_painter) sp_painter_free(shape->fill_painter);
125 if (shape->stroke_painter) sp_painter_free(shape->stroke_painter);
127 if (shape->style) sp_style_unref(shape->style);
128 if (shape->curve) sp_curve_unref(shape->curve);
130 ((NRObjectClass *) shape_parent_class)->finalize(object);
131 }
133 static NRArenaItem *
134 nr_arena_shape_children(NRArenaItem *item)
135 {
136 NRArenaShape *shape = (NRArenaShape *) item;
138 return shape->markers;
139 }
141 static void
142 nr_arena_shape_add_child(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
143 {
144 NRArenaShape *shape = (NRArenaShape *) item;
146 if (!ref) {
147 shape->markers = nr_arena_item_attach_ref(item, child, NULL, shape->markers);
148 } else {
149 ref->next = nr_arena_item_attach_ref(item, child, ref, ref->next);
150 }
152 nr_arena_item_request_update(item, NR_ARENA_ITEM_STATE_ALL, FALSE);
153 }
155 static void
156 nr_arena_shape_remove_child(NRArenaItem *item, NRArenaItem *child)
157 {
158 NRArenaShape *shape = (NRArenaShape *) item;
160 if (child->prev) {
161 nr_arena_item_detach_unref(item, child);
162 } else {
163 shape->markers = nr_arena_item_detach_unref(item, child);
164 }
166 nr_arena_item_request_update(item, NR_ARENA_ITEM_STATE_ALL, FALSE);
167 }
169 static void
170 nr_arena_shape_set_child_position(NRArenaItem *item, NRArenaItem *child, NRArenaItem *ref)
171 {
172 NRArenaShape *shape = (NRArenaShape *) item;
174 if (child->prev) {
175 nr_arena_item_detach_unref(item, child);
176 } else {
177 shape->markers = nr_arena_item_detach_unref(item, child);
178 }
180 if (!ref) {
181 shape->markers = nr_arena_item_attach_ref(item, child, NULL, shape->markers);
182 } else {
183 ref->next = nr_arena_item_attach_ref(item, child, ref, ref->next);
184 }
186 nr_arena_item_request_render(child);
187 }
189 void nr_arena_shape_update_stroke(NRArenaShape *shape, NRGC* gc, NRRectL *area);
190 void nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape = false);
191 void nr_arena_shape_add_bboxes(NRArenaShape* shape,NRRect &bbox);
193 static guint
194 nr_arena_shape_update(NRArenaItem *item, NRRectL *area, NRGC *gc, guint state, guint reset)
195 {
196 NRRect bbox;
198 NRArenaShape *shape = NR_ARENA_SHAPE(item);
200 unsigned int beststate = NR_ARENA_ITEM_STATE_ALL;
202 unsigned int newstate;
203 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
204 newstate = nr_arena_item_invoke_update(child, area, gc, state, reset);
205 beststate = beststate & newstate;
206 }
208 if (!(state & NR_ARENA_ITEM_STATE_RENDER)) {
209 /* We do not have to create rendering structures */
210 shape->ctm = gc->transform;
211 if (state & NR_ARENA_ITEM_STATE_BBOX) {
212 if (shape->curve) {
213 NRBPath bp;
214 /* fixme: */
215 bbox.x0 = bbox.y0 = NR_HUGE;
216 bbox.x1 = bbox.y1 = -NR_HUGE;
217 bp.path = shape->curve->bpath;
218 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
219 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
220 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
221 item->bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
222 item->bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
223 }
224 if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
225 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
226 nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
227 }
228 }
229 }
230 return (state | item->state);
231 }
233 shape->delayed_shp=true;
234 shape->ctm = gc->transform;
235 bbox.x0 = bbox.y0 = NR_HUGE;
236 bbox.x1 = bbox.y1 = -NR_HUGE;
238 if (shape->curve) {
239 NRBPath bp;
240 /* fixme: */
241 bbox.x0 = bbox.y0 = NR_HUGE;
242 bbox.x1 = bbox.y1 = -NR_HUGE;
243 bp.path = shape->curve->bpath;
244 nr_path_matrix_bbox_union(&bp, gc->transform, &bbox);
245 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
246 float width, scale;
247 scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
248 width = MAX(0.125, shape->_stroke.width * scale);
249 if ( fabs(shape->_stroke.width * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
250 bbox.x0-=width;
251 bbox.x1+=width;
252 bbox.y0-=width;
253 bbox.y1+=width;
254 }
255 // those pesky miters, now
256 float miterMax=width*shape->_stroke.mitre_limit;
257 if ( miterMax > 0.01 ) {
258 // grunt mode. we should compute the various miters instead (one for each point on the curve)
259 bbox.x0-=miterMax;
260 bbox.x1+=miterMax;
261 bbox.y0-=miterMax;
262 bbox.y1+=miterMax;
263 }
264 }
265 } else {
266 }
267 shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
268 shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
269 shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
270 shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
271 if ( area && nr_rect_l_test_intersect(area, &shape->approx_bbox) ) shape->delayed_shp=false;
273 /* Release state data */
274 if (TRUE || !nr_matrix_test_transform_equal(&gc->transform, &shape->ctm, NR_EPSILON)) {
275 /* Concept test */
276 if (shape->fill_shp) {
277 delete shape->fill_shp;
278 shape->fill_shp = NULL;
279 }
280 }
281 if (shape->stroke_shp) {
282 delete shape->stroke_shp;
283 shape->stroke_shp = NULL;
284 }
285 if (shape->fill_painter) {
286 sp_painter_free(shape->fill_painter);
287 shape->fill_painter = NULL;
288 }
289 if (shape->stroke_painter) {
290 sp_painter_free(shape->stroke_painter);
291 shape->stroke_painter = NULL;
292 }
294 if (!shape->curve || !shape->style) return NR_ARENA_ITEM_STATE_ALL;
295 if (sp_curve_is_empty(shape->curve)) return NR_ARENA_ITEM_STATE_ALL;
296 if ( ( shape->_fill.paint.type() == NRArenaShape::Paint::NONE ) &&
297 ( shape->_stroke.paint.type() == NRArenaShape::Paint::NONE ) )
298 {
299 return NR_ARENA_ITEM_STATE_ALL;
300 }
302 /* Build state data */
303 if ( shape->delayed_shp ) {
304 item->bbox=shape->approx_bbox;
305 } else {
306 nr_arena_shape_update_stroke(shape, gc, area);
307 nr_arena_shape_update_fill(shape, gc, area);
309 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
310 nr_arena_shape_add_bboxes(shape,bbox);
312 shape->approx_bbox.x0 = (gint32)(bbox.x0 - 1.0F);
313 shape->approx_bbox.y0 = (gint32)(bbox.y0 - 1.0F);
314 shape->approx_bbox.x1 = (gint32)(bbox.x1 + 1.9999F);
315 shape->approx_bbox.y1 = (gint32)(bbox.y1 + 1.9999F);
316 }
318 if (nr_rect_d_test_empty(&bbox)) return NR_ARENA_ITEM_STATE_ALL;
320 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
321 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
322 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
323 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
324 nr_arena_request_render_rect(item->arena, &item->bbox);
326 item->render_opacity = TRUE;
327 if ( shape->_fill.paint.type() == NRArenaShape::Paint::SERVER ) {
328 if (gc && gc->parent) {
329 shape->fill_painter = sp_paint_server_painter_new(shape->_fill.paint.server(),
330 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
331 &shape->paintbox);
332 }
333 item->render_opacity = FALSE;
334 }
335 if ( shape->_stroke.paint.type() == NRArenaShape::Paint::SERVER ) {
336 if (gc && gc->parent) {
337 shape->stroke_painter = sp_paint_server_painter_new(shape->_stroke.paint.server(),
338 NR::Matrix(&gc->transform), NR::Matrix(&gc->parent->transform),
339 &shape->paintbox);
340 }
341 item->render_opacity = FALSE;
342 }
343 if ( item->render_opacity == TRUE
344 && shape->_fill.paint.type() != NRArenaShape::Paint::NONE
345 && shape->_stroke.paint.type() != NRArenaShape::Paint::NONE )
346 {
347 // don't merge item opacity with paint opacity if there is a stroke on the fill
348 item->render_opacity = FALSE;
349 }
351 if (beststate & NR_ARENA_ITEM_STATE_BBOX) {
352 for (NRArenaItem *child = shape->markers; child != NULL; child = child->next) {
353 nr_rect_l_union(&item->bbox, &item->bbox, &child->bbox);
354 }
355 }
357 return NR_ARENA_ITEM_STATE_ALL;
358 }
360 int matrix_is_isometry(NR::Matrix p) {
361 NR::Matrix tp;
362 // transposition
363 tp[0]=p[0];
364 tp[1]=p[2];
365 tp[2]=p[1];
366 tp[3]=p[3];
367 for (int i = 4; i < 6; i++) // shut valgrind up :)
368 tp[i] = p[i] = 0;
369 NR::Matrix isom = tp*p; // A^T * A = adjunct?
370 // Is the adjunct nearly an identity function?
371 if (isom.is_translation(0.01)) {
372 // the transformation is an isometry -> no need to recompute
373 // the uncrossed polygon
374 if ( p.det() < 0 )
375 return -1;
376 else
377 return 1;
378 }
379 return 0;
380 }
382 static bool is_inner_area(NRRectL const &outer, NRRectL const &inner) {
383 return (outer.x0 <= inner.x0 && outer.y0 <= inner.y0 && outer.x1 >= inner.x1 && outer.y1 >= inner.y1);
384 }
386 /** force_shape is used for clipping paths, when we need the shape for clipping even if it's not filled */
387 void
388 nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape)
389 {
390 if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) &&
391 ((shape->curve->end > 2) || (shape->curve->bpath[1].code == NR_CURVETO)) ) {
392 if (TRUE || !shape->fill_shp) {
393 NR::Matrix cached_to_new;
394 int isometry = 0;
395 if ( shape->cached_fill ) {
396 if (shape->cached_fctm == gc->transform) {
397 isometry = 2; // identity
398 } else {
399 cached_to_new = shape->cached_fctm.inverse() * gc->transform;
400 isometry = matrix_is_isometry(cached_to_new);
401 }
402 if (0 != isometry && !is_inner_area(shape->cached_farea, *area))
403 isometry = 0;
404 }
405 if ( isometry == 0 ) {
406 if ( shape->cached_fill == NULL ) shape->cached_fill=new Shape;
407 shape->cached_fill->Reset();
409 Path* thePath=new Path;
410 Shape* theShape=new Shape;
411 {
412 NR::Matrix tempMat(gc->transform);
413 thePath->LoadArtBPath(shape->curve->bpath,tempMat,true);
414 }
416 if (is_inner_area(*area, NR_ARENA_ITEM(shape)->bbox)) {
417 thePath->Convert(1.0);
418 shape->cached_fpartialy = false;
419 } else {
420 thePath->Convert(area, 1.0);
421 shape->cached_fpartialy = true;
422 }
424 thePath->Fill(theShape, 0);
426 if ( shape->_fill.rule == NRArenaShape::EVEN_ODD ) {
427 shape->cached_fill->ConvertToShape(theShape, fill_oddEven);
428 // alternatively, this speeds up rendering of oddeven shapes but disables AA :(
429 //shape->cached_fill->Copy(theShape);
430 } else {
431 shape->cached_fill->ConvertToShape(theShape, fill_nonZero);
432 }
433 shape->cached_fctm=gc->transform;
434 shape->cached_farea = *area;
435 delete theShape;
436 delete thePath;
437 if ( shape->fill_shp == NULL )
438 shape->fill_shp = new Shape;
440 shape->fill_shp->Copy(shape->cached_fill);
442 } else if ( 2 == isometry ) {
443 if ( shape->fill_shp == NULL ) {
444 shape->fill_shp = new Shape;
445 shape->fill_shp->Copy(shape->cached_fill);
446 }
447 } else {
449 if ( shape->fill_shp == NULL )
450 shape->fill_shp = new Shape;
452 shape->fill_shp->Reset(shape->cached_fill->numberOfPoints(),
453 shape->cached_fill->numberOfEdges());
454 for (int i = 0; i < shape->cached_fill->numberOfPoints(); i++)
455 shape->fill_shp->AddPoint(shape->cached_fill->getPoint(i).x * cached_to_new);
456 if ( isometry == 1 ) {
457 for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
458 shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).st,
459 shape->cached_fill->getEdge(i).en);
460 } else if ( isometry == -1 ) { // need to flip poly.
461 for (int i = 0; i < shape->cached_fill->numberOfEdges(); i++)
462 shape->fill_shp->AddEdge(shape->cached_fill->getEdge(i).en,
463 shape->cached_fill->getEdge(i).st);
464 }
465 shape->fill_shp->ForceToPolygon();
466 shape->fill_shp->needPointsSorting();
467 shape->fill_shp->needEdgesSorting();
468 }
469 shape->delayed_shp |= shape->cached_fpartialy;
470 }
471 }
472 }
474 void
475 nr_arena_shape_update_stroke(NRArenaShape *shape,NRGC* gc, NRRectL *area)
476 {
477 SPStyle* style = shape->style;
479 float const scale = NR_MATRIX_DF_EXPANSION(&gc->transform);
481 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE ||
482 ((shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) &&
483 ( fabs(shape->_stroke.width * scale) > 0.01 ))) { // sinon c'est 0=oon veut pas de bord
485 float width = MAX(0.125, shape->_stroke.width * scale);
486 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE)
487 width = 0.5; // 1 pixel wide, independent of zoom
489 NR::Matrix cached_to_new;
491 int isometry = 0;
492 if ( shape->cached_stroke ) {
493 if (shape->cached_sctm == gc->transform) {
494 isometry = 2; // identity
495 } else {
496 cached_to_new = shape->cached_sctm.inverse() * gc->transform;
497 isometry = matrix_is_isometry(cached_to_new);
498 }
499 if (0 != isometry && !is_inner_area(shape->cached_sarea, *area))
500 isometry = 0;
501 }
503 if ( isometry == 0 ) {
504 if ( shape->cached_stroke == NULL ) shape->cached_stroke=new Shape;
505 shape->cached_stroke->Reset();
506 Path* thePath = new Path;
507 Shape* theShape = new Shape;
508 {
509 NR::Matrix tempMat(gc->transform);
510 thePath->LoadArtBPath(shape->curve->bpath, tempMat, true);
511 }
513 // add some padding to the rendering area, so clipped path does not go into a render area
514 NRRectL padded_area = *area;
515 padded_area.x0 -= (NR::ICoord)width;
516 padded_area.x1 += (NR::ICoord)width;
517 padded_area.y0 -= (NR::ICoord)width;
518 padded_area.y1 += (NR::ICoord)width;
519 if ((style->stroke_dash.n_dash && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) || is_inner_area(padded_area, NR_ARENA_ITEM(shape)->bbox)) {
520 thePath->Convert((NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) ? 1.0 : 4.0);
521 shape->cached_spartialy = false;
522 }
523 else {
524 thePath->Convert(&padded_area, (NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) ? 1.0 : 4.0);
525 shape->cached_spartialy = true;
526 }
528 if (style->stroke_dash.n_dash && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) {
529 double dlen = 0.0;
530 for (int i = 0; i < style->stroke_dash.n_dash; i++) {
531 dlen += style->stroke_dash.dash[i] * scale;
532 }
533 if (dlen >= 1.0) {
534 NRVpathDash dash;
535 dash.offset = style->stroke_dash.offset * scale;
536 dash.n_dash = style->stroke_dash.n_dash;
537 dash.dash = g_new(double, dash.n_dash);
538 for (int i = 0; i < dash.n_dash; i++) {
539 dash.dash[i] = style->stroke_dash.dash[i] * scale;
540 }
541 int nbD=dash.n_dash;
542 float *dashs=(float*)malloc((nbD+1)*sizeof(float));
543 while ( dash.offset >= dlen ) dash.offset-=dlen;
544 dashs[0]=dash.dash[0];
545 for (int i=1; i<nbD; i++) {
546 dashs[i]=dashs[i-1]+dash.dash[i];
547 }
548 // modulo dlen
549 thePath->DashPolyline(0.0,0.0,dlen,nbD,dashs,true,dash.offset);
550 free(dashs);
551 g_free(dash.dash);
552 }
553 }
554 ButtType butt=butt_straight;
555 switch (shape->_stroke.cap) {
556 case NRArenaShape::BUTT_CAP:
557 butt = butt_straight;
558 break;
559 case NRArenaShape::ROUND_CAP:
560 butt = butt_round;
561 break;
562 case NRArenaShape::SQUARE_CAP:
563 butt = butt_square;
564 break;
565 }
566 JoinType join=join_straight;
567 switch (shape->_stroke.join) {
568 case NRArenaShape::MITRE_JOIN:
569 join = join_pointy;
570 break;
571 case NRArenaShape::ROUND_JOIN:
572 join = join_round;
573 break;
574 case NRArenaShape::BEVEL_JOIN:
575 join = join_straight;
576 break;
577 }
579 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
580 butt = butt_straight;
581 join = join_straight;
582 }
584 thePath->Stroke(theShape, false, 0.5*width, join, butt,
585 0.5*width*shape->_stroke.mitre_limit);
588 if (NR_ARENA_ITEM(shape)->arena->rendermode == RENDERMODE_OUTLINE) {
589 // speeds it up, but uses evenodd for the stroke shape (which does not matter for 1-pixel wide outline)
590 shape->cached_stroke->Copy(theShape);
591 } else {
592 shape->cached_stroke->ConvertToShape(theShape, fill_nonZero);
593 }
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 SPStyle const *style = shape->style;
719 if ( shape->fill_shp && NR_ARENA_ITEM(shape)->arena->rendermode != RENDERMODE_OUTLINE) {
720 NRPixBlock m;
721 guint32 rgba;
723 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
724 m.visible_area = pb->visible_area;
725 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
726 m.empty = FALSE;
728 if (shape->_fill.paint.type() == NRArenaShape::Paint::NONE) {
729 // do not render fill in any way
730 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::COLOR) {
731 if ( item->render_opacity ) {
732 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
733 shape->_fill.opacity *
734 SP_SCALE24_TO_FLOAT(style->opacity.value));
735 } else {
736 rgba = sp_color_get_rgba32_falpha(&shape->_fill.paint.color(),
737 shape->_fill.opacity);
738 }
739 nr_blit_pixblock_mask_rgba32(pb, &m, rgba);
740 pb->empty = FALSE;
741 } else if (shape->_fill.paint.type() == NRArenaShape::Paint::SERVER) {
742 if (shape->fill_painter) {
743 nr_arena_render_paintserver_fill(pb, area, shape->fill_painter, shape->_fill.opacity, &m);
744 }
745 }
747 nr_pixblock_release(&m);
748 }
750 if ( shape->stroke_shp ) {
751 NRPixBlock m;
752 guint32 rgba;
754 nr_pixblock_setup_fast(&m, NR_PIXBLOCK_MODE_A8, area->x0, area->y0, area->x1, area->y1, TRUE);
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);
814 m.visible_area = pb->visible_area;
815 nr_pixblock_render_shape_mask_or(m,shape->fill_shp);
817 for (int y = area->y0; y < area->y1; y++) {
818 unsigned char *s, *d;
819 s = NR_PIXBLOCK_PX(&m) + (y - area->y0) * m.rs;
820 d = NR_PIXBLOCK_PX(pb) + (y - area->y0) * pb->rs;
821 for (int x = area->x0; x < area->x1; x++) {
822 *d = NR_A7_NORMALIZED(*s,*d);
823 d ++;
824 s ++;
825 }
826 }
827 nr_pixblock_release(&m);
828 pb->empty = FALSE;
829 }
831 return item->state;
832 }
834 static NRArenaItem *
835 nr_arena_shape_pick(NRArenaItem *item, NR::Point p, double delta, unsigned int /*sticky*/)
836 {
837 NRArenaShape *shape = NR_ARENA_SHAPE(item);
839 if (!shape->curve) return NULL;
840 if (!shape->style) return NULL;
841 if ( shape->delayed_shp ) {
842 NRRectL area, updateArea;
843 area.x0=(int)floor(p[NR::X]);
844 area.x1=(int)ceil(p[NR::X]);
845 area.y0=(int)floor(p[NR::Y]);
846 area.y1=(int)ceil(p[NR::Y]);
847 int idelta = (int)ceil(delta) + 1;
848 // njh: inset rect
849 area.x0-=idelta;
850 area.x1+=idelta;
851 area.y0-=idelta;
852 area.y1+=idelta;
853 if ( nr_rect_l_test_intersect(&area, &item->bbox) ) {
854 NRGC tempGC(NULL);
855 tempGC.transform=shape->ctm;
856 updateArea = item->bbox;
857 if (shape->cached_stroke)
858 nr_rect_l_intersect (&updateArea, &updateArea, &shape->cached_sarea);
860 shape->delayed_shp = false;
861 nr_arena_shape_update_stroke(shape, &tempGC, &updateArea);
862 nr_arena_shape_update_fill(shape, &tempGC, &updateArea);
863 /* NRRect bbox;
864 bbox.x0 = bbox.y0 = bbox.x1 = bbox.y1 = 0.0;
865 nr_arena_shape_add_bboxes(shape,bbox);
866 item->bbox.x0 = (gint32)(bbox.x0 - 1.0F);
867 item->bbox.y0 = (gint32)(bbox.y0 - 1.0F);
868 item->bbox.x1 = (gint32)(bbox.x1 + 1.0F);
869 item->bbox.y1 = (gint32)(bbox.y1 + 1.0F);
870 shape->approx_bbox=item->bbox;*/
871 }
872 }
874 if (item->state & NR_ARENA_ITEM_STATE_RENDER) {
875 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
876 if (shape->fill_shp->PtWinding(p) > 0 ) return item;
877 }
878 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
879 if (shape->stroke_shp->PtWinding(p) > 0 ) return item;
880 }
881 if (delta > 1e-3) {
882 if (shape->fill_shp && (shape->_fill.paint.type() != NRArenaShape::Paint::NONE)) {
883 if (distanceLessThanOrEqual(shape->fill_shp, p, delta)) return item;
884 }
885 if (shape->stroke_shp && (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE)) {
886 if (distanceLessThanOrEqual(shape->stroke_shp, p, delta)) return item;
887 }
888 }
889 } else {
890 NRBPath bp;
891 bp.path = shape->curve->bpath;
892 double dist = NR_HUGE;
893 int wind = 0;
894 nr_path_matrix_point_bbox_wind_distance(&bp, shape->ctm, p, NULL, &wind, &dist, NR_EPSILON);
895 if (shape->_fill.paint.type() != NRArenaShape::Paint::NONE) {
896 if (!shape->style->fill_rule.computed) {
897 if (wind != 0) return item;
898 } else {
899 if (wind & 0x1) return item;
900 }
901 }
902 if (shape->_stroke.paint.type() != NRArenaShape::Paint::NONE) {
903 /* fixme: We do not take stroke width into account here (Lauris) */
904 if (dist < delta) return item;
905 }
906 }
908 return NULL;
909 }
911 /**
912 *
913 * Requests a render of the shape, then if the shape is already a curve it
914 * unrefs the old curve; if the new curve is valid it creates a copy of the
915 * curve and adds it to the shape. Finally, it requests an update of the
916 * arena for the shape.
917 */
918 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve,bool justTrans)
919 {
920 g_return_if_fail(shape != NULL);
921 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
923 if ( justTrans == false ) {
924 // dirty cached versions
925 if ( shape->cached_fill ) {
926 delete shape->cached_fill;
927 shape->cached_fill=NULL;
928 }
929 if ( shape->cached_stroke ) {
930 delete shape->cached_stroke;
931 shape->cached_stroke=NULL;
932 }
933 }
935 nr_arena_item_request_render(NR_ARENA_ITEM(shape));
937 if (shape->curve) {
938 sp_curve_unref(shape->curve);
939 shape->curve = NULL;
940 }
942 if (curve) {
943 shape->curve = curve;
944 sp_curve_ref(curve);
945 }
947 nr_arena_item_request_update(NR_ARENA_ITEM(shape), NR_ARENA_ITEM_STATE_ALL, FALSE);
948 }
950 void NRArenaShape::setFill(SPPaintServer *server) {
951 _fill.paint.set(server);
952 _invalidateCachedFill();
953 }
955 void NRArenaShape::setFill(SPColor const &color) {
956 _fill.paint.set(color);
957 _invalidateCachedFill();
958 }
960 void NRArenaShape::setFillOpacity(double opacity) {
961 _fill.opacity = opacity;
962 _invalidateCachedFill();
963 }
965 void NRArenaShape::setFillRule(NRArenaShape::FillRule rule) {
966 _fill.rule = rule;
967 _invalidateCachedFill();
968 }
970 void NRArenaShape::setStroke(SPPaintServer *server) {
971 _stroke.paint.set(server);
972 _invalidateCachedStroke();
973 }
975 void NRArenaShape::setStroke(SPColor const &color) {
976 _stroke.paint.set(color);
977 _invalidateCachedStroke();
978 }
980 void NRArenaShape::setStrokeOpacity(double opacity) {
981 _stroke.opacity = opacity;
982 _invalidateCachedStroke();
983 }
985 void NRArenaShape::setStrokeWidth(double width) {
986 _stroke.width = width;
987 _invalidateCachedStroke();
988 }
990 void NRArenaShape::setMitreLimit(double limit) {
991 _stroke.mitre_limit = limit;
992 _invalidateCachedStroke();
993 }
995 void NRArenaShape::setLineCap(NRArenaShape::CapType cap) {
996 _stroke.cap = cap;
997 _invalidateCachedStroke();
998 }
1000 void NRArenaShape::setLineJoin(NRArenaShape::JoinType join) {
1001 _stroke.join = join;
1002 _invalidateCachedStroke();
1003 }
1005 /** nr_arena_shape_set_style
1006 *
1007 * Unrefs any existing style and ref's to the given one, then requests an update of the arena
1008 */
1009 void
1010 nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style)
1011 {
1012 g_return_if_fail(shape != NULL);
1013 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1015 if (style) sp_style_ref(style);
1016 if (shape->style) sp_style_unref(shape->style);
1017 shape->style = style;
1019 switch (style->fill.type) {
1020 case SP_PAINT_TYPE_NONE: {
1021 shape->setFill(NULL);
1022 break;
1023 }
1024 case SP_PAINT_TYPE_COLOR: {
1025 shape->setFill(style->fill.value.color);
1026 break;
1027 }
1028 case SP_PAINT_TYPE_PAINTSERVER: {
1029 shape->setFill(style->fill.value.paint.server);
1030 break;
1031 }
1032 default: {
1033 g_assert_not_reached();
1034 }
1035 }
1036 shape->setFillOpacity(SP_SCALE24_TO_FLOAT(style->fill_opacity.value));
1037 switch (style->fill_rule.computed) {
1038 case SP_WIND_RULE_EVENODD: {
1039 shape->setFillRule(NRArenaShape::EVEN_ODD);
1040 break;
1041 }
1042 case SP_WIND_RULE_NONZERO: {
1043 shape->setFillRule(NRArenaShape::NONZERO);
1044 break;
1045 }
1046 default: {
1047 g_assert_not_reached();
1048 }
1049 }
1051 switch (style->stroke.type) {
1052 case SP_PAINT_TYPE_NONE: {
1053 shape->setStroke(NULL);
1054 break;
1055 }
1056 case SP_PAINT_TYPE_COLOR: {
1057 shape->setStroke(style->stroke.value.color);
1058 break;
1059 }
1060 case SP_PAINT_TYPE_PAINTSERVER: {
1061 shape->setStroke(style->stroke.value.paint.server);
1062 break;
1063 }
1064 default: {
1065 g_assert_not_reached();
1066 }
1067 }
1068 shape->setStrokeWidth(style->stroke_width.computed);
1069 shape->setStrokeOpacity(SP_SCALE24_TO_FLOAT(style->stroke_opacity.value));
1070 switch (style->stroke_linecap.computed) {
1071 case SP_STROKE_LINECAP_ROUND: {
1072 shape->setLineCap(NRArenaShape::ROUND_CAP);
1073 break;
1074 }
1075 case SP_STROKE_LINECAP_SQUARE: {
1076 shape->setLineCap(NRArenaShape::SQUARE_CAP);
1077 break;
1078 }
1079 case SP_STROKE_LINECAP_BUTT: {
1080 shape->setLineCap(NRArenaShape::BUTT_CAP);
1081 break;
1082 }
1083 default: {
1084 g_assert_not_reached();
1085 }
1086 }
1087 switch (style->stroke_linejoin.computed) {
1088 case SP_STROKE_LINEJOIN_ROUND: {
1089 shape->setLineJoin(NRArenaShape::ROUND_JOIN);
1090 break;
1091 }
1092 case SP_STROKE_LINEJOIN_BEVEL: {
1093 shape->setLineJoin(NRArenaShape::BEVEL_JOIN);
1094 break;
1095 }
1096 case SP_STROKE_LINEJOIN_MITER: {
1097 shape->setLineJoin(NRArenaShape::MITRE_JOIN);
1098 break;
1099 }
1100 default: {
1101 g_assert_not_reached();
1102 }
1103 }
1104 shape->setMitreLimit(style->stroke_miterlimit.value);
1106 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1107 }
1109 void
1110 nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox)
1111 {
1112 g_return_if_fail(shape != NULL);
1113 g_return_if_fail(NR_IS_ARENA_SHAPE(shape));
1114 g_return_if_fail(pbox != NULL);
1116 if ((pbox->x0 < pbox->x1) && (pbox->y0 < pbox->y1)) {
1117 shape->paintbox = *pbox;
1118 } else {
1119 /* fixme: We kill warning, although not sure what to do here (Lauris) */
1120 shape->paintbox.x0 = shape->paintbox.y0 = 0.0F;
1121 shape->paintbox.x1 = shape->paintbox.y1 = 256.0F;
1122 }
1124 nr_arena_item_request_update(shape, NR_ARENA_ITEM_STATE_ALL, FALSE);
1125 }
1127 void NRArenaShape::setPaintBox(NR::Rect const &pbox)
1128 {
1129 paintbox.x0 = pbox.min()[NR::X];
1130 paintbox.y0 = pbox.min()[NR::Y];
1131 paintbox.x1 = pbox.max()[NR::X];
1132 paintbox.y1 = pbox.max()[NR::Y];
1134 nr_arena_item_request_update(this, NR_ARENA_ITEM_STATE_ALL, FALSE);
1135 }
1137 static void
1138 shape_run_A8_OR(raster_info &dest,void */*data*/,int st,float vst,int en,float ven)
1139 {
1140 if ( st >= en ) return;
1141 if ( vst < 0 ) vst=0;
1142 if ( vst > 1 ) vst=1;
1143 if ( ven < 0 ) ven=0;
1144 if ( ven > 1 ) ven=1;
1145 float sv=vst;
1146 float dv=ven-vst;
1147 int len=en-st;
1148 unsigned char* d=(unsigned char*)dest.buffer;
1149 d+=(st-dest.startPix);
1150 if ( fabs(dv) < 0.001 ) {
1151 if ( vst > 0.999 ) {
1152 /* Simple copy */
1153 while (len > 0) {
1154 d[0] = 255;
1155 d += 1;
1156 len -= 1;
1157 }
1158 } else {
1159 sv*=256;
1160 unsigned int c0_24=(int)sv;
1161 c0_24&=0xFF;
1162 while (len > 0) {
1163 unsigned int da;
1164 /* Draw */
1165 da = NR_A7(c0_24,d[0]);
1166 d[0] = NR_PREMUL_SINGLE(da);
1167 d += 1;
1168 len -= 1;
1169 }
1170 }
1171 } else {
1172 if ( en <= st+1 ) {
1173 sv=0.5*(vst+ven);
1174 sv*=256;
1175 unsigned int c0_24=(int)sv;
1176 c0_24&=0xFF;
1177 unsigned int da;
1178 /* Draw */
1179 da = NR_A7(c0_24,d[0]);
1180 d[0] = NR_PREMUL_SINGLE(da);
1181 } else {
1182 dv/=len;
1183 sv+=0.5*dv; // correction trapezoidale
1184 sv*=16777216;
1185 dv*=16777216;
1186 int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
1187 int s0_24 = static_cast<int>(dv);
1188 while (len > 0) {
1189 unsigned int ca, da;
1190 /* Draw */
1191 ca = c0_24 >> 16;
1192 if ( ca > 255 ) ca=255;
1193 da = NR_A7(ca,d[0]);
1194 d[0] = NR_PREMUL_SINGLE(da);
1195 d += 1;
1196 c0_24 += s0_24;
1197 c0_24 = CLAMP(c0_24, 0, 16777216);
1198 len -= 1;
1199 }
1200 }
1201 }
1202 }
1204 void nr_pixblock_render_shape_mask_or(NRPixBlock &m,Shape* theS)
1205 {
1206 theS->CalcBBox();
1207 float l = theS->leftX, r = theS->rightX, t = theS->topY, b = theS->bottomY;
1208 int il,ir,it,ib;
1209 il=(int)floor(l);
1210 ir=(int)ceil(r);
1211 it=(int)floor(t);
1212 ib=(int)ceil(b);
1214 if ( il >= m.area.x1 || ir <= m.area.x0 || it >= m.area.y1 || ib <= m.area.y0 ) return;
1215 if ( il < m.area.x0 ) il=m.area.x0;
1216 if ( it < m.area.y0 ) it=m.area.y0;
1217 if ( ir > m.area.x1 ) ir=m.area.x1;
1218 if ( ib > m.area.y1 ) ib=m.area.y1;
1220 /* This is the FloatLigne version. See svn (prior to Apr 2006) for versions using BitLigne or direct BitLigne. */
1221 int curPt;
1222 float curY;
1223 theS->BeginQuickRaster(curY, curPt);
1225 FloatLigne *theI = new FloatLigne();
1226 IntLigne *theIL = new IntLigne();
1228 theS->DirectQuickScan(curY, curPt, (float) it, true, 1.0);
1230 char *mdata = (char*)m.data.px;
1231 if ( m.size == NR_PIXBLOCK_SIZE_TINY ) mdata=(char*)m.data.p;
1232 uint32_t *ligStart = ((uint32_t*)(mdata + ((il - m.area.x0) + m.rs * (it - m.area.y0))));
1233 for (int y = it; y < ib; y++) {
1234 theI->Reset();
1235 theS->QuickScan(curY, curPt, ((float)(y+1)), theI, 1.0);
1236 theI->Flatten();
1237 theIL->Copy(theI);
1239 raster_info dest;
1240 dest.startPix=il;
1241 dest.endPix=ir;
1242 dest.sth=il;
1243 dest.stv=y;
1244 dest.buffer=ligStart;
1245 theIL->Raster(dest, NULL, shape_run_A8_OR);
1246 ligStart=((uint32_t*)(((char*)ligStart)+m.rs));
1247 }
1248 theS->EndQuickRaster();
1249 delete theI;
1250 delete theIL;
1251 }
1254 /*
1255 Local Variables:
1256 mode:c++
1257 c-file-style:"stroustrup"
1258 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1259 indent-tabs-mode:nil
1260 fill-column:99
1261 End:
1262 */
1263 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :