Addressing Vivian's comments.
This commit is contained in:
parent
23363cf464
commit
300730c335
580
pdf.js
580
pdf.js
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
var ERRORS = 0, WARNINGS = 1, TODOS = 5;
|
var ERRORS = 0, WARNINGS = 1, TODOS = 5;
|
||||||
var verbosity = WARNINGS;
|
var verbosity = WARNINGS;
|
||||||
|
|
||||||
// Set this to true if you want to use workers.
|
// Set this to true if you want to use workers.
|
||||||
var useWorker = false;
|
var useWorker = false;
|
||||||
|
|
||||||
@ -898,10 +899,9 @@ var PredictorStream = (function predictorStream() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
var JpegImage = (function() {
|
var JpegImage = (function() {
|
||||||
function JpegImage(objId, IR, objs) {
|
function JpegImage(objId, imageData, objs) {
|
||||||
var src = 'data:image/jpeg;base64,' + window.btoa(IR);
|
var src = 'data:image/jpeg;base64,' + window.btoa(imageData);
|
||||||
|
|
||||||
// create DOM image
|
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onload = (function() {
|
img.onload = (function() {
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
@ -2375,6 +2375,10 @@ function isStream(v) {
|
|||||||
return typeof v == 'object' && v != null && ('getChar' in v);
|
return typeof v == 'object' && v != null && ('getChar' in v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isArrayBuffer(v) {
|
||||||
|
return typeof v == 'object' && v != null && ('byteLength' in v);
|
||||||
|
}
|
||||||
|
|
||||||
function isRef(v) {
|
function isRef(v) {
|
||||||
return v instanceof Ref;
|
return v instanceof Ref;
|
||||||
}
|
}
|
||||||
@ -3517,20 +3521,15 @@ var Page = (function pagePage() {
|
|||||||
this.IRQueue = IRQueue;
|
this.IRQueue = IRQueue;
|
||||||
var gfx = new CanvasGraphics(this.ctx, this.objs);
|
var gfx = new CanvasGraphics(this.ctx, this.objs);
|
||||||
var startTime = Date.now();
|
var startTime = Date.now();
|
||||||
var continuation = function(err) {
|
|
||||||
this.callback(err);
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
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
|
||||||
// Firefox error reporting from XHR callbacks.
|
// Firefox error reporting from XHR callbacks.
|
||||||
setTimeout(function pageSetTimeout() {
|
setTimeout(function pageSetTimeout() {
|
||||||
var exc = null;
|
|
||||||
try {
|
try {
|
||||||
self.display(gfx, continuation);
|
self.display(gfx, self.callback);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exc = e.toString();
|
if (self.callback) self.callback(e.toString());
|
||||||
continuation(exc);
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -3606,7 +3605,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();
|
||||||
callback();
|
if (callback) callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@ -3853,17 +3852,12 @@ var Catalog = (function catalogCatalog() {
|
|||||||
*/
|
*/
|
||||||
var PDFDocModel = (function pdfDoc() {
|
var PDFDocModel = (function pdfDoc() {
|
||||||
function constructor(arg, callback) {
|
function constructor(arg, callback) {
|
||||||
// Stream argument
|
if (isStream(arg))
|
||||||
if (typeof arg.isStream !== 'undefined') {
|
|
||||||
init.call(this, arg);
|
init.call(this, arg);
|
||||||
}
|
else if (isArrayBuffer(arg))
|
||||||
// ArrayBuffer argument
|
|
||||||
else if (typeof arg.byteLength !== 'undefined') {
|
|
||||||
init.call(this, new Stream(arg));
|
init.call(this, new Stream(arg));
|
||||||
}
|
else
|
||||||
else {
|
error('PDFDocModel: Unknown argument type');
|
||||||
error('Unknown argument type');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(stream) {
|
function init(stream) {
|
||||||
@ -3980,18 +3974,14 @@ var PDFDoc = (function() {
|
|||||||
var stream = null;
|
var stream = null;
|
||||||
var data = null;
|
var data = null;
|
||||||
|
|
||||||
// Stream argument
|
if (isStream(arg)) {
|
||||||
if (typeof arg.isStream !== 'undefined') {
|
|
||||||
stream = arg;
|
stream = arg;
|
||||||
data = arg.bytes;
|
data = arg.bytes;
|
||||||
}
|
} else if (isArrayBuffer(arg)) {
|
||||||
// ArrayBuffer argument
|
|
||||||
else if (typeof arg.byteLength !== 'undefined') {
|
|
||||||
stream = new Stream(arg);
|
stream = new Stream(arg);
|
||||||
data = arg;
|
data = arg;
|
||||||
}
|
} else {
|
||||||
else {
|
error('PDFDoc: Unknown argument type');
|
||||||
error('Unknown argument type');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@ -4004,15 +3994,17 @@ var PDFDoc = (function() {
|
|||||||
this.pageCache = [];
|
this.pageCache = [];
|
||||||
|
|
||||||
if (useWorker) {
|
if (useWorker) {
|
||||||
var worker = this.worker = new Worker('../worker/pdf_worker_loader.js');
|
var 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});
|
||||||
}
|
},
|
||||||
|
terminate: function() {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
this.worker = worker;
|
||||||
|
|
||||||
this.fontsLoading = {};
|
this.fontsLoading = {};
|
||||||
|
|
||||||
@ -4028,13 +4020,13 @@ var PDFDoc = (function() {
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
processorHandler.on('obj', function(data) {
|
processorHandler.on('obj', function(data) {
|
||||||
var objId = data[0];
|
var id = data[0];
|
||||||
var objType = data[1];
|
var type = data[1];
|
||||||
|
|
||||||
switch (objType) {
|
switch (type) {
|
||||||
case 'JpegStream':
|
case 'JpegStream':
|
||||||
var IR = data[2];
|
var IR = data[2];
|
||||||
new JpegImage(objId, IR, this.objs);
|
new JpegImage(id, IR, this.objs);
|
||||||
break;
|
break;
|
||||||
case 'Font':
|
case 'Font':
|
||||||
var name = data[2];
|
var name = data[2];
|
||||||
@ -4060,26 +4052,26 @@ var PDFDoc = (function() {
|
|||||||
|
|
||||||
// For now, resolve the font object here direclty. The real font
|
// For now, resolve the font object here direclty. The real font
|
||||||
// object is then created in FontLoader.bind().
|
// object is then created in FontLoader.bind().
|
||||||
this.objs.resolve(objId, {
|
this.objs.resolve(id, {
|
||||||
name: name,
|
name: name,
|
||||||
file: file,
|
file: file,
|
||||||
properties: properties
|
properties: properties
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw 'Got unkown object type ' + objType;
|
throw 'Got unkown object type ' + type;
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
processorHandler.on('font_ready', function(data) {
|
processorHandler.on('font_ready', function(data) {
|
||||||
var objId = data[0];
|
var id = data[0];
|
||||||
var fontObj = new FontShape(data[1]);
|
var font = new FontShape(data[1]);
|
||||||
|
|
||||||
// If there is no string, then there is nothing to attach to the DOM.
|
// If there is no string, then there is nothing to attach to the DOM.
|
||||||
if (!fontObj.str) {
|
if (!font.str) {
|
||||||
this.objs.resolve(objId, fontObj);
|
this.objs.resolve(id, font);
|
||||||
} else {
|
} else {
|
||||||
this.objs.setData(objId, fontObj);
|
this.objs.setData(id, font);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
@ -4109,9 +4101,8 @@ var PDFDoc = (function() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getPage: function(n) {
|
getPage: function(n) {
|
||||||
if (this.pageCache[n]) {
|
if (this.pageCache[n])
|
||||||
return this.pageCache[n];
|
return this.pageCache[n];
|
||||||
}
|
|
||||||
|
|
||||||
var page = this.pdf.getPage(n);
|
var page = this.pdf.getPage(n);
|
||||||
// Add a reference to the objects such that Page can forward the reference
|
// Add a reference to the objects such that Page can forward the reference
|
||||||
@ -4122,16 +4113,15 @@ var PDFDoc = (function() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
if (this.worker) {
|
if (this.worker)
|
||||||
this.worker.terminate();
|
this.worker.terminate();
|
||||||
}
|
|
||||||
if (this.fontWorker) {
|
|
||||||
this.fontWorker.terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var n in this.pageCache) {
|
if (this.fontWorker)
|
||||||
|
this.fontWorker.terminate();
|
||||||
|
|
||||||
|
for (var n in this.pageCache)
|
||||||
delete this.pageCache[n];
|
delete this.pageCache[n];
|
||||||
}
|
|
||||||
delete this.data;
|
delete this.data;
|
||||||
delete this.stream;
|
delete this.stream;
|
||||||
delete this.pdf;
|
delete this.pdf;
|
||||||
@ -4564,43 +4554,43 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
var loadedName = null;
|
var loadedName = null;
|
||||||
|
|
||||||
var fontRes = resources.get('Font');
|
var fontRes = resources.get('Font');
|
||||||
if (fontRes) {
|
|
||||||
fontRes = xref.fetchIfRef(fontRes);
|
|
||||||
fontRef = fontRef || fontRes.get(fontName);
|
|
||||||
var font = xref.fetchIfRef(fontRef);
|
|
||||||
assertWellFormed(isDict(font));
|
|
||||||
if (!font.translated) {
|
|
||||||
font.translated = self.translateFont(font, xref, resources, handler,
|
|
||||||
uniquePrefix, dependency);
|
|
||||||
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 + ++self.objIdCounter;
|
|
||||||
font.translated.properties.loadedName = loadedName;
|
|
||||||
font.loadedName = loadedName;
|
|
||||||
|
|
||||||
handler.send('obj', [
|
// TODO: TOASK: Is it possible to get here? If so, what does
|
||||||
loadedName,
|
// args[0].name should be like???
|
||||||
'Font',
|
assert(fontRes, 'fontRes not available');
|
||||||
font.translated.name,
|
|
||||||
font.translated.file,
|
fontRes = xref.fetchIfRef(fontRes);
|
||||||
font.translated.properties
|
fontRef = fontRef || fontRes.get(fontName);
|
||||||
]);
|
var font = xref.fetchIfRef(fontRef);
|
||||||
}
|
assertWellFormed(isDict(font));
|
||||||
|
if (!font.translated) {
|
||||||
|
font.translated = self.translateFont(font, xref, resources, handler,
|
||||||
|
uniquePrefix, dependency);
|
||||||
|
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 + ++self.objIdCounter;
|
||||||
|
font.translated.properties.loadedName = loadedName;
|
||||||
|
font.loadedName = loadedName;
|
||||||
|
|
||||||
|
var translated = font.translated;
|
||||||
|
handler.send('obj', [
|
||||||
|
loadedName,
|
||||||
|
'Font',
|
||||||
|
translated.name,
|
||||||
|
translated.file,
|
||||||
|
translated.properties
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
loadedName = loadedName || font.loadedName;
|
|
||||||
|
|
||||||
// Ensure the font is ready before the font is set
|
|
||||||
// and later on used for drawing.
|
|
||||||
// TODO: This should get insert to the IRQueue only once per
|
|
||||||
// page.
|
|
||||||
insertDependency([loadedName]);
|
|
||||||
return loadedName;
|
|
||||||
} else {
|
|
||||||
// TODO: TOASK: Is it possible to get here? If so, what does
|
|
||||||
// args[0].name should be like???
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
loadedName = loadedName || font.loadedName;
|
||||||
|
|
||||||
|
// Ensure the font is ready before the font is set
|
||||||
|
// and later on used for drawing.
|
||||||
|
// TODO: This should get insert to the IRQueue only once per
|
||||||
|
// page.
|
||||||
|
insertDependency([loadedName]);
|
||||||
|
return loadedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPaintImageXObject(image, inline) {
|
function buildPaintImageXObject(image, inline) {
|
||||||
@ -4618,49 +4608,52 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
// The normal fn.
|
// The normal fn.
|
||||||
fn = 'paintJpegXObject';
|
fn = 'paintJpegXObject';
|
||||||
args = [objId, w, h];
|
args = [objId, w, h];
|
||||||
} else {
|
|
||||||
// Needs to be rendered ourself.
|
|
||||||
|
|
||||||
// Figure out if the image has an imageMask.
|
return;
|
||||||
var imageMask = dict.get('ImageMask', 'IM') || false;
|
|
||||||
|
|
||||||
// If there is no imageMask, create the PDFImage and a lot
|
|
||||||
// of image processing can be done here.
|
|
||||||
if (!imageMask) {
|
|
||||||
var imageObj = new PDFImage(xref, resources, image, inline);
|
|
||||||
|
|
||||||
if (imageObj.imageMask) {
|
|
||||||
throw 'Can\'t handle this in the web worker :/';
|
|
||||||
}
|
|
||||||
|
|
||||||
var imgData = {
|
|
||||||
width: w,
|
|
||||||
height: h,
|
|
||||||
data: new Uint8Array(w * h * 4)
|
|
||||||
};
|
|
||||||
var pixels = imgData.data;
|
|
||||||
imageObj.fillRgbaBuffer(pixels, imageObj.decode);
|
|
||||||
|
|
||||||
fn = 'paintImageXObject';
|
|
||||||
args = [imgData];
|
|
||||||
} else /* imageMask == true */ {
|
|
||||||
// This depends on a tmpCanvas beeing filled with the
|
|
||||||
// current fillStyle, such that processing the pixel
|
|
||||||
// data can't be done here. Instead of creating a
|
|
||||||
// complete PDFImage, only read the information needed
|
|
||||||
// for later.
|
|
||||||
fn = 'paintImageMaskXObject';
|
|
||||||
|
|
||||||
var width = dict.get('Width', 'W');
|
|
||||||
var height = dict.get('Height', 'H');
|
|
||||||
var bitStrideLength = (width + 7) >> 3;
|
|
||||||
var imgArray = image.getBytes(bitStrideLength * height);
|
|
||||||
var decode = dict.get('Decode', 'D');
|
|
||||||
var inverseDecode = !!decode && decode[0] > 0;
|
|
||||||
|
|
||||||
args = [imgArray, inverseDecode, width, height];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Needs to be rendered ourself.
|
||||||
|
|
||||||
|
// Figure out if the image has an imageMask.
|
||||||
|
var imageMask = dict.get('ImageMask', 'IM') || false;
|
||||||
|
|
||||||
|
// If there is no imageMask, create the PDFImage and a lot
|
||||||
|
// of image processing can be done here.
|
||||||
|
if (!imageMask) {
|
||||||
|
var imageObj = new PDFImage(xref, resources, image, inline);
|
||||||
|
|
||||||
|
if (imageObj.imageMask) {
|
||||||
|
throw 'Can\'t handle this in the web worker :/';
|
||||||
|
}
|
||||||
|
|
||||||
|
var imgData = {
|
||||||
|
width: w,
|
||||||
|
height: h,
|
||||||
|
data: new Uint8Array(w * h * 4)
|
||||||
|
};
|
||||||
|
var pixels = imgData.data;
|
||||||
|
imageObj.fillRgbaBuffer(pixels, imageObj.decode);
|
||||||
|
|
||||||
|
fn = 'paintImageXObject';
|
||||||
|
args = [imgData];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This depends on a tmpCanvas beeing filled with the
|
||||||
|
// current fillStyle, such that processing the pixel
|
||||||
|
// data can't be done here. Instead of creating a
|
||||||
|
// complete PDFImage, only read the information needed
|
||||||
|
// for later.
|
||||||
|
fn = 'paintImageMaskXObject';
|
||||||
|
|
||||||
|
var width = dict.get('Width', 'W');
|
||||||
|
var height = dict.get('Height', 'H');
|
||||||
|
var bitStrideLength = (width + 7) >> 3;
|
||||||
|
var imgArray = image.getBytes(bitStrideLength * height);
|
||||||
|
var decode = dict.get('Decode', 'D');
|
||||||
|
var inverseDecode = !!decode && decode[0] > 0;
|
||||||
|
|
||||||
|
args = [imgArray, inverseDecode, width, height];
|
||||||
}
|
}
|
||||||
|
|
||||||
uniquePrefix = uniquePrefix || '';
|
uniquePrefix = uniquePrefix || '';
|
||||||
@ -4684,6 +4677,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
parser = this.oldParser;
|
parser = this.oldParser;
|
||||||
return { name: 'BT' };
|
return { name: 'BT' };
|
||||||
};
|
};
|
||||||
|
var TILING_PATTERN = 1, SHADING_PATTERN = 2;
|
||||||
|
|
||||||
while (!isEOF(obj = parser.getObj())) {
|
while (!isEOF(obj = parser.getObj())) {
|
||||||
if (isCmd(obj)) {
|
if (isCmd(obj)) {
|
||||||
@ -4716,8 +4710,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
var dict = isStream(pattern) ? pattern.dict : pattern;
|
var dict = isStream(pattern) ? pattern.dict : pattern;
|
||||||
var typeNum = dict.get('PatternType');
|
var typeNum = dict.get('PatternType');
|
||||||
|
|
||||||
// Type1 is TilingPattern
|
if (typeNum == TILING_PATTERN) {
|
||||||
if (typeNum == 1) {
|
|
||||||
// Create an IR of the pattern code.
|
// Create an IR of the pattern code.
|
||||||
var depIdx = dependency.length;
|
var depIdx = dependency.length;
|
||||||
var codeIR = this.getIRQueue(pattern,
|
var codeIR = this.getIRQueue(pattern,
|
||||||
@ -4729,8 +4722,7 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
|
|
||||||
args = TilingPattern.getIR(codeIR, dict, args);
|
args = TilingPattern.getIR(codeIR, dict, args);
|
||||||
}
|
}
|
||||||
// Type2 is ShadingPattern.
|
else if (typeNum == SHADING_PATTERN) {
|
||||||
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,
|
var pattern = Pattern.parseShading(shading, matrix, xref, res,
|
||||||
@ -4786,88 +4778,89 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
buildPaintImageXObject(args[0], true);
|
buildPaintImageXObject(args[0], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
||||||
var shading = xref.fetchIfRef(shadingRes.get(args[0].name));
|
var shading = xref.fetchIfRef(shadingRes.get(args[0].name));
|
||||||
if (!shading)
|
if (!shading)
|
||||||
error('No shading object found');
|
error('No shading object found');
|
||||||
|
|
||||||
var shadingFill = Pattern.parseShading(shading, null, xref, res,
|
var shadingFill = Pattern.parseShading(shading, null, xref, res,
|
||||||
/* ctx */ null);
|
null);
|
||||||
var patternIR = shadingFill.getIR();
|
var patternIR = shadingFill.getIR();
|
||||||
|
args = [patternIR];
|
||||||
|
fn = 'shadingFill';
|
||||||
|
break;
|
||||||
|
case 'setGState':
|
||||||
|
var dictName = args[0];
|
||||||
|
var extGState = xref.fetchIfRef(resources.get('ExtGState'));
|
||||||
|
|
||||||
args = [patternIR];
|
if (!isDict(extGState) || !extGState.has(dictName.name))
|
||||||
fn = 'shadingFill';
|
break;
|
||||||
|
|
||||||
break;
|
|
||||||
case 'setGState':
|
|
||||||
var dictName = args[0];
|
|
||||||
var extGState = xref.fetchIfRef(resources.get('ExtGState'));
|
|
||||||
if (isDict(extGState) && extGState.has(dictName.name)) {
|
|
||||||
var gsState = xref.fetchIfRef(extGState.get(dictName.name));
|
var gsState = xref.fetchIfRef(extGState.get(dictName.name));
|
||||||
|
|
||||||
// This array holds the converted/processed state data.
|
// This array holds the converted/processed state data.
|
||||||
var gsStateObj = [];
|
var gsStateObj = [];
|
||||||
|
|
||||||
gsState.forEach(
|
gsState.forEach(
|
||||||
function canvasGraphicsSetGStateForEach(key, value) {
|
function canvasGraphicsSetGStateForEach(key, value) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'Type':
|
case 'Type':
|
||||||
break;
|
break;
|
||||||
case 'LW':
|
case 'LW':
|
||||||
case 'LC':
|
case 'LC':
|
||||||
case 'LJ':
|
case 'LJ':
|
||||||
case 'ML':
|
case 'ML':
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'RI':
|
case 'RI':
|
||||||
case 'FL':
|
case 'FL':
|
||||||
gsStateObj.push([key, value]);
|
gsStateObj.push([key, value]);
|
||||||
break;
|
break;
|
||||||
case 'Font':
|
case 'Font':
|
||||||
gsStateObj.push([
|
gsStateObj.push([
|
||||||
'Font',
|
'Font',
|
||||||
handleSetFont(null, value[0]),
|
handleSetFont(null, value[0]),
|
||||||
value[1]
|
value[1]
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
case 'OP':
|
case 'OP':
|
||||||
case 'op':
|
case 'op':
|
||||||
case 'OPM':
|
case 'OPM':
|
||||||
case 'BG':
|
case 'BG':
|
||||||
case 'BG2':
|
case 'BG2':
|
||||||
case 'UCR':
|
case 'UCR':
|
||||||
case 'UCR2':
|
case 'UCR2':
|
||||||
case 'TR':
|
case 'TR':
|
||||||
case 'TR2':
|
case 'TR2':
|
||||||
case 'HT':
|
case 'HT':
|
||||||
case 'SM':
|
case 'SM':
|
||||||
case 'SA':
|
case 'SA':
|
||||||
case 'BM':
|
case 'BM':
|
||||||
case 'SMask':
|
case 'SMask':
|
||||||
case 'CA':
|
case 'CA':
|
||||||
case 'ca':
|
case 'ca':
|
||||||
case 'AIS':
|
case 'AIS':
|
||||||
case 'TK':
|
case 'TK':
|
||||||
TODO('graphic state operator ' + key);
|
TODO('graphic state operator ' + key);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warn('Unknown graphic state operator ' + key);
|
warn('Unknown graphic state operator ' + key);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
args = [gsStateObj];
|
args = [gsStateObj];
|
||||||
}
|
break;
|
||||||
}
|
} // switch
|
||||||
|
|
||||||
fnArray.push(fn);
|
fnArray.push(fn);
|
||||||
argsArray.push(args);
|
argsArray.push(args);
|
||||||
@ -5370,9 +5363,10 @@ function ScratchCanvas(width, height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var CanvasGraphics = (function canvasGraphics() {
|
var CanvasGraphics = (function canvasGraphics() {
|
||||||
// Defines the time the executeIRQueue gonna be executing
|
// Defines the time the executeIRQueue 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;
|
||||||
|
|
||||||
// Number of IR commands to execute before checking
|
// Number of IR commands to execute before checking
|
||||||
// if we execute longer then `kExecutionTime`.
|
// if we execute longer then `kExecutionTime`.
|
||||||
var kExecutionTimeCheck = 500;
|
var kExecutionTimeCheck = 500;
|
||||||
@ -5451,11 +5445,11 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
if (i == argsArrayLen) {
|
if (i == argsArrayLen) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the execution took longer then a certain amount of time, shedule
|
// If the execution took longer then a certain amount of time, shedule
|
||||||
// to continue exeution after a short delay.
|
// to continue exeution after a short delay.
|
||||||
// However, this is only possible if a 'continueCallback' is passed in.
|
// However, this is only possible if a 'continueCallback' is passed in.
|
||||||
else if (continueCallback &&
|
if (continueCallback && (Date.now() - startTime) > kExecutionTime) {
|
||||||
(Date.now() - startTime) > kExecutionTime) {
|
|
||||||
setTimeout(continueCallback, 0);
|
setTimeout(continueCallback, 0);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -5686,7 +5680,6 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
this.current.leading = -leading;
|
this.current.leading = -leading;
|
||||||
},
|
},
|
||||||
setFont: function canvasGraphicsSetFont(fontRefName, size) {
|
setFont: function canvasGraphicsSetFont(fontRefName, size) {
|
||||||
// Lookup the fontObj using fontRefName only.
|
|
||||||
var fontObj = this.objs.get(fontRefName).fontObj;
|
var fontObj = this.objs.get(fontRefName).fontObj;
|
||||||
|
|
||||||
if (!fontObj) {
|
if (!fontObj) {
|
||||||
@ -5731,7 +5724,6 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
nextLine: function canvasGraphicsNextLine() {
|
nextLine: function canvasGraphicsNextLine() {
|
||||||
this.moveText(0, this.current.leading);
|
this.moveText(0, this.current.leading);
|
||||||
},
|
},
|
||||||
|
|
||||||
showText: function canvasGraphicsShowText(text) {
|
showText: function canvasGraphicsShowText(text) {
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var current = this.current;
|
var current = this.current;
|
||||||
@ -5855,12 +5847,10 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
// Color
|
// Color
|
||||||
setStrokeColorSpace:
|
setStrokeColorSpace:
|
||||||
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
|
function canvasGraphicsSetStrokeColorSpacefunction(raw) {
|
||||||
this.current.strokeColorSpace =
|
this.current.strokeColorSpace = ColorSpace.fromIR(raw);
|
||||||
ColorSpace.fromIR(raw);
|
|
||||||
},
|
},
|
||||||
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) {
|
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) {
|
||||||
this.current.fillColorSpace =
|
this.current.fillColorSpace = ColorSpace.fromIR(raw);
|
||||||
ColorSpace.fromIR(raw);
|
|
||||||
},
|
},
|
||||||
setStrokeColor: function canvasGraphicsSetStrokeColor(/*...*/) {
|
setStrokeColor: function canvasGraphicsSetStrokeColor(/*...*/) {
|
||||||
var cs = this.current.strokeColorSpace;
|
var cs = this.current.strokeColorSpace;
|
||||||
@ -5869,8 +5859,6 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
},
|
},
|
||||||
getColorN_IR_Pattern: function(IR, cs) {
|
getColorN_IR_Pattern: function(IR, cs) {
|
||||||
if (IR[0] == 'TilingPattern') {
|
if (IR[0] == 'TilingPattern') {
|
||||||
// First, build the `color` var like it's done in the
|
|
||||||
// Pattern.prototype.parse function.
|
|
||||||
var args = IR[1];
|
var args = IR[1];
|
||||||
var base = cs.base;
|
var base = cs.base;
|
||||||
var color;
|
var color;
|
||||||
@ -5883,8 +5871,6 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
|
|
||||||
color = base.getRgb(color);
|
color = base.getRgb(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the pattern based on the IR data.
|
|
||||||
var pattern = new TilingPattern(IR, color, this.ctx, this.objs);
|
var pattern = new TilingPattern(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);
|
||||||
@ -6016,6 +6002,7 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
|
// scale the image to the unit square
|
||||||
ctx.scale(1 / w, -1 / h);
|
ctx.scale(1 / w, -1 / h);
|
||||||
|
|
||||||
var domImage = image.getImage();
|
var domImage = image.getImage();
|
||||||
@ -6051,7 +6038,6 @@ var CanvasGraphics = (function canvasGraphics() {
|
|||||||
|
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var w = width, h = height;
|
var w = width, h = height;
|
||||||
|
|
||||||
// scale the image to the unit square
|
// scale the image to the unit square
|
||||||
ctx.scale(1 / w, -1 / h);
|
ctx.scale(1 / w, -1 / h);
|
||||||
|
|
||||||
@ -6205,11 +6191,10 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
|||||||
|
|
||||||
constructor.parse = function colorspace_parse(cs, xref, res) {
|
constructor.parse = function colorspace_parse(cs, xref, res) {
|
||||||
var IR = constructor.parseToIR(cs, xref, res, true);
|
var IR = constructor.parseToIR(cs, xref, res, true);
|
||||||
if (!(IR instanceof SeparationCS)) {
|
if (IR instanceof SeparationCS)
|
||||||
return constructor.fromIR(IR);
|
|
||||||
} else {
|
|
||||||
return IR;
|
return IR;
|
||||||
}
|
|
||||||
|
return constructor.fromIR(IR);
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor.fromIR = function(IR) {
|
constructor.fromIR = function(IR) {
|
||||||
@ -6270,67 +6255,67 @@ var ColorSpace = (function colorSpaceColorSpace() {
|
|||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
} else if (isArray(cs)) {
|
} else if (isArray(cs)) {
|
||||||
var mode = cs[0].name;
|
var mode = cs[0].name;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'DeviceGray':
|
case 'DeviceGray':
|
||||||
case 'G':
|
case 'G':
|
||||||
return 'DeviceGrayCS';
|
|
||||||
case 'DeviceRGB':
|
|
||||||
case 'RGB':
|
|
||||||
return 'DeviceRgbCS';
|
|
||||||
case 'DeviceCMYK':
|
|
||||||
case 'CMYK':
|
|
||||||
return 'DeviceCmykCS';
|
|
||||||
case 'CalGray':
|
|
||||||
return 'DeviceGrayCS';
|
|
||||||
case 'CalRGB':
|
|
||||||
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)
|
case 'DeviceRGB':
|
||||||
|
case 'RGB':
|
||||||
return 'DeviceRgbCS';
|
return 'DeviceRgbCS';
|
||||||
if (numComps == 4)
|
case 'DeviceCMYK':
|
||||||
|
case 'CMYK':
|
||||||
return 'DeviceCmykCS';
|
return 'DeviceCmykCS';
|
||||||
break;
|
case 'CalGray':
|
||||||
case 'Pattern':
|
return 'DeviceGrayCS';
|
||||||
var baseCS = cs[1];
|
case 'CalRGB':
|
||||||
if (baseCS)
|
return 'DeviceRgbCS';
|
||||||
baseCS = ColorSpace.parseToIR(baseCS, xref, res);
|
case 'ICCBased':
|
||||||
return ['PatternCS', baseCS];
|
var stream = xref.fetchIfRef(cs[1]);
|
||||||
case 'Indexed':
|
var dict = stream.dict;
|
||||||
var baseCS = ColorSpace.parseToIR(cs[1], xref, res);
|
var numComps = dict.get('N');
|
||||||
var hiVal = cs[2] + 1;
|
if (numComps == 1)
|
||||||
var lookup = xref.fetchIfRef(cs[3]);
|
return 'DeviceGrayCS';
|
||||||
return ['IndexedCS', baseCS, hiVal, lookup];
|
if (numComps == 3)
|
||||||
case 'Separation':
|
return 'DeviceRgbCS';
|
||||||
var alt = ColorSpace.parseToIR(cs[2], xref, res);
|
if (numComps == 4)
|
||||||
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
|
return 'DeviceCmykCS';
|
||||||
return ['SeparationCS', alt, tintFnIR];
|
break;
|
||||||
case 'Lab':
|
case 'Pattern':
|
||||||
case 'DeviceN':
|
var baseCS = cs[1];
|
||||||
default:
|
if (baseCS)
|
||||||
error('unimplemented color space object "' + mode + '"');
|
baseCS = ColorSpace.parseToIR(baseCS, xref, res);
|
||||||
|
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];
|
||||||
|
case 'Separation':
|
||||||
|
var alt = ColorSpace.parseToIR(cs[2], xref, res);
|
||||||
|
var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
|
||||||
|
return ['SeparationCS', alt, tintFnIR];
|
||||||
|
case 'Lab':
|
||||||
|
case 'DeviceN':
|
||||||
|
default:
|
||||||
|
error('unimplemented color space object "' + mode + '"');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error('unrecognized color space object: "' + cs + '"');
|
error('unrecognized color space object: "' + cs + '"');
|
||||||
@ -6758,7 +6743,6 @@ var TilingPattern = (function tilingPattern() {
|
|||||||
var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2;
|
var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2;
|
||||||
|
|
||||||
function TilingPattern(IR, color, ctx, objs) {
|
function TilingPattern(IR, color, ctx, objs) {
|
||||||
// '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];
|
||||||
@ -6766,7 +6750,6 @@ var TilingPattern = (function tilingPattern() {
|
|||||||
var ystep = IR[6];
|
var ystep = IR[6];
|
||||||
var paintType = IR[7];
|
var paintType = IR[7];
|
||||||
|
|
||||||
//
|
|
||||||
TODO('TilingType');
|
TODO('TilingType');
|
||||||
|
|
||||||
this.curMatrix = ctx.mozCurrentTransform;
|
this.curMatrix = ctx.mozCurrentTransform;
|
||||||
@ -6775,6 +6758,7 @@ var TilingPattern = (function tilingPattern() {
|
|||||||
this.type = 'Pattern';
|
this.type = 'Pattern';
|
||||||
|
|
||||||
var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
|
var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
|
||||||
|
|
||||||
var topLeft = [x0, y0];
|
var topLeft = [x0, y0];
|
||||||
// we want the canvas to be as large as the step size
|
// we want the canvas to be as large as the step size
|
||||||
var botRight = [x0 + xstep, y0 + ystep];
|
var botRight = [x0 + xstep, y0 + ystep];
|
||||||
@ -6798,17 +6782,17 @@ var TilingPattern = (function tilingPattern() {
|
|||||||
var graphics = new CanvasGraphics(tmpCtx, objs);
|
var graphics = new CanvasGraphics(tmpCtx, objs);
|
||||||
|
|
||||||
switch (paintType) {
|
switch (paintType) {
|
||||||
case PAINT_TYPE_COLORED:
|
case PAINT_TYPE_COLORED:
|
||||||
tmpCtx.fillStyle = ctx.fillStyle;
|
tmpCtx.fillStyle = ctx.fillStyle;
|
||||||
tmpCtx.strokeStyle = ctx.strokeStyle;
|
tmpCtx.strokeStyle = ctx.strokeStyle;
|
||||||
break;
|
break;
|
||||||
case PAINT_TYPE_UNCOLORED:
|
case PAINT_TYPE_UNCOLORED:
|
||||||
color = Util.makeCssRgb.apply(this, color);
|
color = Util.makeCssRgb.apply(this, color);
|
||||||
tmpCtx.fillStyle = color;
|
tmpCtx.fillStyle = color;
|
||||||
tmpCtx.strokeStyle = color;
|
tmpCtx.strokeStyle = color;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error('Unsupported paint type: ' + paintType);
|
error('Unsupported paint type: ' + paintType);
|
||||||
}
|
}
|
||||||
|
|
||||||
var scale = [width / xstep, height / ystep];
|
var scale = [width / xstep, height / ystep];
|
||||||
@ -7113,7 +7097,6 @@ var PDFFunction = (function() {
|
|||||||
var strBytes = str.getBytes((length * bps + 7) / 8);
|
var strBytes = str.getBytes((length * bps + 7) / 8);
|
||||||
var strIdx = 0;
|
var strIdx = 0;
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
var b;
|
|
||||||
while (codeSize < bps) {
|
while (codeSize < bps) {
|
||||||
codeBuf <<= 8;
|
codeBuf <<= 8;
|
||||||
codeBuf |= strBytes[strIdx++];
|
codeBuf |= strBytes[strIdx++];
|
||||||
@ -7396,7 +7379,7 @@ var PDFFunction = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A PDF document and page is build up of many objects. E.g. there are objects
|
* A PDF document and page is built 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
|
* inside of a worker. The `PDFObjects` implements some basic functions to
|
||||||
* manage these objects.
|
* manage these objects.
|
||||||
@ -7415,11 +7398,9 @@ var PDFObjects = (function() {
|
|||||||
* object *if* it is created.
|
* object *if* it is created.
|
||||||
*/
|
*/
|
||||||
ensureObj: function(objId, data) {
|
ensureObj: function(objId, data) {
|
||||||
if (!this.objs[objId]) {
|
if (this.objs[objId])
|
||||||
return this.objs[objId] = new Promise(objId, data);
|
|
||||||
} else {
|
|
||||||
return this.objs[objId];
|
return this.objs[objId];
|
||||||
}
|
return this.objs[objId] = new Promise(objId, data);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7436,22 +7417,19 @@ var PDFObjects = (function() {
|
|||||||
// not required to be resolved right now
|
// not required to be resolved right now
|
||||||
if (callback) {
|
if (callback) {
|
||||||
this.ensureObj(objId).then(callback);
|
this.ensureObj(objId).then(callback);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there isn't a callback, the user expects to get the resolved data
|
// If there isn't a callback, the user expects to get the resolved data
|
||||||
// directly.
|
// directly.
|
||||||
else {
|
var obj = this.objs[objId];
|
||||||
var obj = this.objs[objId];
|
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
else
|
||||||
// Direct access.
|
return obj.data;
|
||||||
else {
|
|
||||||
return obj.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7494,8 +7472,8 @@ var PDFObjects = (function() {
|
|||||||
* Sets the data of an object but *doesn't* resolve it.
|
* Sets the data of an object but *doesn't* resolve it.
|
||||||
*/
|
*/
|
||||||
setData: function(objId, data) {
|
setData: function(objId, data) {
|
||||||
// Watchout! If you call `this.ensureObj(objId, data)` you'll gonna create
|
// Watchout! If you call `this.ensureObj(objId, data)` you're going to
|
||||||
// a *resolved* promise which shouldn't be the case!
|
// create a *resolved* promise which shouldn't be the case!
|
||||||
this.ensureObj(objId).data = data;
|
this.ensureObj(objId).data = data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user