Skip to content

Commit c1dcb87

Browse files
committed
Add ignoreClearRect functionality
1 parent ae95de3 commit c1dcb87

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

plugins/context2d.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,21 @@
6464
this.pdf.rect(xRect.x, xRect.y, xRect.w, xRect.h, "s");
6565
},
6666

67+
/**
68+
* We cannot clear PDF commands that were already written to PDF, so we use white instead. <br />
69+
* As a special case, read a special flag (_ignoreClearRect) and do nothing if it is set.
70+
* This allows an calls to clearRect() to keep the canvas transparent.
71+
* This flag is stored in the save/restore context can managed in the same way as other drawing states.
72+
* @param x
73+
* @param y
74+
* @param w
75+
* @param h
76+
*/
6777
clearRect: function (x, y, w, h) {
78+
if (this.ctx.ignoreClearRect) {
79+
return;
80+
}
81+
6882
x = this._wrapX(x);
6983
y = this._wrapY(y);
7084

@@ -1159,7 +1173,7 @@
11591173
pushMask: function () {
11601174
var v2Support = typeof this.pdf.internal.newObject2 === 'function';
11611175

1162-
if (!v2Support){
1176+
if (!v2Support) {
11631177
console.log('jsPDF v2 not enabled')
11641178
return;
11651179
}
@@ -1322,6 +1336,16 @@
13221336
return this.ctx.globalAlpha;
13231337
}
13241338
});
1339+
// Not HTML API
1340+
Object.defineProperty(c2d, 'ignoreClearRect', {
1341+
set: function (value) {
1342+
this.ctx.ignoreClearRect = value;
1343+
},
1344+
get: function () {
1345+
return this.ctx.ignoreClearRect;
1346+
}
1347+
});
1348+
// End Not HTML API
13251349

13261350
c2d.internal = {};
13271351

@@ -1560,6 +1584,9 @@
15601584
this._clip_path = [];
15611585
// TODO miter limit //default 10
15621586

1587+
// Not HTML API
1588+
this.ignoreClearRect = false;
1589+
15631590
this.copy = function (ctx) {
15641591
this._isStrokeTransparent = ctx._isStrokeTransparent;
15651592
this._strokeOpacity = ctx._strokeOpacity;
@@ -1578,6 +1605,9 @@
15781605
this.globalCompositeOperation = ctx.globalCompositeOperation;
15791606
this.globalAlpha = ctx.globalAlpha;
15801607
this._clip_path = ctx._clip_path.slice(0); //TODO deep copy?
1608+
1609+
// Not HTML API
1610+
this.ignoreClearRect = ctx.ignoreClearRect;
15811611
};
15821612
}
15831613

0 commit comments

Comments
 (0)