From 2bb926c7d01e59466d663d7ef84cb758cdea3f63 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Fri, 11 Jan 2013 20:31:34 +0200 Subject: [PATCH] Fix webkit-gradient() parsing --- src/Generate.js | 4 ++-- src/Parse.js | 9 +++++---- src/Preload.js | 5 ++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Generate.js b/src/Generate.js index 007232a..eff6b0b 100644 --- a/src/Generate.js +++ b/src/Generate.js @@ -324,7 +324,7 @@ if(bounds.width === 0 || bounds.height === 0) { return; } - + var canvas = document.createElement('canvas'), ctx = canvas.getContext('2d'), gradient, grad, i, len; @@ -378,7 +378,7 @@ canvasRadial.width = canvasRadial.height = di; grad = ctxRadial.createRadialGradient(gradient.rx, gradient.ry, 0, gradient.rx, gradient.ry, ri); - + for (i = 0, len = gradient.colorStops.length; i < len; i+=1) { try { grad.addColorStop(gradient.colorStops[i].stop, gradient.colorStops[i].color); diff --git a/src/Parse.js b/src/Parse.js index 401a30c..85f2105 100644 --- a/src/Parse.js +++ b/src/Parse.js @@ -818,9 +818,10 @@ _html2canvas.Parse = function (images, options) { function renderBackgroundImage(element, bounds, ctx) { var backgroundImage = getCSS(element, "backgroundImage"), backgroundImages = _html2canvas.Util.parseBackgroundImage(backgroundImage), - image; + image, + imageIndex = backgroundImages.length; - for(var imageIndex = backgroundImages.length; imageIndex-- > 0;) { + while(imageIndex--) { backgroundImage = backgroundImages[imageIndex]; if (!backgroundImage.args || backgroundImage.args.length === 0) { @@ -829,7 +830,7 @@ _html2canvas.Parse = function (images, options) { var key = backgroundImage.method === 'url' ? backgroundImage.args[0] : - backgroundImage.value + '/' + element.__html2canvas__id + '/' + imageIndex; + backgroundImage.value; image = loadImage(key); @@ -837,7 +838,7 @@ _html2canvas.Parse = function (images, options) { if (image) { renderBackgroundRepeating(element, bounds, ctx, image, imageIndex); } else { - h2clog("html2canvas: Error loading background:" + backgroundImage); + h2clog("html2canvas: Error loading background:", backgroundImage); } } } diff --git a/src/Preload.js b/src/Preload.js index 92546fd..1313334 100644 --- a/src/Preload.js +++ b/src/Preload.js @@ -139,16 +139,15 @@ _html2canvas.Preload = function( options ) { src = background_image.args[0]; methods.loadImage(src); - } else if( background_image.method.match( /\-gradient$/ ) ) { + } else if( background_image.method.match( /\-?gradient$/ ) ) { if(bounds === undefined) { bounds = _html2canvas.Util.Bounds( el ); } - var key = background_image.value + '/' + el.__html2canvas__id + '/' + imageIndex; img = _html2canvas.Generate.Gradient( background_image.value, bounds); if ( img !== undefined ){ - images[ key ] = { + images[background_image.value] = { img: img, succeeded: true };