diff --git a/example/js/lib/pdf.js b/example/js/lib/pdf.js index 39d4815..ff5cff3 100644 --- a/example/js/lib/pdf.js +++ b/example/js/lib/pdf.js @@ -1,5 +1,3 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* Copyright 2012 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +20,8 @@ if (typeof PDFJS === 'undefined') { (typeof window !== 'undefined' ? window : this).PDFJS = {}; } -PDFJS.version = '1.2.83'; -PDFJS.build = '1280b7b'; +PDFJS.version = '1.2.131'; +PDFJS.build = '194994a'; (function pdfjsWrapper() { // Use strict in our context only - users might not want it @@ -1972,9 +1970,9 @@ PDFJS.getDocument = function getDocument(src, /** * PDF document loading operation. * @class + * @alias PDFDocumentLoadingTask */ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() { - /** @constructs PDFDocumentLoadingTask */ function PDFDocumentLoadingTask() { this._capability = createPromiseCapability(); this._transport = null; @@ -2031,13 +2029,11 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() { /** * Abstract class to support range requests file loading. * @class + * @alias PDFJS.PDFDataRangeTransport + * @param {number} length + * @param {Uint8Array} initialData */ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() { - /** - * @constructs PDFDataRangeTransport - * @param {number} length - * @param {Uint8Array} initialData - */ function PDFDataRangeTransport(length, initialData) { this.length = length; this.initialData = initialData; @@ -2111,6 +2107,7 @@ PDFJS.PDFDataRangeTransport = PDFDataRangeTransport; * Proxy to a PDFDocument in the worker thread. Also, contains commonly used * properties that can be read synchronously. * @class + * @alias PDFDocumentProxy */ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { function PDFDocumentProxy(pdfInfo, transport, loadingTask) { @@ -2285,6 +2282,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { * calling of PDFPage.getViewport method. * @property {string} intent - Rendering intent, can be 'display' or 'print' * (default value is 'display'). + * @property {Array} transform - (optional) Additional transform, applied + * just before viewport transform. * @property {Object} imageLayer - (optional) An object that has beginLayout, * endLayout and appendImage functions. * @property {function} continueCallback - (deprecated) A function that will be @@ -2305,6 +2304,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { /** * Proxy to a PDFPage in the worker thread. * @class + * @alias PDFPageProxy */ var PDFPageProxy = (function PDFPageProxyClosure() { function PDFPageProxy(pageIndex, pageInfo, transport) { @@ -3250,6 +3250,7 @@ var PDFObjects = (function PDFObjectsClosure() { /** * Allows controlling of the rendering tasks. * @class + * @alias RenderTask */ var RenderTask = (function RenderTaskClosure() { function RenderTask(internalRenderTask) { @@ -3345,7 +3346,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() { this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, params.imageLayer); - this.gfx.beginDrawing(params.viewport, transparency); + this.gfx.beginDrawing(params.transform, params.viewport, transparency); this.operatorListIdx = 0; this.graphicsReady = true; if (this.graphicsReadyCallback) { @@ -3642,13 +3643,15 @@ function addContextCurrentTransform(ctx) { } var CachedCanvases = (function CachedCanvasesClosure() { - var cache = {}; - return { + function CachedCanvases() { + this.cache = Object.create(null); + } + CachedCanvases.prototype = { getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) { var canvasEntry; - if (cache[id] !== undefined) { - canvasEntry = cache[id]; + if (this.cache[id] !== undefined) { + canvasEntry = this.cache[id]; canvasEntry.canvas.width = width; canvasEntry.canvas.height = height; // reset canvas transform for emulated mozCurrentTransform, if needed @@ -3659,21 +3662,22 @@ var CachedCanvases = (function CachedCanvasesClosure() { if (trackTransform) { addContextCurrentTransform(ctx); } - cache[id] = canvasEntry = {canvas: canvas, context: ctx}; + this.cache[id] = canvasEntry = {canvas: canvas, context: ctx}; } return canvasEntry; }, clear: function () { - for (var id in cache) { - var canvasEntry = cache[id]; + for (var id in this.cache) { + var canvasEntry = this.cache[id]; // Zeroing the width and height causes Firefox to release graphics // resources immediately, which can greatly reduce memory consumption. canvasEntry.canvas.width = 0; canvasEntry.canvas.height = 0; - delete cache[id]; + delete this.cache[id]; } } }; + return CachedCanvases; })(); function compileType3Glyph(imgData) { @@ -3911,6 +3915,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.smaskStack = []; this.smaskCounter = 0; this.tempSMask = null; + this.cachedCanvases = new CachedCanvases(); if (canvasCtx) { // NOTE: if mozCurrentTransform is polyfilled, then the current state of // the transformation must already be set in canvasCtx._transformMatrix. @@ -4187,28 +4192,39 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { 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 // blend modes can look wrong since we'd be blending with a white // 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 - // we can. + // don't get sub pixel anti aliasing on text, creating temporary + // transparent canvas when we have blend modes. var width = this.ctx.canvas.width; 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) { - this.ctx.clearRect(0, 0, width, height); - } else { - this.ctx.mozOpaque = true; + var transparentCanvas = this.cachedCanvases.getCanvas( + 'transparent', width, height, true); + this.compositeCtx = this.ctx; + this.transparentCanvas = transparentCanvas.canvas; + this.ctx = transparentCanvas.context; this.ctx.save(); - this.ctx.fillStyle = 'rgb(255, 255, 255)'; - this.ctx.fillRect(0, 0, width, height); - this.ctx.restore(); + // The transform can be applied before rendering, transferring it to + // the new canvas. + this.ctx.transform.apply(this.ctx, + this.compositeCtx.mozCurrentTransform); } - var transform = viewport.transform; - 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(); @@ -4290,7 +4306,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { endDrawing: function CanvasGraphics_endDrawing() { 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(); if (this.imageLayer) { @@ -4404,7 +4427,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var drawnWidth = activeSMask.canvas.width; var drawnHeight = activeSMask.canvas.height; var cacheId = 'smaskGroupAt' + this.groupLevel; - var scratchCanvas = CachedCanvases.getCanvas( + var scratchCanvas = this.cachedCanvases.getCanvas( cacheId, drawnWidth, drawnHeight, true); var currentCtx = this.ctx; @@ -5188,7 +5211,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { // Using two cache entries is case if masks are used one after another. cacheId += '_smask_' + ((this.smaskCounter++) % 2); } - var scratchCanvas = CachedCanvases.getCanvas( + var scratchCanvas = this.cachedCanvases.getCanvas( cacheId, drawnWidth, drawnHeight, true); var groupCtx = scratchCanvas.context; @@ -5329,7 +5352,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { return; } - var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); + var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', + width, height); var maskCtx = maskCanvas.context; maskCtx.save(); @@ -5354,7 +5378,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var fillColor = this.current.fillColor; var isPatternFill = this.current.patternFill; - var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height); + var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', + width, height); var maskCtx = maskCanvas.context; maskCtx.save(); @@ -5389,7 +5414,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var image = images[i]; 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; maskCtx.save(); @@ -5462,7 +5488,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { if (imgData instanceof HTMLElement || !imgData.data) { imgToPaint = imgData; } else { - tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height); + tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', + width, height); var tmpCtx = tmpCanvas.context; putBinaryImageData(tmpCtx, imgData); imgToPaint = tmpCanvas.canvas; @@ -5484,7 +5511,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { newHeight = Math.ceil(paintHeight / 2); heightScale /= paintHeight / newHeight; } - tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); + tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, + newWidth, newHeight); tmpCtx = tmpCanvas.context; tmpCtx.clearRect(0, 0, newWidth, newHeight); tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, @@ -5516,7 +5544,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { var w = imgData.width; var h = imgData.height; - var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h); + var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h); var tmpCtx = tmpCanvas.context; putBinaryImageData(tmpCtx, imgData); @@ -6174,7 +6202,7 @@ var createMeshCanvas = (function createMeshCanvasClosure() { } function createMeshCanvas(bounds, combinesScale, coords, colors, figures, - backgroundColor) { + backgroundColor, cachedCanvases) { // we will increase scale on some weird factor to let antialiasing take // care of "rough" edges var EXPECTED_SCALE = 1.1; @@ -6208,11 +6236,11 @@ var createMeshCanvas = (function createMeshCanvasClosure() { figures, context); // 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); canvas = tmpCanvas.canvas; } else { - tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false); + tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false); var tmpCtx = tmpCanvas.context; var data = tmpCtx.createImageData(width, height); @@ -6268,7 +6296,8 @@ ShadingIRs.Mesh = { // Rasterizing on the main thread since sending/queue large canvases // might cause OOM. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, - colors, figures, shadingFill ? null : background); + colors, figures, shadingFill ? null : background, + owner.cachedCanvases); if (!shadingFill) { ctx.setTransform.apply(ctx, owner.baseTransform); @@ -6371,7 +6400,8 @@ var TilingPattern = (function TilingPatternClosure() { height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), 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 graphics = new CanvasGraphics(tmpCtx, commonObjs, objs); graphics.groupLevel = owner.groupLevel; diff --git a/example/js/lib/pdf.worker.js b/example/js/lib/pdf.worker.js index 06663fa..5496ef5 100644 --- a/example/js/lib/pdf.worker.js +++ b/example/js/lib/pdf.worker.js @@ -1,5 +1,3 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ /* Copyright 2012 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,8 +20,8 @@ if (typeof PDFJS === 'undefined') { (typeof window !== 'undefined' ? window : this).PDFJS = {}; } -PDFJS.version = '1.2.83'; -PDFJS.build = '1280b7b'; +PDFJS.version = '1.2.131'; +PDFJS.build = '194994a'; (function pdfjsWrapper() { // Use strict in our context only - users might not want it @@ -1847,11 +1845,13 @@ var NetworkManager = (function NetworkManagerClosure() { }); } else if (pendingRequest.onProgressiveData) { pendingRequest.onDone(null); - } else { + } else if (chunk) { pendingRequest.onDone({ begin: 0, chunk: chunk }); + } else if (pendingRequest.onError) { + pendingRequest.onError(xhr.status); } }, @@ -4983,10 +4983,11 @@ var ExpertSubsetCharset = [ var DEFAULT_ICON_SIZE = 22; // px /** - * @constructor + * @class + * @alias AnnotationFactory */ function AnnotationFactory() {} -AnnotationFactory.prototype = { +AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ { /** * @param {XRef} xref * @param {Object} ref @@ -10232,6 +10233,11 @@ Shadings.RadialAxial = (function RadialAxialClosure() { if (matrix) { p0 = Util.applyTransform(p0, matrix); p1 = Util.applyTransform(p1, matrix); + if (shadingType === ShadingType.RADIAL) { + var scale = Util.singularValueDecompose2dScale(matrix); + r0 *= scale[0]; + r1 *= scale[1]; + } } return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1]; @@ -17837,6 +17843,15 @@ var Font = (function FontClosure() { * PDF spec */ function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) { + if (!cmap) { + warn('No cmap table available.'); + return { + platformId: -1, + encodingId: -1, + mappings: [], + hasShortCmap: false + }; + } var segment; var start = (font.start ? font.start : 0) + cmap.offset; font.pos = start; @@ -27189,7 +27204,12 @@ var PDFImage = (function PDFImageClosure() { this.smask = new PDFImage(xref, res, smask, false); } else if (mask) { if (isStream(mask)) { - this.mask = new PDFImage(xref, res, mask, false, null, null, true); + var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM'); + if (!imageMask) { + warn('Ignoring /Mask in image without /ImageMask.'); + } else { + this.mask = new PDFImage(xref, res, mask, false, null, null, true); + } } else { // Color key mask (just an array). this.mask = mask; @@ -34571,7 +34591,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = { onError: function onError(status) { var exception; - if (status === 404) { + if (status === 404 || status === 0 && /^file:/.test(source.url)) { exception = new MissingPDFException('Missing PDF "' + source.url + '".'); handler.send('MissingPDF', exception); @@ -35109,6 +35129,7 @@ var ArithmeticDecoder = (function ArithmeticDecoderClosure() { })(); + var JpegImage = (function jpegImage() { var dctZigZag = new Uint8Array([ 0, @@ -39787,6 +39808,7 @@ var bidi = PDFJS.bidi = (function bidiClosure() { })(); + var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) { // Workaround for missing math precison in JS. var MASK_HIGH = 0xffff0000;