Fix lint errors
This commit is contained in:
		
							parent
							
								
									a6180830f8
								
							
						
					
					
						commit
						20a348fc0c
					
				
							
								
								
									
										107
									
								
								fonts.js
									
									
									
									
									
								
							
							
						
						
									
										107
									
								
								fonts.js
									
									
									
									
									
								
							| @ -145,7 +145,7 @@ var FontLoader = { | ||||
| 
 | ||||
|     for (var i = 0; i < fonts.length; i++) { | ||||
|       var font = fonts[i]; | ||||
|        | ||||
| 
 | ||||
|       // If there is already a fontObj on the font, then it was loaded/attached
 | ||||
|       // to the page already and we don't have to do anything for this font
 | ||||
|       // here future.
 | ||||
| @ -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). | ||||
|  | ||||
							
								
								
									
										73
									
								
								worker.js
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								worker.js
									
									
									
									
									
								
							| @ -11,23 +11,23 @@ var WorkerPage = (function() { | ||||
|     this.workerPDF = workerPDF; | ||||
|     this.page = page; | ||||
|     this.objs = objs; | ||||
|      | ||||
| 
 | ||||
|     this.ref = page.ref; | ||||
|   } | ||||
|    | ||||
| 
 | ||||
|   constructor.prototype = { | ||||
|     get width() { | ||||
|       return this.page.width; | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     get height() { | ||||
|       return this.page.height; | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     get stats() { | ||||
|       return this.page.stats; | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     get view() { | ||||
|       return this.page.view; | ||||
|     }, | ||||
| @ -37,40 +37,40 @@ var WorkerPage = (function() { | ||||
|       this.callback = callback; | ||||
|       // TODO: Place the worker magic HERE.
 | ||||
|       // this.page.startRendering(ctx, callback, errback);
 | ||||
|        | ||||
| 
 | ||||
|       this.startRenderingTime = Date.now(); | ||||
|       this.workerPDF.startRendering(this) | ||||
|       this.workerPDF.startRendering(this); | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     startRenderingFromIRQueue: function(IRQueue, fonts) { | ||||
|       var gfx = new CanvasGraphics(this.ctx, this.objs); | ||||
|        | ||||
| 
 | ||||
|       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); | ||||
|       }.bind(this); | ||||
|       this.page.startRenderingFromIRQueue(gfx, IRQueue, fonts, callback); | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     getLinks: function() { | ||||
|       return this.page.getLinks(); | ||||
|     } | ||||
|   }; | ||||
|    | ||||
| 
 | ||||
|   return constructor; | ||||
| })(); | ||||
| 
 | ||||
| /** | ||||
|  * 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() { | ||||
| @ -98,16 +98,16 @@ var PDFObjects = (function() { | ||||
|      * object needs to be resolved. If it isn't, this function throws. | ||||
|      * | ||||
|      * If called *with* a callback, the callback is called with the data of the | ||||
|      * object once the object is resolved. That means, if you call this  | ||||
|      * object once the object is resolved. That means, if you call this | ||||
|      * function and the object is already resolved, the callback gets called | ||||
|      * right away. | ||||
|      */ | ||||
|     get: function(objId, callback) { | ||||
|       // If there is a callback, then the get can be async and the object is 
 | ||||
|       // If there is a callback, then the get can be async and the object is
 | ||||
|       // not required to be resolved right now
 | ||||
|       if (callback) { | ||||
|         this.ensureObj(objId).then(callback); | ||||
|       }  | ||||
|       } | ||||
|       // If there isn't a callback, the user expects to get the resolved data
 | ||||
|       // directly.
 | ||||
|       else { | ||||
| @ -116,8 +116,8 @@ 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 { | ||||
|           return obj.data; | ||||
| @ -130,7 +130,7 @@ var PDFObjects = (function() { | ||||
|      */ | ||||
|     resolve: function(objId, data) { | ||||
|       var objs = this.objs; | ||||
|        | ||||
| 
 | ||||
|       // In case there is a promise already on this object, just resolve it.
 | ||||
|       if (objs[objId]) { | ||||
|         objs[objId].resolve(data); | ||||
| @ -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 | ||||
| @ -201,12 +201,12 @@ var Promise = (function() { | ||||
|       this._data = data; | ||||
|       this.hasData = true; | ||||
|     } else { | ||||
|       this.isResolved = false;       | ||||
|       this.isResolved = false; | ||||
|       this._data = EMPTY_PROMISE; | ||||
|     } | ||||
|     this.callbacks = []; | ||||
|   }; | ||||
|    | ||||
| 
 | ||||
|   Promise.prototype = { | ||||
|     hasData: false, | ||||
| 
 | ||||
| @ -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; | ||||
| @ -224,10 +225,10 @@ var Promise = (function() { | ||||
|         this.onDataCallback(data); | ||||
|       } | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     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; | ||||
|     }, | ||||
| @ -239,35 +240,35 @@ var Promise = (function() { | ||||
|         this.onDataCallback = callback; | ||||
|       } | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     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; | ||||
|       this.data = data; | ||||
|       var callbacks = this.callbacks; | ||||
|        | ||||
| 
 | ||||
|       for (var i = 0; i < callbacks.length; i++) { | ||||
|         callbacks[i].call(null, data); | ||||
|       } | ||||
|     }, | ||||
|      | ||||
| 
 | ||||
|     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.
 | ||||
|       if (this.isResolved) { | ||||
|         var data = this.data; | ||||
|         callback.call(null, data); | ||||
|       } else { | ||||
|         this.callbacks.push(callback);         | ||||
|         this.callbacks.push(callback); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   }; | ||||
|   return Promise; | ||||
| })(); | ||||
| 
 | ||||
|  | ||||
| @ -9,15 +9,15 @@ var console = { | ||||
|     var args = Array.prototype.slice.call(arguments); | ||||
|     postMessage({ | ||||
|       action: 'console_log', | ||||
|       data:   args | ||||
|       data: args | ||||
|     }); | ||||
|   }, | ||||
|    | ||||
| 
 | ||||
|   error: function error() { | ||||
|     var args = Array.prototype.slice.call(arguments); | ||||
|     postMessage({ | ||||
|       action: 'console_error', | ||||
|       data:   args | ||||
|       data: args | ||||
|     }); | ||||
|   }, | ||||
| 
 | ||||
|  | ||||
| @ -8,14 +8,14 @@ function MessageHandler(name, comObj) { | ||||
|   this.name = name; | ||||
|   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; | ||||
|     if (data.action in ah) { | ||||
| @ -39,8 +39,8 @@ MessageHandler.prototype = { | ||||
|   send: function(actionName, data) { | ||||
|     this.comObj.postMessage({ | ||||
|       action: actionName, | ||||
|       data:   data | ||||
|     });       | ||||
|       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); | ||||
|  | ||||
| @ -6,20 +6,21 @@ | ||||
| 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,15 +30,16 @@ 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 = {}; | ||||
|    | ||||
| 
 | ||||
|         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,17 +68,17 @@ var WorkerProcessorHandler = { | ||||
|       //   }
 | ||||
|       // }
 | ||||
| 
 | ||||
|       handler.send("page", { | ||||
|         pageNum:  pageNum, | ||||
|         IRQueue:  IRQueue, | ||||
|       handler.send('page', { | ||||
|         pageNum: pageNum, | ||||
|         IRQueue: IRQueue, | ||||
|         depFonts: fonts | ||||
|       }); | ||||
|     }, this); | ||||
|      | ||||
|     handler.on("font", function(data) {   | ||||
|       var objId      = data[0]; | ||||
|       var name       = data[1]; | ||||
|       var file       = data[2]; | ||||
| 
 | ||||
|     handler.on('font', function(data) { | ||||
|       var objId = data[0]; | ||||
|       var name = data[1]; | ||||
|       var file = data[2]; | ||||
|       var properties = data[3]; | ||||
| 
 | ||||
|       var font = { | ||||
| @ -92,15 +94,15 @@ var WorkerProcessorHandler = { | ||||
| 
 | ||||
|         var fontFile = new Stream(file.bytes, file.start, | ||||
|                                   file.end - file.start, fontFileDict); | ||||
|                           | ||||
|         // Check if this is a FlateStream. Otherwise just use the created 
 | ||||
| 
 | ||||
|         // 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); | ||||
| @ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user