Browse Source

PDF.js version 1.2.131 - See mozilla/pdf.js@194994a2898a6d01c434d6d3270357799f3ac820

master v1.2.131
Pdf Bot 9 years ago
parent
commit
0205e44208
  1. 2
      bower.json
  2. 105
      build/pdf.combined.js
  3. 105
      build/pdf.js
  4. 4
      build/pdf.worker.js
  5. 2
      package.json
  6. 23
      web/pdf_viewer.js

2
bower.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.2.129", "version": "1.2.131",
"main": [ "main": [
"build/pdf.js", "build/pdf.js",
"build/pdf.worker.js" "build/pdf.worker.js"

105
build/pdf.combined.js

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.2.129'; PDFJS.version = '1.2.131';
PDFJS.build = '2f1a626'; PDFJS.build = '194994a';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -2273,6 +2273,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* calling of PDFPage.getViewport method. * calling of PDFPage.getViewport method.
* @property {string} intent - Rendering intent, can be 'display' or 'print' * @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display'). * (default value is 'display').
* @property {Array} transform - (optional) Additional transform, applied
* just before viewport transform.
* @property {Object} imageLayer - (optional) An object that has beginLayout, * @property {Object} imageLayer - (optional) An object that has beginLayout,
* endLayout and appendImage functions. * endLayout and appendImage functions.
* @property {function} continueCallback - (deprecated) A function that will be * @property {function} continueCallback - (deprecated) A function that will be
@ -3291,7 +3293,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
this.objs, params.imageLayer); this.objs, params.imageLayer);
this.gfx.beginDrawing(params.viewport, transparency); this.gfx.beginDrawing(params.transform, params.viewport, transparency);
this.operatorListIdx = 0; this.operatorListIdx = 0;
this.graphicsReady = true; this.graphicsReady = true;
if (this.graphicsReadyCallback) { if (this.graphicsReadyCallback) {
@ -3588,13 +3590,15 @@ function addContextCurrentTransform(ctx) {
} }
var CachedCanvases = (function CachedCanvasesClosure() { var CachedCanvases = (function CachedCanvasesClosure() {
var cache = {}; function CachedCanvases() {
return { this.cache = Object.create(null);
}
CachedCanvases.prototype = {
getCanvas: function CachedCanvases_getCanvas(id, width, height, getCanvas: function CachedCanvases_getCanvas(id, width, height,
trackTransform) { trackTransform) {
var canvasEntry; var canvasEntry;
if (cache[id] !== undefined) { if (this.cache[id] !== undefined) {
canvasEntry = cache[id]; canvasEntry = this.cache[id];
canvasEntry.canvas.width = width; canvasEntry.canvas.width = width;
canvasEntry.canvas.height = height; canvasEntry.canvas.height = height;
// reset canvas transform for emulated mozCurrentTransform, if needed // reset canvas transform for emulated mozCurrentTransform, if needed
@ -3605,21 +3609,22 @@ var CachedCanvases = (function CachedCanvasesClosure() {
if (trackTransform) { if (trackTransform) {
addContextCurrentTransform(ctx); addContextCurrentTransform(ctx);
} }
cache[id] = canvasEntry = {canvas: canvas, context: ctx}; this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
} }
return canvasEntry; return canvasEntry;
}, },
clear: function () { clear: function () {
for (var id in cache) { for (var id in this.cache) {
var canvasEntry = cache[id]; var canvasEntry = this.cache[id];
// Zeroing the width and height causes Firefox to release graphics // Zeroing the width and height causes Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption. // resources immediately, which can greatly reduce memory consumption.
canvasEntry.canvas.width = 0; canvasEntry.canvas.width = 0;
canvasEntry.canvas.height = 0; canvasEntry.canvas.height = 0;
delete cache[id]; delete this.cache[id];
} }
} }
}; };
return CachedCanvases;
})(); })();
function compileType3Glyph(imgData) { function compileType3Glyph(imgData) {
@ -3857,6 +3862,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.smaskStack = []; this.smaskStack = [];
this.smaskCounter = 0; this.smaskCounter = 0;
this.tempSMask = null; this.tempSMask = null;
this.cachedCanvases = new CachedCanvases();
if (canvasCtx) { if (canvasCtx) {
// NOTE: if mozCurrentTransform is polyfilled, then the current state of // NOTE: if mozCurrentTransform is polyfilled, then the current state of
// the transformation must already be set in canvasCtx._transformMatrix. // the transformation must already be set in canvasCtx._transformMatrix.
@ -4133,28 +4139,39 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
CanvasGraphics.prototype = { CanvasGraphics.prototype = {
beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) { beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
transparency) {
// For pdfs that use blend modes we have to clear the canvas else certain // For pdfs that use blend modes we have to clear the canvas else certain
// blend modes can look wrong since we'd be blending with a white // blend modes can look wrong since we'd be blending with a white
// backdrop. The problem with a transparent backdrop though is we then // backdrop. The problem with a transparent backdrop though is we then
// don't get sub pixel anti aliasing on text, so we fill with white if // don't get sub pixel anti aliasing on text, creating temporary
// we can. // transparent canvas when we have blend modes.
var width = this.ctx.canvas.width; var width = this.ctx.canvas.width;
var height = this.ctx.canvas.height; var height = this.ctx.canvas.height;
this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)';
this.ctx.fillRect(0, 0, width, height);
this.ctx.restore();
if (transparency) { if (transparency) {
this.ctx.clearRect(0, 0, width, height); var transparentCanvas = this.cachedCanvases.getCanvas(
} else { 'transparent', width, height, true);
this.ctx.mozOpaque = true; this.compositeCtx = this.ctx;
this.transparentCanvas = transparentCanvas.canvas;
this.ctx = transparentCanvas.context;
this.ctx.save(); this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)'; // The transform can be applied before rendering, transferring it to
this.ctx.fillRect(0, 0, width, height); // the new canvas.
this.ctx.restore(); this.ctx.transform.apply(this.ctx,
this.compositeCtx.mozCurrentTransform);
} }
var transform = viewport.transform;
this.ctx.save(); this.ctx.save();
this.ctx.transform.apply(this.ctx, transform); if (transform) {
this.ctx.transform.apply(this.ctx, transform);
}
this.ctx.transform.apply(this.ctx, viewport.transform);
this.baseTransform = this.ctx.mozCurrentTransform.slice(); this.baseTransform = this.ctx.mozCurrentTransform.slice();
@ -4236,7 +4253,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
endDrawing: function CanvasGraphics_endDrawing() { endDrawing: function CanvasGraphics_endDrawing() {
this.ctx.restore(); this.ctx.restore();
CachedCanvases.clear();
if (this.transparentCanvas) {
this.ctx = this.compositeCtx;
this.ctx.drawImage(this.transparentCanvas, 0, 0);
this.transparentCanvas = null;
}
this.cachedCanvases.clear();
WebGLUtils.clear(); WebGLUtils.clear();
if (this.imageLayer) { if (this.imageLayer) {
@ -4350,7 +4374,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var drawnWidth = activeSMask.canvas.width; var drawnWidth = activeSMask.canvas.width;
var drawnHeight = activeSMask.canvas.height; var drawnHeight = activeSMask.canvas.height;
var cacheId = 'smaskGroupAt' + this.groupLevel; var cacheId = 'smaskGroupAt' + this.groupLevel;
var scratchCanvas = CachedCanvases.getCanvas( var scratchCanvas = this.cachedCanvases.getCanvas(
cacheId, drawnWidth, drawnHeight, true); cacheId, drawnWidth, drawnHeight, true);
var currentCtx = this.ctx; var currentCtx = this.ctx;
@ -5134,7 +5158,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Using two cache entries is case if masks are used one after another. // Using two cache entries is case if masks are used one after another.
cacheId += '_smask_' + ((this.smaskCounter++) % 2); cacheId += '_smask_' + ((this.smaskCounter++) % 2);
} }
var scratchCanvas = CachedCanvases.getCanvas( var scratchCanvas = this.cachedCanvases.getCanvas(
cacheId, drawnWidth, drawnHeight, true); cacheId, drawnWidth, drawnHeight, true);
var groupCtx = scratchCanvas.context; var groupCtx = scratchCanvas.context;
@ -5275,7 +5299,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return; return;
} }
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
width, height);
var maskCtx = maskCanvas.context; var maskCtx = maskCanvas.context;
maskCtx.save(); maskCtx.save();
@ -5300,7 +5325,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var fillColor = this.current.fillColor; var fillColor = this.current.fillColor;
var isPatternFill = this.current.patternFill; var isPatternFill = this.current.patternFill;
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
width, height);
var maskCtx = maskCanvas.context; var maskCtx = maskCanvas.context;
maskCtx.save(); maskCtx.save();
@ -5335,7 +5361,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var image = images[i]; var image = images[i];
var width = image.width, height = image.height; var width = image.width, height = image.height;
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
width, height);
var maskCtx = maskCanvas.context; var maskCtx = maskCanvas.context;
maskCtx.save(); maskCtx.save();
@ -5408,7 +5435,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (imgData instanceof HTMLElement || !imgData.data) { if (imgData instanceof HTMLElement || !imgData.data) {
imgToPaint = imgData; imgToPaint = imgData;
} else { } else {
tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
width, height);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
putBinaryImageData(tmpCtx, imgData); putBinaryImageData(tmpCtx, imgData);
imgToPaint = tmpCanvas.canvas; imgToPaint = tmpCanvas.canvas;
@ -5430,7 +5458,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
newHeight = Math.ceil(paintHeight / 2); newHeight = Math.ceil(paintHeight / 2);
heightScale /= paintHeight / newHeight; heightScale /= paintHeight / newHeight;
} }
tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
newWidth, newHeight);
tmpCtx = tmpCanvas.context; tmpCtx = tmpCanvas.context;
tmpCtx.clearRect(0, 0, newWidth, newHeight); tmpCtx.clearRect(0, 0, newWidth, newHeight);
tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
@ -5462,7 +5491,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var w = imgData.width; var w = imgData.width;
var h = imgData.height; var h = imgData.height;
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h); var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
putBinaryImageData(tmpCtx, imgData); putBinaryImageData(tmpCtx, imgData);
@ -6120,7 +6149,7 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
} }
function createMeshCanvas(bounds, combinesScale, coords, colors, figures, function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
backgroundColor) { backgroundColor, cachedCanvases) {
// we will increase scale on some weird factor to let antialiasing take // we will increase scale on some weird factor to let antialiasing take
// care of "rough" edges // care of "rough" edges
var EXPECTED_SCALE = 1.1; var EXPECTED_SCALE = 1.1;
@ -6154,11 +6183,11 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
figures, context); figures, context);
// https://bugzilla.mozilla.org/show_bug.cgi?id=972126 // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
tmpCanvas.context.drawImage(canvas, 0, 0); tmpCanvas.context.drawImage(canvas, 0, 0);
canvas = tmpCanvas.canvas; canvas = tmpCanvas.canvas;
} else { } else {
tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
var data = tmpCtx.createImageData(width, height); var data = tmpCtx.createImageData(width, height);
@ -6214,7 +6243,8 @@ ShadingIRs.Mesh = {
// Rasterizing on the main thread since sending/queue large canvases // Rasterizing on the main thread since sending/queue large canvases
// might cause OOM. // might cause OOM.
var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
colors, figures, shadingFill ? null : background); colors, figures, shadingFill ? null : background,
owner.cachedCanvases);
if (!shadingFill) { if (!shadingFill) {
ctx.setTransform.apply(ctx, owner.baseTransform); ctx.setTransform.apply(ctx, owner.baseTransform);
@ -6317,7 +6347,8 @@ var TilingPattern = (function TilingPatternClosure() {
height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
MAX_PATTERN_SIZE); MAX_PATTERN_SIZE);
var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true); var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
width, height, true);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs); var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
graphics.groupLevel = owner.groupLevel; graphics.groupLevel = owner.groupLevel;

