diff --git a/bower.json b/bower.json index 03e5e0db1..2ddead4f7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "pdfjs-dist", - "version": "1.4.221", + "version": "1.4.225", "main": [ "build/pdf.js", "build/pdf.worker.js" diff --git a/build/pdf.combined.js b/build/pdf.combined.js index 798b6568f..d47d5150f 100644 --- a/build/pdf.combined.js +++ b/build/pdf.combined.js @@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfCombined = {})); // Use strict in our context only - users might not want it 'use strict'; -var pdfjsVersion = '1.4.221'; -var pdfjsBuild = 'b282885'; +var pdfjsVersion = '1.4.225'; +var pdfjsBuild = 'be6754a'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? @@ -32255,7 +32255,8 @@ var CanvasExtraState = (function CanvasExtraStateClosure() { this.fillAlpha = 1; this.strokeAlpha = 1; this.lineWidth = 1; - this.activeSMask = null; // nonclonable field (see the save method below) + this.activeSMask = null; + this.resumeSMaskCtx = null; // nonclonable field (see the save method below) this.old = old; } @@ -32692,6 +32693,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { }, endDrawing: function CanvasGraphics_endDrawing() { + // Finishing all opened operations such as SMask group painting. + if (this.current.activeSMask !== null) { + this.endSMaskGroup(); + } + this.ctx.restore(); if (this.transparentCanvas) { @@ -32800,7 +32806,16 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { break; case 'SMask': if (this.current.activeSMask) { - this.endSMaskGroup(); + // If SMask is currrenly used, it needs to be suspended or + // finished. Suspend only makes sense when at least one save() + // was performed and state needs to be reverted on restore(). + if (this.stateStack.length > 0 && + (this.stateStack[this.stateStack.length - 1].activeSMask === + this.current.activeSMask)) { + this.suspendSMaskGroup(); + } else { + this.endSMaskGroup(); + } } this.current.activeSMask = value ? this.tempSMask : null; if (this.current.activeSMask) { @@ -32829,6 +32844,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY); groupCtx.transform.apply(groupCtx, currentTransform); + activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse; + copyCtxState(currentCtx, groupCtx); this.ctx = groupCtx; this.setGState([ @@ -32839,6 +32856,43 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.groupStack.push(currentCtx); this.groupLevel++; }, + suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() { + // Similar to endSMaskGroup, the intermediate canvas has to be composed + // and future ctx state restored. + var groupCtx = this.ctx; + this.groupLevel--; + this.ctx = this.groupStack.pop(); + + composeSMask(this.ctx, this.current.activeSMask, groupCtx); + this.ctx.restore(); + this.ctx.save(); // save is needed since SMask will be resumed. + copyCtxState(groupCtx, this.ctx); + + // Saving state for resuming. + this.current.resumeSMaskCtx = groupCtx; + // Transform was changed in the SMask canvas, reflecting this change on + // this.ctx. + var deltaTransform = Util.transform( + this.current.activeSMask.startTransformInverse, + groupCtx.mozCurrentTransform); + this.ctx.transform.apply(this.ctx, deltaTransform); + + // SMask was composed, the results at the groupCtx can be cleared. + groupCtx.save(); + groupCtx.setTransform(1, 0, 0, 1, 0, 0); + groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height); + groupCtx.restore(); + }, + resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() { + // Resuming state saved by suspendSMaskGroup. We don't need to restore + // any groupCtx state since restore() command (the only caller) will do + // that for us. See also beginSMaskGroup. + var groupCtx = this.current.resumeSMaskCtx; + var currentCtx = this.ctx; + this.ctx = groupCtx; + this.groupStack.push(currentCtx); + this.groupLevel++; + }, endSMaskGroup: function CanvasGraphics_endSMaskGroup() { var groupCtx = this.ctx; this.groupLevel--; @@ -32847,20 +32901,34 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { composeSMask(this.ctx, this.current.activeSMask, groupCtx); this.ctx.restore(); copyCtxState(groupCtx, this.ctx); + // Transform was changed in the SMask canvas, reflecting this change on + // this.ctx. + var deltaTransform = Util.transform( + this.current.activeSMask.startTransformInverse, + groupCtx.mozCurrentTransform); + this.ctx.transform.apply(this.ctx, deltaTransform); }, save: function CanvasGraphics_save() { this.ctx.save(); var old = this.current; this.stateStack.push(old); this.current = old.clone(); - this.current.activeSMask = null; + this.current.resumeSMaskCtx = null; }, restore: function CanvasGraphics_restore() { - if (this.stateStack.length !== 0) { - if (this.current.activeSMask !== null) { - this.endSMaskGroup(); - } + // SMask was suspended, we just need to resume it. + if (this.current.resumeSMaskCtx) { + this.resumeSMaskGroup(); + } + // SMask has to be finished once there is no states that are using the + // same SMask. + if (this.current.activeSMask !== null && (this.stateStack.length === 0 || + this.stateStack[this.stateStack.length - 1].activeSMask !== + this.current.activeSMask)) { + this.endSMaskGroup(); + } + if (this.stateStack.length !== 0) { this.current = this.stateStack.pop(); this.ctx.restore(); @@ -33648,7 +33716,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { scaleY: scaleY, subtype: group.smask.subtype, backdrop: group.smask.backdrop, - transferMap: group.smask.transferMap || null + transferMap: group.smask.transferMap || null, + startTransformInverse: null, // used during suspend operation }); } else { // Setup the current ctx so when the group is popped we draw it at the @@ -33668,6 +33737,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ]); this.groupStack.push(currentCtx); this.groupLevel++; + + // Reseting mask state, masks will be applied on restore of the group. + this.current.activeSMask = null; }, endGroup: function CanvasGraphics_endGroup(group) { diff --git a/build/pdf.js b/build/pdf.js index 6a810eaa6..a565bb1ee 100644 --- a/build/pdf.js +++ b/build/pdf.js @@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdf = {})); // Use strict in our context only - users might not want it 'use strict'; -var pdfjsVersion = '1.4.221'; -var pdfjsBuild = 'b282885'; +var pdfjsVersion = '1.4.225'; +var pdfjsBuild = 'be6754a'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? @@ -6652,7 +6652,8 @@ var CanvasExtraState = (function CanvasExtraStateClosure() { this.fillAlpha = 1; this.strokeAlpha = 1; this.lineWidth = 1; - this.activeSMask = null; // nonclonable field (see the save method below) + this.activeSMask = null; + this.resumeSMaskCtx = null; // nonclonable field (see the save method below) this.old = old; } @@ -7089,6 +7090,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { }, endDrawing: function CanvasGraphics_endDrawing() { + // Finishing all opened operations such as SMask group painting. + if (this.current.activeSMask !== null) { + this.endSMaskGroup(); + } + this.ctx.restore(); if (this.transparentCanvas) { @@ -7197,7 +7203,16 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { break; case 'SMask': if (this.current.activeSMask) { - this.endSMaskGroup(); + // If SMask is currrenly used, it needs to be suspended or + // finished. Suspend only makes sense when at least one save() + // was performed and state needs to be reverted on restore(). + if (this.stateStack.length > 0 && + (this.stateStack[this.stateStack.length - 1].activeSMask === + this.current.activeSMask)) { + this.suspendSMaskGroup(); + } else { + this.endSMaskGroup(); + } } this.current.activeSMask = value ? this.tempSMask : null; if (this.current.activeSMask) { @@ -7226,6 +7241,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY); groupCtx.transform.apply(groupCtx, currentTransform); + activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse; + copyCtxState(currentCtx, groupCtx); this.ctx = groupCtx; this.setGState([ @@ -7236,6 +7253,43 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.groupStack.push(currentCtx); this.groupLevel++; }, + suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() { + // Similar to endSMaskGroup, the intermediate canvas has to be composed + // and future ctx state restored. + var groupCtx = this.ctx; + this.groupLevel--; + this.ctx = this.groupStack.pop(); + + composeSMask(this.ctx, this.current.activeSMask, groupCtx); + this.ctx.restore(); + this.ctx.save(); // save is needed since SMask will be resumed. + copyCtxState(groupCtx, this.ctx); + + // Saving state for resuming. + this.current.resumeSMaskCtx = groupCtx; + // Transform was changed in the SMask canvas, reflecting this change on + // this.ctx. + var deltaTransform = Util.transform( + this.current.activeSMask.startTransformInverse, + groupCtx.mozCurrentTransform); + this.ctx.transform.apply(this.ctx, deltaTransform); + + // SMask was composed, the results at the groupCtx can be cleared. + groupCtx.save(); + groupCtx.setTransform(1, 0, 0, 1, 0, 0); + groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height); + groupCtx.restore(); + }, + resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() { + // Resuming state saved by suspendSMaskGroup. We don't need to restore + // any groupCtx state since restore() command (the only caller) will do + // that for us. See also beginSMaskGroup. + var groupCtx = this.current.resumeSMaskCtx; + var currentCtx = this.ctx; + this.ctx = groupCtx; + this.groupStack.push(currentCtx); + this.groupLevel++; + }, endSMaskGroup: function CanvasGraphics_endSMaskGroup() { var groupCtx = this.ctx; this.groupLevel--; @@ -7244,20 +7298,34 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { composeSMask(this.ctx, this.current.activeSMask, groupCtx); this.ctx.restore(); copyCtxState(groupCtx, this.ctx); + // Transform was changed in the SMask canvas, reflecting this change on + // this.ctx. + var deltaTransform = Util.transform( + this.current.activeSMask.startTransformInverse, + groupCtx.mozCurrentTransform); + this.ctx.transform.apply(this.ctx, deltaTransform); }, save: function CanvasGraphics_save() { this.ctx.save(); var old = this.current; this.stateStack.push(old); this.current = old.clone(); - this.current.activeSMask = null; + this.current.resumeSMaskCtx = null; }, restore: function CanvasGraphics_restore() { - if (this.stateStack.length !== 0) { - if (this.current.activeSMask !== null) { - this.endSMaskGroup(); - } + // SMask was suspended, we just need to resume it. + if (this.current.resumeSMaskCtx) { + this.resumeSMaskGroup(); + } + // SMask has to be finished once there is no states that are using the + // same SMask. + if (this.current.activeSMask !== null && (this.stateStack.length === 0 || + this.stateStack[this.stateStack.length - 1].activeSMask !== + this.current.activeSMask)) { + this.endSMaskGroup(); + } + if (this.stateStack.length !== 0) { this.current = this.stateStack.pop(); this.ctx.restore(); @@ -8045,7 +8113,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { scaleY: scaleY, subtype: group.smask.subtype, backdrop: group.smask.backdrop, - transferMap: group.smask.transferMap || null + transferMap: group.smask.transferMap || null, + startTransformInverse: null, // used during suspend operation }); } else { // Setup the current ctx so when the group is popped we draw it at the @@ -8065,6 +8134,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ]); this.groupStack.push(currentCtx); this.groupLevel++; + + // Reseting mask state, masks will be applied on restore of the group. + this.current.activeSMask = null; }, endGroup: function CanvasGraphics_endGroup(group) { diff --git a/build/pdf.worker.js b/build/pdf.worker.js index 8690d3869..3231028c6 100644 --- a/build/pdf.worker.js +++ b/build/pdf.worker.js @@ -28,8 +28,8 @@ factory((root.pdfjsDistBuildPdfWorker = {})); // Use strict in our context only - users might not want it 'use strict'; -var pdfjsVersion = '1.4.221'; -var pdfjsBuild = 'b282885'; +var pdfjsVersion = '1.4.225'; +var pdfjsBuild = 'be6754a'; var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? diff --git a/package.json b/package.json index ce00e70f1..083444874 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pdfjs-dist", - "version": "1.4.221", + "version": "1.4.225", "main": "build/pdf.js", "description": "Generic build of Mozilla's PDF.js library.", "keywords": [