Rename IRQueue and codeIR -> operatorList

This commit is contained in:
Julian Viereck 2012-03-12 18:41:40 +01:00
parent f80fd13fe5
commit fd2ab059d3
6 changed files with 61 additions and 55 deletions

View File

@ -188,7 +188,7 @@ function addContextCurrentTransform(ctx) {
}
var CanvasGraphics = (function CanvasGraphicsClosure() {
// Defines the time the executeIRQueue is going to be executing
// Defines the time the executeOperatorList is going to be executing
// before it stops and shedules a continue of execution.
var kExecutionTime = 50;
@ -267,15 +267,16 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.textLayer.beginLayout();
},
executeIRQueue: function canvasGraphicsExecuteIRQueue(codeIR,
executionStartIdx, continueCallback,
stepper) {
var argsArray = codeIR.argsArray;
var fnArray = codeIR.fnArray;
executeOperatorList: function canvasGraphicsExecuteOperatorList(
operatorList,
executionStartIdx, continueCallback,
stepper) {
var argsArray = operatorList.argsArray;
var fnArray = operatorList.fnArray;
var i = executionStartIdx || 0;
var argsArrayLen = argsArray.length;
// Sometimes the IRQueue to execute is empty.
// Sometimes the OperatorList to execute is empty.
if (argsArrayLen == i) {
return i;
}
@ -313,7 +314,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
i++;
// If the entire IRQueue was executed, stop as were done.
// If the entire operatorList was executed, stop as were done.
if (i == argsArrayLen) {
return i;
}
@ -326,8 +327,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
return i;
}
// If the IRQueue isn't executed completly yet OR the execution time
// was short enough, do another execution round.
// If the operatorList isn't executed completely yet OR the execution
// time was short enough, do another execution round.
}
},
@ -706,7 +707,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.save();
ctx.scale(fontSize, fontSize);
ctx.transform.apply(ctx, fontMatrix);
this.executeIRQueue(glyph.codeIRQueue);
this.executeOperatorList(glyph.operatorList);
this.restore();
var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);

View File

