mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Merge branch 'refs/heads/master' into text-select
Conflicts: src/core.js
This commit is contained in:
commit
49a303f2f2
30 changed files with 286 additions and 150 deletions
|
@ -1,8 +1,11 @@
|
|||
// <canvas> contexts store most of the state we need natively.
|
||||
// However, PDF needs a bit more state, which we store here.
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'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() {
|
||||
function constructor(old) {
|
||||
// Are soft masks and alpha values shapes or opacities?
|
||||
|
@ -21,13 +24,18 @@ var CanvasExtraState = (function canvasExtraState() {
|
|||
this.wordSpacing = 0;
|
||||
this.textHScale = 1;
|
||||
// Color spaces
|
||||
this.fillColorSpace = new DeviceGrayCS;
|
||||
this.fillColorSpaceObj = null;
|
||||
this.strokeColorSpace = new DeviceGrayCS;
|
||||
this.strokeColorSpaceObj = null;
|
||||
this.fillColorObj = null;
|
||||
this.strokeColorObj = null;
|
||||
// Default fore and background colors
|
||||
this.fillColor = '#000000';
|
||||
this.strokeColor = '#000000';
|
||||
// Note: fill alpha applies to all non-stroking operations
|
||||
this.fillAlpha = 1;
|
||||
this.strokeAlpha = 1;
|
||||
|
||||
this.old = old;
|
||||
}
|
||||
|
@ -243,6 +251,13 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
case 'Font':
|
||||
this.setFont(state[1], state[2]);
|
||||
break;
|
||||
case 'CA':
|
||||
this.current.strokeAlpha = state[1];
|
||||
break;
|
||||
case 'ca':
|
||||
this.current.fillAlpha = state[1];
|
||||
this.ctx.globalAlpha = state[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -291,9 +306,13 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
rectangle: function canvasGraphicsRectangle(x, y, width, height) {
|
||||
this.ctx.rect(x, y, width, height);
|
||||
},
|
||||
stroke: function canvasGraphicsStroke() {
|
||||
stroke: function canvasGraphicsStroke(consumePath) {
|
||||
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
||||
var ctx = this.ctx;
|
||||
var strokeColor = this.current.strokeColor;
|
||||
// For stroke we want to temporarily change the global alpha to the
|
||||
// stroking alpha.
|
||||
ctx.globalAlpha = this.current.strokeAlpha;
|
||||
if (strokeColor && strokeColor.hasOwnProperty('type') &&
|
||||
strokeColor.type === 'Pattern') {
|
||||
// for patterns, we transform to pattern space, calculate
|
||||
|
@ -305,14 +324,17 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
} else {
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
this.consumePath();
|
||||
if (consumePath)
|
||||
this.consumePath();
|
||||
// Restore the global alpha to the fill alpha
|
||||
ctx.globalAlpha = this.current.fillAlpha;
|
||||
},
|
||||
closeStroke: function canvasGraphicsCloseStroke() {
|
||||
this.closePath();
|
||||
this.stroke();
|
||||
},
|
||||
fill: function canvasGraphicsFill() {
|
||||
fill: function canvasGraphicsFill(consumePath) {
|
||||
consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
|
||||
var ctx = this.ctx;
|
||||
var fillColor = this.current.fillColor;
|
||||
|
||||
|
@ -325,8 +347,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
} else {
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
this.consumePath();
|
||||
if (consumePath)
|
||||
this.consumePath();
|
||||
},
|
||||
eoFill: function canvasGraphicsEoFill() {
|
||||
var savedFillRule = this.setEOFillRule();
|
||||
|
@ -334,29 +356,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
this.restoreFillRule(savedFillRule);
|
||||
},
|
||||
fillStroke: function canvasGraphicsFillStroke() {
|
||||
var ctx = this.ctx;
|
||||
|
||||
var fillColor = this.current.fillColor;
|
||||
if (fillColor && fillColor.hasOwnProperty('type') &&
|
||||
fillColor.type === 'Pattern') {
|
||||
ctx.save();
|
||||
ctx.fillStyle = fillColor.getPattern(ctx);
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
} else {
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
var strokeColor = this.current.strokeColor;
|
||||
if (strokeColor && strokeColor.hasOwnProperty('type') &&
|
||||
strokeColor.type === 'Pattern') {
|
||||
ctx.save();
|
||||
ctx.strokeStyle = strokeColor.getPattern(ctx);
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
} else {
|
||||
ctx.stroke();
|
||||
}
|
||||
this.fill(false);
|
||||
this.stroke(false);
|
||||
|
||||
this.consumePath();
|
||||
},
|
||||
|
@ -366,10 +367,12 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
this.restoreFillRule(savedFillRule);
|
||||
},
|
||||
closeFillStroke: function canvasGraphicsCloseFillStroke() {
|
||||
return this.fillStroke();
|
||||
this.closePath();
|
||||
this.fillStroke();
|
||||
},
|
||||
closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() {
|
||||
var savedFillRule = this.setEOFillRule();
|
||||
this.closePath();
|
||||
this.fillStroke();
|
||||
this.restoreFillRule(savedFillRule);
|
||||
},
|
||||
|
@ -646,8 +649,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
},
|
||||
|
||||
// Color
|
||||
setStrokeColorSpace:
|
||||
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
|
||||
setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpace(raw) {
|
||||
this.current.strokeColorSpace = ColorSpace.fromIR(raw);
|
||||
},
|
||||
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) {
|
||||
|
@ -658,7 +660,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
var color = cs.getRgb(arguments);
|
||||
this.setStrokeRGBColor.apply(this, color);
|
||||
},
|
||||
getColorN_IR_Pattern: function(IR, cs) {
|
||||
getColorN_IR_Pattern: function canvasGraphicsGetColorN_IR_Pattern(IR, cs) {
|
||||
if (IR[0] == 'TilingPattern') {
|
||||
var args = IR[1];
|
||||
var base = cs.base;
|
||||
|
@ -774,8 +776,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
error('Should not call beginImageData');
|
||||
},
|
||||
|
||||
paintFormXObjectBegin:
|
||||
function canvasGraphicsPaintFormXObject(matrix, bbox) {
|
||||
paintFormXObjectBegin: function canvasGraphicsPaintFormXObjectBegin(matrix,
|
||||
bbox) {
|
||||
this.save();
|
||||
|
||||
if (matrix && isArray(matrix) && 6 == matrix.length)
|
||||
|
@ -790,11 +792,11 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
}
|
||||
},
|
||||
|
||||
paintFormXObjectEnd: function() {
|
||||
paintFormXObjectEnd: function canvasGraphicsPaintFormXObjectEnd() {
|
||||
this.restore();
|
||||
},
|
||||
|
||||
paintJpegXObject: function(objId, w, h) {
|
||||
paintJpegXObject: function canvasGraphicsPaintJpegXObject(objId, w, h) {
|
||||
var image = this.objs.get(objId);
|
||||
if (!image) {
|
||||
error('Dependent image isn\'t ready yet');
|
||||
|
@ -813,7 +815,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
this.restore();
|
||||
},
|
||||
|
||||
paintImageMaskXObject: function(imgArray, inverseDecode, width, height) {
|
||||
paintImageMaskXObject: function canvasGraphicsPaintImageMaskXObject(
|
||||
imgArray, inverseDecode, width, height) {
|
||||
function applyStencilMask(buffer, inverseDecode) {
|
||||
var imgArrayPos = 0;
|
||||
var i, j, mask, buf;
|
||||
|
@ -861,7 +864,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
this.restore();
|
||||
},
|
||||
|
||||
paintImageXObject: function(imgData) {
|
||||
paintImageXObject: function canvasGraphicsPaintImageXObject(imgData) {
|
||||
this.save();
|
||||
var ctx = this.ctx;
|
||||
var w = imgData.width;
|
||||
|
@ -950,3 +953,4 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
|
@ -6930,3 +6930,4 @@ var CIDToUnicodeMaps = {
|
|||
{f: 39, c: 19576}, {f: 111, c: 19620}, {f: 148, c: 19738},
|
||||
{f: 7, c: 19887}]
|
||||
};
|
||||
|
||||
|
|
|
@ -12,17 +12,17 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
|||
constructor.prototype = {
|
||||
// Input: array of size numComps representing color component values
|
||||
// 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);
|
||||
},
|
||||
// Input: Uint8Array of component 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);
|
||||
}
|
||||
};
|
||||
|
||||
constructor.parse = function colorspace_parse(cs, xref, res) {
|
||||
constructor.parse = function colorSpaceParse(cs, xref, res) {
|
||||
var IR = constructor.parseToIR(cs, xref, res, true);
|
||||
if (IR instanceof SeparationCS)
|
||||
return IR;
|
||||
|
@ -30,7 +30,7 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
|||
return constructor.fromIR(IR);
|
||||
};
|
||||
|
||||
constructor.fromIR = function(IR) {
|
||||
constructor.fromIR = function colorSpaceFromIR(IR) {
|
||||
var name;
|
||||
if (isArray(IR)) {
|
||||
name = IR[0];
|
||||
|
@ -71,7 +71,8 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
|||
return null;
|
||||
}
|
||||
|
||||
constructor.parseToIR = function colorspace_parse(cs, xref, res, parseOnly) {
|
||||
constructor.parseToIR = function colorSpaceParseToIR(cs, xref, res,
|
||||
parseOnly) {
|
||||
if (isName(cs)) {
|
||||
var colorSpaces = xref.fetchIfRef(res.get('ColorSpace'));
|
||||
if (isDict(colorSpaces)) {
|
||||
|
@ -397,5 +398,7 @@ var DeviceCmykCS = (function deviceCmykCS() {
|
|||
return rgbBuf;
|
||||
}
|
||||
};
|
||||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
39
src/core.js
39
src/core.js
|
@ -153,7 +153,7 @@ var Page = (function pagePage() {
|
|||
return shadow(this, 'rotate', rotate);
|
||||
},
|
||||
|
||||
startRenderingFromIRQueue: function startRenderingFromIRQueue(
|
||||
startRenderingFromIRQueue: function pageStartRenderingFromIRQueue(
|
||||
IRQueue, fonts) {
|
||||
var self = this;
|
||||
this.IRQueue = IRQueue;
|
||||
|
@ -173,12 +173,13 @@ var Page = (function pagePage() {
|
|||
});
|
||||
};
|
||||
|
||||
this.ensureFonts(fonts, function() {
|
||||
this.ensureFonts(fonts,
|
||||
function pageStartRenderingFromIRQueueEnsureFonts() {
|
||||
displayContinuation();
|
||||
});
|
||||
},
|
||||
|
||||
getIRQueue: function(handler, dependency) {
|
||||
getIRQueue: function pageGetIRQueue(handler, dependency) {
|
||||
if (this.IRQueue) {
|
||||
// content was compiled
|
||||
return this.IRQueue;
|
||||
|
@ -202,7 +203,7 @@ var Page = (function pagePage() {
|
|||
content, resources, IRQueue, dependency);
|
||||
},
|
||||
|
||||
ensureFonts: function(fonts, callback) {
|
||||
ensureFonts: function pageEnsureFonts(fonts, callback) {
|
||||
// Convert the font names to the corresponding font obj.
|
||||
for (var i = 0; i < fonts.length; i++) {
|
||||
fonts[i] = this.objs.objs[fonts[i]].data;
|
||||
|
@ -211,7 +212,7 @@ var Page = (function pagePage() {
|
|||
// Load all the fonts
|
||||
var fontObjs = FontLoader.bind(
|
||||
fonts,
|
||||
function(fontObjs) {
|
||||
function pageEnsureFontsFontObjs(fontObjs) {
|
||||
this.stats.fonts = Date.now();
|
||||
|
||||
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 resources = xref.fetchIfRef(this.resources);
|
||||
var mediaBox = xref.fetchIfRef(this.mediaBox);
|
||||
|
@ -306,7 +307,7 @@ var Page = (function pagePage() {
|
|||
}
|
||||
return links;
|
||||
},
|
||||
startRendering: function(ctx, callback, textLayer) {
|
||||
startRendering: function pageStartRendering(ctx, callback, textLayer) {
|
||||
this.ctx = ctx;
|
||||
this.callback = callback;
|
||||
this.textLayer = textLayer;
|
||||
|
@ -448,7 +449,7 @@ var PDFDocModel = (function pdfDoc() {
|
|||
return constructor;
|
||||
})();
|
||||
|
||||
var PDFDoc = (function() {
|
||||
var PDFDoc = (function pdfDoc() {
|
||||
function constructor(arg, callback) {
|
||||
var stream = null;
|
||||
var data = null;
|
||||
|
@ -477,10 +478,10 @@ var PDFDoc = (function() {
|
|||
} else {
|
||||
// If we don't use a worker, just post/sendMessage to the main thread.
|
||||
var worker = {
|
||||
postMessage: function(obj) {
|
||||
postMessage: function pdfDocPostMessage(obj) {
|
||||
worker.onmessage({data: obj});
|
||||
},
|
||||
terminate: function() {}
|
||||
terminate: function pdfDocTerminate() {}
|
||||
};
|
||||
}
|
||||
this.worker = worker;
|
||||
|
@ -490,7 +491,7 @@ var PDFDoc = (function() {
|
|||
var processorHandler = this.processorHandler =
|
||||
new MessageHandler('main', worker);
|
||||
|
||||
processorHandler.on('page', function(data) {
|
||||
processorHandler.on('page', function pdfDocPage(data) {
|
||||
var pageNum = data.pageNum;
|
||||
var page = this.pageCache[pageNum];
|
||||
var depFonts = data.depFonts;
|
||||
|
@ -498,7 +499,7 @@ var PDFDoc = (function() {
|
|||
page.startRenderingFromIRQueue(data.IRQueue, depFonts);
|
||||
}, this);
|
||||
|
||||
processorHandler.on('obj', function(data) {
|
||||
processorHandler.on('obj', function pdfDocObj(data) {
|
||||
var id = data[0];
|
||||
var type = data[1];
|
||||
|
||||
|
@ -542,7 +543,7 @@ var PDFDoc = (function() {
|
|||
}
|
||||
}, this);
|
||||
|
||||
processorHandler.on('font_ready', function(data) {
|
||||
processorHandler.on('font_ready', function pdfDocFontReady(data) {
|
||||
var id = data[0];
|
||||
var font = new FontShape(data[1]);
|
||||
|
||||
|
@ -561,7 +562,7 @@ var PDFDoc = (function() {
|
|||
}
|
||||
|
||||
this.workerReadyPromise = new Promise('workerReady');
|
||||
setTimeout(function() {
|
||||
setTimeout(function pdfDocFontReadySetTimeout() {
|
||||
processorHandler.send('doc', this.data);
|
||||
this.workerReadyPromise.resolve(true);
|
||||
}.bind(this));
|
||||
|
@ -572,14 +573,14 @@ var PDFDoc = (function() {
|
|||
return this.pdf.numPages;
|
||||
},
|
||||
|
||||
startRendering: function(page) {
|
||||
startRendering: function pdfDocStartRendering(page) {
|
||||
// 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);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
getPage: function(n) {
|
||||
getPage: function pdfDocGetPage(n) {
|
||||
if (this.pageCache[n])
|
||||
return this.pageCache[n];
|
||||
|
||||
|
@ -591,7 +592,7 @@ var PDFDoc = (function() {
|
|||
return this.pageCache[n] = page;
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
destroy: function pdfDocDestroy() {
|
||||
if (this.worker)
|
||||
this.worker.terminate();
|
||||
|
||||
|
@ -610,4 +611,6 @@ var PDFDoc = (function() {
|
|||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
globalScope.PDFJS.PDFDoc = PDFDoc;
|
||||
|
||||
|
|
|
@ -595,3 +595,4 @@ var CipherTransformFactory = (function cipherTransformFactory() {
|
|||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
|
@ -405,6 +405,8 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||
case 'D':
|
||||
case 'RI':
|
||||
case 'FL':
|
||||
case 'CA':
|
||||
case 'ca':
|
||||
gsStateObj.push([key, value]);
|
||||
break;
|
||||
case 'Font':
|
||||
|
@ -428,8 +430,6 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||
case 'SA':
|
||||
case 'BM':
|
||||
case 'SMask':
|
||||
case 'CA':
|
||||
case 'ca':
|
||||
case 'AIS':
|
||||
case 'TK':
|
||||
TODO('graphic state operator ' + key);
|
||||
|
@ -918,3 +918,4 @@ var EvalState = (function evalState() {
|
|||
};
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
|
@ -3272,3 +3272,4 @@ var Type2CFF = (function type2CFF() {
|
|||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
|
@ -3,14 +3,15 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
var PDFFunction = (function() {
|
||||
var PDFFunction = (function pdfFunction() {
|
||||
var CONSTRUCT_SAMPLED = 0;
|
||||
var CONSTRUCT_INTERPOLATED = 2;
|
||||
var CONSTRUCT_STICHED = 3;
|
||||
var CONSTRUCT_POSTSCRIPT = 4;
|
||||
|
||||
return {
|
||||
getSampleArray: function(size, outputSize, bps, str) {
|
||||
getSampleArray: function pdfFunctionGetSampleArray(size, outputSize, bps,
|
||||
str) {
|
||||
var length = 1;
|
||||
for (var i = 0; i < size.length; i++)
|
||||
length *= size[i];
|
||||
|
@ -35,7 +36,7 @@ var PDFFunction = (function() {
|
|||
return array;
|
||||
},
|
||||
|
||||
getIR: function(xref, fn) {
|
||||
getIR: function pdfFunctionGetIR(xref, fn) {
|
||||
var dict = fn.dict;
|
||||
if (!dict)
|
||||
dict = fn;
|
||||
|
@ -54,7 +55,7 @@ var PDFFunction = (function() {
|
|||
return typeFn.call(this, fn, dict, xref);
|
||||
},
|
||||
|
||||
fromIR: function(IR) {
|
||||
fromIR: function pdfFunctionFromIR(IR) {
|
||||
var type = IR[0];
|
||||
switch (type) {
|
||||
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);
|
||||
return this.fromIR(IR);
|
||||
},
|
||||
|
||||
constructSampled: function(str, dict) {
|
||||
constructSampled: function pdfFunctionConstructSampled(str, dict) {
|
||||
var domain = dict.get('Domain');
|
||||
var range = dict.get('Range');
|
||||
|
||||
|
@ -116,7 +117,7 @@ var PDFFunction = (function() {
|
|||
];
|
||||
},
|
||||
|
||||
constructSampledFromIR: function(IR) {
|
||||
constructSampledFromIR: function pdfFunctionConstructSampledFromIR(IR) {
|
||||
var inputSize = IR[1];
|
||||
var domain = IR[2];
|
||||
var encode = IR[3];
|
||||
|
@ -127,8 +128,8 @@ var PDFFunction = (function() {
|
|||
var bps = IR[8];
|
||||
var range = IR[9];
|
||||
|
||||
return function(args) {
|
||||
var clip = function(v, min, max) {
|
||||
return function constructSampledFromIRResult(args) {
|
||||
var clip = function constructSampledFromIRClip(v, min, max) {
|
||||
if (v > max)
|
||||
v = max;
|
||||
else if (v < min)
|
||||
|
@ -212,7 +213,7 @@ var PDFFunction = (function() {
|
|||
|
||||
var length = diff.length;
|
||||
|
||||
return function(args) {
|
||||
return function constructInterpolatedFromIRResult(args) {
|
||||
var x = n == 1 ? args[0] : Math.pow(args[0], n);
|
||||
|
||||
var out = [];
|
||||
|
@ -257,8 +258,8 @@ var PDFFunction = (function() {
|
|||
fns.push(PDFFunction.fromIR(fnsIR[i]));
|
||||
}
|
||||
|
||||
return function(args) {
|
||||
var clip = function(v, min, max) {
|
||||
return function constructStichedFromIRResult(args) {
|
||||
var clip = function constructStichedFromIRClip(v, min, max) {
|
||||
if (v > max)
|
||||
v = max;
|
||||
else if (v < min)
|
||||
|
@ -298,9 +299,10 @@ var PDFFunction = (function() {
|
|||
|
||||
constructPostScriptFromIR: function pdfFunctionConstructPostScriptFromIR() {
|
||||
TODO('unhandled type of function');
|
||||
return function() {
|
||||
return function constructPostScriptFromIRResult() {
|
||||
return [255, 105, 180];
|
||||
};
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
|
|
@ -229,12 +229,12 @@ var PDFImage = (function pdfImage() {
|
|||
return constructor;
|
||||
})();
|
||||
|
||||
var JpegImage = (function() {
|
||||
var JpegImage = (function jpegImage() {
|
||||
function JpegImage(objId, imageData, objs) {
|
||||
var src = 'data:image/jpeg;base64,' + window.btoa(imageData);
|
||||
|
||||
var img = new Image();
|
||||
img.onload = (function() {
|
||||
img.onload = (function jpegImageOnload() {
|
||||
this.loaded = true;
|
||||
|
||||
objs.resolve(objId, this);
|
||||
|
@ -247,10 +247,11 @@ var JpegImage = (function() {
|
|||
}
|
||||
|
||||
JpegImage.prototype = {
|
||||
getImage: function() {
|
||||
getImage: function jpegImageGetImage() {
|
||||
return this.domImage;
|
||||
}
|
||||
};
|
||||
|
||||
return JpegImage;
|
||||
})();
|
||||
|
||||
|
|
|
@ -2941,3 +2941,4 @@ var Metrics = {
|
|||
'a191': 918
|
||||
}
|
||||
};
|
||||
|
||||
|
|
17
src/obj.js
17
src/obj.js
|
@ -642,7 +642,7 @@ var XRef = (function xRefXRef() {
|
|||
* inside of a worker. The `PDFObjects` implements some basic functions to
|
||||
* manage these objects.
|
||||
*/
|
||||
var PDFObjects = (function() {
|
||||
var PDFObjects = (function pdfObjects() {
|
||||
function PDFObjects() {
|
||||
this.objs = {};
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ var PDFObjects = (function() {
|
|||
* Ensures there is an object defined for `objId`. Stores `data` on the
|
||||
* object *if* it is created.
|
||||
*/
|
||||
ensureObj: function(objId, data) {
|
||||
ensureObj: function pdfObjectsEnsureObj(objId, data) {
|
||||
if (this.objs[objId])
|
||||
return this.objs[objId];
|
||||
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
|
||||
* 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
|
||||
// not required to be resolved right now
|
||||
if (callback) {
|
||||
|
@ -695,7 +695,7 @@ var PDFObjects = (function() {
|
|||
/**
|
||||
* Resolves the object `objId` with optional `data`.
|
||||
*/
|
||||
resolve: function(objId, data) {
|
||||
resolve: function pdfObjectsResolve(objId, data) {
|
||||
var objs = this.objs;
|
||||
|
||||
// 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);
|
||||
},
|
||||
|
||||
isResolved: function(objId) {
|
||||
isResolved: function pdfObjectsIsResolved(objId) {
|
||||
var objs = this.objs;
|
||||
if (!objs[objId]) {
|
||||
return false;
|
||||
|
@ -719,7 +719,7 @@ var PDFObjects = (function() {
|
|||
}
|
||||
},
|
||||
|
||||
hasData: function(objId) {
|
||||
hasData: function pdfObjectsHasData(objId) {
|
||||
var objs = this.objs;
|
||||
if (!objs[objId]) {
|
||||
return false;
|
||||
|
@ -731,7 +731,7 @@ var PDFObjects = (function() {
|
|||
/**
|
||||
* 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
|
||||
// create a *resolved* promise which shouldn't be the case!
|
||||
this.ensureObj(objId).data = data;
|
||||
|
@ -739,3 +739,4 @@ var PDFObjects = (function() {
|
|||
};
|
||||
return PDFObjects;
|
||||
})();
|
||||
|
||||
|
|
|
@ -633,3 +633,4 @@ var Linearization = (function linearizationLinearization() {
|
|||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ Shadings.RadialAxial = (function radialAxialShading() {
|
|||
this.colorStops = colorStops;
|
||||
}
|
||||
|
||||
constructor.fromIR = function(ctx, raw) {
|
||||
constructor.fromIR = function radialAxialShadingGetIR(ctx, raw) {
|
||||
var type = raw[1];
|
||||
var colorStops = raw[2];
|
||||
var p0 = raw[3];
|
||||
|
@ -129,7 +129,7 @@ Shadings.RadialAxial = (function radialAxialShading() {
|
|||
}
|
||||
|
||||
constructor.prototype = {
|
||||
getIR: function RadialAxialShading_getIR() {
|
||||
getIR: function radialAxialShadingGetIR() {
|
||||
var coordsArr = this.coordsArr;
|
||||
var type = this.shadingType;
|
||||
if (type == 2) {
|
||||
|
@ -164,12 +164,12 @@ Shadings.Dummy = (function dummyShading() {
|
|||
this.type = 'Pattern';
|
||||
}
|
||||
|
||||
constructor.fromIR = function() {
|
||||
constructor.fromIR = function dummyShadingFromIR() {
|
||||
return 'hotpink';
|
||||
}
|
||||
|
||||
constructor.prototype = {
|
||||
getIR: function dummpy_getir() {
|
||||
getIR: function dummyShadingGetIR() {
|
||||
return ['Dummy'];
|
||||
}
|
||||
};
|
||||
|
@ -287,3 +287,4 @@ var TilingPattern = (function tilingPattern() {
|
|||
|
||||
return TilingPattern;
|
||||
})();
|
||||
|
||||
|
|
|
@ -12,3 +12,4 @@ var PDFJS = {};
|
|||
/* PDFJSSCRIPT_INCLUDE_ALL */
|
||||
|
||||
})();
|
||||
|
||||
|
|
|
@ -801,7 +801,7 @@ var JpegStream = (function jpegStream() {
|
|||
}
|
||||
|
||||
constructor.prototype = {
|
||||
getIR: function() {
|
||||
getIR: function jpegStreamGetIR() {
|
||||
return this.src;
|
||||
},
|
||||
getChar: function jpegStreamGetChar() {
|
||||
|
@ -2073,3 +2073,4 @@ var LZWStream = (function lzwStream() {
|
|||
|
||||
return constructor;
|
||||
})();
|
||||
|
||||
|
|
23
src/util.js
23
src/util.js
|
@ -16,16 +16,15 @@ function warn(msg) {
|
|||
}
|
||||
|
||||
function backtrace() {
|
||||
var stackStr;
|
||||
try {
|
||||
throw new Error();
|
||||
} 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) {
|
||||
log('Error: ' + msg);
|
||||
log(backtrace());
|
||||
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
|
||||
* it was set, an exception is throw.
|
||||
*/
|
||||
var Promise = (function() {
|
||||
var Promise = (function promise() {
|
||||
var EMPTY_PROMISE = {};
|
||||
|
||||
/**
|
||||
|
@ -222,19 +221,19 @@ var Promise = (function() {
|
|||
Promise.prototype = {
|
||||
hasData: false,
|
||||
|
||||
set data(data) {
|
||||
if (data === undefined) {
|
||||
set data(value) {
|
||||
if (value === undefined) {
|
||||
return;
|
||||
}
|
||||
if (this._data !== EMPTY_PROMISE) {
|
||||
throw 'Promise ' + this.name +
|
||||
': Cannot set the data of a promise twice';
|
||||
}
|
||||
this._data = data;
|
||||
this._data = value;
|
||||
this.hasData = true;
|
||||
|
||||
if (this.onDataCallback) {
|
||||
this.onDataCallback(data);
|
||||
this.onDataCallback(value);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -245,7 +244,7 @@ var Promise = (function() {
|
|||
return this._data;
|
||||
},
|
||||
|
||||
onData: function(callback) {
|
||||
onData: function promiseOnData(callback) {
|
||||
if (this._data !== EMPTY_PROMISE) {
|
||||
callback(this._data);
|
||||
} else {
|
||||
|
@ -253,7 +252,7 @@ var Promise = (function() {
|
|||
}
|
||||
},
|
||||
|
||||
resolve: function(data) {
|
||||
resolve: function promiseResolve(data) {
|
||||
if (this.isResolved) {
|
||||
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) {
|
||||
throw 'Requiring callback' + this.name;
|
||||
}
|
||||
|
@ -281,5 +280,7 @@ var Promise = (function() {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Promise;
|
||||
})();
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ function MessageHandler(name, comObj) {
|
|||
this.comObj = comObj;
|
||||
var ah = this.actionHandler = {};
|
||||
|
||||
ah['console_log'] = [function(data) {
|
||||
ah['console_log'] = [function ahConsoleLog(data) {
|
||||
console.log.apply(console, data);
|
||||
}];
|
||||
ah['console_error'] = [function(data) {
|
||||
ah['console_error'] = [function ahConsoleError(data) {
|
||||
console.error.apply(console, data);
|
||||
}];
|
||||
|
||||
comObj.onmessage = function(event) {
|
||||
comObj.onmessage = function messageHandlerComObjOnMessage(event) {
|
||||
var data = event.data;
|
||||
if (data.action in ah) {
|
||||
var action = ah[data.action];
|
||||
|
@ -27,15 +27,15 @@ function MessageHandler(name, comObj) {
|
|||
}
|
||||
|
||||
MessageHandler.prototype = {
|
||||
on: function(actionName, handler, scope) {
|
||||
on: function messageHandlerOn(actionName, handler, scope) {
|
||||
var ah = this.actionHandler;
|
||||
if (ah[actionName]) {
|
||||
throw "There is already an actionName called '" + actionName + "'";
|
||||
throw 'There is already an actionName called "' + actionName + '"';
|
||||
}
|
||||
ah[actionName] = [handler, scope];
|
||||
},
|
||||
|
||||
send: function(actionName, data) {
|
||||
send: function messageHandlerSend(actionName, data) {
|
||||
this.comObj.postMessage({
|
||||
action: actionName,
|
||||
data: data
|
||||
|
@ -44,16 +44,16 @@ MessageHandler.prototype = {
|
|||
};
|
||||
|
||||
var WorkerProcessorHandler = {
|
||||
setup: function(handler) {
|
||||
setup: function wphSetup(handler) {
|
||||
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
|
||||
// processing the content of the pdf.
|
||||
pdfDoc = new PDFDocModel(new Stream(data));
|
||||
});
|
||||
|
||||
handler.on('page_request', function(pageNum) {
|
||||
handler.on('page_request', function wphSetupPageRequest(pageNum) {
|
||||
pageNum = parseInt(pageNum);
|
||||
|
||||
var page = pdfDoc.getPage(pageNum);
|
||||
|
@ -89,7 +89,7 @@ var WorkerProcessorHandler = {
|
|||
});
|
||||
}, this);
|
||||
|
||||
handler.on('font', function(data) {
|
||||
handler.on('font', function wphSetupFont(data) {
|
||||
var objId = data[0];
|
||||
var name = data[1];
|
||||
var file = data[2];
|
||||
|
@ -122,11 +122,11 @@ var WorkerProcessorHandler = {
|
|||
var obj = new Font(font.name, font.file, font.properties);
|
||||
|
||||
var str = '';
|
||||
var data = obj.data;
|
||||
if (data) {
|
||||
var length = data.length;
|
||||
for (var j = 0; j < length; j++)
|
||||
str += String.fromCharCode(data[j]);
|
||||
var objData = obj.data;
|
||||
if (objData) {
|
||||
var length = objData.length;
|
||||
for (var j = 0; j < length; ++j)
|
||||
str += String.fromCharCode(objData[j]);
|
||||
}
|
||||
|
||||
obj.str = str;
|
||||
|
@ -159,11 +159,11 @@ var workerConsole = {
|
|||
});
|
||||
},
|
||||
|
||||
time: function(name) {
|
||||
time: function time(name) {
|
||||
consoleTimer[name] = Date.now();
|
||||
},
|
||||
|
||||
timeEnd: function(name) {
|
||||
timeEnd: function timeEnd(name) {
|
||||
var time = consoleTimer[name];
|
||||
if (time == null) {
|
||||
throw 'Unkown timer name ' + name;
|
||||
|
@ -180,3 +180,4 @@ if (typeof window === 'undefined') {
|
|||
var handler = new MessageHandler('worker_processor', globalScope);
|
||||
WorkerProcessorHandler.setup(handler);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,3 +21,4 @@ importScripts('../src/parser.js');
|
|||
importScripts('../src/pattern.js');
|
||||
importScripts('../src/stream.js');
|
||||
importScripts('../src/worker.js');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue