Merge upstream

This commit is contained in:
Brendan Dahl 2011-10-31 08:51:45 -07:00
commit 3592baf39c
23 changed files with 213 additions and 93 deletions

View File

@ -1,8 +1,11 @@
// <canvas> contexts store most of the state we need natively. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// However, PDF needs a bit more state, which we store here. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict'; 'use strict';
// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.
var CanvasExtraState = (function canvasExtraState() { var CanvasExtraState = (function canvasExtraState() {
function constructor(old) { function constructor(old) {
// Are soft masks and alpha values shapes or opacities? // Are soft masks and alpha values shapes or opacities?
@ -21,7 +24,9 @@ var CanvasExtraState = (function canvasExtraState() {
this.wordSpacing = 0; this.wordSpacing = 0;
this.textHScale = 1; this.textHScale = 1;
// Color spaces // Color spaces
this.fillColorSpace = new DeviceGrayCS;
this.fillColorSpaceObj = null; this.fillColorSpaceObj = null;
this.strokeColorSpace = new DeviceGrayCS;
this.strokeColorSpaceObj = null; this.strokeColorSpaceObj = null;
this.fillColorObj = null; this.fillColorObj = null;
this.strokeColorObj = null; this.strokeColorObj = null;
@ -325,10 +330,12 @@ var CanvasGraphics = (function canvasGraphics() {
this.restoreFillRule(savedFillRule); this.restoreFillRule(savedFillRule);
}, },
closeFillStroke: function canvasGraphicsCloseFillStroke() { closeFillStroke: function canvasGraphicsCloseFillStroke() {
return this.fillStroke(); this.closePath();
this.fillStroke();
}, },
closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() { closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() {
var savedFillRule = this.setEOFillRule(); var savedFillRule = this.setEOFillRule();
this.closePath();
this.fillStroke(); this.fillStroke();
this.restoreFillRule(savedFillRule); this.restoreFillRule(savedFillRule);
}, },
@ -530,8 +537,7 @@ var CanvasGraphics = (function canvasGraphics() {
}, },
// Color // Color
setStrokeColorSpace: setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpace(raw) {
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
this.current.strokeColorSpace = ColorSpace.fromIR(raw); this.current.strokeColorSpace = ColorSpace.fromIR(raw);
}, },
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) { setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) {
@ -542,7 +548,7 @@ var CanvasGraphics = (function canvasGraphics() {
var color = cs.getRgb(arguments); var color = cs.getRgb(arguments);
this.setStrokeRGBColor.apply(this, color); this.setStrokeRGBColor.apply(this, color);
}, },
getColorN_IR_Pattern: function(IR, cs) { getColorN_IR_Pattern: function canvasGraphicsGetColorN_IR_Pattern(IR, cs) {
if (IR[0] == 'TilingPattern') { if (IR[0] == 'TilingPattern') {
var args = IR[1]; var args = IR[1];
var base = cs.base; var base = cs.base;
@ -658,8 +664,8 @@ var CanvasGraphics = (function canvasGraphics() {
error('Should not call beginImageData'); error('Should not call beginImageData');
}, },
paintFormXObjectBegin: paintFormXObjectBegin: function canvasGraphicsPaintFormXObjectBegin(matrix,
function canvasGraphicsPaintFormXObject(matrix, bbox) { bbox) {
this.save(); this.save();
if (matrix && isArray(matrix) && 6 == matrix.length) if (matrix && isArray(matrix) && 6 == matrix.length)
@ -674,11 +680,11 @@ var CanvasGraphics = (function canvasGraphics() {
} }
}, },
paintFormXObjectEnd: function() { paintFormXObjectEnd: function canvasGraphicsPaintFormXObjectEnd() {
this.restore(); this.restore();
}, },
paintJpegXObject: function(objId, w, h) { paintJpegXObject: function canvasGraphicsPaintJpegXObject(objId, w, h) {
var image = this.objs.get(objId); var image = this.objs.get(objId);
if (!image) { if (!image) {
error('Dependent image isn\'t ready yet'); error('Dependent image isn\'t ready yet');
@ -697,7 +703,8 @@ var CanvasGraphics = (function canvasGraphics() {
this.restore(); this.restore();
}, },
paintImageMaskXObject: function(imgArray, inverseDecode, width, height) { paintImageMaskXObject: function canvasGraphicsPaintImageMaskXObject(
imgArray, inverseDecode, width, height) {
function applyStencilMask(buffer, inverseDecode) { function applyStencilMask(buffer, inverseDecode) {
var imgArrayPos = 0; var imgArrayPos = 0;
var i, j, mask, buf; var i, j, mask, buf;
@ -745,7 +752,7 @@ var CanvasGraphics = (function canvasGraphics() {
this.restore(); this.restore();
}, },
paintImageXObject: function(imgData) { paintImageXObject: function canvasGraphicsPaintImageXObject(imgData) {
this.save(); this.save();
var ctx = this.ctx; var ctx = this.ctx;
var w = imgData.width; var w = imgData.width;
@ -834,3 +841,4 @@ var CanvasGraphics = (function canvasGraphics() {
return constructor; return constructor;
})(); })();

View File

@ -6930,3 +6930,4 @@ var CIDToUnicodeMaps = {
{f: 39, c: 19576}, {f: 111, c: 19620}, {f: 148, c: 19738}, {f: 39, c: 19576}, {f: 111, c: 19620}, {f: 148, c: 19738},
{f: 7, c: 19887}] {f: 7, c: 19887}]
}; };

View File

@ -12,17 +12,17 @@ var ColorSpace = (function colorSpaceColorSpace() {
constructor.prototype = { constructor.prototype = {
// Input: array of size numComps representing color component values // Input: array of size numComps representing color component values
// Output: array of rgb values, each value ranging from [0.1] // Output: array of rgb values, each value ranging from [0.1]
getRgb: function cs_getRgb(color) { getRgb: function colorSpaceGetRgb(color) {
error('Should not call ColorSpace.getRgb: ' + color); error('Should not call ColorSpace.getRgb: ' + color);
}, },
// Input: Uint8Array of component values, each value scaled to [0,255] // Input: Uint8Array of component values, each value scaled to [0,255]
// Output: Uint8Array of rgb values, each value scaled to [0,255] // Output: Uint8Array of rgb values, each value scaled to [0,255]
getRgbBuffer: function cs_getRgbBuffer(input) { getRgbBuffer: function colorSpaceGetRgbBuffer(input) {
error('Should not call ColorSpace.getRgbBuffer: ' + input); error('Should not call ColorSpace.getRgbBuffer: ' + input);
} }
}; };
constructor.parse = function colorspace_parse(cs, xref, res) { constructor.parse = function colorSpaceParse(cs, xref, res) {
var IR = constructor.parseToIR(cs, xref, res, true); var IR = constructor.parseToIR(cs, xref, res, true);
if (IR instanceof SeparationCS) if (IR instanceof SeparationCS)
return IR; return IR;
@ -30,7 +30,7 @@ var ColorSpace = (function colorSpaceColorSpace() {
return constructor.fromIR(IR); return constructor.fromIR(IR);
}; };
constructor.fromIR = function(IR) { constructor.fromIR = function colorSpaceFromIR(IR) {
var name; var name;
if (isArray(IR)) { if (isArray(IR)) {
name = IR[0]; name = IR[0];
@ -71,7 +71,8 @@ var ColorSpace = (function colorSpaceColorSpace() {
return null; return null;
} }
constructor.parseToIR = function colorspace_parse(cs, xref, res, parseOnly) { constructor.parseToIR = function colorSpaceParseToIR(cs, xref, res,
parseOnly) {
if (isName(cs)) { if (isName(cs)) {
var colorSpaces = xref.fetchIfRef(res.get('ColorSpace')); var colorSpaces = xref.fetchIfRef(res.get('ColorSpace'));
if (isDict(colorSpaces)) { if (isDict(colorSpaces)) {
@ -397,5 +398,7 @@ var DeviceCmykCS = (function deviceCmykCS() {
return rgbBuf; return rgbBuf;
} }
}; };
return constructor; return constructor;
})(); })();

View File

@ -153,7 +153,7 @@ var Page = (function pagePage() {
return shadow(this, 'rotate', rotate); return shadow(this, 'rotate', rotate);
}, },
startRenderingFromIRQueue: function startRenderingFromIRQueue( startRenderingFromIRQueue: function pageStartRenderingFromIRQueue(
IRQueue, fonts) { IRQueue, fonts) {
var self = this; var self = this;
this.IRQueue = IRQueue; this.IRQueue = IRQueue;
@ -173,12 +173,13 @@ var Page = (function pagePage() {
}); });
}; };
this.ensureFonts(fonts, function() { this.ensureFonts(fonts,
function pageStartRenderingFromIRQueueEnsureFonts() {
displayContinuation(); displayContinuation();
}); });
}, },
getIRQueue: function(handler, dependency) { getIRQueue: function pageGetIRQueue(handler, dependency) {
if (this.IRQueue) { if (this.IRQueue) {
// content was compiled // content was compiled
return this.IRQueue; return this.IRQueue;
@ -202,7 +203,7 @@ var Page = (function pagePage() {
content, resources, IRQueue, dependency); content, resources, IRQueue, dependency);
}, },
ensureFonts: function(fonts, callback) { ensureFonts: function pageEnsureFonts(fonts, callback) {
// Convert the font names to the corresponding font obj. // Convert the font names to the corresponding font obj.
for (var i = 0; i < fonts.length; i++) { for (var i = 0; i < fonts.length; i++) {
fonts[i] = this.objs.objs[fonts[i]].data; fonts[i] = this.objs.objs[fonts[i]].data;
@ -211,7 +212,7 @@ var Page = (function pagePage() {
// Load all the fonts // Load all the fonts
var fontObjs = FontLoader.bind( var fontObjs = FontLoader.bind(
fonts, fonts,
function(fontObjs) { function pageEnsureFontsFontObjs(fontObjs) {
this.stats.fonts = Date.now(); this.stats.fonts = Date.now();
callback.call(this); callback.call(this);
@ -220,7 +221,7 @@ var Page = (function pagePage() {
); );
}, },
display: function(gfx, callback) { display: function pageDisplay(gfx, callback) {
var xref = this.xref; var xref = this.xref;
var resources = xref.fetchIfRef(this.resources); var resources = xref.fetchIfRef(this.resources);
var mediaBox = xref.fetchIfRef(this.mediaBox); var mediaBox = xref.fetchIfRef(this.mediaBox);
@ -305,7 +306,7 @@ var Page = (function pagePage() {
} }
return links; return links;
}, },
startRendering: function(ctx, callback) { startRendering: function pageStartRendering(ctx, callback) {
this.ctx = ctx; this.ctx = ctx;
this.callback = callback; this.callback = callback;
@ -446,7 +447,7 @@ var PDFDocModel = (function pdfDoc() {
return constructor; return constructor;
})(); })();
var PDFDoc = (function() { var PDFDoc = (function pdfDoc() {
function constructor(arg, callback) { function constructor(arg, callback) {
var stream = null; var stream = null;
var data = null; var data = null;
@ -475,10 +476,10 @@ var PDFDoc = (function() {
} else { } else {
// If we don't use a worker, just post/sendMessage to the main thread. // If we don't use a worker, just post/sendMessage to the main thread.
var worker = { var worker = {
postMessage: function(obj) { postMessage: function pdfDocPostMessage(obj) {
worker.onmessage({data: obj}); worker.onmessage({data: obj});
}, },
terminate: function() {} terminate: function pdfDocTerminate() {}
}; };
} }
this.worker = worker; this.worker = worker;
@ -488,7 +489,7 @@ var PDFDoc = (function() {
var processorHandler = this.processorHandler = var processorHandler = this.processorHandler =
new MessageHandler('main', worker); new MessageHandler('main', worker);
processorHandler.on('page', function(data) { processorHandler.on('page', function pdfDocPage(data) {
var pageNum = data.pageNum; var pageNum = data.pageNum;
var page = this.pageCache[pageNum]; var page = this.pageCache[pageNum];
var depFonts = data.depFonts; var depFonts = data.depFonts;
@ -496,7 +497,7 @@ var PDFDoc = (function() {
page.startRenderingFromIRQueue(data.IRQueue, depFonts); page.startRenderingFromIRQueue(data.IRQueue, depFonts);
}, this); }, this);
processorHandler.on('obj', function(data) { processorHandler.on('obj', function pdfDocObj(data) {
var id = data[0]; var id = data[0];
var type = data[1]; var type = data[1];
@ -540,7 +541,7 @@ var PDFDoc = (function() {
} }
}, this); }, this);
processorHandler.on('font_ready', function(data) { processorHandler.on('font_ready', function pdfDocFontReady(data) {
var id = data[0]; var id = data[0];
var font = new FontShape(data[1]); var font = new FontShape(data[1]);
@ -559,7 +560,7 @@ var PDFDoc = (function() {
} }
this.workerReadyPromise = new Promise('workerReady'); this.workerReadyPromise = new Promise('workerReady');
setTimeout(function() { setTimeout(function pdfDocFontReadySetTimeout() {
processorHandler.send('doc', this.data); processorHandler.send('doc', this.data);
this.workerReadyPromise.resolve(true); this.workerReadyPromise.resolve(true);
}.bind(this)); }.bind(this));
@ -570,14 +571,14 @@ var PDFDoc = (function() {
return this.pdf.numPages; return this.pdf.numPages;
}, },
startRendering: function(page) { startRendering: function pdfDocStartRendering(page) {
// The worker might not be ready to receive the page request yet. // The worker might not be ready to receive the page request yet.
this.workerReadyPromise.then(function() { this.workerReadyPromise.then(function pdfDocStartRenderingThen() {
this.processorHandler.send('page_request', page.pageNumber + 1); this.processorHandler.send('page_request', page.pageNumber + 1);
}.bind(this)); }.bind(this));
}, },
getPage: function(n) { getPage: function pdfDocGetPage(n) {
if (this.pageCache[n]) if (this.pageCache[n])
return this.pageCache[n]; return this.pageCache[n];
@ -589,7 +590,7 @@ var PDFDoc = (function() {
return this.pageCache[n] = page; return this.pageCache[n] = page;
}, },
destroy: function() { destroy: function pdfDocDestroy() {
if (this.worker) if (this.worker)
this.worker.terminate(); this.worker.terminate();
@ -608,4 +609,6 @@ var PDFDoc = (function() {
return constructor; return constructor;
})(); })();
globalScope.PDFJS.PDFDoc = PDFDoc; globalScope.PDFJS.PDFDoc = PDFDoc;

View File

@ -595,3 +595,4 @@ var CipherTransformFactory = (function cipherTransformFactory() {
return constructor; return constructor;
})(); })();

View File

@ -918,3 +918,4 @@ var EvalState = (function evalState() {
}; };
return constructor; return constructor;
})(); })();

View File

@ -3272,3 +3272,4 @@ var Type2CFF = (function type2CFF() {
return constructor; return constructor;
})(); })();

View File

@ -3,14 +3,15 @@
'use strict'; 'use strict';
var PDFFunction = (function() { var PDFFunction = (function pdfFunction() {
var CONSTRUCT_SAMPLED = 0; var CONSTRUCT_SAMPLED = 0;
var CONSTRUCT_INTERPOLATED = 2; var CONSTRUCT_INTERPOLATED = 2;
var CONSTRUCT_STICHED = 3; var CONSTRUCT_STICHED = 3;
var CONSTRUCT_POSTSCRIPT = 4; var CONSTRUCT_POSTSCRIPT = 4;
return { return {
getSampleArray: function(size, outputSize, bps, str) { getSampleArray: function pdfFunctionGetSampleArray(size, outputSize, bps,
str) {
var length = 1; var length = 1;
for (var i = 0; i < size.length; i++) for (var i = 0; i < size.length; i++)
length *= size[i]; length *= size[i];
@ -35,7 +36,7 @@ var PDFFunction = (function() {
return array; return array;
}, },
getIR: function(xref, fn) { getIR: function pdfFunctionGetIR(xref, fn) {
var dict = fn.dict; var dict = fn.dict;
if (!dict) if (!dict)
dict = fn; dict = fn;
@ -54,7 +55,7 @@ var PDFFunction = (function() {
return typeFn.call(this, fn, dict, xref); return typeFn.call(this, fn, dict, xref);
}, },
fromIR: function(IR) { fromIR: function pdfFunctionFromIR(IR) {
var type = IR[0]; var type = IR[0];
switch (type) { switch (type) {
case CONSTRUCT_SAMPLED: case CONSTRUCT_SAMPLED:
@ -69,12 +70,12 @@ var PDFFunction = (function() {
} }
}, },
parse: function(xref, fn) { parse: function pdfFunctionParse(xref, fn) {
var IR = this.getIR(xref, fn); var IR = this.getIR(xref, fn);
return this.fromIR(IR); return this.fromIR(IR);
}, },
constructSampled: function(str, dict) { constructSampled: function pdfFunctionConstructSampled(str, dict) {
var domain = dict.get('Domain'); var domain = dict.get('Domain');
var range = dict.get('Range'); var range = dict.get('Range');
@ -116,7 +117,7 @@ var PDFFunction = (function() {
]; ];
}, },
constructSampledFromIR: function(IR) { constructSampledFromIR: function pdfFunctionConstructSampledFromIR(IR) {
var inputSize = IR[1]; var inputSize = IR[1];
var domain = IR[2]; var domain = IR[2];
var encode = IR[3]; var encode = IR[3];
@ -127,8 +128,8 @@ var PDFFunction = (function() {
var bps = IR[8]; var bps = IR[8];
var range = IR[9]; var range = IR[9];
return function(args) { return function constructSampledFromIRResult(args) {
var clip = function(v, min, max) { var clip = function constructSampledFromIRClip(v, min, max) {
if (v > max) if (v > max)
v = max; v = max;
else if (v < min) else if (v < min)
@ -212,7 +213,7 @@ var PDFFunction = (function() {
var length = diff.length; var length = diff.length;
return function(args) { return function constructInterpolatedFromIRResult(args) {
var x = n == 1 ? args[0] : Math.pow(args[0], n); var x = n == 1 ? args[0] : Math.pow(args[0], n);
var out = []; var out = [];
@ -257,8 +258,8 @@ var PDFFunction = (function() {
fns.push(PDFFunction.fromIR(fnsIR[i])); fns.push(PDFFunction.fromIR(fnsIR[i]));
} }
return function(args) { return function constructStichedFromIRResult(args) {
var clip = function(v, min, max) { var clip = function constructStichedFromIRClip(v, min, max) {
if (v > max) if (v > max)
v = max; v = max;
else if (v < min) else if (v < min)
@ -298,9 +299,10 @@ var PDFFunction = (function() {
constructPostScriptFromIR: function pdfFunctionConstructPostScriptFromIR() { constructPostScriptFromIR: function pdfFunctionConstructPostScriptFromIR() {
TODO('unhandled type of function'); TODO('unhandled type of function');
return function() { return function constructPostScriptFromIRResult() {
return [255, 105, 180]; return [255, 105, 180];
}; };
} }
}; };
})(); })();

View File

@ -229,12 +229,12 @@ var PDFImage = (function pdfImage() {
return constructor; return constructor;
})(); })();
var JpegImage = (function() { var JpegImage = (function jpegImage() {
function JpegImage(objId, imageData, objs) { function JpegImage(objId, imageData, objs) {
var src = 'data:image/jpeg;base64,' + window.btoa(imageData); var src = 'data:image/jpeg;base64,' + window.btoa(imageData);
var img = new Image(); var img = new Image();
img.onload = (function() { img.onload = (function jpegImageOnload() {
this.loaded = true; this.loaded = true;
objs.resolve(objId, this); objs.resolve(objId, this);
@ -247,10 +247,11 @@ var JpegImage = (function() {
} }
JpegImage.prototype = { JpegImage.prototype = {
getImage: function() { getImage: function jpegImageGetImage() {
return this.domImage; return this.domImage;
} }
}; };
return JpegImage; return JpegImage;
})(); })();

View File

@ -2941,3 +2941,4 @@ var Metrics = {
'a191': 918 'a191': 918
} }
}; };

View File

@ -642,7 +642,7 @@ var XRef = (function xRefXRef() {
* inside of a worker. The `PDFObjects` implements some basic functions to * inside of a worker. The `PDFObjects` implements some basic functions to
* manage these objects. * manage these objects.
*/ */
var PDFObjects = (function() { var PDFObjects = (function pdfObjects() {
function PDFObjects() { function PDFObjects() {
this.objs = {}; this.objs = {};
} }
@ -655,7 +655,7 @@ var PDFObjects = (function() {
* Ensures there is an object defined for `objId`. Stores `data` on the * Ensures there is an object defined for `objId`. Stores `data` on the
* object *if* it is created. * object *if* it is created.
*/ */
ensureObj: function(objId, data) { ensureObj: function pdfObjectsEnsureObj(objId, data) {
if (this.objs[objId]) if (this.objs[objId])
return this.objs[objId]; return this.objs[objId];
return this.objs[objId] = new Promise(objId, data); return this.objs[objId] = new Promise(objId, data);
@ -670,7 +670,7 @@ var PDFObjects = (function() {
* function and the object is already resolved, the callback gets called * function and the object is already resolved, the callback gets called
* right away. * right away.
*/ */
get: function(objId, callback) { get: function pdfObjectsGet(objId, callback) {
// If there is a callback, then the get can be async and the object is // If there is a callback, then the get can be async and the object is
// not required to be resolved right now // not required to be resolved right now
if (callback) { if (callback) {
@ -695,7 +695,7 @@ var PDFObjects = (function() {
/** /**
* Resolves the object `objId` with optional `data`. * Resolves the object `objId` with optional `data`.
*/ */
resolve: function(objId, data) { resolve: function pdfObjectsResolve(objId, data) {
var objs = this.objs; var objs = this.objs;
// In case there is a promise already on this object, just resolve it. // In case there is a promise already on this object, just resolve it.
@ -706,11 +706,11 @@ var PDFObjects = (function() {
} }
}, },
onData: function(objId, callback) { onData: function pdfObjectsOnData(objId, callback) {
this.ensureObj(objId).onData(callback); this.ensureObj(objId).onData(callback);
}, },
isResolved: function(objId) { isResolved: function pdfObjectsIsResolved(objId) {
var objs = this.objs; var objs = this.objs;
if (!objs[objId]) { if (!objs[objId]) {
return false; return false;
@ -719,7 +719,7 @@ var PDFObjects = (function() {
} }
}, },
hasData: function(objId) { hasData: function pdfObjectsHasData(objId) {
var objs = this.objs; var objs = this.objs;
if (!objs[objId]) { if (!objs[objId]) {
return false; return false;
@ -731,7 +731,7 @@ var PDFObjects = (function() {
/** /**
* Sets the data of an object but *doesn't* resolve it. * Sets the data of an object but *doesn't* resolve it.
*/ */
setData: function(objId, data) { setData: function pdfObjectsSetData(objId, data) {
// Watchout! If you call `this.ensureObj(objId, data)` you're going to // Watchout! If you call `this.ensureObj(objId, data)` you're going to
// create a *resolved* promise which shouldn't be the case! // create a *resolved* promise which shouldn't be the case!
this.ensureObj(objId).data = data; this.ensureObj(objId).data = data;
@ -739,3 +739,4 @@ var PDFObjects = (function() {
}; };
return PDFObjects; return PDFObjects;
})(); })();

View File

@ -633,3 +633,4 @@ var Linearization = (function linearizationLinearization() {
return constructor; return constructor;
})(); })();

View File

@ -97,7 +97,7 @@ Shadings.RadialAxial = (function radialAxialShading() {
this.colorStops = colorStops; this.colorStops = colorStops;
} }
constructor.fromIR = function(ctx, raw) { constructor.fromIR = function radialAxialShadingGetIR(ctx, raw) {
var type = raw[1]; var type = raw[1];
var colorStops = raw[2]; var colorStops = raw[2];
var p0 = raw[3]; var p0 = raw[3];
@ -129,7 +129,7 @@ Shadings.RadialAxial = (function radialAxialShading() {
} }
constructor.prototype = { constructor.prototype = {
getIR: function RadialAxialShading_getIR() { getIR: function radialAxialShadingGetIR() {
var coordsArr = this.coordsArr; var coordsArr = this.coordsArr;
var type = this.shadingType; var type = this.shadingType;
if (type == 2) { if (type == 2) {
@ -164,12 +164,12 @@ Shadings.Dummy = (function dummyShading() {
this.type = 'Pattern'; this.type = 'Pattern';
} }
constructor.fromIR = function() { constructor.fromIR = function dummyShadingFromIR() {
return 'hotpink'; return 'hotpink';
} }
constructor.prototype = { constructor.prototype = {
getIR: function dummpy_getir() { getIR: function dummyShadingGetIR() {
return ['Dummy']; return ['Dummy'];
} }
}; };
@ -287,3 +287,4 @@ var TilingPattern = (function tilingPattern() {
return TilingPattern; return TilingPattern;
})(); })();

View File

@ -12,3 +12,4 @@ var PDFJS = {};
/* PDFJSSCRIPT_INCLUDE_ALL */ /* PDFJSSCRIPT_INCLUDE_ALL */
})(); })();

View File

@ -801,7 +801,7 @@ var JpegStream = (function jpegStream() {
} }
constructor.prototype = { constructor.prototype = {
getIR: function() { getIR: function jpegStreamGetIR() {
return this.src; return this.src;
}, },
getChar: function jpegStreamGetChar() { getChar: function jpegStreamGetChar() {
@ -2073,3 +2073,4 @@ var LZWStream = (function lzwStream() {
return constructor; return constructor;
})(); })();

View File

@ -16,16 +16,15 @@ function warn(msg) {
} }
function backtrace() { function backtrace() {
var stackStr;
try { try {
throw new Error(); throw new Error();
} catch (e) { } catch (e) {
stackStr = e.stack; return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
} }
return stackStr.split('\n').slice(1).join('\n');
} }
function error(msg) { function error(msg) {
log('Error: ' + msg);
log(backtrace()); log(backtrace());
throw new Error(msg); throw new Error(msg);
} }
@ -198,7 +197,7 @@ function isPDFFunction(v) {
* can be set. If any of these happens twice or the data is required before * can be set. If any of these happens twice or the data is required before
* it was set, an exception is throw. * it was set, an exception is throw.
*/ */
var Promise = (function() { var Promise = (function promise() {
var EMPTY_PROMISE = {}; var EMPTY_PROMISE = {};
/** /**
@ -222,19 +221,19 @@ var Promise = (function() {
Promise.prototype = { Promise.prototype = {
hasData: false, hasData: false,
set data(data) { set data(value) {
if (data === undefined) { if (value === undefined) {
return; return;
} }
if (this._data !== EMPTY_PROMISE) { if (this._data !== EMPTY_PROMISE) {
throw 'Promise ' + this.name + throw 'Promise ' + this.name +
': Cannot set the data of a promise twice'; ': Cannot set the data of a promise twice';
} }
this._data = data; this._data = value;
this.hasData = true; this.hasData = true;
if (this.onDataCallback) { if (this.onDataCallback) {
this.onDataCallback(data); this.onDataCallback(value);
} }
}, },
@ -245,7 +244,7 @@ var Promise = (function() {
return this._data; return this._data;
}, },
onData: function(callback) { onData: function promiseOnData(callback) {
if (this._data !== EMPTY_PROMISE) { if (this._data !== EMPTY_PROMISE) {
callback(this._data); callback(this._data);
} else { } else {
@ -253,7 +252,7 @@ var Promise = (function() {
} }
}, },
resolve: function(data) { resolve: function promiseResolve(data) {
if (this.isResolved) { if (this.isResolved) {
throw 'A Promise can be resolved only once ' + this.name; throw 'A Promise can be resolved only once ' + this.name;
} }
@ -267,7 +266,7 @@ var Promise = (function() {
} }
}, },
then: function(callback) { then: function promiseThen(callback) {
if (!callback) { if (!callback) {
throw 'Requiring callback' + this.name; throw 'Requiring callback' + this.name;
} }
@ -281,5 +280,7 @@ var Promise = (function() {
} }
} }
}; };
return Promise; return Promise;
})(); })();

View File

@ -8,14 +8,14 @@ function MessageHandler(name, comObj) {
this.comObj = comObj; this.comObj = comObj;
var ah = this.actionHandler = {}; var ah = this.actionHandler = {};
ah['console_log'] = [function(data) { ah['console_log'] = [function ahConsoleLog(data) {
console.log.apply(console, data); console.log.apply(console, data);
}]; }];
ah['console_error'] = [function(data) { ah['console_error'] = [function ahConsoleError(data) {
console.error.apply(console, data); console.error.apply(console, data);
}]; }];
comObj.onmessage = function(event) { comObj.onmessage = function messageHandlerComObjOnMessage(event) {
var data = event.data; var data = event.data;
if (data.action in ah) { if (data.action in ah) {
var action = ah[data.action]; var action = ah[data.action];
@ -27,15 +27,15 @@ function MessageHandler(name, comObj) {
} }
MessageHandler.prototype = { MessageHandler.prototype = {
on: function(actionName, handler, scope) { on: function messageHandlerOn(actionName, handler, scope) {
var ah = this.actionHandler; var ah = this.actionHandler;
if (ah[actionName]) { if (ah[actionName]) {
throw "There is already an actionName called '" + actionName + "'"; throw 'There is already an actionName called "' + actionName + '"';
} }
ah[actionName] = [handler, scope]; ah[actionName] = [handler, scope];
}, },
send: function(actionName, data) { send: function messageHandlerSend(actionName, data) {
this.comObj.postMessage({ this.comObj.postMessage({
action: actionName, action: actionName,
data: data data: data
@ -44,16 +44,16 @@ MessageHandler.prototype = {
}; };
var WorkerProcessorHandler = { var WorkerProcessorHandler = {
setup: function(handler) { setup: function wphSetup(handler) {
var pdfDoc = null; var pdfDoc = null;
handler.on('doc', function(data) { handler.on('doc', function wphSetupDoc(data) {
// Create only the model of the PDFDoc, which is enough for // Create only the model of the PDFDoc, which is enough for
// processing the content of the pdf. // processing the content of the pdf.
pdfDoc = new PDFDocModel(new Stream(data)); pdfDoc = new PDFDocModel(new Stream(data));
}); });
handler.on('page_request', function(pageNum) { handler.on('page_request', function wphSetupPageRequest(pageNum) {
pageNum = parseInt(pageNum); pageNum = parseInt(pageNum);
var page = pdfDoc.getPage(pageNum); var page = pdfDoc.getPage(pageNum);
@ -89,7 +89,7 @@ var WorkerProcessorHandler = {
}); });
}, this); }, this);
handler.on('font', function(data) { handler.on('font', function wphSetupFont(data) {
var objId = data[0]; var objId = data[0];
var name = data[1]; var name = data[1];
var file = data[2]; var file = data[2];
@ -122,11 +122,11 @@ var WorkerProcessorHandler = {
var obj = new Font(font.name, font.file, font.properties); var obj = new Font(font.name, font.file, font.properties);
var str = ''; var str = '';
var data = obj.data; var objData = obj.data;
if (data) { if (objData) {
var length = data.length; var length = objData.length;
for (var j = 0; j < length; j++) for (var j = 0; j < length; ++j)
str += String.fromCharCode(data[j]); str += String.fromCharCode(objData[j]);
} }
obj.str = str; obj.str = str;
@ -159,11 +159,11 @@ var workerConsole = {
}); });
}, },
time: function(name) { time: function time(name) {
consoleTimer[name] = Date.now(); consoleTimer[name] = Date.now();
}, },
timeEnd: function(name) { timeEnd: function timeEnd(name) {
var time = consoleTimer[name]; var time = consoleTimer[name];
if (time == null) { if (time == null) {
throw 'Unkown timer name ' + name; throw 'Unkown timer name ' + name;
@ -180,3 +180,4 @@ if (typeof window === 'undefined') {
var handler = new MessageHandler('worker_processor', globalScope); var handler = new MessageHandler('worker_processor', globalScope);
WorkerProcessorHandler.setup(handler); WorkerProcessorHandler.setup(handler);
} }

View File

@ -21,3 +21,4 @@ importScripts('../src/parser.js');
importScripts('../src/pattern.js'); importScripts('../src/pattern.js');
importScripts('../src/stream.js'); importScripts('../src/stream.js');
importScripts('../src/worker.js'); importScripts('../src/worker.js');

View File

@ -12,5 +12,6 @@
!rotation.pdf !rotation.pdf
!simpletype3font.pdf !simpletype3font.pdf
!sizes.pdf !sizes.pdf
!close-path-bug.pdf
!alphatrans.pdf !alphatrans.pdf

View File

@ -0,0 +1,69 @@
%PDF-1.4
1 0 obj
<</Type /Catalog/Outlines 2 0 R/Pages 3 0 R>>
endobj
2 0 obj
<</Type /Outlines/Count 0>>
endobj
3 0 obj
<</Type /Pages/Kids [4 0 R]/Count 1>>
endobj
4 0 obj
<</Type /Page/Parent 3 0 R/MediaBox [0 0 612 792]/Contents 5 0 R/Resources << /ProcSet 6 0 R >>>>
endobj
5 0 obj
<< /Length 885 >>
stream
% Draw a black line segment, using the default line width.
150 250 m
150 350 l
S
% Draw a thicker, dashed line segment.
4 w % Set line width to 4 points
[4 6] 0 d % Set dash pattern to 4 units on, 6 units off
150 250 m
400 250 l
S
[] 0 d % Reset dash pattern to a solid line
1 w % Reset line width to 1 unit
% Draw a rectangle with a 1unit red border, filled with light blue.
1.0 0.0 0.0 RG % Red for stroke color
0.5 0.75 1.0 rg % Light blue for fill color
200 300 50 75 re
B
% Draw a curve filled with gray and with a colored border.
0.5 0.1 0.2 RG
0.7 g
300 300 m
300 400 400 400 400 300 c
b
endstream
endobj
6 0 obj
[/PDF]
endobj
xref
0 7
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n
0000000179 00000 n
0000000300 00000 n
0000001532 00000 n
trailer
<</Size 7/Root 1 0 R>>
startxref
1556
%%EOF

View File

@ -218,6 +218,11 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "close-path-bug",
"file": "pdfs/close-path-bug.pdf",
"rounds": 1,
"type": "eq"
},
{ "id": "alphatrans", { "id": "alphatrans",
"file": "pdfs/alphatrans.pdf", "file": "pdfs/alphatrans.pdf",
"link": false, "link": false,

View File

@ -83,6 +83,21 @@
}; };
})(); })();
// Object.keys() ?
(function checkObjectKeysCompatibility() {
if (typeof Object.keys !== 'undefined')
return;
Object.keys = function objectKeys(obj) {
var result = [];
for (var i in obj) {
if (obj.hasOwnProperty(i))
result.push(i);
}
return result;
};
})();
// No XMLHttpRequest.response ? // No XMLHttpRequest.response ?
(function checkXMLHttpRequestResponseCompatibility() { (function checkXMLHttpRequestResponseCompatibility() {
var xhrPrototype = XMLHttpRequest.prototype; var xhrPrototype = XMLHttpRequest.prototype;

View File

@ -3,6 +3,7 @@
<head> <head>
<title>Simple pdf.js page viewer</title> <title>Simple pdf.js page viewer</title>
<link rel="stylesheet" href="viewer.css"/> <link rel="stylesheet" href="viewer.css"/>
<script type="text/javascript" src="compatibility.js"></script>
<!-- PDFJSSCRIPT_INCLUDE_BUILD --> <!-- PDFJSSCRIPT_INCLUDE_BUILD -->
@ -25,7 +26,6 @@
<script type="text/javascript" src="../src/stream.js"></script> <!-- PDFJSSCRIPT_REMOVE --> <script type="text/javascript" src="../src/stream.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE --> <script type="text/javascript" src="../src/worker.js"></script> <!-- PDFJSSCRIPT_REMOVE -->
<script type="text/javascript" src="compatibility.js"></script>
<script type="text/javascript" src="viewer.js"></script> <script type="text/javascript" src="viewer.js"></script>
</head> </head>