Fix lint errors
This commit is contained in:
parent
a6180830f8
commit
20a348fc0c
105
fonts.js
105
fonts.js
@ -415,111 +415,6 @@ function getUnicodeRangeFor(value) {
|
||||
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
|
||||
* decoding logics whatever type it is (assuming the font type is supported).
|
||||
|
219
pdf.js
219
pdf.js
@ -917,10 +917,10 @@ var JpegStreamIR = (function() {
|
||||
getImage: function() {
|
||||
return this.domImage;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return JpegStreamIR;
|
||||
})()
|
||||
})();
|
||||
|
||||
// A JpegStream can't be read directly. We use the platform to render
|
||||
// the underlying JPEG data for us.
|
||||
@ -956,7 +956,7 @@ var JpegStream = (function jpegStream() {
|
||||
}
|
||||
|
||||
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
|
||||
this.dict = dict;
|
||||
|
||||
@ -3536,7 +3536,8 @@ var Page = (function pagePage() {
|
||||
return shadow(this, 'rotate', rotate);
|
||||
},
|
||||
|
||||
startRenderingFromIRQueue: function startRenderingFromIRQueue(gfx, IRQueue, fonts, continuation) {
|
||||
startRenderingFromIRQueue: function startRenderingFromIRQueue(gfx,
|
||||
IRQueue, fonts, continuation) {
|
||||
var self = this;
|
||||
this.IRQueue = IRQueue;
|
||||
|
||||
@ -3581,7 +3582,8 @@ var Page = (function pagePage() {
|
||||
|
||||
var pe = this.pe = new PartialEvaluator();
|
||||
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) {
|
||||
@ -3628,7 +3630,7 @@ var Page = (function pagePage() {
|
||||
startIdx = gfx.executeIRQueue(IRQueue, startIdx, next);
|
||||
if (startIdx == length) {
|
||||
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);
|
||||
callback();
|
||||
}
|
||||
@ -4020,20 +4022,22 @@ var PDFDoc = (function() {
|
||||
this.pageCache = [];
|
||||
|
||||
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 {
|
||||
// If we don't use a worker, just post/sendMessage to the main thread.
|
||||
var worker = {
|
||||
postMessage: function(obj) {
|
||||
worker.onmessage({data: obj});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.fontsLoading = {};
|
||||
|
||||
var processorHandler = this.processorHandler = new MessageHandler("main", worker);
|
||||
processorHandler.on("page", function(data) {
|
||||
var processorHandler = this.processorHandler =
|
||||
new MessageHandler('main', worker);
|
||||
|
||||
processorHandler.on('page', function(data) {
|
||||
var pageNum = data.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
|
||||
// // call startRenderingFromIRQueue twice with the same font. That makes
|
||||
// // the font getting loaded twice and throw an error later as the font
|
||||
// // promise gets resolved twice.
|
||||
// // call startRenderingFromIRQueue twice with the same font. That
|
||||
// // makes the font getting loaded twice and throw an error later as
|
||||
// // the font promise gets resolved twice.
|
||||
// //
|
||||
// // This prevents thats fonts are loaded really only once.
|
||||
// for (var j = 0; j < fontsToLoad.length; j++) {
|
||||
// var fontName = fontsToLoad[j];
|
||||
@ -4084,7 +4089,8 @@ var PDFDoc = (function() {
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
@ -4094,17 +4100,17 @@ var PDFDoc = (function() {
|
||||
page.startRenderingFromIRQueue(data.IRQueue, Object.keys(data.depFonts));
|
||||
}, this);
|
||||
|
||||
processorHandler.on("obj", function(data) {
|
||||
processorHandler.on('obj', function(data) {
|
||||
var objId = data[0];
|
||||
var objType = data[1];
|
||||
|
||||
switch (objType) {
|
||||
case "JpegStream":
|
||||
case 'JpegStream':
|
||||
var IR = data[2];
|
||||
new JpegStreamIR(objId, IR, this.objs);
|
||||
console.log('got image');
|
||||
break;
|
||||
case "Font":
|
||||
case 'Font':
|
||||
var name = data[2];
|
||||
var file = data[3];
|
||||
var properties = data[4];
|
||||
@ -4127,8 +4133,8 @@ var PDFDoc = (function() {
|
||||
}
|
||||
|
||||
|
||||
// For now, resolve the font object here direclty. The real font object
|
||||
// is then created in FontLoader.bind().
|
||||
// For now, resolve the font object here direclty. The real font
|
||||
// object is then created in FontLoader.bind().
|
||||
this.objs.resolve(objId, {
|
||||
name: name,
|
||||
file: file,
|
||||
@ -4191,10 +4197,10 @@ var PDFDoc = (function() {
|
||||
// this.objs.setData(objId, fontObj);
|
||||
// }
|
||||
|
||||
// processorHandler.send("font", [objId, name, file, properties]);
|
||||
// processorHandler.send('font', [objId, name, file, properties]);
|
||||
break;
|
||||
default:
|
||||
throw "Got unkown object type " + objType;
|
||||
throw 'Got unkown object type ' + objType;
|
||||
}
|
||||
}, this);
|
||||
|
||||
@ -4218,7 +4224,7 @@ var PDFDoc = (function() {
|
||||
WorkerProcessorHandler.setup(processorHandler);
|
||||
}
|
||||
|
||||
processorHandler.send("doc", this.data);
|
||||
processorHandler.send('doc', this.data);
|
||||
}
|
||||
|
||||
constructor.prototype = {
|
||||
@ -4227,7 +4233,7 @@ var PDFDoc = (function() {
|
||||
},
|
||||
|
||||
startRendering: function(page) {
|
||||
this.processorHandler.send("page_request", page.page.pageNumber + 1);
|
||||
this.processorHandler.send('page_request', page.page.pageNumber + 1);
|
||||
},
|
||||
|
||||
getPage: function(n) {
|
||||
@ -4243,7 +4249,7 @@ var PDFDoc = (function() {
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
console.log("destroy worker");
|
||||
console.log('destroy worker');
|
||||
if (this.worker) {
|
||||
this.worker.terminate();
|
||||
}
|
||||
@ -4663,11 +4669,11 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
};
|
||||
|
||||
constructor.prototype = {
|
||||
getIRQueue: function partialEvaluatorGetIRQueue(stream, xref, resources, queue, handler,
|
||||
uniquePrefix, dependency) {
|
||||
getIRQueue: function partialEvaluatorGetIRQueue(stream, xref, resources,
|
||||
queue, handler, uniquePrefix, dependency) {
|
||||
|
||||
function insertDependency(depList) {
|
||||
fnArray.push("dependency");
|
||||
fnArray.push('dependency');
|
||||
argsArray.push(depList);
|
||||
for (var i = 0; i < depList.length; i++) {
|
||||
var dep = depList[i];
|
||||
@ -4692,14 +4698,14 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
if (font.translated) {
|
||||
// keep track of each font we translated so the caller can
|
||||
// load them asynchronously before calling display on a page
|
||||
loadedName = "font_" + uniquePrefix + (FontLoadedCounter++);
|
||||
loadedName = 'font_' + uniquePrefix + (FontLoadedCounter++);
|
||||
font.translated.properties.loadedName = loadedName;
|
||||
font.loadedName = loadedName;
|
||||
FontsMap[loadedName] = font;
|
||||
|
||||
handler.send("obj", [
|
||||
handler.send('obj', [
|
||||
loadedName,
|
||||
"Font",
|
||||
'Font',
|
||||
font.translated.name,
|
||||
font.translated.file,
|
||||
font.translated.properties
|
||||
@ -4717,6 +4723,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
} else {
|
||||
// TODO: TOASK: Is it possible to get here? If so, what does
|
||||
// args[0].name should be like???
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4727,7 +4734,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
|
||||
if (image instanceof JpegStream) {
|
||||
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.
|
||||
insertDependency([objId]);
|
||||
@ -4747,7 +4754,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
var imageObj = new PDFImage(xref, resources, image, inline);
|
||||
|
||||
if (imageObj.imageMask) {
|
||||
throw "Can't handle this in the web worker :/";
|
||||
throw 'Can\'t handle this in the web worker :/';
|
||||
}
|
||||
|
||||
var imgData = {
|
||||
@ -4758,7 +4765,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
var pixels = imgData.data;
|
||||
imageObj.fillRgbaBuffer(pixels, imageObj.decode);
|
||||
|
||||
fn = "paintImageXObject";
|
||||
fn = 'paintImageXObject';
|
||||
args = [imgData];
|
||||
} else /* imageMask == true */ {
|
||||
// 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
|
||||
// complete PDFImage, only read the information needed
|
||||
// for later.
|
||||
fn = "paintImageMaskXObject";
|
||||
fn = 'paintImageMaskXObject';
|
||||
|
||||
var width = dict.get('Width', 'W');
|
||||
var height = dict.get('Height', 'H');
|
||||
@ -4780,9 +4787,9 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
}
|
||||
}
|
||||
|
||||
uniquePrefix = uniquePrefix || "";
|
||||
uniquePrefix = uniquePrefix || '';
|
||||
if (!queue.argsArray) {
|
||||
queue.argsArray = []
|
||||
queue.argsArray = [];
|
||||
}
|
||||
if (!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
|
||||
|
||||
if ((cmd == 'SCN' || cmd == 'scn') && !args[args.length - 1].code) {
|
||||
@ -4850,10 +4857,11 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
else if (typeNum == 2) {
|
||||
var shading = xref.fetchIfRef(dict.get('Shading'));
|
||||
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();
|
||||
} else {
|
||||
error("Unkown PatternType " + typeNum);
|
||||
error('Unkown PatternType ' + typeNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4875,7 +4883,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
var matrix = xobj.dict.get('Matrix');
|
||||
var bbox = xobj.dict.get('BBox');
|
||||
|
||||
fnArray.push("paintFormXObjectBegin");
|
||||
fnArray.push('paintFormXObjectBegin');
|
||||
argsArray.push([matrix, bbox]);
|
||||
|
||||
// This adds the IRQueue of the xObj to the current queue.
|
||||
@ -4888,10 +4896,10 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
// codeIR.
|
||||
insertDependency(dependency.slice(depIdx));
|
||||
|
||||
fn = "paintFormXObjectEnd";
|
||||
fn = 'paintFormXObjectEnd';
|
||||
args = [];
|
||||
} else if ('Image' == type.name) {
|
||||
buildPaintImageXObject(xobj, false)
|
||||
buildPaintImageXObject(xobj, false);
|
||||
} else {
|
||||
error('Unhandled XObject subtype ' + type.name);
|
||||
}
|
||||
@ -4907,7 +4915,8 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
// font.translated = this.translateFont(font, xref, resources);
|
||||
// if (font.translated) {
|
||||
// // 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);
|
||||
// dependency.push(font.translated);
|
||||
// }
|
||||
@ -4921,11 +4930,11 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
// Transform some cmds.
|
||||
switch (fn) {
|
||||
// Parse the ColorSpace data to a raw format.
|
||||
case "setFillColorSpace":
|
||||
case "setStrokeColorSpace":
|
||||
case 'setFillColorSpace':
|
||||
case 'setStrokeColorSpace':
|
||||
args = [ColorSpace.parseToIR(args[0], xref, resources)];
|
||||
break;
|
||||
case "shadingFill":
|
||||
case 'shadingFill':
|
||||
var shadingRes = xref.fetchIfRef(res.get('Shading'));
|
||||
if (!shadingRes)
|
||||
error('No shading resource found');
|
||||
@ -4934,14 +4943,15 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
if (!shading)
|
||||
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();
|
||||
|
||||
args = [patternIR];
|
||||
fn = "shadingFill";
|
||||
fn = 'shadingFill';
|
||||
|
||||
break;
|
||||
case "setGState":
|
||||
case 'setGState':
|
||||
var dictName = args[0];
|
||||
var extGState = xref.fetchIfRef(resources.get('ExtGState'));
|
||||
if (isDict(extGState) && extGState.has(dictName.name)) {
|
||||
@ -4950,7 +4960,8 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
// This array holds the converted/processed state data.
|
||||
var gsStateObj = [];
|
||||
|
||||
gsState.forEach(function canvasGraphicsSetGStateForEach(key, value) {
|
||||
gsState.forEach(
|
||||
function canvasGraphicsSetGStateForEach(key, value) {
|
||||
switch (key) {
|
||||
case 'Type':
|
||||
break;
|
||||
@ -4964,7 +4975,10 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
gsStateObj.push([key, value]);
|
||||
break;
|
||||
case 'Font':
|
||||
gsStateObj.push(['Font', handleSetFont(value[0]), value[1] ]);
|
||||
gsStateObj.push([
|
||||
'Font',
|
||||
handleSetFont(value[0]), value[1]
|
||||
]);
|
||||
break;
|
||||
case 'OP':
|
||||
case 'op':
|
||||
@ -5279,8 +5293,8 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
};
|
||||
},
|
||||
|
||||
translateFont: function partialEvaluatorTranslateFont(dict, xref,
|
||||
resources, queue, handler, uniquePrefix, dependency) {
|
||||
translateFont: function partialEvaluatorTranslateFont(dict, xref, resources,
|
||||
queue, handler, uniquePrefix, dependency) {
|
||||
var baseDict = dict;
|
||||
var type = dict.get('Subtype');
|
||||
assertWellFormed(isName(type), 'invalid font Subtype');
|
||||
@ -5426,8 +5440,8 @@ var PartialEvaluator = (function partialEvaluator() {
|
||||
for (var key in charProcs.map) {
|
||||
var glyphStream = xref.fetchIfRef(charProcs.map[key]);
|
||||
var queue = {};
|
||||
properties.glyphs[key].IRQueue = this.getIRQueue(glyphStream,
|
||||
xref, fontResources, queue, handler, uniquePrefix, dependency);
|
||||
properties.glyphs[key].IRQueue = this.getIRQueue(glyphStream, xref,
|
||||
fontResources, queue, handler, uniquePrefix, dependency);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5554,7 +5568,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck);
|
||||
|
||||
for (i; i < executionEndIdx; i++) {
|
||||
if (fnArray[i] !== "dependency") {
|
||||
if (fnArray[i] !== 'dependency') {
|
||||
this[fnArray[i]].apply(this, argsArray[i]);
|
||||
} else {
|
||||
var deps = argsArray[i];
|
||||
@ -5820,7 +5834,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
var fontObj = this.objs.get(fontRefName).fontObj;
|
||||
|
||||
if (!fontObj) {
|
||||
throw "Can't find font for " + fontRefName;
|
||||
throw 'Can\'t find font for ' + fontRefName;
|
||||
}
|
||||
|
||||
var name = fontObj.loadedName || 'sans-serif';
|
||||
@ -6032,7 +6046,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
},
|
||||
|
||||
// Color
|
||||
setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpacefunction(raw) {
|
||||
setStrokeColorSpace:
|
||||
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
|
||||
this.current.strokeColorSpace =
|
||||
ColorSpace.fromIR(raw);
|
||||
},
|
||||
@ -6046,7 +6061,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
this.setStrokeRGBColor.apply(this, color);
|
||||
},
|
||||
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
|
||||
// Pattern.prototype.parse function.
|
||||
var args = IR[1];
|
||||
@ -6064,10 +6079,10 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
|
||||
// Build the pattern based on the IR data.
|
||||
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);
|
||||
} else {
|
||||
throw "Unkown IR type";
|
||||
throw 'Unkown IR type';
|
||||
}
|
||||
return pattern;
|
||||
},
|
||||
@ -6165,7 +6180,8 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
error('Should not call beginImageData');
|
||||
},
|
||||
|
||||
paintFormXObjectBegin: function canvasGraphicsPaintFormXObject(matrix, bbox) {
|
||||
paintFormXObjectBegin:
|
||||
function canvasGraphicsPaintFormXObject(matrix, bbox) {
|
||||
this.save();
|
||||
|
||||
if (matrix && isArray(matrix) && 6 == matrix.length)
|
||||
@ -6187,7 +6203,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
||||
paintJpegXObject: function(objId, w, h) {
|
||||
var image = this.objs.get(objId);
|
||||
if (!image) {
|
||||
error("Dependent image isn't ready yet");
|
||||
error('Dependent image isn\'t ready yet');
|
||||
}
|
||||
|
||||
this.save();
|
||||
@ -6388,7 +6404,7 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
||||
if (!(IR instanceof SeparationCS)) {
|
||||
return constructor.fromIR(IR);
|
||||
} else {
|
||||
return IR
|
||||
return IR;
|
||||
}
|
||||
};
|
||||
|
||||
@ -6401,25 +6417,25 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
||||
}
|
||||
|
||||
switch (name) {
|
||||
case "DeviceGrayCS":
|
||||
case 'DeviceGrayCS':
|
||||
return new DeviceGrayCS();
|
||||
case "DeviceRgbCS":
|
||||
case 'DeviceRgbCS':
|
||||
return new DeviceRgbCS();
|
||||
case "DeviceCmykCS":
|
||||
case 'DeviceCmykCS':
|
||||
return new DeviceCmykCS();
|
||||
case "PatternCS":
|
||||
case 'PatternCS':
|
||||
var baseCS = IR[1];
|
||||
if (baseCS == null) {
|
||||
return new PatternCS(null);
|
||||
} else {
|
||||
return new PatternCS(ColorSpace.fromIR(baseCS));
|
||||
}
|
||||
case "IndexedCS":
|
||||
case 'IndexedCS':
|
||||
var baseCS = IR[1];
|
||||
var hiVal = IR[2];
|
||||
var lookup = IR[3];
|
||||
return new IndexedCS(ColorSpace.fromIR(baseCS), hiVal, lookup)
|
||||
case "SeparationCS":
|
||||
return new IndexedCS(ColorSpace.fromIR(baseCS), hiVal, lookup);
|
||||
case 'SeparationCS':
|
||||
var alt = IR[1];
|
||||
var tintFnIR = IR[2];
|
||||
|
||||
@ -6428,7 +6444,7 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
||||
PDFFunction.fromIR(tintFnIR)
|
||||
);
|
||||
default:
|
||||
error("Unkown name " + name);
|
||||
error('Unkown name ' + name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -6452,15 +6468,15 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
||||
switch (mode) {
|
||||
case 'DeviceGray':
|
||||
case 'G':
|
||||
return "DeviceGrayCS";
|
||||
return 'DeviceGrayCS';
|
||||
case 'DeviceRGB':
|
||||
case 'RGB':
|
||||
return "DeviceRgbCS";
|
||||
return 'DeviceRgbCS';
|
||||
case 'DeviceCMYK':
|
||||
case 'CMYK':
|
||||
return "DeviceCmykCS";
|
||||
return 'DeviceCmykCS';
|
||||
case 'Pattern':
|
||||
return ["PatternCS", null];
|
||||
return ['PatternCS', null];
|
||||
default:
|
||||
error('unrecognized colorspace ' + mode);
|
||||
}
|
||||
@ -6471,42 +6487,42 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
||||
switch (mode) {
|
||||
case 'DeviceGray':
|
||||
case 'G':
|
||||
return "DeviceGrayCS";
|
||||
return 'DeviceGrayCS';
|
||||
case 'DeviceRGB':
|
||||
case 'RGB':
|
||||
return "DeviceRgbCS";
|
||||
return 'DeviceRgbCS';
|
||||
case 'DeviceCMYK':
|
||||
case 'CMYK':
|
||||
return "DeviceCmykCS";
|
||||
return 'DeviceCmykCS';
|
||||
case 'CalGray':
|
||||
return "DeviceGrayCS";
|
||||
return 'DeviceGrayCS';
|
||||
case 'CalRGB':
|
||||
return "DeviceRgbCS";
|
||||
return 'DeviceRgbCS';
|
||||
case 'ICCBased':
|
||||
var stream = xref.fetchIfRef(cs[1]);
|
||||
var dict = stream.dict;
|
||||
var numComps = dict.get('N');
|
||||
if (numComps == 1)
|
||||
return "DeviceGrayCS";
|
||||
return 'DeviceGrayCS';
|
||||
if (numComps == 3)
|
||||
return "DeviceRgbCS";
|
||||
return 'DeviceRgbCS';
|
||||
if (numComps == 4)
|
||||
return "DeviceCmykCS";
|
||||
return 'DeviceCmykCS';
|
||||
break;
|
||||
case 'Pattern':
|
||||
var baseCS = cs[1];
|
||||
if (baseCS)
|
||||
baseCS = ColorSpace.parseToIR(baseCS, xref, res);
|
||||
return ["PatternCS", baseCS];
|
||||
return ['PatternCS', baseCS];
|
||||
case 'Indexed':
|
||||
var baseCS = ColorSpace.parseToIR(cs[1], xref, res);
|
||||
var hiVal = cs[2] + 1;
|
||||
var lookup = xref.fetchIfRef(cs[3]);
|
||||
return ["IndexedCS", baseCS, hiVal, lookup];
|
||||
return ['IndexedCS', baseCS, hiVal, lookup];
|
||||
case 'Separation':
|
||||
var alt = ColorSpace.parseToIR(cs[2], xref, res);
|
||||
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
|
||||
return ["SeparationCS", alt, tintFnIR];
|
||||
return ['SeparationCS', alt, tintFnIR];
|
||||
case 'Lab':
|
||||
case 'DeviceN':
|
||||
default:
|
||||
@ -6927,7 +6943,7 @@ var RadialAxialShading = (function radialAxialShading() {
|
||||
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;
|
||||
|
||||
function TilingPatternIR(IR, color, ctx, objs) {
|
||||
// "Unfolding" the IR.
|
||||
// 'Unfolding' the IR.
|
||||
var IRQueue = IR[2];
|
||||
this.matrix = IR[3];
|
||||
var bbox = IR[4];
|
||||
@ -7030,7 +7046,7 @@ var TilingPatternIR = (function tilingPattern() {
|
||||
|
||||
return ctx.createPattern(this.canvas, 'repeat');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return TilingPatternIR;
|
||||
})();
|
||||
@ -7043,7 +7059,9 @@ var TilingPattern = {
|
||||
var ystep = dict.get('YStep');
|
||||
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);
|
||||
|
||||
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) {
|
||||
var inputSize = IR[1];
|
||||
var domain = IR[2];
|
||||
var encode = IR[3];
|
||||
var decode = IR[4]
|
||||
var samples = IR[5]
|
||||
var size = IR[6]
|
||||
var decode = IR[4];
|
||||
var samples = IR[5];
|
||||
var size = IR[6];
|
||||
var outputSize = IR[7];
|
||||
var bps = IR[8];
|
||||
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 c1 = dict.get('C1') || [1];
|
||||
var n = dict.get('N');
|
||||
@ -7470,7 +7492,8 @@ var PDFFunction = (function() {
|
||||
return [CONSTRUCT_INTERPOLATED, c0, diff, n, i];
|
||||
},
|
||||
|
||||
constructInterpolatedFromIR: function pdfFunctionconstructInterpolatedFromIR(IR) {
|
||||
constructInterpolatedFromIR:
|
||||
function pdfFunctionconstructInterpolatedFromIR(IR) {
|
||||
var c0 = IR[1];
|
||||
var diff = IR[2];
|
||||
var n = IR[3];
|
||||
@ -7568,6 +7591,6 @@ var PDFFunction = (function() {
|
||||
return [255, 105, 180];
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
|
27
worker.js
27
worker.js
@ -39,7 +39,7 @@ var WorkerPage = (function() {
|
||||
// this.page.startRendering(ctx, callback, errback);
|
||||
|
||||
this.startRenderingTime = Date.now();
|
||||
this.workerPDF.startRendering(this)
|
||||
this.workerPDF.startRendering(this);
|
||||
},
|
||||
|
||||
startRenderingFromIRQueue: function(IRQueue, fonts) {
|
||||
@ -48,9 +48,9 @@ var WorkerPage = (function() {
|
||||
var startTime = Date.now();
|
||||
var callback = function(err) {
|
||||
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);
|
||||
console.log("page=%d - total time: time=%dms",
|
||||
console.log('page=%d - total time: time=%dms',
|
||||
pageNum, Date.now() - this.startRenderingTime);
|
||||
|
||||
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
|
||||
* for fonts, images, rendering code and such. These objects might get processed
|
||||
* inside of a worker. The `PDFObjects` implements some basic functions to manage
|
||||
* these objects.
|
||||
* inside of a worker. The `PDFObjects` implements some basic functions to
|
||||
* manage these objects.
|
||||
*/
|
||||
var PDFObjects = (function() {
|
||||
function PDFObjects() {
|
||||
@ -116,7 +116,7 @@ var PDFObjects = (function() {
|
||||
// If there isn't an object yet or the object isn't resolved, then the
|
||||
// data isn't ready yet!
|
||||
if (!obj || !obj.isResolved) {
|
||||
throw "Requesting object that isn't resolved yet " + objId;
|
||||
throw 'Requesting object that isn\'t resolved yet ' + objId;
|
||||
}
|
||||
// Direct access.
|
||||
else {
|
||||
@ -169,13 +169,13 @@ var PDFObjects = (function() {
|
||||
// a *resolved* promise which shouldn't be the case!
|
||||
this.ensureObj(objId).data = data;
|
||||
}
|
||||
}
|
||||
};
|
||||
return PDFObjects;
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* "Promise" object.
|
||||
* 'Promise' object.
|
||||
* 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,
|
||||
* 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;
|
||||
}
|
||||
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.hasData = true;
|
||||
@ -227,7 +228,7 @@ var Promise = (function() {
|
||||
|
||||
get data() {
|
||||
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;
|
||||
},
|
||||
@ -242,7 +243,7 @@ var Promise = (function() {
|
||||
|
||||
resolve: function(data) {
|
||||
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;
|
||||
@ -256,7 +257,7 @@ var Promise = (function() {
|
||||
|
||||
then: function(callback) {
|
||||
if (!callback) {
|
||||
throw "Requiring callback" + this.name;
|
||||
throw 'Requiring callback' + this.name;
|
||||
}
|
||||
|
||||
// If the promise is already resolved, call the callback directly.
|
||||
@ -267,7 +268,7 @@ var Promise = (function() {
|
||||
this.callbacks.push(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return Promise;
|
||||
})();
|
||||
|
||||
|
@ -9,12 +9,12 @@ function MessageHandler(name, comObj) {
|
||||
this.comObj = comObj;
|
||||
var ah = this.actionHandler = {};
|
||||
|
||||
ah["console_log"] = [function(data) {
|
||||
ah['console_log'] = [function(data) {
|
||||
console.log.apply(console, data);
|
||||
}]
|
||||
ah["console_error"] = [function(data) {
|
||||
}];
|
||||
ah['console_error'] = [function(data) {
|
||||
console.error.apply(console, data);
|
||||
}]
|
||||
}];
|
||||
|
||||
comObj.onmessage = function(event) {
|
||||
var data = event.data;
|
||||
@ -42,5 +42,5 @@ MessageHandler.prototype = {
|
||||
data: data
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -15,5 +15,5 @@ importScripts('processor_handler.js');
|
||||
// Listen for messages from the main thread.
|
||||
var pdfDoc = null;
|
||||
|
||||
var handler = new MessageHandler("worker_processor", this);
|
||||
var handler = new MessageHandler('worker_processor', this);
|
||||
WorkerProcessorHandler.setup(handler);
|
||||
|
@ -7,19 +7,20 @@ var WorkerProcessorHandler = {
|
||||
setup: function(handler) {
|
||||
var pdfDoc = null;
|
||||
|
||||
handler.on("doc", function(data) {
|
||||
handler.on('doc', function(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(pageNum) {
|
||||
pageNum = parseInt(pageNum);
|
||||
|
||||
var page = pdfDoc.getPage(pageNum);
|
||||
|
||||
// The following code does quite the same as Page.prototype.startRendering,
|
||||
// but stops at one point and sends the result back to the main thread.
|
||||
// The following code does quite the same as
|
||||
// Page.prototype.startRendering, but stops at one point and sends the
|
||||
// result back to the main thread.
|
||||
var gfx = new CanvasGraphics(null);
|
||||
|
||||
var start = Date.now();
|
||||
@ -29,7 +30,8 @@ var WorkerProcessorHandler = {
|
||||
// Pre compile the pdf page and fetch the fonts/images.
|
||||
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 */) {
|
||||
var cmdMap = {};
|
||||
@ -37,7 +39,7 @@ var WorkerProcessorHandler = {
|
||||
var fnArray = IRQueue .fnArray;
|
||||
for (var i = 0; i < fnArray.length; i++) {
|
||||
var entry = fnArray[i];
|
||||
if (entry == "paintReadyFormXObject") {
|
||||
if (entry == 'paintReadyFormXObject') {
|
||||
//console.log(preCompilation.argsArray[i]);
|
||||
}
|
||||
if (cmdMap[entry] == null) {
|
||||
@ -46,7 +48,7 @@ var WorkerProcessorHandler = {
|
||||
cmdMap[entry] += 1;
|
||||
}
|
||||
}
|
||||
console.log("cmds", JSON.stringify(cmdMap));
|
||||
console.log('cmds', JSON.stringify(cmdMap));
|
||||
}
|
||||
|
||||
// Filter the dependecies for fonts.
|
||||
@ -66,14 +68,14 @@ var WorkerProcessorHandler = {
|
||||
// }
|
||||
// }
|
||||
|
||||
handler.send("page", {
|
||||
handler.send('page', {
|
||||
pageNum: pageNum,
|
||||
IRQueue: IRQueue,
|
||||
depFonts: fonts
|
||||
});
|
||||
}, this);
|
||||
|
||||
handler.on("font", function(data) {
|
||||
handler.on('font', function(data) {
|
||||
var objId = data[0];
|
||||
var name = data[1];
|
||||
var file = data[2];
|
||||
@ -119,7 +121,7 @@ var WorkerProcessorHandler = {
|
||||
// anymore as we sent over the ready str.
|
||||
delete obj.data;
|
||||
|
||||
handler.send("font_ready", [objId, obj]);
|
||||
handler.send('font_ready', [objId, obj]);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user