123
125
sp_canvas_item_reset_bounds (item);
126
delete cbp->fill_shp;
127
cbp->fill_shp = NULL;
130
if (cbp->stroke_shp) {
131
delete cbp->stroke_shp;
132
cbp->stroke_shp = NULL;
134
127
if (!cbp->curve) return;
138
dbox.x0 = dbox.y0 = 0.0;
139
dbox.x1 = dbox.y1 = -1.0;
141
if ((cbp->fill_rgba & 0xff) || (cbp->stroke_rgba & 0xff)) {
142
Path* thePath=new Path;
143
thePath->LoadArtBPath(SP_CURVE_BPATH(cbp->curve), affine, true);
144
thePath->Convert(0.25);
145
if ((cbp->fill_rgba & 0xff) && (cbp->curve->end > 2)) {
146
Shape* theShape=new Shape;
147
thePath->Fill(theShape,0);
148
if ( cbp->fill_shp == NULL ) cbp->fill_shp=new Shape;
149
if ( cbp->fill_rule == SP_WIND_RULE_EVENODD ) {
150
cbp->fill_shp->ConvertToShape(theShape,fill_oddEven);
152
cbp->fill_shp->ConvertToShape(theShape,fill_nonZero);
155
cbp->fill_shp->CalcBBox();
156
if ( cbp->fill_shp->leftX < cbp->fill_shp->rightX ) {
157
if ( dbox.x0 >= dbox.x1 ) {
158
dbox.x0 = cbp->fill_shp->leftX; dbox.x1 = cbp->fill_shp->rightX;
159
dbox.y0 = cbp->fill_shp->topY; dbox.y1 = cbp->fill_shp->bottomY;
161
if ( cbp->fill_shp->leftX < dbox.x0 ) dbox.x0=cbp->fill_shp->leftX;
162
if ( cbp->fill_shp->rightX > dbox.x1 ) dbox.x1=cbp->fill_shp->rightX;
163
if ( cbp->fill_shp->topY < dbox.y0 ) dbox.y0=cbp->fill_shp->topY;
164
if ( cbp->fill_shp->bottomY > dbox.y1 ) dbox.y1=cbp->fill_shp->bottomY;
168
if ((cbp->stroke_rgba & 0xff) && (cbp->curve->end > 1)) {
169
JoinType join=join_straight;
170
// Shape* theShape=new Shape;
171
ButtType butt=butt_straight;
172
if ( cbp->stroke_shp == NULL ) cbp->stroke_shp=new Shape;
173
if ( cbp->stroke_linecap == SP_STROKE_LINECAP_BUTT ) butt=butt_straight;
174
if ( cbp->stroke_linecap == SP_STROKE_LINECAP_ROUND ) butt=butt_round;
175
if ( cbp->stroke_linecap == SP_STROKE_LINECAP_SQUARE ) butt=butt_square;
176
if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_MITER ) join=join_pointy;
177
if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_ROUND ) join=join_round;
178
if ( cbp->stroke_linejoin == SP_STROKE_LINEJOIN_BEVEL ) join=join_straight;
179
thePath->Stroke(cbp->stroke_shp,false,0.5*cbp->stroke_width, join,butt,cbp->stroke_width*cbp->stroke_miterlimit );
180
// thePath->Stroke(theShape,false,0.5*cbp->stroke_width, join,butt,cbp->stroke_width*cbp->stroke_miterlimit );
181
// cbp->stroke_shp->ConvertToShape(theShape,fill_nonZero);
183
cbp->stroke_shp->CalcBBox();
184
if ( cbp->stroke_shp->leftX < cbp->stroke_shp->rightX ) {
185
if ( dbox.x0 >= dbox.x1 ) {
186
dbox.x0 = cbp->stroke_shp->leftX;dbox.x1 = cbp->stroke_shp->rightX;
187
dbox.y0 = cbp->stroke_shp->topY;dbox.y1 = cbp->stroke_shp->bottomY;
189
if ( cbp->stroke_shp->leftX < dbox.x0 ) dbox.x0 = cbp->stroke_shp->leftX;
190
if ( cbp->stroke_shp->rightX > dbox.x1 ) dbox.x1 = cbp->stroke_shp->rightX;
191
if ( cbp->stroke_shp->topY < dbox.y0 ) dbox.y0 = cbp->stroke_shp->topY;
192
if ( cbp->stroke_shp->bottomY > dbox.y1 ) dbox.y1 = cbp->stroke_shp->bottomY;
129
cbp->affine = affine;
131
Geom::OptRect bbox = bounds_exact_transformed(cbp->curve->get_pathvector(), affine);
134
item->x1 = (int)bbox->min()[Geom::X] - 1;
135
item->y1 = (int)bbox->min()[Geom::Y] - 1;
136
item->x2 = (int)bbox->max()[Geom::X] + 1;
137
item->y2 = (int)bbox->max()[Geom::Y] + 1;
201
item->x1 = (int)dbox.x0;
202
item->y1 = (int)dbox.y0;
203
item->x2 = (int)dbox.x1;
204
item->y2 = (int)dbox.y1;
206
144
sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
214
152
sp_canvas_prepare_buffer(buf);
217
area.x0=buf->rect.x0;
218
area.x1=buf->rect.x1;
219
area.y0=buf->rect.y0;
220
area.y1=buf->rect.y1;
221
if ( cbp->fill_shp ) {
222
nr_pixblock_render_bpath_rgba (cbp->fill_shp,cbp->fill_rgba,area,(char*)buf->buf, buf->buf_rowstride);
224
if ( cbp->stroke_shp ) {
225
nr_pixblock_render_bpath_rgba (cbp->stroke_shp,cbp->stroke_rgba,area,(char*)buf->buf, buf->buf_rowstride);
154
Geom::Rect area (Geom::Point(buf->rect.x0, buf->rect.y0), Geom::Point(buf->rect.x1, buf->rect.y1));
157
((cbp->stroke_rgba & 0xff) == 0 && (cbp->fill_rgba & 0xff) == 0 ) ||
158
cbp->curve->get_segment_count() < 1)
164
bool dofill = ((cbp->fill_rgba & 0xff) != 0);
165
bool dostroke = ((cbp->stroke_rgba & 0xff) != 0);
167
cairo_set_tolerance(buf->ct, 1.25); // low quality, but good enough for canvas items
168
cairo_new_path(buf->ct);
171
feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), cbp->affine, area, true, 1);
173
feed_pathvector_to_cairo (buf->ct, cbp->curve->get_pathvector(), cbp->affine, area, false, 1);
177
cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(cbp->fill_rgba), SP_RGBA32_G_F(cbp->fill_rgba), SP_RGBA32_R_F(cbp->fill_rgba), SP_RGBA32_A_F(cbp->fill_rgba));
178
cairo_set_fill_rule(buf->ct, cbp->fill_rule == SP_WIND_RULE_EVENODD? CAIRO_FILL_RULE_EVEN_ODD
179
: CAIRO_FILL_RULE_WINDING);
181
cairo_fill_preserve(buf->ct);
188
cairo_set_source_rgba(buf->ct, SP_RGBA32_B_F(cbp->stroke_rgba), SP_RGBA32_G_F(cbp->stroke_rgba), SP_RGBA32_R_F(cbp->stroke_rgba), SP_RGBA32_A_F(cbp->stroke_rgba));
189
cairo_set_line_width(buf->ct, 1);
190
if (cbp->dashes[0] != 0 && cbp->dashes[1] != 0) {
191
cairo_set_dash (buf->ct, cbp->dashes, 2, 0);
193
cairo_stroke(buf->ct);
233
sp_canvas_bpath_point (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item)
198
sp_canvas_bpath_point (SPCanvasItem *item, Geom::Point p, SPCanvasItem **actual_item)
235
200
SPCanvasBPath *cbp = SP_CANVAS_BPATH (item);
237
if (cbp->fill_shp && (cbp->fill_shp->PtWinding(p) > 0 )) {
203
((cbp->stroke_rgba & 0xff) == 0 && (cbp->fill_rgba & 0xff) == 0 ) ||
204
cbp->curve->get_segment_count() < 1)
208
Geom::Rect viewbox = item->canvas->getViewbox();
209
viewbox.expandBy (width);
210
double dist = NR_HUGE;
211
pathv_matrix_point_bbox_wind_distance(cbp->curve->get_pathvector(), cbp->affine, p, NULL, NULL, &dist, 0.5, &viewbox);
238
214
*actual_item = item;
241
if (cbp->stroke_shp ) {
242
if (cbp->stroke_shp->PtWinding(p) > 0 ) {
246
return distance(cbp->stroke_shp, p);
249
return distance(cbp->fill_shp, p);
304
269
cbp->stroke_width = MAX (width, 0.1);
305
270
cbp->stroke_linejoin = join;
306
271
cbp->stroke_linecap = cap;
272
cbp->dashes[0] = dash;
273
cbp->dashes[1] = gap;
308
275
sp_canvas_item_request_update (SP_CANVAS_ITEM (cbp));
314
bpath_run_A8_OR (raster_info &dest,void *data,int st,float vst,int en,float ven)
320
if ( st >= en ) return;
321
tempCol.col=*(uint32_t*)data;
323
unsigned int r, g, b, a;
324
r = NR_RGBA32_R (tempCol.col);
325
g = NR_RGBA32_G (tempCol.col);
326
b = NR_RGBA32_B (tempCol.col);
327
a = NR_RGBA32_A (tempCol.col);
333
if ( vst < 0 ) vst=0;
334
if ( vst > 255 ) vst=255;
335
if ( ven < 0 ) ven=0;
336
if ( ven > 255 ) ven=255;
340
uint8_t* d=(uint8_t*)dest.buffer;
342
d+=3*(st-dest.startPix);
343
if ( fabs(dv) < 0.001 ) {
344
if ( sv > 249.999 ) {
347
d[0] = NR_COMPOSEN11_1111 (r, 255, d[0]);
348
d[1] = NR_COMPOSEN11_1111 (g, 255, d[1]);
349
d[2] = NR_COMPOSEN11_1111 (b, 255, d[2]);
354
unsigned int c0_24=(int)sv;
357
d[0] = NR_COMPOSEN11_1111 (r, c0_24, d[0]);
358
d[1] = NR_COMPOSEN11_1111 (g, c0_24, d[1]);
359
d[2] = NR_COMPOSEN11_1111 (b, c0_24, d[2]);
367
unsigned int c0_24=(int)sv;
369
d[0] = NR_COMPOSEN11_1111 (r, c0_24, d[0]);
370
d[1] = NR_COMPOSEN11_1111 (g, c0_24, d[1]);
371
d[2] = NR_COMPOSEN11_1111 (b, c0_24, d[2]);
374
sv+=0.5*dv; // correction trapezoidale
377
int c0_24 = static_cast<int>(CLAMP(sv, 0, 16777216));
378
int s0_24 = static_cast<int>(dv);
383
if ( ca > 255 ) ca=255;
384
d[0] = NR_COMPOSEN11_1111 (r, ca, d[0]);
385
d[1] = NR_COMPOSEN11_1111 (g, ca, d[1]);
386
d[2] = NR_COMPOSEN11_1111 (b, ca, d[2]);
389
c0_24 = CLAMP (c0_24, 0, 16777216);
396
void nr_pixblock_render_bpath_rgba (Shape* theS,uint32_t color,NRRectL &area,char* destBuf,int stride)
400
float l=theS->leftX,r=theS->rightX,t=theS->topY,b=theS->bottomY;
407
if ( il >= area.x1 || ir <= area.x0 || it >= area.y1 || ib <= area.y0 ) return;
408
if ( il < area.x0 ) il=area.x0;
409
if ( it < area.y0 ) it=area.y0;
410
if ( ir > area.x1 ) ir=area.x1;
411
if ( ib > area.y1 ) ib=area.y1;
413
/* // version par FloatLigne
416
theS->BeginRaster(curY,curPt,1.0);
418
FloatLigne* theI=new FloatLigne();
419
IntLigne* theIL=new IntLigne();
421
theS->Scan(curY,curPt,(float)(it),1.0);
423
char* mdata=(char*)destBuf;
424
uint32_t* ligStart=((uint32_t*)(mdata+(3*(il-area.x0)+stride*(it-area.y0))));
425
for (int y=it;y<ib;y++) {
427
if ( y&0x00000003 ) {
428
theS->Scan(curY,curPt,((float)(y+1)),theI,false,1.0);
430
theS->Scan(curY,curPt,((float)(y+1)),theI,true,1.0);
440
dest.buffer=ligStart;
441
theIL->Raster(dest,&color,bpath_run_A8_OR);
442
ligStart=((uint32_t*)(((char*)ligStart)+stride));
448
// version par BitLigne directe
451
theS->BeginQuickRaster(curY, curPt);
454
for (int i=0;i<4;i++) theI[i]=new BitLigne(il,ir);
455
IntLigne* theIL=new IntLigne();
457
theS->DirectQuickScan(curY,curPt,(float)(it),true,0.25);
459
char* mdata=(char*)destBuf;
460
uint32_t* ligStart=((uint32_t*)(mdata+(3*(il-area.x0)+stride*(it-area.y0))));
461
for (int y=it;y<ib;y++) {
462
for (int i = 0; i < 4; i++)
465
for (int i = 0; i < 4; i++)
466
theS->QuickScan(curY, curPt, ((float)(y+0.25*(i+1))),
467
fill_oddEven, theI[i], 0.25);
470
// theI[0]->Affiche();
478
dest.buffer=ligStart;
479
theIL->Raster(dest,&color,bpath_run_A8_OR);
480
ligStart=((uint32_t*)(((char*)ligStart)+stride));
482
theS->EndQuickRaster();
483
for (int i=0;i<4;i++) delete theI[i];