mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
rebuilt source
This commit is contained in:
parent
ea966da911
commit
f1f15bb92d
@ -46,7 +46,9 @@ function html2canvas(el, userOptions) {
|
||||
iframeDefault: "default",
|
||||
flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",
|
||||
renderViewport: false,
|
||||
reorderZ: true
|
||||
reorderZ: true,
|
||||
throttle:true,
|
||||
renderOrder: "canvas flash html"
|
||||
});
|
||||
|
||||
this.element = el;
|
||||
@ -68,16 +70,40 @@ function html2canvas(el, userOptions) {
|
||||
|
||||
this.ignoreRe = new RegExp("("+this.ignoreElements+")");
|
||||
|
||||
// test how to measure text bounding boxes
|
||||
this.useRangeBounds = false;
|
||||
|
||||
// Check disabled as Opera doesn't provide bounds.height/bottom even though it supports the method.
|
||||
// TODO take the check back into use, but fix the issue for Opera
|
||||
/*
|
||||
this.support = {
|
||||
rangeBounds: false
|
||||
|
||||
};
|
||||
|
||||
// Test whether we can use ranges to measure bounding boxes
|
||||
// Opera doesn't provide valid bounds.height/bottom even though it supports the method.
|
||||
|
||||
|
||||
if (document.createRange){
|
||||
var r = document.createRange();
|
||||
this.useRangeBounds = new Boolean(r.getBoundingClientRect);
|
||||
}*/
|
||||
//this.support.rangeBounds = new Boolean(r.getBoundingClientRect);
|
||||
if (r.getBoundingClientRect){
|
||||
var testElement = document.createElement('boundtest');
|
||||
testElement.style.height = "123px";
|
||||
testElement.style.display = "block";
|
||||
document.getElementsByTagName('body')[0].appendChild(testElement);
|
||||
|
||||
r.selectNode(testElement);
|
||||
var rangeBounds = r.getBoundingClientRect();
|
||||
var rangeHeight = rangeBounds.height;
|
||||
|
||||
if (rangeHeight==123){
|
||||
this.support.rangeBounds = true;
|
||||
}
|
||||
document.getElementsByTagName('body')[0].removeChild(testElement);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Start script
|
||||
this.init();
|
||||
@ -91,7 +117,7 @@ function html2canvas(el, userOptions) {
|
||||
html2canvas.prototype.init = function(){
|
||||
|
||||
var _ = this;
|
||||
|
||||
/*
|
||||
this.ctx = new this.stackingContext($(document).width(),$(document).height());
|
||||
|
||||
if (!this.ctx){
|
||||
@ -101,7 +127,7 @@ html2canvas.prototype.init = function(){
|
||||
}
|
||||
|
||||
this.canvas = this.ctx.canvas;
|
||||
|
||||
*/
|
||||
this.log('Finding background images');
|
||||
|
||||
this.getImages(this.element);
|
||||
@ -129,15 +155,13 @@ html2canvas.prototype.start = function(){
|
||||
this.log('Started parsing');
|
||||
this.bodyOverflow = document.getElementsByTagName('body')[0].style.overflow;
|
||||
document.getElementsByTagName('body')[0].style.overflow = "hidden";
|
||||
var rootStack = new this.storageContext($(document).width(),$(document).height());
|
||||
rootStack.opacity = this.getCSS(this.element,"opacity");
|
||||
var stack = this.newElement(this.element,rootStack);
|
||||
|
||||
var stack = this.newElement(this.element,{
|
||||
ctx:this.ctx,
|
||||
opacity:this.getCSS(this.element,"opacity")
|
||||
|
||||
}) || this.ctx;
|
||||
}
|
||||
|
||||
this.parseElement(this.element,stack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -145,9 +169,9 @@ html2canvas.prototype.start = function(){
|
||||
html2canvas.prototype.stackingContext = function(width,height){
|
||||
this.canvas = document.createElement('canvas');
|
||||
|
||||
// TODO remove jQuery dependency
|
||||
this.canvas.width = $(document).width();
|
||||
this.canvas.height = $(document).height();
|
||||
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = width;
|
||||
|
||||
if (!this.canvas.getContext){
|
||||
|
||||
@ -178,8 +202,9 @@ html2canvas.prototype.stackingContext = function(width,height){
|
||||
|
||||
html2canvas.prototype.storageContext = function(width,height){
|
||||
this.storage = [];
|
||||
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
//this.zIndex;
|
||||
|
||||
// todo simplify this whole section
|
||||
this.fillRect = function(x, y, w, h){
|
||||
@ -221,9 +246,11 @@ html2canvas.prototype.storageContext = function(width,height){
|
||||
*/
|
||||
|
||||
html2canvas.prototype.finish = function(){
|
||||
this.log("Finished rendering");
|
||||
document.getElementsByTagName('body')[0].style.overflow = this.bodyOverflow;
|
||||
|
||||
this.log("Finished rendering");
|
||||
|
||||
document.getElementsByTagName('body')[0].style.overflow = this.bodyOverflow;
|
||||
/*
|
||||
if (this.opts.renderViewport){
|
||||
// let's crop it to viewport only then
|
||||
var newCanvas = document.createElement('canvas');
|
||||
@ -231,7 +258,7 @@ html2canvas.prototype.finish = function(){
|
||||
newCanvas.width = window.innerWidth;
|
||||
newCanvas.height = window.innerHeight;
|
||||
|
||||
}
|
||||
}*/
|
||||
this.opts.ready(this);
|
||||
}
|
||||
|
||||
@ -343,8 +370,8 @@ html2canvas.prototype.backgroundImageUrl = function(src){
|
||||
*/
|
||||
|
||||
html2canvas.prototype.getBackgroundPosition = function(el,bounds,image){
|
||||
|
||||
var bgposition = this.getCSS(el,"background-position").split(" "),
|
||||
var bgpos = this.getCSS(el,"backgroundPosition") || "0 0";
|
||||
var bgposition = bgpos.split(" "),
|
||||
top,
|
||||
left,
|
||||
percentage;
|
||||
@ -475,44 +502,13 @@ html2canvas.prototype.getBorderData = function(el){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
html2canvas.prototype.newElement = function(el,parentStack){
|
||||
|
||||
var bounds = this.getBounds(el);
|
||||
|
||||
var x = bounds.left;
|
||||
var y = bounds.top;
|
||||
var w = bounds.width;
|
||||
var h = bounds.height;
|
||||
var _ = this,
|
||||
image;
|
||||
var bgcolor = this.getCSS(el,"background-color");
|
||||
|
||||
var zindex = this.formatZ(this.getCSS(el,"z-index"),this.getCSS(el,"position"),parentStack.zIndex,el.parentNode);
|
||||
|
||||
//console.log(el.nodeName+":"+zindex+":"+this.getCSS(el,"position")+":"+this.numDraws+":"+this.getCSS(el,"z-index"))
|
||||
|
||||
var opacity = this.getCSS(el,"opacity");
|
||||
|
||||
|
||||
var stack = {
|
||||
ctx: new this.storageContext(),
|
||||
zIndex: zindex,
|
||||
opacity: opacity*parentStack.opacity
|
||||
};
|
||||
|
||||
var stackLength = this.contextStacks.push(stack);
|
||||
|
||||
var ctx = this.contextStacks[stackLength-1].ctx;
|
||||
|
||||
this.setContextVariable(ctx,"globalAlpha",stack.opacity);
|
||||
html2canvas.prototype.drawBorders = function(el,ctx, x, y, w, h){
|
||||
|
||||
/*
|
||||
* TODO add support for different border-style's than solid
|
||||
*/
|
||||
var borders = this.getBorderData(el);
|
||||
var _ = this;
|
||||
|
||||
this.each(borders,function(borderSide,borderData){
|
||||
if (borderData.width>0){
|
||||
@ -549,6 +545,50 @@ html2canvas.prototype.newElement = function(el,parentStack){
|
||||
|
||||
});
|
||||
|
||||
return borders;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
html2canvas.prototype.newElement = function(el,parentStack){
|
||||
|
||||
var bounds = this.getBounds(el);
|
||||
|
||||
var x = bounds.left;
|
||||
var y = bounds.top;
|
||||
var w = bounds.width;
|
||||
var h = bounds.height;
|
||||
var _ = this,
|
||||
image;
|
||||
var bgcolor = this.getCSS(el,"background-color");
|
||||
|
||||
|
||||
parentStack = parentStack || {};
|
||||
|
||||
var zindex = this.formatZ(this.getCSS(el,"zIndex"),this.getCSS(el,"position"),parentStack.zIndex,el.parentNode);
|
||||
|
||||
//console.log(el.nodeName+":"+zindex+":"+this.getCSS(el,"position")+":"+this.numDraws+":"+this.getCSS(el,"z-index"))
|
||||
|
||||
var opacity = this.getCSS(el,"opacity");
|
||||
|
||||
|
||||
var stack = {
|
||||
ctx: new this.storageContext(),
|
||||
zIndex: zindex,
|
||||
opacity: opacity*parentStack.opacity
|
||||
};
|
||||
|
||||
var stackLength = this.contextStacks.push(stack);
|
||||
|
||||
var ctx = this.contextStacks[stackLength-1].ctx;
|
||||
|
||||
this.setContextVariable(ctx,"globalAlpha",stack.opacity);
|
||||
|
||||
// draw element borders
|
||||
var borders = this.drawBorders(el, ctx, bounds.left, bounds.top, bounds.width, bounds.height);
|
||||
|
||||
|
||||
if (this.ignoreRe.test(el.nodeName) && this.opts.iframeDefault != "transparent"){
|
||||
@ -687,7 +727,7 @@ html2canvas.prototype.getImages = function(el) {
|
||||
|
||||
html2canvas.prototype.loadImage = function(src){
|
||||
|
||||
var imgIndex = this.images.indexOf(src);
|
||||
var imgIndex = this.getIndex(this.images,src);
|
||||
if (imgIndex!=-1){
|
||||
return this.images[imgIndex+1];
|
||||
}else{
|
||||
@ -698,9 +738,12 @@ html2canvas.prototype.loadImage = function(src){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
html2canvas.prototype.preloadImage = function(src){
|
||||
|
||||
if (this.images.indexOf(src)==-1){
|
||||
|
||||
if (this.getIndex(this.images,src)==-1){
|
||||
this.images.push(src);
|
||||
|
||||
var img = new Image();
|
||||
@ -723,6 +766,69 @@ html2canvas.prototype.preloadImage = function(src){
|
||||
|
||||
}
|
||||
|
||||
html2canvas.prototype.Renderer = function(queue){
|
||||
|
||||
var _ = this;
|
||||
|
||||
this.each(this.opts.renderOrder.split(" "),function(i,renderer){
|
||||
|
||||
switch(renderer){
|
||||
case "canvas":
|
||||
_.canvas = document.createElement('canvas');
|
||||
if (_.canvas.getContext){
|
||||
_.canvasRenderer(queue);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case "flash":
|
||||
/*
|
||||
var script = document.createElement('script');
|
||||
script.type = "text/javascript";
|
||||
script.src = _.opts.flashCanvasPath;
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(script, s);
|
||||
|
||||
|
||||
if (typeof FlashCanvas != "undefined") {
|
||||
_.canvas = document.createElement('canvas');
|
||||
FlashCanvas.initElement(_.canvas);
|
||||
_.canvasRenderer(queue);
|
||||
return false;
|
||||
} */
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
// this.canvasRenderer(queue);
|
||||
|
||||
/*
|
||||
if (!this.canvas.getContext){
|
||||
|
||||
|
||||
}*/
|
||||
// TODO include Flashcanvas
|
||||
/*
|
||||
var script = document.createElement('script');
|
||||
script.type = "text/javascript";
|
||||
script.src = this.opts.flashCanvasPath;
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(script, s);
|
||||
|
||||
if (typeof FlashCanvas != "undefined") {
|
||||
|
||||
FlashCanvas.initElement(this.canvas);
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
html2canvas.prototype.canvasRenderer = function(queue){
|
||||
@ -730,6 +836,20 @@ html2canvas.prototype.canvasRenderer = function(queue){
|
||||
|
||||
queue = this.sortQueue(queue);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.canvas.width = $(document).width();
|
||||
this.canvas.height = $(document).height();
|
||||
|
||||
this.ctx = this.canvas.getContext("2d");
|
||||
|
||||
// set common settings for canvas
|
||||
this.ctx.textBaseline = "bottom";
|
||||
|
||||
|
||||
|
||||
this.each(queue,function(i,storageContext){
|
||||
|
||||
if (storageContext.ctx.storage){
|
||||
@ -884,7 +1004,7 @@ html2canvas.prototype.newText = function(el,textNode,ctx){
|
||||
for(var c=0;c<text.length;c++){
|
||||
var newTextNode = oldTextNode.splitText(1);
|
||||
|
||||
if (this.useRangeBounds){
|
||||
if (this.support.rangeBounds){
|
||||
// getBoundingClientRect is supported for ranges
|
||||
if (document.createRange){
|
||||
var range = document.createRange();
|
||||
@ -1067,7 +1187,7 @@ html2canvas.prototype.parseElement = function(element,stack){
|
||||
_.parsing(el,stack);
|
||||
});
|
||||
|
||||
this.canvasRenderer(this.contextStacks);
|
||||
this.Renderer(this.contextStacks);
|
||||
this.finish();
|
||||
}
|
||||
|
||||
@ -1181,7 +1301,7 @@ html2canvas.prototype.getBounds = function(el){
|
||||
html2canvas.prototype.each = function(arrayLoop,callbackFunc){
|
||||
callbackFunc = callbackFunc || function(){};
|
||||
for (var i=0;i<arrayLoop.length;i++){
|
||||
callbackFunc(i,arrayLoop[i]);
|
||||
if (callbackFunc(i,arrayLoop[i]) === false) return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1278,3 +1398,17 @@ html2canvas.prototype.getContents = function(el){
|
||||
html2canvas.prototype.getCSS = function(el,attribute){
|
||||
return $(el).css(attribute);
|
||||
}
|
||||
|
||||
|
||||
html2canvas.prototype.getIndex = function(array,src){
|
||||
|
||||
if (array.indexOf){
|
||||
return array.indexOf(src);
|
||||
}else{
|
||||
for(var i = 0; i < array.length; i++){
|
||||
if(this[i] == src) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
47
build/html2canvas.min.js
vendored
47
build/html2canvas.min.js
vendored
@ -6,37 +6,40 @@
|
||||
* Released under MIT License
|
||||
*/
|
||||
|
||||
function html2canvas(a,b){this.opts=this.extendObj(b||{},{logging:!1,ready:function(a){document.body.appendChild(a.canvas)},iframeDefault:"default",flashCanvasPath:"http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",renderViewport:!1,reorderZ:!0});this.element=a;this.imagesLoaded=0;this.images=[];this.fontData=[];this.numDraws=0;this.contextStacks=[];this.ignoreElements="IFRAME|OBJECT|PARAM";this.needReorder=!1;this.blockElements=/(BR|PARAM)/;this.ignoreRe=RegExp("("+this.ignoreElements+
|
||||
")");this.useRangeBounds=!1;this.init();return this}html2canvas.prototype.init=function(){var a=this;(this.ctx=new this.stackingContext($(document).width(),$(document).height()))?(this.canvas=this.ctx.canvas,this.log("Finding background images"),this.getImages(this.element),this.log("Finding images"),this.each(document.images,function(b,c){a.preloadImage(a.getAttr(c,"src"))}),this.images.length==0&&this.start()):this.log("Canvas not available")};
|
||||
html2canvas.prototype.start=function(){if(this.images.length==0||this.imagesLoaded==this.images.length/2){this.log("Started parsing");this.bodyOverflow=document.getElementsByTagName("body")[0].style.overflow;document.getElementsByTagName("body")[0].style.overflow="hidden";var a=this.newElement(this.element,{ctx:this.ctx,opacity:this.getCSS(this.element,"opacity")})||this.ctx}this.parseElement(this.element,a)};
|
||||
html2canvas.prototype.stackingContext=function(){this.canvas=document.createElement("canvas");this.canvas.width=$(document).width();this.canvas.height=$(document).height();if(this.canvas.getContext)this.ctx=this.canvas.getContext("2d");this.ctx.textBaseline="bottom";return this.ctx};
|
||||
html2canvas.prototype.storageContext=function(){this.storage=[];this.fillRect=function(a,b,c,d){this.storage.push({type:"function",name:"fillRect",arguments:[a,b,c,d]})};this.drawImage=function(a,b,c,d,e,g,f,i,h){this.storage.push({type:"function",name:"drawImage",arguments:[a,b,c,d,e,g,f,i,h]})};this.fillText=function(a,b,c){this.storage.push({type:"function",name:"fillText",arguments:[a,b,c]})};return this};
|
||||
html2canvas.prototype.finish=function(){this.log("Finished rendering");document.getElementsByTagName("body")[0].style.overflow=this.bodyOverflow;if(this.opts.renderViewport){var a=document.createElement("canvas");a.getContext("2d");a.width=window.innerWidth;a.height=window.innerHeight}this.opts.ready(this)};
|
||||
function html2canvas(a,b){this.opts=this.extendObj(b||{},{logging:!1,ready:function(a){document.body.appendChild(a.canvas)},iframeDefault:"default",flashCanvasPath:"http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",renderViewport:!1,reorderZ:!0,throttle:!0,renderOrder:"canvas flash html"});this.element=a;this.imagesLoaded=0;this.images=[];this.fontData=[];this.numDraws=0;this.contextStacks=[];this.ignoreElements="IFRAME|OBJECT|PARAM";this.needReorder=!1;this.blockElements=/(BR|PARAM)/;
|
||||
this.ignoreRe=RegExp("("+this.ignoreElements+")");this.support={rangeBounds:!1};if(document.createRange){var c=document.createRange();if(c.getBoundingClientRect){var d=document.createElement("boundtest");d.style.height="123px";d.style.display="block";document.getElementsByTagName("body")[0].appendChild(d);c.selectNode(d);if(c.getBoundingClientRect().height==123)this.support.rangeBounds=!0;document.getElementsByTagName("body")[0].removeChild(d)}}this.init();return this}
|
||||
html2canvas.prototype.init=function(){var a=this;this.log("Finding background images");this.getImages(this.element);this.log("Finding images");this.each(document.images,function(b,c){a.preloadImage(a.getAttr(c,"src"))});this.images.length==0&&this.start()};
|
||||
html2canvas.prototype.start=function(){if(this.images.length==0||this.imagesLoaded==this.images.length/2){this.log("Started parsing");this.bodyOverflow=document.getElementsByTagName("body")[0].style.overflow;document.getElementsByTagName("body")[0].style.overflow="hidden";var a=new this.storageContext($(document).width(),$(document).height());a.opacity=this.getCSS(this.element,"opacity");this.parseElement(this.element,this.newElement(this.element,a))}};
|
||||
html2canvas.prototype.stackingContext=function(a){this.canvas=document.createElement("canvas");this.canvas.width=a;this.canvas.height=a;if(this.canvas.getContext)this.ctx=this.canvas.getContext("2d");this.ctx.textBaseline="bottom";return this.ctx};
|
||||
html2canvas.prototype.storageContext=function(a,b){this.storage=[];this.width=a;this.height=b;this.fillRect=function(a,b,e,g){this.storage.push({type:"function",name:"fillRect",arguments:[a,b,e,g]})};this.drawImage=function(a,b,e,g,f,k,h,j,i){this.storage.push({type:"function",name:"drawImage",arguments:[a,b,e,g,f,k,h,j,i]})};this.fillText=function(a,b,e){this.storage.push({type:"function",name:"fillText",arguments:[a,b,e]})};return this};
|
||||
html2canvas.prototype.finish=function(){this.log("Finished rendering");document.getElementsByTagName("body")[0].style.overflow=this.bodyOverflow;this.opts.ready(this)};
|
||||
html2canvas.prototype.drawBackground=function(a,b,c){var d=this.getCSS(a,"background-image"),e=this.getCSS(a,"background-repeat");if(typeof d!="undefined"&&/^(1|none)$/.test(d)==!1){var d=this.backgroundImageUrl(d),g=this.loadImage(d),a=this.getBackgroundPosition(a,b,g);if(g)switch(e){case "repeat-x":this.drawbackgroundRepeatX(c,g,a,b.left,b.top,b.width,b.height);break;case "repeat-y":this.drawbackgroundRepeatY(c,g,a,b.left,b.top,b.width,b.height);break;case "no-repeat":this.drawBackgroundRepeat(c,
|
||||
g,a.left+b.left,a.top+b.top,Math.min(b.width,g.width),Math.min(b.height,g.height),b.left,b.top);break;default:var f;a.top-=Math.ceil(a.top/g.height)*g.height;for(d=b.top+a.top;d<b.height+b.top;)e=Math.min(g.height,b.height+b.top-d),e=Math.floor(d+g.height)>e+d?e+d-d:g.height,d<b.top?(f=b.top-d,d=b.top):f=0,this.drawbackgroundRepeatX(c,g,a,b.left,d,b.width,e),f>0&&(a.top+=f),d=Math.floor(d+g.height)-f}else this.log("Error loading background:"+d)}};
|
||||
html2canvas.prototype.backgroundImageUrl=function(a){a.substr(0,5)=='url("'?(a=a.substr(5),a=a.substr(0,a.length-2)):(a=a.substr(4),a=a.substr(0,a.length-1));return a};
|
||||
html2canvas.prototype.getBackgroundPosition=function(a,b,c){var a=this.getCSS(a,"background-position").split(" "),d,e;a.length==1&&(d=a,a=[],a[0]=d,a[1]=d);a[0].toString().indexOf("%")!=-1?(e=parseFloat(a[0])/100,d=b.width*e-c.width*e):d=parseInt(a[0],10);a[1].toString().indexOf("%")!=-1?(e=parseFloat(a[1])/100,b=b.height*e-c.height*e):b=parseInt(a[1],10);return{top:b,left:d}};
|
||||
html2canvas.prototype.drawbackgroundRepeatY=function(a,b,c,d,e,g,f){var i=Math.min(b.width,g),h;c.top-=Math.ceil(c.top/b.height)*b.height;for(h=e+c.top;h<f+e;)g=Math.floor(h+b.height)>f+e?f+e-h:b.height,this.drawBackgroundRepeat(a,b,d+c.left,h,i,g,d,e),h=Math.floor(h+b.height)};
|
||||
html2canvas.prototype.drawbackgroundRepeatX=function(a,b,c,d,e,g,f){var f=Math.min(b.height,f),i,h;c.left-=Math.ceil(c.left/b.width)*b.width;for(h=d+c.left;h<g+d;)i=Math.floor(h+b.width)>g+d?g+d-h:b.width,this.drawBackgroundRepeat(a,b,h,e+c.top,i,f,d,e),h=Math.floor(h+b.width)};html2canvas.prototype.drawBackgroundRepeat=function(a,b,c,d,e,g,f,i){var h=0,k=0;f-c>0&&(h=f-c);i-d>0&&(k=i-d);this.drawImage(a,b,h,k,e-h,g-k,c+h,d+k,e-h,g-k)};
|
||||
html2canvas.prototype.getBackgroundPosition=function(a,b,c){var a=(this.getCSS(a,"backgroundPosition")||"0 0").split(" "),d,e;a.length==1&&(d=a,a=[],a[0]=d,a[1]=d);a[0].toString().indexOf("%")!=-1?(e=parseFloat(a[0])/100,d=b.width*e-c.width*e):d=parseInt(a[0],10);a[1].toString().indexOf("%")!=-1?(e=parseFloat(a[1])/100,b=b.height*e-c.height*e):b=parseInt(a[1],10);return{top:b,left:d}};
|
||||
html2canvas.prototype.drawbackgroundRepeatY=function(a,b,c,d,e,g,f){var k=Math.min(b.width,g),h;c.top-=Math.ceil(c.top/b.height)*b.height;for(h=e+c.top;h<f+e;)g=Math.floor(h+b.height)>f+e?f+e-h:b.height,this.drawBackgroundRepeat(a,b,d+c.left,h,k,g,d,e),h=Math.floor(h+b.height)};
|
||||
html2canvas.prototype.drawbackgroundRepeatX=function(a,b,c,d,e,g,f){var f=Math.min(b.height,f),k,h;c.left-=Math.ceil(c.left/b.width)*b.width;for(h=d+c.left;h<g+d;)k=Math.floor(h+b.width)>g+d?g+d-h:b.width,this.drawBackgroundRepeat(a,b,h,e+c.top,k,f,d,e),h=Math.floor(h+b.width)};html2canvas.prototype.drawBackgroundRepeat=function(a,b,c,d,e,g,f,k){var h=0,j=0;f-c>0&&(h=f-c);k-d>0&&(j=k-d);this.drawImage(a,b,h,j,e-h,g-j,c+h,d+j,e-h,g-j)};
|
||||
html2canvas.prototype.getBorderData=function(a){var b=[],c=this;this.each(["top","right","bottom","left"],function(d,e){b.push({width:parseInt(c.getCSS(a,"border-"+e+"-width"),10),color:c.getCSS(a,"border-"+e+"-color")})});return b};
|
||||
html2canvas.prototype.newElement=function(a,b){var c=this.getBounds(a),d=c.left,e=c.top,g=c.width,f=c.height,i=this,h;h=this.getCSS(a,"background-color");var k=this.formatZ(this.getCSS(a,"z-index"),this.getCSS(a,"position"),b.zIndex,a.parentNode),l=this.getCSS(a,"opacity"),l={ctx:new this.storageContext,zIndex:k,opacity:l*b.opacity},k=this.contextStacks.push(l),m=this.contextStacks[k-1].ctx;this.setContextVariable(m,"globalAlpha",l.opacity);var j=this.getBorderData(a);this.each(j,function(a,b){if(b.width>
|
||||
0){var c=d,h=e,k=g,l=f-j[2].width;switch(a){case 0:l=j[0].width;break;case 1:c=d+g-j[1].width;k=j[1].width;break;case 2:h=h+f-j[2].width;l=j[2].width;break;case 3:k=j[3].width}i.newRect(m,c,h,k,l,b.color)}});this.ignoreRe.test(a.nodeName)&&this.opts.iframeDefault!="transparent"&&(h=this.opts.iframeDefault=="default"?"#efefef":this.opts.iframeDefault);this.newRect(m,d+j[3].width,e+j[0].width,g-(j[1].width+j[3].width),f-(j[0].width+j[2].width),h);this.drawBackground(a,{left:d+j[3].width,top:e+j[0].width,
|
||||
width:g-(j[1].width+j[3].width),height:f-(j[0].width+j[2].width)},m);a.nodeName=="IMG"&&((h=i.loadImage(i.getAttr(a,"src")))?this.drawImage(m,h,0,0,h.width,h.height,d+parseInt(i.getCSS(a,"padding-left"),10)+j[3].width,e+parseInt(i.getCSS(a,"padding-top"),10)+j[0].width,c.width-(j[1].width+j[3].width+parseInt(i.getCSS(a,"padding-left"),10)+parseInt(i.getCSS(a,"padding-right"),10)),c.height-(j[0].width+j[2].width+parseInt(i.getCSS(a,"padding-top"),10)+parseInt(i.getCSS(a,"padding-bottom"),10))):this.log("Error loading <img>:"+
|
||||
i.getAttr(a,"src")));return this.contextStacks[k-1]};html2canvas.prototype.printText=function(a,b,c,d){this.trim(a).length>0&&(d.fillText(a,b,c),this.numDraws++)};html2canvas.prototype.newRect=function(a,b,c,d,e,g){g!="transparent"&&(this.setContextVariable(a,"fillStyle",g),a.fillRect(b,c,d,e),this.numDraws++)};html2canvas.prototype.drawImage=function(a,b,c,d,e,g,f,i,h,k){a.drawImage(b,c,d,e,g,f,i,h,k);this.numDraws++};
|
||||
html2canvas.prototype.drawBorders=function(a,b,c,d,e,g){var f=this.getBorderData(a),k=this;this.each(f,function(a,j){if(j.width>0){var i=c,l=d,m=e,n=g-f[2].width;switch(a){case 0:n=f[0].width;break;case 1:i=c+e-f[1].width;m=f[1].width;break;case 2:l=l+g-f[2].width;n=f[2].width;break;case 3:m=f[3].width}k.newRect(b,i,l,m,n,j.color)}});return f};
|
||||
html2canvas.prototype.newElement=function(a,b){var c=this.getBounds(a),d=c.left,e=c.top,g=c.width,f=c.height,k=this.getCSS(a,"background-color"),b=b||{},h=this.formatZ(this.getCSS(a,"zIndex"),this.getCSS(a,"position"),b.zIndex,a.parentNode),j=this.getCSS(a,"opacity"),i={ctx:new this.storageContext,zIndex:h,opacity:j*b.opacity},h=this.contextStacks.push(i),j=this.contextStacks[h-1].ctx;this.setContextVariable(j,"globalAlpha",i.opacity);i=this.drawBorders(a,j,c.left,c.top,c.width,c.height);this.ignoreRe.test(a.nodeName)&&
|
||||
this.opts.iframeDefault!="transparent"&&(k=this.opts.iframeDefault=="default"?"#efefef":this.opts.iframeDefault);this.newRect(j,d+i[3].width,e+i[0].width,g-(i[1].width+i[3].width),f-(i[0].width+i[2].width),k);this.drawBackground(a,{left:d+i[3].width,top:e+i[0].width,width:g-(i[1].width+i[3].width),height:f-(i[0].width+i[2].width)},j);a.nodeName=="IMG"&&((g=this.loadImage(this.getAttr(a,"src")))?this.drawImage(j,g,0,0,g.width,g.height,d+parseInt(this.getCSS(a,"padding-left"),10)+i[3].width,e+parseInt(this.getCSS(a,
|
||||
"padding-top"),10)+i[0].width,c.width-(i[1].width+i[3].width+parseInt(this.getCSS(a,"padding-left"),10)+parseInt(this.getCSS(a,"padding-right"),10)),c.height-(i[0].width+i[2].width+parseInt(this.getCSS(a,"padding-top"),10)+parseInt(this.getCSS(a,"padding-bottom"),10))):this.log("Error loading <img>:"+this.getAttr(a,"src")));return this.contextStacks[h-1]};html2canvas.prototype.printText=function(a,b,c,d){this.trim(a).length>0&&(d.fillText(a,b,c),this.numDraws++)};
|
||||
html2canvas.prototype.newRect=function(a,b,c,d,e,g){g!="transparent"&&(this.setContextVariable(a,"fillStyle",g),a.fillRect(b,c,d,e),this.numDraws++)};html2canvas.prototype.drawImage=function(a,b,c,d,e,g,f,k,h,j){a.drawImage(b,c,d,e,g,f,k,h,j);this.numDraws++};
|
||||
html2canvas.prototype.getImages=function(a){var b=this;this.ignoreRe.test(a.nodeName)||this.each($(a).contents(),function(a,d){RegExp("("+this.ignoreElements+")").test(d.nodeName)||b.getImages(d)});if(a.nodeType==1||typeof a.nodeType=="undefined")(a=this.getCSS(a,"background-image"))&&a!="1"&&a!="none"&&a.substring(0,7)!="-webkit"&&a.substring(0,4)!="-moz"&&this.preloadImage(this.backgroundImageUrl(a))};
|
||||
html2canvas.prototype.loadImage=function(a){a=this.images.indexOf(a);return a!=-1?this.images[a+1]:!1};html2canvas.prototype.preloadImage=function(a){if(this.images.indexOf(a)==-1){this.images.push(a);var b=new Image,c=this;$(b).load(function(){c.imagesLoaded++;c.start()});b.onerror=function(){c.images.splice(c.images.indexOf(b.src),2);c.imagesLoaded++;c.start()};b.src=a;this.images.push(b)}};
|
||||
html2canvas.prototype.canvasRenderer=function(a){var b=this,a=this.sortQueue(a);this.each(a,function(a,d){d.ctx.storage&&b.each(d.ctx.storage,function(a,c){switch(c.type){case "variable":b.ctx[c.name]=c.arguments;break;case "function":c.name=="fillRect"?b.ctx.fillRect(c.arguments[0],c.arguments[1],c.arguments[2],c.arguments[3]):c.name=="fillText"?b.ctx.fillText(c.arguments[0],c.arguments[1],c.arguments[2]):c.name=="drawImage"?b.ctx.drawImage(c.arguments[0],c.arguments[1],c.arguments[2],c.arguments[3],
|
||||
c.arguments[4],c.arguments[5],c.arguments[6],c.arguments[7],c.arguments[8]):this.log(c)}})})};
|
||||
html2canvas.prototype.loadImage=function(a){a=this.getIndex(this.images,a);return a!=-1?this.images[a+1]:!1};html2canvas.prototype.preloadImage=function(a){if(this.getIndex(this.images,a)==-1){this.images.push(a);var b=new Image,c=this;$(b).load(function(){c.imagesLoaded++;c.start()});b.onerror=function(){c.images.splice(c.images.indexOf(b.src),2);c.imagesLoaded++;c.start()};b.src=a;this.images.push(b)}};
|
||||
html2canvas.prototype.Renderer=function(a){var b=this;this.each(this.opts.renderOrder.split(" "),function(c,d){switch(d){case "canvas":if(b.canvas=document.createElement("canvas"),b.canvas.getContext)return b.canvasRenderer(a),!1}})};
|
||||
html2canvas.prototype.canvasRenderer=function(a){var b=this,a=this.sortQueue(a);this.canvas.width=$(document).width();this.canvas.height=$(document).height();this.ctx=this.canvas.getContext("2d");this.ctx.textBaseline="bottom";this.each(a,function(a,d){d.ctx.storage&&b.each(d.ctx.storage,function(a,c){switch(c.type){case "variable":b.ctx[c.name]=c.arguments;break;case "function":c.name=="fillRect"?b.ctx.fillRect(c.arguments[0],c.arguments[1],c.arguments[2],c.arguments[3]):c.name=="fillText"?b.ctx.fillText(c.arguments[0],
|
||||
c.arguments[1],c.arguments[2]):c.name=="drawImage"?b.ctx.drawImage(c.arguments[0],c.arguments[1],c.arguments[2],c.arguments[3],c.arguments[4],c.arguments[5],c.arguments[6],c.arguments[7],c.arguments[8]):this.log(c)}})})};
|
||||
html2canvas.prototype.sortQueue=function(a){if(!this.opts.reorderZ||!this.needReorder)return a;var b=0;this.each(a,function(a,c){if(b<c.zIndex.length)b=c.zIndex.length});var c=0;this.each(a,function(d,e){for(var g=a.length.toString().length-c.toString().length;b>e.zIndex.length;)e.zIndex+="0";for(e.zIndex+=c;b+g+c.toString().length>e.zIndex.length;)e.zIndex+="0";c++});return a=a.sort(function(a,b){return a.zIndex<b.zIndex?-1:a.zIndex>b.zIndex?1:0})};
|
||||
html2canvas.prototype.setContextVariable=function(a,b,c){a.storage?a.storage.push({type:"variable",name:b,arguments:c}):a[b]=c};
|
||||
html2canvas.prototype.newText=function(a,b,c){var d=this.getCSS(a,"font-family"),e=this.getCSS(a,"font-size"),g=this.getCSS(a,"color"),f=this.getCSS(a,"font-weight"),i=this.getCSS(a,"font-style"),h=this.getCSS(a,"font-variant"),k=this.getCSS(a,"text-decoration");b.nodeValue=this.textTransform(b.nodeValue,this.getCSS(a,"text-transform"));a=b.nodeValue;if(a.length>0){switch(f){case "401":f="bold"}if(k!="none")var l=this.fontMetrics(d,e);this.setContextVariable(c,"fillStyle",g);this.setContextVariable(c,
|
||||
"font",h+" "+f+" "+i+" "+e+" "+d);for(d=0;d<a.length;d++){e=b.splitText(1);if(this.useRangeBounds)document.createRange?(f=document.createRange(),f.selectNode(b)):f=document.body.createTextRange(),f=f.getBoundingClientRect()?f.getBoundingClientRect():{};else{var i=b.parentNode,h=document.createElement("wrapper"),m=b.cloneNode(!0);h.appendChild(b.cloneNode(!0));i.replaceChild(h,b);f=this.getBounds(h);i.replaceChild(m,h)}this.printText(b.nodeValue,f.left,f.bottom,c);switch(k){case "underline":this.newRect(c,
|
||||
f.left,Math.round(f.top+l.baseline+l.lineWidth),f.width,1,g);break;case "overline":this.newRect(c,f.left,f.top,f.width,1,g);break;case "line-through":this.newRect(c,f.left,Math.ceil(f.top+l.middle+l.lineWidth),f.width,1,g)}b=e}}};
|
||||
html2canvas.prototype.newText=function(a,b,c){var d=this.getCSS(a,"font-family"),e=this.getCSS(a,"font-size"),g=this.getCSS(a,"color"),f=this.getCSS(a,"font-weight"),k=this.getCSS(a,"font-style"),h=this.getCSS(a,"font-variant"),j=this.getCSS(a,"text-decoration");b.nodeValue=this.textTransform(b.nodeValue,this.getCSS(a,"text-transform"));a=b.nodeValue;if(a.length>0){switch(f){case "401":f="bold"}if(j!="none")var i=this.fontMetrics(d,e);this.setContextVariable(c,"fillStyle",g);this.setContextVariable(c,
|
||||
"font",h+" "+f+" "+k+" "+e+" "+d);for(d=0;d<a.length;d++){e=b.splitText(1);if(this.support.rangeBounds)document.createRange?(f=document.createRange(),f.selectNode(b)):f=document.body.createTextRange(),f=f.getBoundingClientRect()?f.getBoundingClientRect():{};else{var k=b.parentNode,h=document.createElement("wrapper"),l=b.cloneNode(!0);h.appendChild(b.cloneNode(!0));k.replaceChild(h,b);f=this.getBounds(h);k.replaceChild(l,h)}this.printText(b.nodeValue,f.left,f.bottom,c);switch(j){case "underline":this.newRect(c,
|
||||
f.left,Math.round(f.top+i.baseline+i.lineWidth),f.width,1,g);break;case "overline":this.newRect(c,f.left,f.top,f.width,1,g);break;case "line-through":this.newRect(c,f.left,Math.ceil(f.top+i.middle+i.lineWidth),f.width,1,g)}b=e}}};
|
||||
html2canvas.prototype.fontMetrics=function(a,b){var c=this.fontData.indexOf(a+"-"+b);if(c>-1)return this.fontData[c+1];c=document.createElement("div");document.getElementsByTagName("body")[0].appendChild(c);$(c).css({visibility:"hidden",fontFamily:a,fontSize:b,margin:0,padding:0});var d=document.createElement("img");d.src="http://html2canvas.hertzen.com/images/8.jpg";d.width=1;d.height=1;$(d).css({margin:0,padding:0});var e=document.createElement("span");$(e).css({fontFamily:a,fontSize:b,margin:0,
|
||||
padding:0});e.appendChild(document.createTextNode("Hidden Text"));c.appendChild(e);c.appendChild(d);var g=d.offsetTop-e.offsetTop+1;c.removeChild(e);c.appendChild(document.createTextNode("Hidden Text"));$(c).css("line-height","normal");$(d).css("vertical-align","super");d={baseline:g,lineWidth:1,middle:d.offsetTop-c.offsetTop+1};this.fontData.push(a+"-"+b);this.fontData.push(d);$(c).remove();return d};
|
||||
html2canvas.prototype.textTransform=function(a,b){switch(b){case "lowercase":return a.toLowerCase();case "capitalize":return a.replace(/(^|\s|:|-|\(|\))([a-z])/g,function(a,b,e){return b+e.toUpperCase()});case "uppercase":return a.toUpperCase();default:return a}};html2canvas.prototype.trim=function(a){return a.replace(/^\s*/,"").replace(/\s*$/,"")};
|
||||
html2canvas.prototype.parseElement=function(a,b){var c=this;this.each(a.children,function(a,e){c.parsing(e,b)});this.canvasRenderer(this.contextStacks);this.finish()};
|
||||
html2canvas.prototype.textTransform=function(a,b){switch(b){case "lowercase":return a.toLowerCase();case "capitalize":return a.replace(/(^|\s|:|-|\(|\))([a-z])/g,function(a,b,e){return b+e.toUpperCase()});case "uppercase":return a.toUpperCase();default:return a}};html2canvas.prototype.trim=function(a){return a.replace(/^\s*/,"").replace(/\s*$/,"")};html2canvas.prototype.parseElement=function(a,b){var c=this;this.each(a.children,function(a,e){c.parsing(e,b)});this.Renderer(this.contextStacks);this.finish()};
|
||||
html2canvas.prototype.parsing=function(a,b){if(this.getCSS(a,"display")!="none"&&this.getCSS(a,"visibility")!="hidden"){var c=this,b=this.newElement(a,b)||b,d=b.ctx;if(!this.ignoreRe.test(a.nodeName)){var e=this.contentsInZ(a);e.length==1?e[0].nodeType==1?this.parsing(e[0],b):e[0].nodeType==3&&this.newText(a,e[0],b.ctx):this.each(e,function(e,f){f.nodeType==1?c.parsing(f,b):f.nodeType==3&&c.newText(a,f,d)})}}};html2canvas.prototype.log=function(){};
|
||||
html2canvas.prototype.getBounds=function(a){window.scroll(0,0);if(a.getBoundingClientRect)return a=a.getBoundingClientRect(),a.top=a.top,a.left=a.left,a;else{var b=$(a).offset();return{left:b.left+parseInt(this.getCSS(a,"border-left-width"),10),top:b.top+parseInt(this.getCSS(a,"border-top-width"),10),width:$(a).innerWidth(),height:$(a).innerHeight()}}};html2canvas.prototype.each=function(a,b){for(var b=b||function(){},c=0;c<a.length;c++)b(c,a[c])};html2canvas.prototype.contentsInZ=function(a){return $(a).contents()};
|
||||
html2canvas.prototype.getBounds=function(a){window.scroll(0,0);if(a.getBoundingClientRect)return a=a.getBoundingClientRect(),a.top=a.top,a.left=a.left,a;else{var b=$(a).offset();return{left:b.left+parseInt(this.getCSS(a,"border-left-width"),10),top:b.top+parseInt(this.getCSS(a,"border-top-width"),10),width:$(a).innerWidth(),height:$(a).innerHeight()}}};html2canvas.prototype.each=function(a,b){for(var b=b||function(){},c=0;c<a.length;c++)if(b(c,a[c])===!1)break};html2canvas.prototype.contentsInZ=function(a){return $(a).contents()};
|
||||
html2canvas.prototype.getAttr=function(a,b){return a.getAttribute(b)};html2canvas.prototype.extendObj=function(a,b){for(var c in a)b[c]=a[c];return b};html2canvas.prototype.leadingZero=function(a,b){var c="000000000"+a;return c.substr(c.length-b)};
|
||||
html2canvas.prototype.formatZ=function(a,b,c,d){c||(c="0");if(b!="static"&&c.charAt(0)=="0")this.needReorder=!0,c="1"+c.slice(1);if(a=="auto")if(a=this.getCSS(d,"position"),a!="static"&&typeof a!="undefined")a=0;else return c;b=this.leadingZero(this.numDraws,9);a=this.leadingZero(a+1,9);return c+""+a+""+b};html2canvas.prototype.getContents=function(a){return a.nodeName=="iframe"?a.contentDocument||a.contentWindow.document:a.childNodes};html2canvas.prototype.getCSS=function(a,b){return $(a).css(b)};
|
||||
html2canvas.prototype.getIndex=function(a,b){if(a.indexOf)return a.indexOf(b);else{for(var c=0;c<a.length;c++)if(this[c]==b)return c;return-1}};
|
||||
|
Loading…
Reference in New Issue
Block a user