Fix lint errors

This commit is contained in:
Julian Viereck 2011-10-09 10:37:53 +02:00
parent a6180830f8
commit 20a348fc0c
7 changed files with 342 additions and 421 deletions

105
fonts.js
View File

@ -415,111 +415,6 @@ function getUnicodeRangeFor(value) {
return -1; return -1;
} }
/**
* FontShape is the minimal shape a FontObject can have to be useful during
* executing the IRQueue.
*/
var FontShape = (function FontShape() {
var constructor = function FontShape_constructor(obj) {
for (var name in obj) {
this[name] = obj[name];
}
var name = this.loadedName;
var bold = this.black ? (this.bold ? 'bolder' : 'bold') :
(this.bold ? 'bold' : 'normal');
var italic = this.italic ? 'italic' : 'normal';
this.fontFallback = this.serif ? 'serif' : 'sans-serif';
this.namePart1 = italic + ' ' + bold + ' ';
this.namePart2 = 'px "' + name + '", "';
this.supported = Object.keys(this.encoding).length != 0;
// Set the loading flag. Gets set to false in FontLoader.bind().
this.loading = true;
};
function int16(bytes) {
return (bytes[0] << 8) + (bytes[1] & 0xff);
};
constructor.prototype = {
getRule: function fonts_getRule(size, fallback) {
fallback = fallback || this.fontFallback;
return this.namePart1 + size + this.namePart2 + fallback + '"';
},
charsToUnicode: function fonts_chars2Unicode(chars) {
var charsCache = this.charsCache;
var str;
// if we translated this string before, just grab it from the cache
if (charsCache) {
str = charsCache[chars];
if (str)
return str;
}
// lazily create the translation cache
if (!charsCache)
charsCache = this.charsCache = Object.create(null);
// translate the string using the font's encoding
var encoding = this.encoding;
if (!encoding)
return chars;
str = '';
if (this.composite) {
// composite fonts have multi-byte strings convert the string from
// single-byte to multi-byte
// XXX assuming CIDFonts are two-byte - later need to extract the
// correct byte encoding according to the PDF spec
var length = chars.length - 1; // looping over two bytes at a time so
// loop should never end on the last byte
for (var i = 0; i < length; i++) {
var charcode = int16([chars.charCodeAt(i++), chars.charCodeAt(i)]);
var unicode = encoding[charcode];
if ('undefined' == typeof(unicode)) {
warn('Unencoded charcode ' + charcode);
unicode = charcode;
} else {
unicode = unicode.unicode;
}
str += String.fromCharCode(unicode);
}
}
else {
for (var i = 0; i < chars.length; ++i) {
var charcode = chars.charCodeAt(i);
var unicode = encoding[charcode];
if ('undefined' == typeof(unicode)) {
warn('Unencoded charcode ' + charcode);
unicode = charcode;
} else {
unicode = unicode.unicode;
}
// Handle surrogate pairs
if (unicode > 0xFFFF) {
str += String.fromCharCode(unicode & 0xFFFF);
unicode >>= 16;
}
str += String.fromCharCode(unicode);
}
}
// Enter the translated string into the cache
return (charsCache[chars] = str);
}
}
return constructor;
})();
/** /**
* 'Font' is the class the outside world should use, it encapsulate all the font * 'Font' is the class the outside world should use, it encapsulate all the font
* decoding logics whatever type it is (assuming the font type is supported). * decoding logics whatever type it is (assuming the font type is supported).

219
pdf.js
View File

@ -917,10 +917,10 @@ var JpegStreamIR = (function() {
getImage: function() { getImage: function() {
return this.domImage; return this.domImage;
} }
} };
return JpegStreamIR; return JpegStreamIR;
})() })();
// A JpegStream can't be read directly. We use the platform to render // A JpegStream can't be read directly. We use the platform to render
// the underlying JPEG data for us. // the underlying JPEG data for us.
@ -956,7 +956,7 @@ var JpegStream = (function jpegStream() {
} }
function constructor(bytes, dict) { function constructor(bytes, dict) {
// TODO: per poppler, some images may have "junk" before that // TODO: per poppler, some images may have 'junk' before that
// need to be removed // need to be removed
this.dict = dict; this.dict = dict;
@ -3536,7 +3536,8 @@ var Page = (function pagePage() {
return shadow(this, 'rotate', rotate); return shadow(this, 'rotate', rotate);
}, },
startRenderingFromIRQueue: function startRenderingFromIRQueue(gfx, IRQueue, fonts, continuation) { startRenderingFromIRQueue: function startRenderingFromIRQueue(gfx,
IRQueue, fonts, continuation) {
var self = this; var self = this;
this.IRQueue = IRQueue; this.IRQueue = IRQueue;
@ -3581,7 +3582,8 @@ var Page = (function pagePage() {
var pe = this.pe = new PartialEvaluator(); var pe = this.pe = new PartialEvaluator();
var IRQueue = {}; var IRQueue = {};
return this.IRQueue = pe.getIRQueue(content, xref, resources, IRQueue, handler, "p" + this.pageNumber + "_", dependency); return this.IRQueue = pe.getIRQueue(content, xref, resources, IRQueue,
handler, 'p' + this.pageNumber + '_', dependency);
}, },
ensureFonts: function(fonts, callback) { ensureFonts: function(fonts, callback) {
@ -3628,7 +3630,7 @@ var Page = (function pagePage() {
startIdx = gfx.executeIRQueue(IRQueue, startIdx, next); startIdx = gfx.executeIRQueue(IRQueue, startIdx, next);
if (startIdx == length) { if (startIdx == length) {
self.stats.render = Date.now(); self.stats.render = Date.now();
console.log("page=%d - executeIRQueue: time=%dms", console.log('page=%d - executeIRQueue: time=%dms',
self.pageNumber + 1, self.stats.render - startTime); self.pageNumber + 1, self.stats.render - startTime);
callback(); callback();
} }
@ -4020,20 +4022,22 @@ var PDFDoc = (function() {
this.pageCache = []; this.pageCache = [];
if (useWorker) { if (useWorker) {
var worker = this.worker = new Worker("../worker/pdf_worker_loader.js"); var worker = this.worker = new Worker('../worker/pdf_worker_loader.js');
} 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(obj) {
worker.onmessage({data: obj}); worker.onmessage({data: obj});
} }
} };
} }
this.fontsLoading = {}; this.fontsLoading = {};
var processorHandler = this.processorHandler = new MessageHandler("main", worker); var processorHandler = this.processorHandler =
processorHandler.on("page", function(data) { new MessageHandler('main', worker);
processorHandler.on('page', function(data) {
var pageNum = data.pageNum; var pageNum = data.pageNum;
var page = this.pageCache[pageNum]; var page = this.pageCache[pageNum];
@ -4065,9 +4069,10 @@ var PDFDoc = (function() {
// } // }
// //
// // There can be edge cases where two pages wait for one font and then // // There can be edge cases where two pages wait for one font and then
// // call startRenderingFromIRQueue twice with the same font. That makes // // call startRenderingFromIRQueue twice with the same font. That
// // the font getting loaded twice and throw an error later as the font // // makes the font getting loaded twice and throw an error later as
// // promise gets resolved twice. // // the font promise gets resolved twice.
// //
// // This prevents thats fonts are loaded really only once. // // This prevents thats fonts are loaded really only once.
// for (var j = 0; j < fontsToLoad.length; j++) { // for (var j = 0; j < fontsToLoad.length; j++) {
// var fontName = fontsToLoad[j]; // var fontName = fontsToLoad[j];
@ -4084,7 +4089,8 @@ var PDFDoc = (function() {
// fontsToLoad.push(this.objs.get(depFonts[i])); // fontsToLoad.push(this.objs.get(depFonts[i]));
// } // }
// //
// // At this point, all font data ia loaded. Start the actuall rendering. // // At this point, all font data ia loaded. Start the actuall
// // rendering.
// page.startRenderingFromIRQueue(data.IRQueue, fontsToLoad); // page.startRenderingFromIRQueue(data.IRQueue, fontsToLoad);
// } // }
// //
@ -4094,17 +4100,17 @@ var PDFDoc = (function() {
page.startRenderingFromIRQueue(data.IRQueue, Object.keys(data.depFonts)); page.startRenderingFromIRQueue(data.IRQueue, Object.keys(data.depFonts));
}, this); }, this);
processorHandler.on("obj", function(data) { processorHandler.on('obj', function(data) {
var objId = data[0]; var objId = data[0];
var objType = data[1]; var objType = data[1];
switch (objType) { switch (objType) {
case "JpegStream": case 'JpegStream':
var IR = data[2]; var IR = data[2];
new JpegStreamIR(objId, IR, this.objs); new JpegStreamIR(objId, IR, this.objs);
console.log('got image'); console.log('got image');
break; break;
case "Font": case 'Font':
var name = data[2]; var name = data[2];
var file = data[3]; var file = data[3];
var properties = data[4]; var properties = data[4];
@ -4127,8 +4133,8 @@ var PDFDoc = (function() {
} }
// For now, resolve the font object here direclty. The real font object // For now, resolve the font object here direclty. The real font
// is then created in FontLoader.bind(). // object is then created in FontLoader.bind().
this.objs.resolve(objId, { this.objs.resolve(objId, {
name: name, name: name,
file: file, file: file,
@ -4191,10 +4197,10 @@ var PDFDoc = (function() {
// this.objs.setData(objId, fontObj); // this.objs.setData(objId, fontObj);
// } // }
// processorHandler.send("font", [objId, name, file, properties]); // processorHandler.send('font', [objId, name, file, properties]);
break; break;
default: default:
throw "Got unkown object type " + objType; throw 'Got unkown object type ' + objType;
} }
}, this); }, this);
@ -4218,7 +4224,7 @@ var PDFDoc = (function() {
WorkerProcessorHandler.setup(processorHandler); WorkerProcessorHandler.setup(processorHandler);
} }
processorHandler.send("doc", this.data); processorHandler.send('doc', this.data);
} }
constructor.prototype = { constructor.prototype = {
@ -4227,7 +4233,7 @@ var PDFDoc = (function() {
}, },
startRendering: function(page) { startRendering: function(page) {
this.processorHandler.send("page_request", page.page.pageNumber + 1); this.processorHandler.send('page_request', page.page.pageNumber + 1);
}, },
getPage: function(n) { getPage: function(n) {
@ -4243,7 +4249,7 @@ var PDFDoc = (function() {
}, },
destroy: function() { destroy: function() {
console.log("destroy worker"); console.log('destroy worker');
if (this.worker) { if (this.worker) {
this.worker.terminate(); this.worker.terminate();
} }
@ -4663,11 +4669,11 @@ var PartialEvaluator = (function partialEvaluator() {
}; };
constructor.prototype = { constructor.prototype = {
getIRQueue: function partialEvaluatorGetIRQueue(stream, xref, resources, queue, handler, getIRQueue: function partialEvaluatorGetIRQueue(stream, xref, resources,
uniquePrefix, dependency) { queue, handler, uniquePrefix, dependency) {
function insertDependency(depList) { function insertDependency(depList) {
fnArray.push("dependency"); fnArray.push('dependency');
argsArray.push(depList); argsArray.push(depList);
for (var i = 0; i < depList.length; i++) { for (var i = 0; i < depList.length; i++) {
var dep = depList[i]; var dep = depList[i];
@ -4692,14 +4698,14 @@ var PartialEvaluator = (function partialEvaluator() {
if (font.translated) { if (font.translated) {
// keep track of each font we translated so the caller can // keep track of each font we translated so the caller can
// load them asynchronously before calling display on a page // load them asynchronously before calling display on a page
loadedName = "font_" + uniquePrefix + (FontLoadedCounter++); loadedName = 'font_' + uniquePrefix + (FontLoadedCounter++);
font.translated.properties.loadedName = loadedName; font.translated.properties.loadedName = loadedName;
font.loadedName = loadedName; font.loadedName = loadedName;
FontsMap[loadedName] = font; FontsMap[loadedName] = font;
handler.send("obj", [ handler.send('obj', [
loadedName, loadedName,
"Font", 'Font',
font.translated.name, font.translated.name,
font.translated.file, font.translated.file,
font.translated.properties font.translated.properties
@ -4717,6 +4723,7 @@ var PartialEvaluator = (function partialEvaluator() {
} else { } else {
// TODO: TOASK: Is it possible to get here? If so, what does // TODO: TOASK: Is it possible to get here? If so, what does
// args[0].name should be like??? // args[0].name should be like???
return null;
} }
} }
@ -4727,7 +4734,7 @@ var PartialEvaluator = (function partialEvaluator() {
if (image instanceof JpegStream) { if (image instanceof JpegStream) {
var objId = 'img_' + ++objIdCounter; var objId = 'img_' + ++objIdCounter;
handler.send("obj", [objId, "JpegStream", image.getIR()]); handler.send('obj', [objId, 'JpegStream', image.getIR()]);
// Add the dependency on the image object. // Add the dependency on the image object.
insertDependency([objId]); insertDependency([objId]);
@ -4747,7 +4754,7 @@ var PartialEvaluator = (function partialEvaluator() {
var imageObj = new PDFImage(xref, resources, image, inline); var imageObj = new PDFImage(xref, resources, image, inline);
if (imageObj.imageMask) { if (imageObj.imageMask) {
throw "Can't handle this in the web worker :/"; throw 'Can\'t handle this in the web worker :/';
} }
var imgData = { var imgData = {
@ -4758,7 +4765,7 @@ var PartialEvaluator = (function partialEvaluator() {
var pixels = imgData.data; var pixels = imgData.data;
imageObj.fillRgbaBuffer(pixels, imageObj.decode); imageObj.fillRgbaBuffer(pixels, imageObj.decode);
fn = "paintImageXObject"; fn = 'paintImageXObject';
args = [imgData]; args = [imgData];
} else /* imageMask == true */ { } else /* imageMask == true */ {
// This depends on a tmpCanvas beeing filled with the // This depends on a tmpCanvas beeing filled with the
@ -4766,7 +4773,7 @@ var PartialEvaluator = (function partialEvaluator() {
// data can't be done here. Instead of creating a // data can't be done here. Instead of creating a
// complete PDFImage, only read the information needed // complete PDFImage, only read the information needed
// for later. // for later.
fn = "paintImageMaskXObject"; fn = 'paintImageMaskXObject';
var width = dict.get('Width', 'W'); var width = dict.get('Width', 'W');
var height = dict.get('Height', 'H'); var height = dict.get('Height', 'H');
@ -4780,9 +4787,9 @@ var PartialEvaluator = (function partialEvaluator() {
} }
} }
uniquePrefix = uniquePrefix || ""; uniquePrefix = uniquePrefix || '';
if (!queue.argsArray) { if (!queue.argsArray) {
queue.argsArray = [] queue.argsArray = [];
} }
if (!queue.fnArray) { if (!queue.fnArray) {
queue.fnArray = []; queue.fnArray = [];
@ -4816,7 +4823,7 @@ var PartialEvaluator = (function partialEvaluator() {
}; };
} }
} }
assertWellFormed(fn, "Unknown command '" + cmd + "'"); assertWellFormed(fn, 'Unknown command "' + cmd + '"');
// TODO figure out how to type-check vararg functions // TODO figure out how to type-check vararg functions
if ((cmd == 'SCN' || cmd == 'scn') && !args[args.length - 1].code) { if ((cmd == 'SCN' || cmd == 'scn') && !args[args.length - 1].code) {
@ -4850,10 +4857,11 @@ var PartialEvaluator = (function partialEvaluator() {
else if (typeNum == 2) { else if (typeNum == 2) {
var shading = xref.fetchIfRef(dict.get('Shading')); var shading = xref.fetchIfRef(dict.get('Shading'));
var matrix = dict.get('Matrix'); var matrix = dict.get('Matrix');
var pattern = Pattern.parseShading(shading, matrix, xref, res, null /*ctx*/); var pattern = Pattern.parseShading(shading, matrix, xref, res,
null /*ctx*/);
args = pattern.getIR(); args = pattern.getIR();
} else { } else {
error("Unkown PatternType " + typeNum); error('Unkown PatternType ' + typeNum);
} }
} }
} }
@ -4875,7 +4883,7 @@ var PartialEvaluator = (function partialEvaluator() {
var matrix = xobj.dict.get('Matrix'); var matrix = xobj.dict.get('Matrix');
var bbox = xobj.dict.get('BBox'); var bbox = xobj.dict.get('BBox');
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 IRQueue of the xObj to the current queue.
@ -4888,10 +4896,10 @@ var PartialEvaluator = (function partialEvaluator() {
// codeIR. // codeIR.
insertDependency(dependency.slice(depIdx)); insertDependency(dependency.slice(depIdx));
fn = "paintFormXObjectEnd"; fn = 'paintFormXObjectEnd';
args = []; args = [];
} else if ('Image' == type.name) { } else if ('Image' == type.name) {
buildPaintImageXObject(xobj, false) buildPaintImageXObject(xobj, false);
} else { } else {
error('Unhandled XObject subtype ' + type.name); error('Unhandled XObject subtype ' + type.name);
} }
@ -4907,7 +4915,8 @@ var PartialEvaluator = (function partialEvaluator() {
// font.translated = this.translateFont(font, xref, resources); // font.translated = this.translateFont(font, xref, resources);
// if (font.translated) { // if (font.translated) {
// // keep track of each font we translated so the caller can // // keep track of each font we translated so the caller can
// // load them asynchronously before calling display on a page // // load them asynchronously before calling display on a
// // page
// // fonts.push(font.translated); // // fonts.push(font.translated);
// dependency.push(font.translated); // dependency.push(font.translated);
// } // }
@ -4921,11 +4930,11 @@ var PartialEvaluator = (function partialEvaluator() {
// Transform some cmds. // Transform some cmds.
switch (fn) { switch (fn) {
// Parse the ColorSpace data to a raw format. // Parse the ColorSpace data to a raw format.
case "setFillColorSpace": case 'setFillColorSpace':
case "setStrokeColorSpace": case 'setStrokeColorSpace':
args = [ColorSpace.parseToIR(args[0], xref, resources)]; args = [ColorSpace.parseToIR(args[0], xref, resources)];
break; break;
case "shadingFill": case 'shadingFill':
var shadingRes = xref.fetchIfRef(res.get('Shading')); var shadingRes = xref.fetchIfRef(res.get('Shading'));
if (!shadingRes) if (!shadingRes)
error('No shading resource found'); error('No shading resource found');
@ -4934,14 +4943,15 @@ var PartialEvaluator = (function partialEvaluator() {
if (!shading) if (!shading)
error('No shading object found'); error('No shading object found');
var shadingFill = Pattern.parseShading(shading, null, xref, res, /* ctx */ null); var shadingFill = Pattern.parseShading(shading, null, xref, res,
/* ctx */ null);
var patternIR = shadingFill.getIR(); var patternIR = shadingFill.getIR();
args = [patternIR]; args = [patternIR];
fn = "shadingFill"; fn = 'shadingFill';
break; break;
case "setGState": case 'setGState':
var dictName = args[0]; var dictName = args[0];
var extGState = xref.fetchIfRef(resources.get('ExtGState')); var extGState = xref.fetchIfRef(resources.get('ExtGState'));
if (isDict(extGState) && extGState.has(dictName.name)) { if (isDict(extGState) && extGState.has(dictName.name)) {
@ -4950,7 +4960,8 @@ var PartialEvaluator = (function partialEvaluator() {
// This array holds the converted/processed state data. // This array holds the converted/processed state data.
var gsStateObj = []; var gsStateObj = [];
gsState.forEach(function canvasGraphicsSetGStateForEach(key, value) { gsState.forEach(
function canvasGraphicsSetGStateForEach(key, value) {
switch (key) { switch (key) {
case 'Type': case 'Type':
break; break;
@ -4964,7 +4975,10 @@ var PartialEvaluator = (function partialEvaluator() {
gsStateObj.push([key, value]); gsStateObj.push([key, value]);
break; break;
case 'Font': case 'Font':
gsStateObj.push(['Font', handleSetFont(value[0]), value[1] ]); gsStateObj.push([
'Font',
handleSetFont(value[0]), value[1]
]);
break; break;
case 'OP': case 'OP':
case 'op': case 'op':
@ -5279,8 +5293,8 @@ var PartialEvaluator = (function partialEvaluator() {
}; };
}, },
translateFont: function partialEvaluatorTranslateFont(dict, xref, translateFont: function partialEvaluatorTranslateFont(dict, xref, resources,
resources, queue, handler, uniquePrefix, dependency) { queue, handler, uniquePrefix, dependency) {
var baseDict = dict; var baseDict = dict;
var type = dict.get('Subtype'); var type = dict.get('Subtype');
assertWellFormed(isName(type), 'invalid font Subtype'); assertWellFormed(isName(type), 'invalid font Subtype');
@ -5426,8 +5440,8 @@ var PartialEvaluator = (function partialEvaluator() {
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]);
var queue = {}; var queue = {};
properties.glyphs[key].IRQueue = this.getIRQueue(glyphStream, properties.glyphs[key].IRQueue = this.getIRQueue(glyphStream, xref,
xref, fontResources, queue, handler, uniquePrefix, dependency); fontResources, queue, handler, uniquePrefix, dependency);
} }
} }
@ -5554,7 +5568,7 @@ var CanvasGraphics = (function canvasGraphics() {
executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck); executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck);
for (i; i < executionEndIdx; i++) { for (i; i < executionEndIdx; i++) {
if (fnArray[i] !== "dependency") { if (fnArray[i] !== 'dependency') {
this[fnArray[i]].apply(this, argsArray[i]); this[fnArray[i]].apply(this, argsArray[i]);
} else { } else {
var deps = argsArray[i]; var deps = argsArray[i];
@ -5820,7 +5834,7 @@ var CanvasGraphics = (function canvasGraphics() {
var fontObj = this.objs.get(fontRefName).fontObj; var fontObj = this.objs.get(fontRefName).fontObj;
if (!fontObj) { if (!fontObj) {
throw "Can't find font for " + fontRefName; throw 'Can\'t find font for ' + fontRefName;
} }
var name = fontObj.loadedName || 'sans-serif'; var name = fontObj.loadedName || 'sans-serif';
@ -6032,7 +6046,8 @@ var CanvasGraphics = (function canvasGraphics() {
}, },
// Color // Color
setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpacefunction(raw) { setStrokeColorSpace:
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
this.current.strokeColorSpace = this.current.strokeColorSpace =
ColorSpace.fromIR(raw); ColorSpace.fromIR(raw);
}, },
@ -6046,7 +6061,7 @@ var CanvasGraphics = (function canvasGraphics() {
this.setStrokeRGBColor.apply(this, color); this.setStrokeRGBColor.apply(this, color);
}, },
getColorN_IR_Pattern: function(IR, cs) { getColorN_IR_Pattern: function(IR, cs) {
if (IR[0] == "TilingPatternIR") { if (IR[0] == 'TilingPatternIR') {
// First, build the `color` var like it's done in the // First, build the `color` var like it's done in the
// Pattern.prototype.parse function. // Pattern.prototype.parse function.
var args = IR[1]; var args = IR[1];
@ -6064,10 +6079,10 @@ var CanvasGraphics = (function canvasGraphics() {
// Build the pattern based on the IR data. // Build the pattern based on the IR data.
var pattern = new TilingPatternIR(IR, color, this.ctx, this.objs); var pattern = new TilingPatternIR(IR, color, this.ctx, this.objs);
} else if (IR[0] == "RadialAxialShading" || IR[0] == "DummyShading") { } else if (IR[0] == 'RadialAxialShading' || IR[0] == 'DummyShading') {
var pattern = Pattern.shadingFromIR(this.ctx, IR); var pattern = Pattern.shadingFromIR(this.ctx, IR);
} else { } else {
throw "Unkown IR type"; throw 'Unkown IR type';
} }
return pattern; return pattern;
}, },
@ -6165,7 +6180,8 @@ var CanvasGraphics = (function canvasGraphics() {
error('Should not call beginImageData'); error('Should not call beginImageData');
}, },
paintFormXObjectBegin: function canvasGraphicsPaintFormXObject(matrix, bbox) { paintFormXObjectBegin:
function canvasGraphicsPaintFormXObject(matrix, bbox) {
this.save(); this.save();
if (matrix && isArray(matrix) && 6 == matrix.length) if (matrix && isArray(matrix) && 6 == matrix.length)
@ -6187,7 +6203,7 @@ var CanvasGraphics = (function canvasGraphics() {
paintJpegXObject: function(objId, w, h) { paintJpegXObject: function(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');
} }
this.save(); this.save();
@ -6388,7 +6404,7 @@ var ColorSpace = (function colorSpaceColorSpace() {
if (!(IR instanceof SeparationCS)) { if (!(IR instanceof SeparationCS)) {
return constructor.fromIR(IR); return constructor.fromIR(IR);
} else { } else {
return IR return IR;
} }
}; };
@ -6401,25 +6417,25 @@ var ColorSpace = (function colorSpaceColorSpace() {
} }
switch (name) { switch (name) {
case "DeviceGrayCS": case 'DeviceGrayCS':
return new DeviceGrayCS(); return new DeviceGrayCS();
case "DeviceRgbCS": case 'DeviceRgbCS':
return new DeviceRgbCS(); return new DeviceRgbCS();
case "DeviceCmykCS": case 'DeviceCmykCS':
return new DeviceCmykCS(); return new DeviceCmykCS();
case "PatternCS": case 'PatternCS':
var baseCS = IR[1]; var baseCS = IR[1];
if (baseCS == null) { if (baseCS == null) {
return new PatternCS(null); return new PatternCS(null);
} else { } else {
return new PatternCS(ColorSpace.fromIR(baseCS)); return new PatternCS(ColorSpace.fromIR(baseCS));
} }
case "IndexedCS": case 'IndexedCS':
var baseCS = IR[1]; var baseCS = IR[1];
var hiVal = IR[2]; var hiVal = IR[2];
var lookup = IR[3]; var lookup = IR[3];
return new IndexedCS(ColorSpace.fromIR(baseCS), hiVal, lookup) return new IndexedCS(ColorSpace.fromIR(baseCS), hiVal, lookup);
case "SeparationCS": case 'SeparationCS':
var alt = IR[1]; var alt = IR[1];
var tintFnIR = IR[2]; var tintFnIR = IR[2];
@ -6428,7 +6444,7 @@ var ColorSpace = (function colorSpaceColorSpace() {
PDFFunction.fromIR(tintFnIR) PDFFunction.fromIR(tintFnIR)
); );
default: default:
error("Unkown name " + name); error('Unkown name ' + name);
} }
return null; return null;
} }
@ -6452,15 +6468,15 @@ var ColorSpace = (function colorSpaceColorSpace() {
switch (mode) { switch (mode) {
case 'DeviceGray': case 'DeviceGray':
case 'G': case 'G':
return "DeviceGrayCS"; return 'DeviceGrayCS';
case 'DeviceRGB': case 'DeviceRGB':
case 'RGB': case 'RGB':
return "DeviceRgbCS"; return 'DeviceRgbCS';
case 'DeviceCMYK': case 'DeviceCMYK':
case 'CMYK': case 'CMYK':
return "DeviceCmykCS"; return 'DeviceCmykCS';
case 'Pattern': case 'Pattern':
return ["PatternCS", null]; return ['PatternCS', null];
default: default:
error('unrecognized colorspace ' + mode); error('unrecognized colorspace ' + mode);
} }
@ -6471,42 +6487,42 @@ var ColorSpace = (function colorSpaceColorSpace() {
switch (mode) { switch (mode) {
case 'DeviceGray': case 'DeviceGray':
case 'G': case 'G':
return "DeviceGrayCS"; return 'DeviceGrayCS';
case 'DeviceRGB': case 'DeviceRGB':
case 'RGB': case 'RGB':
return "DeviceRgbCS"; return 'DeviceRgbCS';
case 'DeviceCMYK': case 'DeviceCMYK':
case 'CMYK': case 'CMYK':
return "DeviceCmykCS"; return 'DeviceCmykCS';
case 'CalGray': case 'CalGray':
return "DeviceGrayCS"; return 'DeviceGrayCS';
case 'CalRGB': case 'CalRGB':
return "DeviceRgbCS"; return 'DeviceRgbCS';
case 'ICCBased': case 'ICCBased':
var stream = xref.fetchIfRef(cs[1]); var stream = xref.fetchIfRef(cs[1]);
var dict = stream.dict; var dict = stream.dict;
var numComps = dict.get('N'); var numComps = dict.get('N');
if (numComps == 1) if (numComps == 1)
return "DeviceGrayCS"; return 'DeviceGrayCS';
if (numComps == 3) if (numComps == 3)
return "DeviceRgbCS"; return 'DeviceRgbCS';
if (numComps == 4) if (numComps == 4)
return "DeviceCmykCS"; return 'DeviceCmykCS';
break; break;
case 'Pattern': case 'Pattern':
var baseCS = cs[1]; var baseCS = cs[1];
if (baseCS) if (baseCS)
baseCS = ColorSpace.parseToIR(baseCS, xref, res); baseCS = ColorSpace.parseToIR(baseCS, xref, res);
return ["PatternCS", baseCS]; return ['PatternCS', baseCS];
case 'Indexed': case 'Indexed':
var baseCS = ColorSpace.parseToIR(cs[1], xref, res); var baseCS = ColorSpace.parseToIR(cs[1], xref, res);
var hiVal = cs[2] + 1; var hiVal = cs[2] + 1;
var lookup = xref.fetchIfRef(cs[3]); var lookup = xref.fetchIfRef(cs[3]);
return ["IndexedCS", baseCS, hiVal, lookup]; return ['IndexedCS', baseCS, hiVal, lookup];
case 'Separation': case 'Separation':
var alt = ColorSpace.parseToIR(cs[2], xref, res); var alt = ColorSpace.parseToIR(cs[2], xref, res);
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3])); var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
return ["SeparationCS", alt, tintFnIR]; return ['SeparationCS', alt, tintFnIR];
case 'Lab': case 'Lab':
case 'DeviceN': case 'DeviceN':
default: default:
@ -6927,7 +6943,7 @@ var RadialAxialShading = (function radialAxialShading() {
p1 = Util.applyTransform(p1, matrix); p1 = Util.applyTransform(p1, matrix);
} }
return [ "RadialAxialShading", type, this.colorStops, p0, p1, r0, r1 ]; return ['RadialAxialShading', type, this.colorStops, p0, p1, r0, r1];
} }
}; };
@ -6938,7 +6954,7 @@ var TilingPatternIR = (function tilingPattern() {
var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2; var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2;
function TilingPatternIR(IR, color, ctx, objs) { function TilingPatternIR(IR, color, ctx, objs) {
// "Unfolding" the IR. // 'Unfolding' the IR.
var IRQueue = IR[2]; var IRQueue = IR[2];
this.matrix = IR[3]; this.matrix = IR[3];
var bbox = IR[4]; var bbox = IR[4];
@ -7030,7 +7046,7 @@ var TilingPatternIR = (function tilingPattern() {
return ctx.createPattern(this.canvas, 'repeat'); return ctx.createPattern(this.canvas, 'repeat');
} }
} };
return TilingPatternIR; return TilingPatternIR;
})(); })();
@ -7043,7 +7059,9 @@ var TilingPattern = {
var ystep = dict.get('YStep'); var ystep = dict.get('YStep');
var paintType = dict.get('PaintType'); var paintType = dict.get('PaintType');
return ["TilingPatternIR", args, codeIR, matrix, bbox, xstep, ystep, paintType]; return [
'TilingPatternIR', args, codeIR, matrix, bbox, xstep, ystep, paintType
];
} }
}; };
@ -7380,16 +7398,19 @@ var PDFFunction = (function() {
var samples = this.getSampleArray(size, outputSize, bps, str); var samples = this.getSampleArray(size, outputSize, bps, str);
return [ CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size, outputSize, bps, range ]; return [
CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
outputSize, bps, range
];
}, },
constructSampledFromIR: function(IR) { constructSampledFromIR: function(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];
var decode = IR[4] var decode = IR[4];
var samples = IR[5] var samples = IR[5];
var size = IR[6] var size = IR[6];
var outputSize = IR[7]; var outputSize = IR[7];
var bps = IR[8]; var bps = IR[8];
var range = IR[9]; var range = IR[9];
@ -7454,7 +7475,8 @@ var PDFFunction = (function() {
} }
}, },
constructInterpolated: function pdfFunctionConstructInterpolated(str, dict) { constructInterpolated:
function pdfFunctionConstructInterpolated(str, dict) {
var c0 = dict.get('C0') || [0]; var c0 = dict.get('C0') || [0];
var c1 = dict.get('C1') || [1]; var c1 = dict.get('C1') || [1];
var n = dict.get('N'); var n = dict.get('N');
@ -7470,7 +7492,8 @@ var PDFFunction = (function() {
return [CONSTRUCT_INTERPOLATED, c0, diff, n, i]; return [CONSTRUCT_INTERPOLATED, c0, diff, n, i];
}, },
constructInterpolatedFromIR: function pdfFunctionconstructInterpolatedFromIR(IR) { constructInterpolatedFromIR:
function pdfFunctionconstructInterpolatedFromIR(IR) {
var c0 = IR[1]; var c0 = IR[1];
var diff = IR[2]; var diff = IR[2];
var n = IR[3]; var n = IR[3];
@ -7568,6 +7591,6 @@ var PDFFunction = (function() {
return [255, 105, 180]; return [255, 105, 180];
}; };
} }
} };
})(); })();

View File

@ -39,7 +39,7 @@ var WorkerPage = (function() {
// this.page.startRendering(ctx, callback, errback); // this.page.startRendering(ctx, callback, errback);
this.startRenderingTime = Date.now(); this.startRenderingTime = Date.now();
this.workerPDF.startRendering(this) this.workerPDF.startRendering(this);
}, },
startRenderingFromIRQueue: function(IRQueue, fonts) { startRenderingFromIRQueue: function(IRQueue, fonts) {
@ -48,9 +48,9 @@ var WorkerPage = (function() {
var startTime = Date.now(); var startTime = Date.now();
var callback = function(err) { var callback = function(err) {
var pageNum = this.page.pageNumber + 1; var pageNum = this.page.pageNumber + 1;
console.log("page=%d - rendering time: time=%dms", console.log('page=%d - rendering time: time=%dms',
pageNum, Date.now() - startTime); pageNum, Date.now() - startTime);
console.log("page=%d - total time: time=%dms", console.log('page=%d - total time: time=%dms',
pageNum, Date.now() - this.startRenderingTime); pageNum, Date.now() - this.startRenderingTime);
this.callback(err); this.callback(err);
@ -69,8 +69,8 @@ var WorkerPage = (function() {
/** /**
* A PDF document and page is build up of many objects. E.g. there are objects * A PDF document and page is build up of many objects. E.g. there are objects
* for fonts, images, rendering code and such. These objects might get processed * for fonts, images, rendering code and such. These objects might get processed
* inside of a worker. The `PDFObjects` implements some basic functions to manage * inside of a worker. The `PDFObjects` implements some basic functions to
* these objects. * manage these objects.
*/ */
var PDFObjects = (function() { var PDFObjects = (function() {
function PDFObjects() { function PDFObjects() {
@ -116,7 +116,7 @@ var PDFObjects = (function() {
// If there isn't an object yet or the object isn't resolved, then the // If there isn't an object yet or the object isn't resolved, then the
// data isn't ready yet! // data isn't ready yet!
if (!obj || !obj.isResolved) { if (!obj || !obj.isResolved) {
throw "Requesting object that isn't resolved yet " + objId; throw 'Requesting object that isn\'t resolved yet ' + objId;
} }
// Direct access. // Direct access.
else { else {
@ -169,13 +169,13 @@ var PDFObjects = (function() {
// a *resolved* promise which shouldn't be the case! // a *resolved* promise which shouldn't be the case!
this.ensureObj(objId).data = data; this.ensureObj(objId).data = data;
} }
} };
return PDFObjects; return PDFObjects;
})(); })();
/** /**
* "Promise" object. * 'Promise' object.
* Each object that is stored in PDFObjects is based on a Promise object that * Each object that is stored in PDFObjects is based on a Promise object that
* contains the status of the object and the data. There migth be situations, * contains the status of the object and the data. There migth be situations,
* where a function want to use the value of an object, but it isn't ready at * where a function want to use the value of an object, but it isn't ready at
@ -215,7 +215,8 @@ var Promise = (function() {
return; return;
} }
if (this._data !== EMPTY_PROMISE) { if (this._data !== EMPTY_PROMISE) {
throw "Promise " + this.name + ": Cannot set the data of a promise twice"; throw 'Promise ' + this.name +
': Cannot set the data of a promise twice';
} }
this._data = data; this._data = data;
this.hasData = true; this.hasData = true;
@ -227,7 +228,7 @@ var Promise = (function() {
get data() { get data() {
if (this._data === EMPTY_PROMISE) { if (this._data === EMPTY_PROMISE) {
throw "Promise " + this.name + ": Cannot get data that isn't set"; throw 'Promise ' + this.name + ': Cannot get data that isn\'t set';
} }
return this._data; return this._data;
}, },
@ -242,7 +243,7 @@ var Promise = (function() {
resolve: function(data) { resolve: function(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;
} }
this.isResolved = true; this.isResolved = true;
@ -256,7 +257,7 @@ var Promise = (function() {
then: function(callback) { then: function(callback) {
if (!callback) { if (!callback) {
throw "Requiring callback" + this.name; throw 'Requiring callback' + this.name;
} }
// If the promise is already resolved, call the callback directly. // If the promise is already resolved, call the callback directly.
@ -267,7 +268,7 @@ var Promise = (function() {
this.callbacks.push(callback); this.callbacks.push(callback);
} }
} }
} };
return Promise; return Promise;
})(); })();

View File

@ -9,12 +9,12 @@ 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(data) {
console.log.apply(console, data); console.log.apply(console, data);
}] }];
ah["console_error"] = [function(data) { ah['console_error'] = [function(data) {
console.error.apply(console, data); console.error.apply(console, data);
}] }];
comObj.onmessage = function(event) { comObj.onmessage = function(event) {
var data = event.data; var data = event.data;
@ -42,5 +42,5 @@ MessageHandler.prototype = {
data: data data: data
}); });
} }
} };

View File

@ -15,5 +15,5 @@ importScripts('processor_handler.js');
// Listen for messages from the main thread. // Listen for messages from the main thread.
var pdfDoc = null; var pdfDoc = null;
var handler = new MessageHandler("worker_processor", this); var handler = new MessageHandler('worker_processor', this);
WorkerProcessorHandler.setup(handler); WorkerProcessorHandler.setup(handler);

View File

@ -7,19 +7,20 @@ var WorkerProcessorHandler = {
setup: function(handler) { setup: function(handler) {
var pdfDoc = null; var pdfDoc = null;
handler.on("doc", function(data) { handler.on('doc', function(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(pageNum) {
pageNum = parseInt(pageNum); pageNum = parseInt(pageNum);
var page = pdfDoc.getPage(pageNum); var page = pdfDoc.getPage(pageNum);
// The following code does quite the same as Page.prototype.startRendering, // The following code does quite the same as
// but stops at one point and sends the result back to the main thread. // Page.prototype.startRendering, but stops at one point and sends the
// result back to the main thread.
var gfx = new CanvasGraphics(null); var gfx = new CanvasGraphics(null);
var start = Date.now(); var start = Date.now();
@ -29,7 +30,8 @@ var WorkerProcessorHandler = {
// Pre compile the pdf page and fetch the fonts/images. // Pre compile the pdf page and fetch the fonts/images.
var IRQueue = page.getIRQueue(handler, dependency); var IRQueue = page.getIRQueue(handler, dependency);
console.log("page=%d - getIRQueue: time=%dms, len=%d", pageNum, Date.now() - start, IRQueue.fnArray.length); console.log('page=%d - getIRQueue: time=%dms, len=%d', pageNum,
Date.now() - start, IRQueue.fnArray.length);
if (false /* show used commands */) { if (false /* show used commands */) {
var cmdMap = {}; var cmdMap = {};
@ -37,7 +39,7 @@ var WorkerProcessorHandler = {
var fnArray = IRQueue .fnArray; var fnArray = IRQueue .fnArray;
for (var i = 0; i < fnArray.length; i++) { for (var i = 0; i < fnArray.length; i++) {
var entry = fnArray[i]; var entry = fnArray[i];
if (entry == "paintReadyFormXObject") { if (entry == 'paintReadyFormXObject') {
//console.log(preCompilation.argsArray[i]); //console.log(preCompilation.argsArray[i]);
} }
if (cmdMap[entry] == null) { if (cmdMap[entry] == null) {
@ -46,7 +48,7 @@ var WorkerProcessorHandler = {
cmdMap[entry] += 1; cmdMap[entry] += 1;
} }
} }
console.log("cmds", JSON.stringify(cmdMap)); console.log('cmds', JSON.stringify(cmdMap));
} }
// Filter the dependecies for fonts. // Filter the dependecies for fonts.
@ -66,14 +68,14 @@ var WorkerProcessorHandler = {
// } // }
// } // }
handler.send("page", { handler.send('page', {
pageNum: pageNum, pageNum: pageNum,
IRQueue: IRQueue, IRQueue: IRQueue,
depFonts: fonts depFonts: fonts
}); });
}, this); }, this);
handler.on("font", function(data) { handler.on('font', function(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];
@ -119,7 +121,7 @@ var WorkerProcessorHandler = {
// anymore as we sent over the ready str. // anymore as we sent over the ready str.
delete obj.data; delete obj.data;
handler.send("font_ready", [objId, obj]); handler.send('font_ready', [objId, obj]);
}); });
} }
} };