Remove commented out code and change some comments to fit current code state

This commit is contained in:
Julian Viereck 2011-10-11 19:51:35 +02:00
parent 7acec47b80
commit 1b69ca80a6
2 changed files with 12 additions and 191 deletions

193
pdf.js
View File

@ -3590,8 +3590,6 @@ var Page = (function pagePage() {
console.log('--ensureFonts--', '' + fonts);
// Convert the font names to the corresponding font obj.
for (var i = 0; i < fonts.length; i++) {
// HACK FOR NOW. Access the data directly. This isn't allowed as the
// font object isn't resolved yet.
fonts[i] = this.objs.objs[fonts[i]].data;
}
@ -4040,64 +4038,9 @@ var PDFDoc = (function() {
processorHandler.on('page', function(data) {
var pageNum = data.pageNum;
var page = this.pageCache[pageNum];
// DepFonts are all fonts are required to render the page. `fontsToLoad`
// are all the fonts that are required to render the page AND that
// aren't loaded on the page yet.
var depFonts = data.depFonts;
var objs = this.objs;
var fontsToLoad = [];
var fontsLoading = this.fontsLoading;
// The `i` for the checkFontData is stored here to keep the state in
// the closure.
var i = 0;
// function checkFontData() {
// // Check if all fontObjs have been processed. If not, shedule a
// // callback that is called once the data arrives and that checks
// // the next fonts.
// for (i; i < depFonts.length; i++) {
// var fontName = depFonts[i];
// if (!objs.hasData(fontName)) {
// console.log('need to wait for fontData', fontName);
// objs.onData(fontName, checkFontData);
// return;
// } else if (!objs.isResolved(fontName)) {
// fontsToLoad.push(fontName);
// }
// }
//
// // 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.
// //
// // This prevents thats fonts are loaded really only once.
// for (var j = 0; j < fontsToLoad.length; j++) {
// var fontName = fontsToLoad[j];
// if (fontsLoading[fontName]) {
// fontsToLoad.splice(j, 1);
// j--;
// } else {
// fontsLoading[fontName] = true;
// }
// }
//
// for (var i = 0; i < depFonts.lenght; i++) {
// // Get fonts from the objects.
// fontsToLoad.push(this.objs.get(depFonts[i]));
// }
//
// // At this point, all font data ia loaded. Start the actuall
// // rendering.
// page.startRenderingFromIRQueue(data.IRQueue, fontsToLoad);
// }
//
// checkFontData();
// Start rendering directly for now, as the fonts are
page.startRenderingFromIRQueue(data.IRQueue, Object.keys(data.depFonts));
page.startRenderingFromIRQueue(data.IRQueue, depFonts);
}, this);
processorHandler.on('obj', function(data) {
@ -4132,7 +4075,6 @@ var PDFDoc = (function() {
}
}
// For now, resolve the font object here direclty. The real font
// object is then created in FontLoader.bind().
this.objs.resolve(objId, {
@ -4140,64 +4082,6 @@ var PDFDoc = (function() {
file: file,
properties: properties
});
//
//
// // << CODE TAKEN FROM WORKER >>
// data = [objId, name, file, properties];
// var objId = data[0];
// var name = data[1];
// var file = data[2];
// var properties = data[3];
//
// var font = {
// name: name,
// file: file,
// properties: properties
// };
//
// // Some fonts don't have a file, e.g. the build in ones like Arial.
// if (file) {
// var fontFileDict = new Dict();
// fontFileDict.map = file.dict.map;
//
// var fontFile = new Stream(file.bytes, file.start,
// file.end - file.start, fontFileDict);
//
// // Check if this is a FlateStream. Otherwise just use the created
// // Stream one. This makes complex_ttf_font.pdf work.
// var cmf = file.bytes[0];
// if ((cmf & 0x0f) == 0x08) {
// font.file = new FlateStream(fontFile);
// } else {
// font.file = fontFile;
// }
// }
//
// var obj = new Font(font.name, font.file, font.properties);
//
// var str = '';
// var data = obj.data;
// if (data) {
// var length = data.length;
// for (var j = 0; j < length; j++)
// str += String.fromCharCode(data[j]);
// }
//
// obj.str = str;
//
// var fontObj = new FontShape(obj);
// for (var prop in obj) {
// fontObj[prop] = obj[prop];
// }
//
// if (!str) {
// this.objs.resolve(objId, fontObj);
// } else {
// this.objs.setData(objId, fontObj);
// }
// processorHandler.send('font', [objId, name, file, properties]);
break;
default:
throw 'Got unkown object type ' + objType;
@ -4914,23 +4798,6 @@ var PartialEvaluator = (function partialEvaluator() {
}
} else if (cmd == 'Tf') { // eagerly collect all fonts
args[0].name = handleSetFont(args[0].name);
// var fontRes = resources.get('Font');
// if (fontRes) {
// fontRes = xref.fetchIfRef(fontRes);
// var font = xref.fetchIfRef(fontRes.get(args[0].name));
// assertWellFormed(isDict(font));
// if (!font.translated) {
// 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
// // fonts.push(font.translated);
// dependency.push(font.translated);
// }
// }
// }
//
} else if (cmd == 'EI') {
buildPaintImageXObject(args[0], true);
}
@ -5850,22 +5717,6 @@ var CanvasGraphics = (function canvasGraphics() {
var name = fontObj.loadedName || 'sans-serif';
// var font;
// // the tf command uses a name, but graphics state uses a reference
// if (isName(fontRef)) {
// font = this.xref.fetchIfRef(this.res.get('Font'));
// if (!isDict(font))
// return;
//
// font = font.get(fontRef.name);
// } else if (isRef(fontRef)) {
// font = fontRef;
// }
// font = this.xref.fetchIfRef(font);
// if (!font)
// error('Referenced font is not found');
//
// var fontObj = font.fontObj;
this.current.font = fontObj;
this.current.fontSize = size;
@ -5914,15 +5765,6 @@ var CanvasGraphics = (function canvasGraphics() {
},
showText: function canvasGraphicsShowText(text) {
// If the current font isn't supported, we can't display the text and
// bail out.
// if (!this.current.font.supported) {
// console.log("showText BAIL OUT");
// return;
// }
// console.log("showText", text);
var ctx = this.ctx;
var current = this.current;
var font = current.font;
@ -5995,16 +5837,6 @@ var CanvasGraphics = (function canvasGraphics() {
},
showSpacedText: function canvasGraphicsShowSpacedText(arr) {
// If the current font isn't supported, we can't display the text and
// bail out.
// if (!this.current.font.supported) {
// console.log("showSpacedText BAIL OUT");
// return;
// }
// console.log("showSpacedText", arr);
var ctx = this.ctx;
var current = this.current;
var fontSize = current.fontSize;
@ -6290,21 +6122,18 @@ var CanvasGraphics = (function canvasGraphics() {
var tmpCtx = tmpCanvas.getContext('2d');
var tmpImgData;
// Deactivating this for now until we have feature detection.
// if (isGecko) {
// tmpImgData = imgData;
// } else {
tmpImgData = tmpCtx.getImageData(0, 0, w, h);
// Some browsers can set an UInt8Array directly as imageData, some
// can't. As long as we don't have proper feature detection, just
// copy over each pixel and set the imageData that way.
tmpImgData = tmpCtx.getImageData(0, 0, w, h);
// Copy over the imageData.
var tmpImgDataPixels = tmpImgData.data;
var len = tmpImgDataPixels.length;
// Copy over the imageData.
var tmpImgDataPixels = tmpImgData.data;
var len = tmpImgDataPixels.length;
// TODO: There got to be a better way to copy an ImageData array
// then coping over all the bytes one by one :/
while (len--)
tmpImgDataPixels[len] = imgData.data[len];
// }
while (len--) {
tmpImgDataPixels[len] = imgData.data[len];
}
tmpCtx.putImageData(tmpImgData, 0, 0);
ctx.drawImage(tmpCanvas, 0, -h);

View File

@ -60,18 +60,10 @@ var WorkerProcessorHandler = {
}
}
// var fonts = [];
// for (var i = 0; i < dependency.length; i++) {
// var dep = dependency[i];
// if (typeof dep === "object") {
// fonts.push(dep);
// }
// }
handler.send('page', {
pageNum: pageNum,
IRQueue: IRQueue,
depFonts: fonts
depFonts: Object.keys(fonts)
});
}, this);