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

View File

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

View File

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

View File

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

View File

@ -190,7 +190,7 @@ var TilingPattern = (function TilingPatternClosure() {
var MAX_PATTERN_SIZE = 512; var MAX_PATTERN_SIZE = 512;
function TilingPattern(IR, color, ctx, objs) { function TilingPattern(IR, color, ctx, objs) {
var IRQueue = IR[2]; var operatorList = IR[2];
this.matrix = IR[3]; this.matrix = IR[3];
var bbox = IR[4]; var bbox = IR[4];
var xstep = IR[5]; var xstep = IR[5];
@ -259,12 +259,12 @@ var TilingPattern = (function TilingPatternClosure() {
graphics.endPath(); graphics.endPath();
} }
graphics.executeIRQueue(IRQueue); graphics.executeOperatorList(operatorList);
this.canvas = tmpCanvas; 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 matrix = dict.get('Matrix');
var bbox = dict.get('BBox'); var bbox = dict.get('BBox');
var xstep = dict.get('XStep'); var xstep = dict.get('XStep');
@ -272,7 +272,7 @@ var TilingPattern = (function TilingPatternClosure() {
var paintType = dict.get('PaintType'); var paintType = dict.get('PaintType');
return [ 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 start = Date.now();
var dependency = []; var dependency = [];
var IRQueue = null; var operatorList = null;
try { try {
var page = pdfModel.getPage(pageNum); var page = pdfModel.getPage(pageNum);
// Pre compile the pdf page and fetch the fonts/images. // Pre compile the pdf page and fetch the fonts/images.
IRQueue = page.getIRQueue(handler, dependency); operatorList = page.getOperatorList(handler, dependency);
} catch (e) { } catch (e) {
var minimumStackMessage = 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 // Turn the error into an obj that can be serialized
if (typeof e === 'string') { if (typeof e === 'string') {
@ -137,8 +137,8 @@ var WorkerMessageHandler = {
return; return;
} }
console.log('page=%d - getIRQueue: time=%dms, len=%d', pageNum, console.log('page=%d - getOperatorList: time=%dms, len=%d', pageNum,
Date.now() - start, IRQueue.fnArray.length); Date.now() - start, operatorList.fnArray.length);
// Filter the dependecies for fonts. // Filter the dependecies for fonts.
var fonts = {}; var fonts = {};
@ -151,7 +151,7 @@ var WorkerMessageHandler = {
handler.send('page', { handler.send('page', {
pageNum: pageNum, pageNum: pageNum,
IRQueue: IRQueue, operatorList: operatorList,
depFonts: Object.keys(fonts) depFonts: Object.keys(fonts)
}); });
}, this); }, this);