@ -170,10 +170,10 @@ var Page = (function PageClosure() {
return shadow(this, 'rotate', rotate);
},
startRenderingFromIRQueue: function pageStartRenderingFromIRQueue(
IRQueue, fonts) {
startRenderingFromOperatorList: function pageStartRenderingFromOperatorList(
operatorList, fonts) {
var self = this;
this.IRQueue = IRQueue;
this.operatorList = operatorList;
var displayContinuation = function pageDisplayContinuation() {
// Always defer call to display() to work around bug in
@ -184,15 +184,16 @@ var Page = (function PageClosure() {
};
this.ensureFonts(fonts,
function pageStartRenderingFromIRQueueEnsureFonts() {
displayContinuation();
});
function pageStartRenderingFromOperatorListEnsureFonts() {
displayContinuation();
}
);
},
getIRQueue: function pageGetIRQueue(handler, dependency) {
if (this.IRQueue) {
getOperatorList: function pageGetOperatorList(handler, dependency) {
if (this.operatorList) {
// content was compiled
return this.IRQueue;
return this.operatorList;
}
this.stats.time('Build IR Queue');
@ -214,9 +215,9 @@ var Page = (function PageClosure() {
var pe = this.pe = new PartialEvaluator(
xref, handler, 'p' + this.pageNumber + '_');
this.IRQueue = pe.getIRQueue(content, resources, dependency);
this.operatorList = pe.getOperatorList(content, resources, dependency));
this.stats.timeEnd('Build IR Queue');
return this.IRQueue;
return this.operatorList;
},
ensureFonts: function pageEnsureFonts(fonts, callback) {
@ -253,18 +254,19 @@ var Page = (function PageClosure() {
rotate: this.rotate });
var startIdx = 0;
var length = this.IRQueue.fnArray.length;
var IRQueue = this.IRQueue;
var length = this.operatorList.fnArray.length;
var operatorList = this.operatorList;
var stepper = null;
if (PDFJS.pdfBug && StepperManager.enabled) {
stepper = StepperManager.create(this.pageNumber);
stepper.init(IRQueue);
stepper.init(operatorList);
stepper.nextBreakPoint = stepper.getNextBreakPoint();
}
var self = this;
function next() {
startIdx = gfx.executeIRQueue(IRQueue, startIdx, next, stepper);
startIdx =
gfx.executeOperatorList(operatorList, startIdx, next, stepper);
if (startIdx == length) {
gfx.endDrawing();
stats.timeEnd('Rendering');
@ -434,13 +436,14 @@ var Page = (function PageClosure() {
startRendering: function pageStartRendering(ctx, callback, textLayer) {
var stats = this.stats;
stats.time('Overall');
// If there is no displayReadyPromise yet, then the IRQueue was never
// If there is no displayReadyPromise yet, then the operatorList was never
// requested before. Make the request and create the promise.
if (!this.displayReadyPromise) {
this.pdf.startRendering(this);
this.displayReadyPromise = new Promise();
}
// Once the IRQueue and fonts are loaded, perform the actual rendering.
// Once the operatorList and fonts are loaded, do the actual rendering.
this.displayReadyPromise.then(
function pageDisplayReadyPromise() {
var gfx = new CanvasGraphics(ctx, this.objs, textLayer);
@ -728,8 +731,9 @@ var PDFDoc = (function PDFDocClosure() {
var pageNum = data.pageNum;
var page = this.pageCache[pageNum];
var depFonts = data.depFonts;
page.stats.timeEnd('Page Request');
page.startRenderingFromIRQueue(data.IRQueue, depFonts);
page.startRenderingFromOperatorList(data.operatorList, depFonts);
}, this);
messageHandler.on('obj', function pdfDocObj(data) {

View File

@ -112,7 +112,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
};
PartialEvaluator.prototype = {
getIRQueue: function partialEvaluatorGetIRQueue(stream, resources,
getOperatorList: function partialEvaluatorGetOperatorList(stream, resources,
dependency, queue) {
var self = this;
@ -175,7 +175,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// Ensure the font is ready before the font is set
// and later on used for drawing.
// OPTIMIZE: This should get insert to the IRQueue only once per
// OPTIMIZE: This should get insert to the operatorList only once per
// page.
insertDependency([loadedName]);
return loadedName;
@ -293,14 +293,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (typeNum == TILING_PATTERN) {
// Create an IR of the pattern code.
var depIdx = dependencyArray.length;
var codeIR = this.getIRQueue(pattern, dict.get('Resources') ||
resources, dependencyArray);
var operatorList = this.getOperatorList(pattern,
dict.get('Resources') || resources, dependencyArray);
// Add the dependencies that are required to execute the
// codeIR.
// operatorList.
insertDependency(dependencyArray.slice(depIdx));
args = TilingPattern.getIR(codeIR, dict, args);
args = TilingPattern.getIR(operatorList, dict, args);
}
else if (typeNum == SHADING_PATTERN) {
var shading = xref.fetchIfRef(dict.get('Shading'));
@ -334,17 +334,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
fnArray.push('paintFormXObjectBegin');
argsArray.push([matrix, bbox]);
// This adds the IRQueue of the xObj to the current queue.
// This adds the operatorList of the xObj to the current queue.
var depIdx = dependencyArray.length;
// Pass in the current `queue` object. That means the `fnArray`
// and the `argsArray` in this scope is reused and new commands
// are added to them.
this.getIRQueue(xobj, xobj.dict.get('Resources') || resources,
this.getOperatorList(xobj,
xobj.dict.get('Resources') || resources,
dependencyArray, queue);
// Add the dependencies that are required to execute the
// codeIR.
// operatorList.
insertDependency(dependencyArray.slice(depIdx));
fn = 'paintFormXObjectEnd';
@ -852,11 +853,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var charProcs = xref.fetchIfRef(dict.get('CharProcs'));
var fontResources = xref.fetchIfRef(dict.get('Resources')) || resources;
properties.resources = fontResources;
properties.charProcIRQueues = {};
properties.charProcOperatorLists = {};
for (var key in charProcs.map) {
var glyphStream = xref.fetchIfRef(charProcs.map[key]);
properties.charProcIRQueues[key] =
this.getIRQueue(glyphStream, fontResources, dependency);
properties.charProcOperatorList[key] =
this.getOperatorList(glyphStream, fontResources, dependency);
}
}

View File

@ -757,7 +757,7 @@ var Font = (function FontClosure() {
function Font(name, file, properties) {
this.name = name;
this.coded = properties.coded;
this.charProcIRQueues = properties.charProcIRQueues;
this.charProcOperatorList = properties.charProcOperatorList;
this.resources = properties.resources;
this.sizes = [];
@ -2318,7 +2318,7 @@ var Font = (function FontClosure() {
},
charToGlyph: function fonts_charToGlyph(charcode) {
var fontCharCode, width, codeIRQueue;
var fontCharCode, width, operatorList;
var width = this.widths[charcode];
@ -2353,7 +2353,7 @@ var Font = (function FontClosure() {
break;
case 'Type3':
var glyphName = this.differences[charcode] || this.encoding[charcode];
codeIRQueue = this.charProcIRQueues[glyphName];
operatorList = this.charProcOperatorList[glyphName];
fontCharCode = charcode;
break;
case 'TrueType':
@ -2396,7 +2396,7 @@ var Font = (function FontClosure() {
fontChar: String.fromCharCode(fontCharCode),
unicode: unicodeChars,
width: width,
codeIRQueue: codeIRQueue
operatorList: operatorList
};
},

View File

@ -190,7 +190,7 @@ var TilingPattern = (function TilingPatternClosure() {
var MAX_PATTERN_SIZE = 512;
function TilingPattern(IR, color, ctx, objs) {
var IRQueue = IR[2];
var operatorList = IR[2];
this.matrix = IR[3];
var bbox = IR[4];
var xstep = IR[5];
@ -259,12 +259,12 @@ var TilingPattern = (function TilingPatternClosure() {
graphics.endPath();
}
graphics.executeIRQueue(IRQueue);
graphics.executeOperatorList(operatorList);
this.canvas = tmpCanvas;
}
TilingPattern.getIR = function tiling_getIR(codeIR, dict, args) {
TilingPattern.getIR = function tiling_getIR(operatorList, dict, args) {
var matrix = dict.get('Matrix');
var bbox = dict.get('BBox');
var xstep = dict.get('XStep');
@ -272,7 +272,7 @@ var TilingPattern = (function TilingPatternClosure() {
var paintType = dict.get('PaintType');
return [
'TilingPattern', args, codeIR, matrix, bbox, xstep, ystep, paintType
'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep, paintType
];
};

View File

@ -103,14 +103,14 @@ var WorkerMessageHandler = {
var start = Date.now();
var dependency = [];
var IRQueue = null;
var operatorList = null;
try {
var page = pdfModel.getPage(pageNum);
// Pre compile the pdf page and fetch the fonts/images.
IRQueue = page.getIRQueue(handler, dependency);
operatorList = page.getOperatorList(handler, dependency);
} catch (e) {
var minimumStackMessage =
'worker.js: while trying to getPage() and getIRQueue()';
'worker.js: while trying to getPage() and getOperatorList()';
// Turn the error into an obj that can be serialized
if (typeof e === 'string') {
@ -137,8 +137,8 @@ var WorkerMessageHandler = {
return;
}
console.log('page=%d - getIRQueue: time=%dms, len=%d', pageNum,
Date.now() - start, IRQueue.fnArray.length);
console.log('page=%d - getOperatorList: time=%dms, len=%d', pageNum,
Date.now() - start, operatorList.fnArray.length);
// Filter the dependecies for fonts.
var fonts = {};
@ -151,7 +151,7 @@ var WorkerMessageHandler = {
handler.send('page', {
pageNum: pageNum,
IRQueue: IRQueue,
operatorList: operatorList,
depFonts: Object.keys(fonts)
});
}, this);