Skip to content

Commit 78e1f98

Browse files
committed
fixed z-index ordering bug with backgrounds
1 parent 71369d3 commit 78e1f98

4 files changed

Lines changed: 34 additions & 42 deletions

File tree

build/html2canvas.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ html2canvas.prototype.canvasRenderContext = function(storageContext,ctx){
10781078
if (storageContext.clip){
10791079
ctx.save();
10801080
ctx.beginPath();
1081-
// console.log(storageContext);
1081+
// console.log(storageContext);
10821082
ctx.rect(storageContext.clip.left,storageContext.clip.top,storageContext.clip.width,storageContext.clip.height);
10831083
ctx.clip();
10841084

@@ -1094,34 +1094,29 @@ html2canvas.prototype.canvasRenderContext = function(storageContext,ctx){
10941094
break;
10951095
case "function":
10961096
if (renderItem.name=="fillRect"){
1097+
10971098
ctx.fillRect(
1098-
renderItem.arguments[0]-(storageContext.canvasPosition.x || 0),
1099-
renderItem.arguments[1]-(storageContext.canvasPosition.y || 0),
1099+
renderItem.arguments[0],
1100+
renderItem.arguments[1],
11001101
renderItem.arguments[2],
11011102
renderItem.arguments[3]
11021103
);
11031104
}else if(renderItem.name=="fillText"){
11041105
// console.log(renderItem.arguments[0]);
1105-
1106-
ctx.fillText(renderItem.arguments[0],renderItem.arguments[1]-(storageContext.canvasPosition.x || 0),renderItem.arguments[2]-(storageContext.canvasPosition.y || 0));
1107-
/*
1108-
if (renderItem.arguments[0]=="Highlights"){
1109-
console.log(renderItem);
1110-
console.log(storageContext);
1111-
$('body').append(ctx.canvas);
1112-
}*/
1106+
ctx.fillText(renderItem.arguments[0],renderItem.arguments[1],renderItem.arguments[2]);
1107+
11131108
}else if(renderItem.name=="drawImage"){
11141109
// console.log(renderItem);
1115-
// console.log(renderItem.arguments[0].width);
1110+
// console.log(renderItem.arguments[0].width);
11161111
if (renderItem.arguments[8] > 0 && renderItem.arguments[7]){
11171112
ctx.drawImage(
11181113
renderItem.arguments[0],
11191114
renderItem.arguments[1],
11201115
renderItem.arguments[2],
11211116
renderItem.arguments[3],
11221117
renderItem.arguments[4],
1123-
renderItem.arguments[5]-(storageContext.canvasPosition.x || 0),
1124-
renderItem.arguments[6]-(storageContext.canvasPosition.y || 0),
1118+
renderItem.arguments[5],
1119+
renderItem.arguments[6],
11251120
renderItem.arguments[7],
11261121
renderItem.arguments[8]
11271122
);
@@ -1140,9 +1135,9 @@ html2canvas.prototype.canvasRenderContext = function(storageContext,ctx){
11401135
});
11411136

11421137
}
1143-
if (storageContext.clip){
1144-
ctx.restore();
1145-
}
1138+
if (storageContext.clip){
1139+
ctx.restore();
1140+
}
11461141

11471142
}
11481143

@@ -1790,9 +1785,10 @@ html2canvas.prototype.formatZ = function(zindex,position,parentZ,parentNode){
17901785
var parentPosition = this.getCSS(parentNode,"position");
17911786
if (parentPosition!="static" && typeof parentPosition != "undefined"){
17921787
zindex = 0;
1793-
}else{
1794-
return parentZ;
17951788
}
1789+
/*else{
1790+
return parentZ;
1791+
}*/
17961792
}
17971793

17981794
var b = this.leadingZero(this.numDraws,9);

build/html2canvas.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Renderer.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ html2canvas.prototype.canvasRenderContext = function(storageContext,ctx){
9494
if (storageContext.clip){
9595
ctx.save();
9696
ctx.beginPath();
97-
// console.log(storageContext);
97+
// console.log(storageContext);
9898
ctx.rect(storageContext.clip.left,storageContext.clip.top,storageContext.clip.width,storageContext.clip.height);
9999
ctx.clip();
100100

@@ -110,34 +110,29 @@ html2canvas.prototype.canvasRenderContext = function(storageContext,ctx){
110110
break;
111111
case "function":
112112
if (renderItem.name=="fillRect"){
113+
113114
ctx.fillRect(
114-
renderItem.arguments[0]-(storageContext.canvasPosition.x || 0),
115-
renderItem.arguments[1]-(storageContext.canvasPosition.y || 0),
115+
renderItem.arguments[0],
116+
renderItem.arguments[1],
116117
renderItem.arguments[2],
117118
renderItem.arguments[3]
118119
);
119120
}else if(renderItem.name=="fillText"){
120121
// console.log(renderItem.arguments[0]);
121-
122-
ctx.fillText(renderItem.arguments[0],renderItem.arguments[1]-(storageContext.canvasPosition.x || 0),renderItem.arguments[2]-(storageContext.canvasPosition.y || 0));
123-
/*
124-
if (renderItem.arguments[0]=="Highlights"){
125-
console.log(renderItem);
126-
console.log(storageContext);
127-
$('body').append(ctx.canvas);
128-
}*/
122+
ctx.fillText(renderItem.arguments[0],renderItem.arguments[1],renderItem.arguments[2]);
123+
129124
}else if(renderItem.name=="drawImage"){
130125
// console.log(renderItem);
131-
// console.log(renderItem.arguments[0].width);
126+
// console.log(renderItem.arguments[0].width);
132127
if (renderItem.arguments[8] > 0 && renderItem.arguments[7]){
133128
ctx.drawImage(
134129
renderItem.arguments[0],
135130
renderItem.arguments[1],
136131
renderItem.arguments[2],
137132
renderItem.arguments[3],
138133
renderItem.arguments[4],
139-
renderItem.arguments[5]-(storageContext.canvasPosition.x || 0),
140-
renderItem.arguments[6]-(storageContext.canvasPosition.y || 0),
134+
renderItem.arguments[5],
135+
renderItem.arguments[6],
141136
renderItem.arguments[7],
142137
renderItem.arguments[8]
143138
);
@@ -156,9 +151,9 @@ html2canvas.prototype.canvasRenderContext = function(storageContext,ctx){
156151
});
157152

158153
}
159-
if (storageContext.clip){
160-
ctx.restore();
161-
}
154+
if (storageContext.clip){
155+
ctx.restore();
156+
}
162157

163158
}
164159

src/Util.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ html2canvas.prototype.formatZ = function(zindex,position,parentZ,parentNode){
144144
var parentPosition = this.getCSS(parentNode,"position");
145145
if (parentPosition!="static" && typeof parentPosition != "undefined"){
146146
zindex = 0;
147-
}else{
148-
return parentZ;
149147
}
148+
/*else{
149+
return parentZ;
150+
}*/
150151
}
151152

152153
var b = this.leadingZero(this.numDraws,9);

0 commit comments

Comments
 (0)