/** * CanvasRenderer */ ( function( root, factory ) { // module definition if ( typeof module == 'object' && module.exports ) { // CommonJS module.exports = factory(); } else { // browser global root.Zdog.CanvasRenderer = factory(); } }( this, function factory() { var CanvasRenderer = { isCanvas: true }; CanvasRenderer.begin = function( ctx ) { ctx.beginPath(); }; CanvasRenderer.move = function( ctx, elem, point ) { ctx.moveTo( point.x, point.y ); }; CanvasRenderer.line = function( ctx, elem, point ) { ctx.lineTo( point.x, point.y ); }; CanvasRenderer.bezier = function( ctx, elem, cp0, cp1, end ) { ctx.bezierCurveTo( cp0.x, cp0.y, cp1.x, cp1.y, end.x, end.y ); }; CanvasRenderer.closePath = function( ctx ) { ctx.closePath(); }; CanvasRenderer.setPath = function() {}; CanvasRenderer.renderPath = function( ctx, elem, pathCommands, isClosed ) { this.begin( ctx, elem ); pathCommands.forEach( function( command ) { command.render( ctx, elem, CanvasRenderer ); } ); if ( isClosed ) { this.closePath( ctx, elem ); } }; CanvasRenderer.stroke = function( ctx, elem, isStroke, color, lineWidth ) { if ( !isStroke ) { return; } ctx.lineWidth = lineWidth; if (color && color.getCanvasFill) { ctx.save(); ctx.strokeStyle = color.getCanvasFill(ctx); ctx.stroke(); ctx.restore(); } else { ctx.strokeStyle = color; ctx.stroke(); } }; CanvasRenderer.fill = function( ctx, elem, isFill, color ) { if ( !isFill ) { return; } if (color && color.getCanvasFill) { ctx.save(); ctx.fillStyle = color.getCanvasFill(ctx); ctx.fill(); ctx.restore(); } else { ctx.fillStyle = color; ctx.fill(); } }; CanvasRenderer.end = function() {}; return CanvasRenderer; } ) );