Merge pull request #8437 from yurydelendik/default-ctx
Resets canvas 2d context to the default state.
This commit is contained in:
commit
ac942ac657
@ -354,7 +354,7 @@ function compileType3Glyph(imgData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var CanvasExtraState = (function CanvasExtraStateClosure() {
|
var CanvasExtraState = (function CanvasExtraStateClosure() {
|
||||||
function CanvasExtraState(old) {
|
function CanvasExtraState() {
|
||||||
// Are soft masks and alpha values shapes or opacities?
|
// Are soft masks and alpha values shapes or opacities?
|
||||||
this.alphaIsShape = false;
|
this.alphaIsShape = false;
|
||||||
this.fontSize = 0;
|
this.fontSize = 0;
|
||||||
@ -385,8 +385,6 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
|
|||||||
this.lineWidth = 1;
|
this.lineWidth = 1;
|
||||||
this.activeSMask = null;
|
this.activeSMask = null;
|
||||||
this.resumeSMaskCtx = null; // nonclonable field (see the save method below)
|
this.resumeSMaskCtx = null; // nonclonable field (see the save method below)
|
||||||
|
|
||||||
this.old = old;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CanvasExtraState.prototype = {
|
CanvasExtraState.prototype = {
|
||||||
@ -609,6 +607,23 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetCtxToDefault(ctx) {
|
||||||
|
ctx.strokeStyle = '#000000';
|
||||||
|
ctx.fillStyle = '#000000';
|
||||||
|
ctx.fillRule = 'nonzero';
|
||||||
|
ctx.globalAlpha = 1;
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
ctx.lineCap = 'butt';
|
||||||
|
ctx.lineJoin = 'miter';
|
||||||
|
ctx.miterLimit = 10;
|
||||||
|
ctx.globalCompositeOperation = 'source-over';
|
||||||
|
ctx.font = '10px sans-serif';
|
||||||
|
if (ctx.setLineDash !== undefined) {
|
||||||
|
ctx.setLineDash([]);
|
||||||
|
ctx.lineDashOffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function composeSMaskBackdrop(bytes, r0, g0, b0) {
|
function composeSMaskBackdrop(bytes, r0, g0, b0) {
|
||||||
var length = bytes.length;
|
var length = bytes.length;
|
||||||
for (var i = 3; i < length; i += 4) {
|
for (var i = 3; i < length; i += 4) {
|
||||||
@ -734,6 +749,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
|
resetCtxToDefault(this.ctx);
|
||||||
if (transform) {
|
if (transform) {
|
||||||
this.ctx.transform.apply(this.ctx, transform);
|
this.ctx.transform.apply(this.ctx, transform);
|
||||||
}
|
}
|
||||||
@ -1863,8 +1879,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
|
|
||||||
beginAnnotations: function CanvasGraphics_beginAnnotations() {
|
beginAnnotations: function CanvasGraphics_beginAnnotations() {
|
||||||
this.save();
|
this.save();
|
||||||
this.current = new CanvasExtraState();
|
|
||||||
|
|
||||||
if (this.baseTransform) {
|
if (this.baseTransform) {
|
||||||
this.ctx.setTransform.apply(this.ctx, this.baseTransform);
|
this.ctx.setTransform.apply(this.ctx, this.baseTransform);
|
||||||
}
|
}
|
||||||
@ -1877,6 +1891,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
|
beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
|
||||||
matrix) {
|
matrix) {
|
||||||
this.save();
|
this.save();
|
||||||
|
resetCtxToDefault(this.ctx);
|
||||||
|
this.current = new CanvasExtraState();
|
||||||
|
|
||||||
if (isArray(rect) && rect.length === 4) {
|
if (isArray(rect) && rect.length === 4) {
|
||||||
var width = rect[2] - rect[0];
|
var width = rect[2] - rect[0];
|
||||||
|
1
test/pdfs/issue8047.pdf.link
Normal file
1
test/pdfs/issue8047.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/762326/212241.6.pdf
|
@ -2474,6 +2474,14 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "load"
|
"type": "load"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue8047",
|
||||||
|
"file": "pdfs/issue8047.pdf",
|
||||||
|
"md5": "83f1b9f7e95caa8e2625390afd7c7276",
|
||||||
|
"rounds": 1,
|
||||||
|
"lastPage": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue818",
|
{ "id": "issue818",
|
||||||
"file": "pdfs/issue818.pdf",
|
"file": "pdfs/issue818.pdf",
|
||||||
"md5": "dd2f8a5bd65164ad74da2b45a6ca90cc",
|
"md5": "dd2f8a5bd65164ad74da2b45a6ca90cc",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user