2011-11-16 03:25:02 +04:00
|
|
|
/*
|
|
|
|
html2canvas @VERSION@ <http://html2canvas.hertzen.com>
|
|
|
|
Copyright (c) 2011 Niklas von Hertzen. All rights reserved.
|
|
|
|
http://www.twitter.com/niklasvh
|
|
|
|
|
|
|
|
Released under MIT License
|
2012-03-03 21:18:39 +04:00
|
|
|
*/
|
2011-11-16 03:25:02 +04:00
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
_html2canvas.Generate = {};
|
2011-09-13 00:50:43 +04:00
|
|
|
|
2011-09-13 18:09:33 +04:00
|
|
|
|
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
_html2canvas.Generate.Gradient = function(src, bounds) {
|
2011-09-13 00:50:43 +04:00
|
|
|
var canvas = document.createElement('canvas'),
|
|
|
|
ctx = canvas.getContext('2d'),
|
|
|
|
tmp,
|
|
|
|
p0 = 0,
|
|
|
|
p1 = 0,
|
|
|
|
p2 = 0,
|
|
|
|
p3 = 0,
|
|
|
|
steps = [],
|
|
|
|
position,
|
|
|
|
i,
|
|
|
|
len,
|
|
|
|
lingrad,
|
|
|
|
increment,
|
|
|
|
p,
|
|
|
|
img;
|
|
|
|
|
|
|
|
canvas.width = bounds.width;
|
|
|
|
canvas.height = bounds.height;
|
|
|
|
|
2012-03-03 21:18:39 +04:00
|
|
|
|
2011-12-07 02:53:40 +04:00
|
|
|
function getColors(input) {
|
2011-09-13 00:50:43 +04:00
|
|
|
var j = -1,
|
|
|
|
color = '',
|
|
|
|
chr;
|
|
|
|
while( j++ < input.length ) {
|
|
|
|
chr = input.charAt( j );
|
|
|
|
if (chr === ')') {
|
2011-12-22 02:06:09 +04:00
|
|
|
color += chr;
|
2011-09-13 00:50:43 +04:00
|
|
|
steps.push( color );
|
|
|
|
color = '';
|
2012-03-02 20:05:03 +04:00
|
|
|
j = input.indexOf(",", j) + 1;
|
|
|
|
if (j === 0) {
|
|
|
|
break;
|
2011-12-22 02:06:09 +04:00
|
|
|
}
|
2012-03-02 20:05:03 +04:00
|
|
|
// while (j++ < input.length && input.charAt( j ) !== ',') {}
|
2011-12-22 02:06:09 +04:00
|
|
|
} else {
|
2011-09-13 00:50:43 +04:00
|
|
|
color += chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-03 21:18:39 +04:00
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
if ( (tmp = src.match(/-webkit-linear-gradient\((.*)\)/)) !== null ) {
|
2011-09-13 00:50:43 +04:00
|
|
|
|
|
|
|
position = tmp[1].split( ",", 1 )[0];
|
|
|
|
getColors( tmp[1].substr( position.length + 2 ) );
|
|
|
|
position = position.split(' ');
|
|
|
|
|
2012-03-02 23:53:20 +04:00
|
|
|
for ( p = 0, len = position.length; p < len; p+=1 ) {
|
2011-09-13 00:50:43 +04:00
|
|
|
|
2012-03-02 23:53:20 +04:00
|
|
|
switch( position[ p ] ) {
|
2011-09-13 00:50:43 +04:00
|
|
|
case 'top':
|
|
|
|
p3 = bounds.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'right':
|
|
|
|
p0 = bounds.width;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'bottom':
|
|
|
|
p1 = bounds.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'left':
|
|
|
|
p2 = bounds.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
} else if ( (tmp = src.match(/-webkit-gradient\(linear, (\d+)[%]{0,1} (\d+)[%]{0,1}, (\d+)[%]{0,1} (\d+)[%]{0,1}, from\((.*)\), to\((.*)\)\)/)) !== null ) {
|
2011-09-13 00:50:43 +04:00
|
|
|
|
|
|
|
p0 = (tmp[1] * bounds.width) / 100;
|
|
|
|
p1 = (tmp[2] * bounds.height) / 100;
|
|
|
|
p2 = (tmp[3] * bounds.width) / 100;
|
|
|
|
p3 = (tmp[4] * bounds.height) / 100;
|
|
|
|
|
|
|
|
steps.push(tmp[5]);
|
|
|
|
steps.push(tmp[6]);
|
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
} else if ( (tmp = src.match(/-moz-linear-gradient\((\d+)[%]{0,1} (\d+)[%]{0,1}, (.*)\)/)) !== null ) {
|
2011-09-13 00:50:43 +04:00
|
|
|
|
|
|
|
p0 = (tmp[1] * bounds.width) / 100;
|
|
|
|
p1 = (tmp[2] * bounds.width) / 100;
|
|
|
|
p2 = bounds.width - p0;
|
|
|
|
p3 = bounds.height - p1;
|
|
|
|
getColors( tmp[3] );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lingrad = ctx.createLinearGradient( p0, p1, p2, p3 );
|
|
|
|
increment = 1 / (steps.length - 1);
|
|
|
|
|
|
|
|
for (i = 0, len = steps.length; i < len; i+=1) {
|
2011-12-22 02:06:09 +04:00
|
|
|
try {
|
|
|
|
lingrad.addColorStop(increment * i, steps[i]);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2012-02-25 22:58:04 +04:00
|
|
|
h2clog(['failed to add color stop: ', e, '; tried to add: ', steps[i], '; stop: ', i, '; in: ', src]);
|
2011-12-22 02:06:09 +04:00
|
|
|
}
|
2011-09-13 00:50:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.fillStyle = lingrad;
|
|
|
|
|
|
|
|
// draw shapes
|
|
|
|
ctx.fillRect(0, 0, bounds.width,bounds.height);
|
|
|
|
|
|
|
|
img = new Image();
|
|
|
|
img.src = canvas.toDataURL();
|
|
|
|
|
|
|
|
return img;
|
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
};
|
2011-09-13 18:09:33 +04:00
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
_html2canvas.Generate.ListAlpha = function(number) {
|
2011-09-13 18:09:33 +04:00
|
|
|
var tmp = "",
|
|
|
|
modulus;
|
|
|
|
|
|
|
|
do {
|
|
|
|
modulus = number % 26;
|
|
|
|
tmp = String.fromCharCode((modulus) + 64) + tmp;
|
|
|
|
number = number / 26;
|
|
|
|
}while((number*26) > 26);
|
|
|
|
|
|
|
|
return tmp;
|
2012-03-02 20:05:03 +04:00
|
|
|
};
|
2011-09-13 18:09:33 +04:00
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
_html2canvas.Generate.ListRoman = function(number) {
|
2011-09-13 18:09:33 +04:00
|
|
|
var romanArray = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"],
|
|
|
|
decimal = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],
|
|
|
|
roman = "",
|
|
|
|
v,
|
|
|
|
len = romanArray.length;
|
|
|
|
|
|
|
|
if (number <= 0 || number >= 4000) {
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (v=0; v < len; v+=1) {
|
|
|
|
while (number >= decimal[v]) {
|
|
|
|
number -= decimal[v];
|
|
|
|
roman += romanArray[v];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return roman;
|
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
};
|