1
- /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
- /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3
1
/* Copyright 2012 Mozilla Foundation
4
2
*
5
3
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +20,8 @@ if (typeof PDFJS === 'undefined') {
22
20
( typeof window !== 'undefined' ? window : this ) . PDFJS = { } ;
23
21
}
24
22
25
- PDFJS .version = '1.2.83 ' ;
26
- PDFJS .build = '1280b7b ' ;
23
+ PDFJS . version = '1.2.131 ' ;
24
+ PDFJS . build = '194994a ' ;
27
25
28
26
( function pdfjsWrapper ( ) {
29
27
// Use strict in our context only - users might not want it
@@ -1972,9 +1970,9 @@ PDFJS.getDocument = function getDocument(src,
1972
1970
/**
1973
1971
* PDF document loading operation.
1974
1972
* @class
1973
+ * @alias PDFDocumentLoadingTask
1975
1974
*/
1976
1975
var PDFDocumentLoadingTask = ( function PDFDocumentLoadingTaskClosure ( ) {
1977
- /** @constructs PDFDocumentLoadingTask */
1978
1976
function PDFDocumentLoadingTask ( ) {
1979
1977
this . _capability = createPromiseCapability ( ) ;
1980
1978
this . _transport = null ;
@@ -2031,13 +2029,11 @@ var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
2031
2029
/**
2032
2030
* Abstract class to support range requests file loading.
2033
2031
* @class
2032
+ * @alias PDFJS.PDFDataRangeTransport
2033
+ * @param {number } length
2034
+ * @param {Uint8Array } initialData
2034
2035
*/
2035
2036
var PDFDataRangeTransport = ( function pdfDataRangeTransportClosure ( ) {
2036
- /**
2037
- * @constructs PDFDataRangeTransport
2038
- * @param {number} length
2039
- * @param {Uint8Array} initialData
2040
- */
2041
2037
function PDFDataRangeTransport ( length , initialData ) {
2042
2038
this . length = length ;
2043
2039
this . initialData = initialData ;
@@ -2111,6 +2107,7 @@ PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
2111
2107
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
2112
2108
* properties that can be read synchronously.
2113
2109
* @class
2110
+ * @alias PDFDocumentProxy
2114
2111
*/
2115
2112
var PDFDocumentProxy = ( function PDFDocumentProxyClosure ( ) {
2116
2113
function PDFDocumentProxy ( pdfInfo , transport , loadingTask ) {
@@ -2285,6 +2282,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
2285
2282
* calling of PDFPage.getViewport method.
2286
2283
* @property {string } intent - Rendering intent, can be 'display' or 'print'
2287
2284
* (default value is 'display').
2285
+ * @property {Array } transform - (optional) Additional transform, applied
2286
+ * just before viewport transform.
2288
2287
* @property {Object } imageLayer - (optional) An object that has beginLayout,
2289
2288
* endLayout and appendImage functions.
2290
2289
* @property {function } continueCallback - (deprecated) A function that will be
@@ -2305,6 +2304,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
2305
2304
/**
2306
2305
* Proxy to a PDFPage in the worker thread.
2307
2306
* @class
2307
+ * @alias PDFPageProxy
2308
2308
*/
2309
2309
var PDFPageProxy = ( function PDFPageProxyClosure ( ) {
2310
2310
function PDFPageProxy ( pageIndex , pageInfo , transport ) {
@@ -3250,6 +3250,7 @@ var PDFObjects = (function PDFObjectsClosure() {
3250
3250
/**
3251
3251
* Allows controlling of the rendering tasks.
3252
3252
* @class
3253
+ * @alias RenderTask
3253
3254
*/
3254
3255
var RenderTask = ( function RenderTaskClosure ( ) {
3255
3256
function RenderTask ( internalRenderTask ) {
@@ -3345,7 +3346,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
3345
3346
this . gfx = new CanvasGraphics ( params . canvasContext , this . commonObjs ,
3346
3347
this . objs , params . imageLayer ) ;
3347
3348
3348
- this .gfx .beginDrawing (params .viewport , transparency );
3349
+ this . gfx . beginDrawing ( params . transform , params . viewport , transparency ) ;
3349
3350
this . operatorListIdx = 0 ;
3350
3351
this . graphicsReady = true ;
3351
3352
if ( this . graphicsReadyCallback ) {
@@ -3642,13 +3643,15 @@ function addContextCurrentTransform(ctx) {
3642
3643
}
3643
3644
3644
3645
var CachedCanvases = ( function CachedCanvasesClosure ( ) {
3645
- var cache = {};
3646
- return {
3646
+ function CachedCanvases ( ) {
3647
+ this . cache = Object . create ( null ) ;
3648
+ }
3649
+ CachedCanvases . prototype = {
3647
3650
getCanvas : function CachedCanvases_getCanvas ( id , width , height ,
3648
3651
trackTransform ) {
3649
3652
var canvasEntry ;
3650
- if (cache [id ] !== undefined ) {
3651
- canvasEntry = cache [id ];
3653
+ if ( this . cache [ id ] !== undefined ) {
3654
+ canvasEntry = this . cache [ id ] ;
3652
3655
canvasEntry . canvas . width = width ;
3653
3656
canvasEntry . canvas . height = height ;
3654
3657
// reset canvas transform for emulated mozCurrentTransform, if needed
@@ -3659,21 +3662,22 @@ var CachedCanvases = (function CachedCanvasesClosure() {
3659
3662
if ( trackTransform ) {
3660
3663
addContextCurrentTransform ( ctx ) ;
3661
3664
}
3662
- cache [id ] = canvasEntry = {canvas : canvas , context : ctx };
3665
+ this . cache [ id ] = canvasEntry = { canvas : canvas , context : ctx } ;
3663
3666
}
3664
3667
return canvasEntry ;
3665
3668
} ,
3666
3669
clear : function ( ) {
3667
- for (var id in cache ) {
3668
- var canvasEntry = cache [id ];
3670
+ for ( var id in this . cache ) {
3671
+ var canvasEntry = this . cache [ id ] ;
3669
3672
// Zeroing the width and height causes Firefox to release graphics
3670
3673
// resources immediately, which can greatly reduce memory consumption.
3671
3674
canvasEntry . canvas . width = 0 ;
3672
3675
canvasEntry . canvas . height = 0 ;
3673
- delete cache [id ];
3676
+ delete this . cache [ id ] ;
3674
3677
}
3675
3678
}
3676
3679
} ;
3680
+ return CachedCanvases ;
3677
3681
} ) ( ) ;
3678
3682
3679
3683
function compileType3Glyph ( imgData ) {
@@ -3911,6 +3915,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
3911
3915
this . smaskStack = [ ] ;
3912
3916
this . smaskCounter = 0 ;
3913
3917
this . tempSMask = null ;
3918
+ this . cachedCanvases = new CachedCanvases ( ) ;
3914
3919
if ( canvasCtx ) {
3915
3920
// NOTE: if mozCurrentTransform is polyfilled, then the current state of
3916
3921
// the transformation must already be set in canvasCtx._transformMatrix.
@@ -4187,28 +4192,39 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
4187
4192
4188
4193
CanvasGraphics . prototype = {
4189
4194
4190
- beginDrawing : function CanvasGraphics_beginDrawing (viewport , transparency ) {
4195
+ beginDrawing : function CanvasGraphics_beginDrawing ( transform , viewport ,
4196
+ transparency ) {
4191
4197
// For pdfs that use blend modes we have to clear the canvas else certain
4192
4198
// blend modes can look wrong since we'd be blending with a white
4193
4199
// backdrop. The problem with a transparent backdrop though is we then
4194
- // don't get sub pixel anti aliasing on text, so we fill with white if
4195
- // we can .
4200
+ // don't get sub pixel anti aliasing on text, creating temporary
4201
+ // transparent canvas when we have blend modes .
4196
4202
var width = this . ctx . canvas . width ;
4197
4203
var height = this . ctx . canvas . height ;
4204
+
4205
+ this . ctx . save ( ) ;
4206
+ this . ctx . fillStyle = 'rgb(255, 255, 255)' ;
4207
+ this . ctx . fillRect ( 0 , 0 , width , height ) ;
4208
+ this . ctx . restore ( ) ;
4209
+
4198
4210
if ( transparency ) {
4199
- this .ctx .clearRect (0 , 0 , width , height );
4200
- } else {
4201
- this .ctx .mozOpaque = true ;
4211
+ var transparentCanvas = this . cachedCanvases . getCanvas (
4212
+ 'transparent' , width , height , true ) ;
4213
+ this . compositeCtx = this . ctx ;
4214
+ this . transparentCanvas = transparentCanvas . canvas ;
4215
+ this . ctx = transparentCanvas . context ;
4202
4216
this . ctx . save ( ) ;
4203
- this .ctx .fillStyle = 'rgb(255, 255, 255)' ;
4204
- this .ctx .fillRect (0 , 0 , width , height );
4205
- this .ctx .restore ();
4217
+ // The transform can be applied before rendering, transferring it to
4218
+ // the new canvas.
4219
+ this . ctx . transform . apply ( this . ctx ,
4220
+ this . compositeCtx . mozCurrentTransform ) ;
4206
4221
}
4207
4222
4208
- var transform = viewport .transform ;
4209
-
4210
4223
this . ctx . save ( ) ;
4211
- this .ctx .transform .apply (this .ctx , transform );
4224
+ if ( transform ) {
4225
+ this . ctx . transform . apply ( this . ctx , transform ) ;
4226
+ }
4227
+ this . ctx . transform . apply ( this . ctx , viewport . transform ) ;
4212
4228
4213
4229
this . baseTransform = this . ctx . mozCurrentTransform . slice ( ) ;
4214
4230
@@ -4290,7 +4306,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
4290
4306
4291
4307
endDrawing : function CanvasGraphics_endDrawing ( ) {
4292
4308
this . ctx . restore ( ) ;
4293
- CachedCanvases .clear ();
4309
+
4310
+ if ( this . transparentCanvas ) {
4311
+ this . ctx = this . compositeCtx ;
4312
+ this . ctx . drawImage ( this . transparentCanvas , 0 , 0 ) ;
4313
+ this . transparentCanvas = null ;
4314
+ }
4315
+
4316
+ this . cachedCanvases . clear ( ) ;
4294
4317
WebGLUtils . clear ( ) ;
4295
4318
4296
4319
if ( this . imageLayer ) {
@@ -4404,7 +4427,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
4404
4427
var drawnWidth = activeSMask . canvas . width ;
4405
4428
var drawnHeight = activeSMask . canvas . height ;
4406
4429
var cacheId = 'smaskGroupAt' + this . groupLevel ;
4407
- var scratchCanvas = CachedCanvases .getCanvas (
4430
+ var scratchCanvas = this . cachedCanvases . getCanvas (
4408
4431
cacheId , drawnWidth , drawnHeight , true ) ;
4409
4432
4410
4433
var currentCtx = this . ctx ;
@@ -5188,7 +5211,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5188
5211
// Using two cache entries is case if masks are used one after another.
5189
5212
cacheId += '_smask_' + ( ( this . smaskCounter ++ ) % 2 ) ;
5190
5213
}
5191
- var scratchCanvas = CachedCanvases .getCanvas (
5214
+ var scratchCanvas = this . cachedCanvases . getCanvas (
5192
5215
cacheId , drawnWidth , drawnHeight , true ) ;
5193
5216
var groupCtx = scratchCanvas . context ;
5194
5217
@@ -5329,7 +5352,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5329
5352
return ;
5330
5353
}
5331
5354
5332
- var maskCanvas = CachedCanvases .getCanvas ('maskCanvas' , width , height );
5355
+ var maskCanvas = this . cachedCanvases . getCanvas ( 'maskCanvas' ,
5356
+ width , height ) ;
5333
5357
var maskCtx = maskCanvas . context ;
5334
5358
maskCtx . save ( ) ;
5335
5359
@@ -5354,7 +5378,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5354
5378
var fillColor = this . current . fillColor ;
5355
5379
var isPatternFill = this . current . patternFill ;
5356
5380
5357
- var maskCanvas = CachedCanvases .getCanvas ('maskCanvas' , width , height );
5381
+ var maskCanvas = this . cachedCanvases . getCanvas ( 'maskCanvas' ,
5382
+ width , height ) ;
5358
5383
var maskCtx = maskCanvas . context ;
5359
5384
maskCtx . save ( ) ;
5360
5385
@@ -5389,7 +5414,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5389
5414
var image = images [ i ] ;
5390
5415
var width = image . width , height = image . height ;
5391
5416
5392
- var maskCanvas = CachedCanvases .getCanvas ('maskCanvas' , width , height );
5417
+ var maskCanvas = this . cachedCanvases . getCanvas ( 'maskCanvas' ,
5418
+ width , height ) ;
5393
5419
var maskCtx = maskCanvas . context ;
5394
5420
maskCtx . save ( ) ;
5395
5421
@@ -5462,7 +5488,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5462
5488
if ( imgData instanceof HTMLElement || ! imgData . data ) {
5463
5489
imgToPaint = imgData ;
5464
5490
} else {
5465
- tmpCanvas = CachedCanvases .getCanvas ('inlineImage' , width , height );
5491
+ tmpCanvas = this . cachedCanvases . getCanvas ( 'inlineImage' ,
5492
+ width , height ) ;
5466
5493
var tmpCtx = tmpCanvas . context ;
5467
5494
putBinaryImageData ( tmpCtx , imgData ) ;
5468
5495
imgToPaint = tmpCanvas . canvas ;
@@ -5484,7 +5511,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5484
5511
newHeight = Math . ceil ( paintHeight / 2 ) ;
5485
5512
heightScale /= paintHeight / newHeight ;
5486
5513
}
5487
- tmpCanvas = CachedCanvases .getCanvas (tmpCanvasId , newWidth , newHeight );
5514
+ tmpCanvas = this . cachedCanvases . getCanvas ( tmpCanvasId ,
5515
+ newWidth , newHeight ) ;
5488
5516
tmpCtx = tmpCanvas . context ;
5489
5517
tmpCtx . clearRect ( 0 , 0 , newWidth , newHeight ) ;
5490
5518
tmpCtx . drawImage ( imgToPaint , 0 , 0 , paintWidth , paintHeight ,
@@ -5516,7 +5544,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
5516
5544
var w = imgData . width ;
5517
5545
var h = imgData . height ;
5518
5546
5519
- var tmpCanvas = CachedCanvases .getCanvas ('inlineImage' , w , h );
5547
+ var tmpCanvas = this . cachedCanvases . getCanvas ( 'inlineImage' , w , h ) ;
5520
5548
var tmpCtx = tmpCanvas . context ;
5521
5549
putBinaryImageData ( tmpCtx , imgData ) ;
5522
5550
@@ -6174,7 +6202,7 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
6174
6202
}
6175
6203
6176
6204
function createMeshCanvas ( bounds , combinesScale , coords , colors , figures ,
6177
- backgroundColor ) {
6205
+ backgroundColor , cachedCanvases ) {
6178
6206
// we will increase scale on some weird factor to let antialiasing take
6179
6207
// care of "rough" edges
6180
6208
var EXPECTED_SCALE = 1.1 ;
@@ -6208,11 +6236,11 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
6208
6236
figures , context ) ;
6209
6237
6210
6238
// https://bugzilla.mozilla.org/show_bug.cgi?id=972126
6211
- tmpCanvas = CachedCanvases .getCanvas ('mesh' , width , height , false );
6239
+ tmpCanvas = cachedCanvases . getCanvas ( 'mesh' , width , height , false ) ;
6212
6240
tmpCanvas . context . drawImage ( canvas , 0 , 0 ) ;
6213
6241
canvas = tmpCanvas . canvas ;
6214
6242
} else {
6215
- tmpCanvas = CachedCanvases .getCanvas ('mesh' , width , height , false );
6243
+ tmpCanvas = cachedCanvases . getCanvas ( 'mesh' , width , height , false ) ;
6216
6244
var tmpCtx = tmpCanvas . context ;
6217
6245
6218
6246
var data = tmpCtx . createImageData ( width , height ) ;
@@ -6268,7 +6296,8 @@ ShadingIRs.Mesh = {
6268
6296
// Rasterizing on the main thread since sending/queue large canvases
6269
6297
// might cause OOM.
6270
6298
var temporaryPatternCanvas = createMeshCanvas ( bounds , scale , coords ,
6271
- colors , figures , shadingFill ? null : background );
6299
+ colors , figures , shadingFill ? null : background ,
6300
+ owner . cachedCanvases ) ;
6272
6301
6273
6302
if ( ! shadingFill ) {
6274
6303
ctx . setTransform . apply ( ctx , owner . baseTransform ) ;
@@ -6371,7 +6400,8 @@ var TilingPattern = (function TilingPatternClosure() {
6371
6400
height = Math . min ( Math . ceil ( Math . abs ( height * combinedScale [ 1 ] ) ) ,
6372
6401
MAX_PATTERN_SIZE ) ;
6373
6402
6374
- var tmpCanvas = CachedCanvases .getCanvas ('pattern' , width , height , true );
6403
+ var tmpCanvas = owner . cachedCanvases . getCanvas ( 'pattern' ,
6404
+ width , height , true ) ;
6375
6405
var tmpCtx = tmpCanvas . context ;
6376
6406
var graphics = new CanvasGraphics ( tmpCtx , commonObjs , objs ) ;
6377
6407
graphics . groupLevel = owner . groupLevel ;
0 commit comments