faster imeplementation of 0d370d09f

also added try/catch around that addColourStop call
because trowing an exception and failing to finish
the rendering is not nice...
This commit is contained in:
Obexer Christoph 2011-12-21 23:06:09 +01:00
parent 447db0c5f5
commit 594f735d29

View File

@ -39,20 +39,17 @@ html2canvas.Generate.Gradient = function(src, bounds) {
while( j++ < input.length ) {
chr = input.charAt( j );
if (chr === ')') {
color += chr;
color += chr;
steps.push( color );
color = '';
j+=2;
} else if (color || isValidColorStartChar(chr)) {
while (j++ < input.length && input.charAt( j ) !== ',') {
}
} else {
color += chr;
}
}
}
function isValidColorStartChar(c) {
return c && /[^0-9%,]/.test(c);
}
if ( tmp = src.match(/-webkit-linear-gradient\((.*)\)/) ) {
position = tmp[1].split( ",", 1 )[0];
@ -107,7 +104,12 @@ html2canvas.Generate.Gradient = function(src, bounds) {
increment = 1 / (steps.length - 1);
for (i = 0, len = steps.length; i < len; i+=1) {
lingrad.addColorStop(increment * i, steps[i]);
try {
lingrad.addColorStop(increment * i, steps[i]);
}
catch(e) {
html2canvas.log(['failed to add color stop: ', e, '; tried to add: ', steps[i], '; stop: ', i, '; in: ', src]);
}
}
ctx.fillStyle = lingrad;