105
build/pdf.js

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.2.129'; PDFJS.version = '1.2.131';
PDFJS.build = '2f1a626'; PDFJS.build = '194994a';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it
@ -2282,6 +2282,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* calling of PDFPage.getViewport method. * calling of PDFPage.getViewport method.
* @property {string} intent - Rendering intent, can be 'display' or 'print' * @property {string} intent - Rendering intent, can be 'display' or 'print'
* (default value is 'display'). * (default value is 'display').
* @property {Array} transform - (optional) Additional transform, applied
* just before viewport transform.
* @property {Object} imageLayer - (optional) An object that has beginLayout, * @property {Object} imageLayer - (optional) An object that has beginLayout,
* endLayout and appendImage functions. * endLayout and appendImage functions.
* @property {function} continueCallback - (deprecated) A function that will be * @property {function} continueCallback - (deprecated) A function that will be
@ -3344,7 +3346,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
this.objs, params.imageLayer); this.objs, params.imageLayer);
this.gfx.beginDrawing(params.viewport, transparency); this.gfx.beginDrawing(params.transform, params.viewport, transparency);
this.operatorListIdx = 0; this.operatorListIdx = 0;
this.graphicsReady = true; this.graphicsReady = true;
if (this.graphicsReadyCallback) { if (this.graphicsReadyCallback) {
@ -3641,13 +3643,15 @@ function addContextCurrentTransform(ctx) {
} }
var CachedCanvases = (function CachedCanvasesClosure() { var CachedCanvases = (function CachedCanvasesClosure() {
var cache = {}; function CachedCanvases() {
return { this.cache = Object.create(null);
}
CachedCanvases.prototype = {
getCanvas: function CachedCanvases_getCanvas(id, width, height, getCanvas: function CachedCanvases_getCanvas(id, width, height,
trackTransform) { trackTransform) {
var canvasEntry; var canvasEntry;
if (cache[id] !== undefined) { if (this.cache[id] !== undefined) {
canvasEntry = cache[id]; canvasEntry = this.cache[id];
canvasEntry.canvas.width = width; canvasEntry.canvas.width = width;
canvasEntry.canvas.height = height; canvasEntry.canvas.height = height;
// reset canvas transform for emulated mozCurrentTransform, if needed // reset canvas transform for emulated mozCurrentTransform, if needed
@ -3658,21 +3662,22 @@ var CachedCanvases = (function CachedCanvasesClosure() {
if (trackTransform) { if (trackTransform) {
addContextCurrentTransform(ctx); addContextCurrentTransform(ctx);
} }
cache[id] = canvasEntry = {canvas: canvas, context: ctx}; this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
} }
return canvasEntry; return canvasEntry;
}, },
clear: function () { clear: function () {
for (var id in cache) { for (var id in this.cache) {
var canvasEntry = cache[id]; var canvasEntry = this.cache[id];
// Zeroing the width and height causes Firefox to release graphics // Zeroing the width and height causes Firefox to release graphics
// resources immediately, which can greatly reduce memory consumption. // resources immediately, which can greatly reduce memory consumption.
canvasEntry.canvas.width = 0; canvasEntry.canvas.width = 0;
canvasEntry.canvas.height = 0; canvasEntry.canvas.height = 0;
delete cache[id]; delete this.cache[id];
} }
} }
}; };
return CachedCanvases;
})(); })();
function compileType3Glyph(imgData) { function compileType3Glyph(imgData) {
@ -3910,6 +3915,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.smaskStack = []; this.smaskStack = [];
this.smaskCounter = 0; this.smaskCounter = 0;
this.tempSMask = null; this.tempSMask = null;
this.cachedCanvases = new CachedCanvases();
if (canvasCtx) { if (canvasCtx) {
// NOTE: if mozCurrentTransform is polyfilled, then the current state of // NOTE: if mozCurrentTransform is polyfilled, then the current state of
// the transformation must already be set in canvasCtx._transformMatrix. // the transformation must already be set in canvasCtx._transformMatrix.
@ -4186,28 +4192,39 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
CanvasGraphics.prototype = { CanvasGraphics.prototype = {
beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) { beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
transparency) {
// For pdfs that use blend modes we have to clear the canvas else certain // For pdfs that use blend modes we have to clear the canvas else certain
// blend modes can look wrong since we'd be blending with a white // blend modes can look wrong since we'd be blending with a white
// backdrop. The problem with a transparent backdrop though is we then // backdrop. The problem with a transparent backdrop though is we then
// don't get sub pixel anti aliasing on text, so we fill with white if // don't get sub pixel anti aliasing on text, creating temporary
// we can. // transparent canvas when we have blend modes.
var width = this.ctx.canvas.width; var width = this.ctx.canvas.width;
var height = this.ctx.canvas.height; var height = this.ctx.canvas.height;
this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)';
this.ctx.fillRect(0, 0, width, height);
this.ctx.restore();
if (transparency) { if (transparency) {
this.ctx.clearRect(0, 0, width, height); var transparentCanvas = this.cachedCanvases.getCanvas(
} else { 'transparent', width, height, true);
this.ctx.mozOpaque = true; this.compositeCtx = this.ctx;
this.transparentCanvas = transparentCanvas.canvas;
this.ctx = transparentCanvas.context;
this.ctx.save(); this.ctx.save();
this.ctx.fillStyle = 'rgb(255, 255, 255)'; // The transform can be applied before rendering, transferring it to
this.ctx.fillRect(0, 0, width, height); // the new canvas.
this.ctx.restore(); this.ctx.transform.apply(this.ctx,
this.compositeCtx.mozCurrentTransform);
} }
var transform = viewport.transform;
this.ctx.save(); this.ctx.save();
this.ctx.transform.apply(this.ctx, transform); if (transform) {
this.ctx.transform.apply(this.ctx, transform);
}
this.ctx.transform.apply(this.ctx, viewport.transform);
this.baseTransform = this.ctx.mozCurrentTransform.slice(); this.baseTransform = this.ctx.mozCurrentTransform.slice();
@ -4289,7 +4306,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
endDrawing: function CanvasGraphics_endDrawing() { endDrawing: function CanvasGraphics_endDrawing() {
this.ctx.restore(); this.ctx.restore();
CachedCanvases.clear();
if (this.transparentCanvas) {
this.ctx = this.compositeCtx;
this.ctx.drawImage(this.transparentCanvas, 0, 0);
this.transparentCanvas = null;
}
this.cachedCanvases.clear();
WebGLUtils.clear(); WebGLUtils.clear();
if (this.imageLayer) { if (this.imageLayer) {
@ -4403,7 +4427,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var drawnWidth = activeSMask.canvas.width; var drawnWidth = activeSMask.canvas.width;
var drawnHeight = activeSMask.canvas.height; var drawnHeight = activeSMask.canvas.height;
var cacheId = 'smaskGroupAt' + this.groupLevel; var cacheId = 'smaskGroupAt' + this.groupLevel;
var scratchCanvas = CachedCanvases.getCanvas( var scratchCanvas = this.cachedCanvases.getCanvas(
cacheId, drawnWidth, drawnHeight, true); cacheId, drawnWidth, drawnHeight, true);
var currentCtx = this.ctx; var currentCtx = this.ctx;
@ -5187,7 +5211,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
// Using two cache entries is case if masks are used one after another. // Using two cache entries is case if masks are used one after another.
cacheId += '_smask_' + ((this.smaskCounter++) % 2); cacheId += '_smask_' + ((this.smaskCounter++) % 2);
} }
var scratchCanvas = CachedCanvases.getCanvas( var scratchCanvas = this.cachedCanvases.getCanvas(
cacheId, drawnWidth, drawnHeight, true); cacheId, drawnWidth, drawnHeight, true);
var groupCtx = scratchCanvas.context; var groupCtx = scratchCanvas.context;
@ -5328,7 +5352,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return; return;
} }
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
width, height);
var maskCtx = maskCanvas.context; var maskCtx = maskCanvas.context;
maskCtx.save(); maskCtx.save();
@ -5353,7 +5378,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var fillColor = this.current.fillColor; var fillColor = this.current.fillColor;
var isPatternFill = this.current.patternFill; var isPatternFill = this.current.patternFill;
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
width, height);
var maskCtx = maskCanvas.context; var maskCtx = maskCanvas.context;
maskCtx.save(); maskCtx.save();
@ -5388,7 +5414,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var image = images[i]; var image = images[i];
var width = image.width, height = image.height; var width = image.width, height = image.height;
var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
width, height);
var maskCtx = maskCanvas.context; var maskCtx = maskCanvas.context;
maskCtx.save(); maskCtx.save();
@ -5461,7 +5488,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
if (imgData instanceof HTMLElement || !imgData.data) { if (imgData instanceof HTMLElement || !imgData.data) {
imgToPaint = imgData; imgToPaint = imgData;
} else { } else {
tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
width, height);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
putBinaryImageData(tmpCtx, imgData); putBinaryImageData(tmpCtx, imgData);
imgToPaint = tmpCanvas.canvas; imgToPaint = tmpCanvas.canvas;
@ -5483,7 +5511,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
newHeight = Math.ceil(paintHeight / 2); newHeight = Math.ceil(paintHeight / 2);
heightScale /= paintHeight / newHeight; heightScale /= paintHeight / newHeight;
} }
tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
newWidth, newHeight);
tmpCtx = tmpCanvas.context; tmpCtx = tmpCanvas.context;
tmpCtx.clearRect(0, 0, newWidth, newHeight); tmpCtx.clearRect(0, 0, newWidth, newHeight);
tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
@ -5515,7 +5544,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var w = imgData.width; var w = imgData.width;
var h = imgData.height; var h = imgData.height;
var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h); var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
putBinaryImageData(tmpCtx, imgData); putBinaryImageData(tmpCtx, imgData);
@ -6173,7 +6202,7 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
} }
function createMeshCanvas(bounds, combinesScale, coords, colors, figures, function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
backgroundColor) { backgroundColor, cachedCanvases) {
// we will increase scale on some weird factor to let antialiasing take // we will increase scale on some weird factor to let antialiasing take
// care of "rough" edges // care of "rough" edges
var EXPECTED_SCALE = 1.1; var EXPECTED_SCALE = 1.1;
@ -6207,11 +6236,11 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
figures, context); figures, context);
// https://bugzilla.mozilla.org/show_bug.cgi?id=972126 // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
tmpCanvas.context.drawImage(canvas, 0, 0); tmpCanvas.context.drawImage(canvas, 0, 0);
canvas = tmpCanvas.canvas; canvas = tmpCanvas.canvas;
} else { } else {
tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
var data = tmpCtx.createImageData(width, height); var data = tmpCtx.createImageData(width, height);
@ -6267,7 +6296,8 @@ ShadingIRs.Mesh = {
// Rasterizing on the main thread since sending/queue large canvases // Rasterizing on the main thread since sending/queue large canvases
// might cause OOM. // might cause OOM.
var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
colors, figures, shadingFill ? null : background); colors, figures, shadingFill ? null : background,
owner.cachedCanvases);
if (!shadingFill) { if (!shadingFill) {
ctx.setTransform.apply(ctx, owner.baseTransform); ctx.setTransform.apply(ctx, owner.baseTransform);
@ -6370,7 +6400,8 @@ var TilingPattern = (function TilingPatternClosure() {
height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
MAX_PATTERN_SIZE); MAX_PATTERN_SIZE);
var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true); var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
width, height, true);
var tmpCtx = tmpCanvas.context; var tmpCtx = tmpCanvas.context;
var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs); var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
graphics.groupLevel = owner.groupLevel; graphics.groupLevel = owner.groupLevel;

