Skip to content

Commit 924cd96

Browse files
committed
re-enabled bound measurement type checking, working for Opera now.
1 parent 9134d70 commit 924cd96

2 files changed

Lines changed: 54 additions & 27 deletions

File tree

src/Core.js

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function html2canvas(el, userOptions) {
1616
iframeDefault: "default",
1717
flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",
1818
renderViewport: false,
19-
reorderZ: true
19+
reorderZ: true,
20+
throttle:true,
21+
renderOrder: "canvas flash html"
2022
});
2123

2224
this.element = el;
@@ -35,20 +37,44 @@ function html2canvas(el, userOptions) {
3537
this.ignoreElements = "IFRAME|OBJECT|PARAM";
3638
this.needReorder = false;
3739
this.blockElements = new RegExp("(BR|PARAM)");
38-
40+
3941
this.ignoreRe = new RegExp("("+this.ignoreElements+")");
4042

41-
// test how to measure text bounding boxes
42-
this.useRangeBounds = false;
4343

44-
// Check disabled as Opera doesn't provide bounds.height/bottom even though it supports the method.
45-
// TODO take the check back into use, but fix the issue for Opera
46-
/*
44+
this.support = {
45+
rangeBounds: false
46+
47+
};
48+
49+
// Test whether we can use ranges to measure bounding boxes
50+
// Opera doesn't provide valid bounds.height/bottom even though it supports the method.
51+
52+
4753
if (document.createRange){
4854
var r = document.createRange();
49-
this.useRangeBounds = new Boolean(r.getBoundingClientRect);
50-
}*/
55+
//this.support.rangeBounds = new Boolean(r.getBoundingClientRect);
56+
if (r.getBoundingClientRect){
57+
var testElement = document.createElement('boundtest');
58+
testElement.style.height = "123px";
59+
testElement.style.display = "block";
60+
document.getElementsByTagName('body')[0].appendChild(testElement);
61+
62+
r.selectNode(testElement);
63+
var rangeBounds = r.getBoundingClientRect();
64+
var rangeHeight = rangeBounds.height;
65+
66+
if (rangeHeight==123){
67+
this.support.rangeBounds = true;
68+
}
69+
document.getElementsByTagName('body')[0].removeChild(testElement);
70+
71+
72+
}
73+
74+
}
5175

76+
77+
5278
// Start script
5379
this.init();
5480

@@ -61,7 +87,7 @@ function html2canvas(el, userOptions) {
6187
html2canvas.prototype.init = function(){
6288

6389
var _ = this;
64-
90+
/*
6591
this.ctx = new this.stackingContext($(document).width(),$(document).height());
6692
6793
if (!this.ctx){
@@ -71,7 +97,7 @@ html2canvas.prototype.init = function(){
7197
}
7298
7399
this.canvas = this.ctx.canvas;
74-
100+
*/
75101
this.log('Finding background images');
76102

77103
this.getImages(this.element);
@@ -99,25 +125,23 @@ html2canvas.prototype.start = function(){
99125
this.log('Started parsing');
100126
this.bodyOverflow = document.getElementsByTagName('body')[0].style.overflow;
101127
document.getElementsByTagName('body')[0].style.overflow = "hidden";
102-
103-
var stack = this.newElement(this.element,{
104-
ctx:this.ctx,
105-
opacity:this.getCSS(this.element,"opacity")
128+
var rootStack = new this.storageContext($(document).width(),$(document).height());
129+
rootStack.opacity = this.getCSS(this.element,"opacity");
130+
var stack = this.newElement(this.element,rootStack);
106131

107-
}) || this.ctx;
132+
133+
this.parseElement(this.element,stack);
108134
}
109-
110-
this.parseElement(this.element,stack);
111-
135+
112136
}
113137

114138

115139
html2canvas.prototype.stackingContext = function(width,height){
116140
this.canvas = document.createElement('canvas');
117141

118-
// TODO remove jQuery dependency
119-
this.canvas.width = $(document).width();
120-
this.canvas.height = $(document).height();
142+
143+
this.canvas.width = width;
144+
this.canvas.height = width;
121145

122146
if (!this.canvas.getContext){
123147

@@ -148,8 +172,9 @@ html2canvas.prototype.stackingContext = function(width,height){
148172

149173
html2canvas.prototype.storageContext = function(width,height){
150174
this.storage = [];
151-
152-
175+
this.width = width;
176+
this.height = height;
177+
//this.zIndex;
153178

154179
// todo simplify this whole section
155180
this.fillRect = function(x, y, w, h){
@@ -191,17 +216,19 @@ html2canvas.prototype.storageContext = function(width,height){
191216
*/
192217

193218
html2canvas.prototype.finish = function(){
219+
194220
this.log("Finished rendering");
195-
document.getElementsByTagName('body')[0].style.overflow = this.bodyOverflow;
196221

222+
document.getElementsByTagName('body')[0].style.overflow = this.bodyOverflow;
223+
/*
197224
if (this.opts.renderViewport){
198225
// let's crop it to viewport only then
199226
var newCanvas = document.createElement('canvas');
200227
var newctx = newCanvas.getContext('2d');
201228
newCanvas.width = window.innerWidth;
202229
newCanvas.height = window.innerHeight;
203230
204-
}
231+
}*/
205232
this.opts.ready(this);
206233
}
207234

src/Text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ html2canvas.prototype.newText = function(el,textNode,ctx){
4040
for(var c=0;c<text.length;c++){
4141
var newTextNode = oldTextNode.splitText(1);
4242

43-
if (this.useRangeBounds){
43+
if (this.support.rangeBounds){
4444
// getBoundingClientRect is supported for ranges
4545
if (document.createRange){
4646
var range = document.createRange();

0 commit comments

Comments
 (0)