344 |
344 |
*/
|
345 |
345 |
function DotsPathRenderer(canvasRenderer, basicStroke, strokeColor)
|
346 |
346 |
{
|
347 |
|
var pixel = canvasRenderer.createImageData(1, 1);
|
|
347 |
var state = {};
|
|
348 |
var width = basicStroke.getWidth();
|
|
349 |
var pixel = canvasRenderer.createImageData(width, width);
|
348 |
350 |
var pixelData = pixel.data;
|
349 |
|
pixelData[3] = 0xFF;
|
350 |
|
var state = {};
|
351 |
|
var color = strokeColor.concat([255]);
|
352 |
|
var width = basicStroke.getWidth();
|
|
351 |
|
|
352 |
var length = 4 * width * width;
|
|
353 |
|
|
354 |
// Fill a line image with the given stroke color
|
|
355 |
pixelData[0] = strokeColor[0];
|
|
356 |
pixelData[1] = strokeColor[1];
|
|
357 |
pixelData[2] = strokeColor[2];
|
|
358 |
pixelData[3] = 255;
|
|
359 |
|
|
360 |
var pos = 4;
|
|
361 |
var seqLen = 4;
|
|
362 |
while(pos < length)
|
|
363 |
{
|
|
364 |
pixelData.copyWithin(pos, 0, seqLen);
|
|
365 |
// increment position by the length of the current segment
|
|
366 |
pos += seqLen;
|
|
367 |
// double the length of the next segment
|
|
368 |
seqLen <<= 1;
|
|
369 |
}
|
353 |
370 |
|
354 |
371 |
/**
|
355 |
372 |
* Normalizes a dash offset distance according to the given dash pattern.
|
... | ... | |
437 |
454 |
var x = x1;
|
438 |
455 |
var y = y1;
|
439 |
456 |
var triangles = [];
|
440 |
|
var dots = [];
|
441 |
|
var a;
|
442 |
|
var b;
|
443 |
457 |
// precondition: y2 should be greater or equal than y1.
|
444 |
458 |
while(x <= x2 && y <= y2)
|
445 |
459 |
{
|
... | ... | |
448 |
462 |
idx = (idx + 1) % len;
|
449 |
463 |
rest = state.dash[idx];
|
450 |
464 |
dashOn = !dashOn;
|
451 |
|
if (dots.length > 0)
|
452 |
|
{
|
453 |
|
a = dots[0];
|
454 |
|
b = dots.pop();
|
455 |
|
dots.length = 0;
|
456 |
|
if (dx === 0)
|
457 |
|
{
|
458 |
|
triangles.push([a.x, a.y, a.x + width, a.y, b.x, b.y, color[0], color[1], color[2], color[3]]);
|
459 |
|
triangles.push([b.x, b.y, b.x + width, b.y, a.x + width, a.y, color[0], color[1], color[2], color[3]]);
|
460 |
|
}
|
461 |
|
else
|
462 |
|
{
|
463 |
|
triangles.push([a.x, a.y, a.x, a.y + width, b.x, b.y, color[0], color[1], color[2], color[3]]);
|
464 |
|
triangles.push([b.x, b.y, b.x, b.y + width, a.x, a.y + width, color[0], color[1], color[2], color[3]]);
|
465 |
|
}
|
466 |
|
}
|
467 |
465 |
}
|
468 |
466 |
rest -= 1;
|
469 |
467 |
|
470 |
468 |
if (dashOn)
|
471 |
469 |
{
|
472 |
|
dots.push({x:x,y:y});
|
473 |
|
// fill a pixel and put it on the canvas.
|
474 |
|
// pixelData[0] = strokeColor[0];
|
475 |
|
// pixelData[1] = strokeColor[1];
|
476 |
|
// pixelData[2] = strokeColor[2];
|
477 |
|
|
478 |
|
// TODO
|
479 |
|
//canvasRenderer.putImageData(pixel, x, y);
|
|
470 |
canvasRenderer.drawImage(x, y, width, width, pixelData);
|
480 |
471 |
}
|
481 |
472 |
// vertical line: increase Y-coordinate
|
482 |
473 |
if (dx === 0)
|
... | ... | |
519 |
510 |
rest -= 1;
|
520 |
511 |
if (dashOn)
|
521 |
512 |
{
|
522 |
|
// fill a pixel and put it on the canvas.
|
523 |
|
pixelData[0] = strokeColor[0];
|
524 |
|
pixelData[1] = strokeColor[1];
|
525 |
|
pixelData[2] = strokeColor[2];
|
526 |
|
|
527 |
|
// TODO
|
528 |
|
//canvasRenderer.putImageData(pixel, x, y);
|
|
513 |
canvasRenderer.drawImage(x, y, width, width, pixelData);
|
529 |
514 |
}
|
530 |
515 |
// save the dash pattern state in order to continue this dash pattern for next drawings
|
531 |
516 |
state.dashOn = dashOn;
|