4
build/pdf.worker.js vendored

@ -20,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {}; (typeof window !== 'undefined' ? window : this).PDFJS = {};
} }
PDFJS.version = '1.2.129'; PDFJS.version = '1.2.131';
PDFJS.build = '2f1a626'; PDFJS.build = '194994a';
(function pdfjsWrapper() { (function pdfjsWrapper() {
// Use strict in our context only - users might not want it // Use strict in our context only - users might not want it

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "pdfjs-dist", "name": "pdfjs-dist",
"version": "1.2.129", "version": "1.2.131",
"description": "Generic build of Mozilla's PDF.js library.", "description": "Generic build of Mozilla's PDF.js library.",
"keywords": [ "keywords": [
"Mozilla", "Mozilla",

23
web/pdf_viewer.js

@ -1083,8 +1083,7 @@ var PDFPageView = (function PDFPageViewClosure() {
var isScalingRestricted = false; var isScalingRestricted = false;
if (this.canvas && PDFJS.maxCanvasPixels > 0) { if (this.canvas && PDFJS.maxCanvasPixels > 0) {
var ctx = this.canvas.getContext('2d'); var outputScale = this.outputScale;
var outputScale = getOutputScale(ctx);
var pixelsInViewport = this.viewport.width * this.viewport.height; var pixelsInViewport = this.viewport.width * this.viewport.height;
var maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport); var maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport);
if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) * if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
@ -1228,6 +1227,7 @@ var PDFPageView = (function PDFPageViewClosure() {
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.id = 'page' + this.id; canvas.id = 'page' + this.id;
canvas.setAttribute('hidden', 'hidden');
canvasWrapper.appendChild(canvas); canvasWrapper.appendChild(canvas);
if (this.annotationLayer && this.annotationLayer.div) { if (this.annotationLayer && this.annotationLayer.div) {
// annotationLayer needs to stay on top // annotationLayer needs to stay on top
@ -1235,10 +1235,12 @@ var PDFPageView = (function PDFPageViewClosure() {
} else { } else {
div.appendChild(canvasWrapper); div.appendChild(canvasWrapper);
} }
var isCanvasHidden = true;
this.canvas = canvas; this.canvas = canvas;
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d', {alpha: false});
var outputScale = getOutputScale(ctx); var outputScale = getOutputScale(ctx);
this.outputScale = outputScale;
if (PDFJS.useOnlyCssZoom) { if (PDFJS.useOnlyCssZoom) {
var actualSizeViewport = viewport.clone({scale: CSS_UNITS}); var actualSizeViewport = viewport.clone({scale: CSS_UNITS});
@ -1291,12 +1293,6 @@ var PDFPageView = (function PDFPageViewClosure() {
} }
this.textLayer = textLayer; this.textLayer = textLayer;
if (outputScale.scaled) {
// Used by the mozCurrentTransform polyfill in src/display/canvas.js.
ctx._transformMatrix = [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
ctx.scale(outputScale.sx, outputScale.sy);
}
var resolveRenderPromise, rejectRenderPromise; var resolveRenderPromise, rejectRenderPromise;
var promise = new Promise(function (resolve, reject) { var promise = new Promise(function (resolve, reject) {
resolveRenderPromise = resolve; resolveRenderPromise = resolve;
@ -1367,12 +1363,19 @@ var PDFPageView = (function PDFPageViewClosure() {
}; };
return; return;
} }
if (isCanvasHidden) {
self.canvas.removeAttribute('hidden');
isCanvasHidden = false;
}
cont(); cont();
}; };
} }
var transform = !outputScale.scaled ? null :
[outputScale.sx, 0, 0, outputScale.sy, 0, 0];
var renderContext = { var renderContext = {
canvasContext: ctx, canvasContext: ctx,
transform: transform,
viewport: this.viewport, viewport: this.viewport,
// intent: 'default', // === 'display' // intent: 'default', // === 'display'
}; };
@ -1536,7 +1539,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
var textDivs = this.textDivs; var textDivs = this.textDivs;
var textDivsLength = textDivs.length; var textDivsLength = textDivs.length;
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d', {alpha: false});
// No point in rendering many divs as it would make the browser // No point in rendering many divs as it would make the browser
// unusable even after the divs are rendered. // unusable even after the divs are rendered.

Loading…
Cancel
Save