Merge branch 'master' of https://github.com/andreasgal/pdf.js
This commit is contained in:
		
						commit
						697aa0f15e
					
				
							
								
								
									
										14
									
								
								fonts.js
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								fonts.js
									
									
									
									
									
								
							| @ -3,6 +3,8 @@ | |||||||
| 
 | 
 | ||||||
| "use strict"; | "use strict"; | ||||||
| 
 | 
 | ||||||
|  | var isWorker = (typeof window == "undefined"); | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Maximum file size of the font. |  * Maximum file size of the font. | ||||||
|  */ |  */ | ||||||
| @ -36,9 +38,12 @@ var kDisableFonts = false; | |||||||
| 
 | 
 | ||||||
| var Fonts = (function Fonts() { | var Fonts = (function Fonts() { | ||||||
|   var kScalePrecision = 40; |   var kScalePrecision = 40; | ||||||
|   var fonts = Object.create(null); |   var fonts = Object.create(null);   | ||||||
|   var ctx = document.createElement("canvas").getContext("2d"); | 
 | ||||||
|   ctx.scale(1 / kScalePrecision, 1); |   if (!isWorker) { | ||||||
|  |     var ctx = document.createElement("canvas").getContext("2d"); | ||||||
|  |     ctx.scale(1 / kScalePrecision, 1);     | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   function Font(name, data, properties) { |   function Font(name, data, properties) { | ||||||
|     this.name = name; |     this.name = name; | ||||||
| @ -120,7 +125,6 @@ var Fonts = (function Fonts() { | |||||||
| 
 | 
 | ||||||
| var FontLoader = { | var FontLoader = { | ||||||
|   bind: function(fonts) { |   bind: function(fonts) { | ||||||
|     var worker = (typeof window == "undefined"); |  | ||||||
|     var ready = true; |     var ready = true; | ||||||
| 
 | 
 | ||||||
|     for (var i = 0; i < fonts.length; i++) { |     for (var i = 0; i < fonts.length; i++) { | ||||||
| @ -140,7 +144,7 @@ var FontLoader = { | |||||||
|       for (var j = 0; j < length; j++) |       for (var j = 0; j < length; j++) | ||||||
|         str += String.fromCharCode(data[j]); |         str += String.fromCharCode(data[j]); | ||||||
| 
 | 
 | ||||||
|       worker ? obj.bindWorker(str) : obj.bindDOM(str); |       isWorker ? obj.bindWorker(str) : obj.bindDOM(str); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return ready; |     return ready; | ||||||
|  | |||||||
| @ -27,9 +27,9 @@ | |||||||
|       <select id="scaleSelect"> |       <select id="scaleSelect"> | ||||||
|         <option value="50">50%</option> |         <option value="50">50%</option> | ||||||
|         <option value="75">75%</option> |         <option value="75">75%</option> | ||||||
|         <option value="100" selected="selected">100%</option> |         <option value="100">100%</option> | ||||||
|         <option value="125">125%</option> |         <option value="125">125%</option> | ||||||
|         <option value="150">150%</option> |         <option value="150" selected="selected">150%</option> | ||||||
|         <option value="200">200%</option> |         <option value="200">200%</option> | ||||||
|       </select> |       </select> | ||||||
|       <span class="label">Zoom</span> |       <span class="label">Zoom</span> | ||||||
|  | |||||||
| @ -59,14 +59,15 @@ FontWorker.prototype = { | |||||||
|     "fonts": function(data) { |     "fonts": function(data) { | ||||||
|       // console.log("got processed fonts from worker", Object.keys(data));
 |       // console.log("got processed fonts from worker", Object.keys(data));
 | ||||||
|       for (name in data) { |       for (name in data) { | ||||||
|         // Update the 
 |         // Update the encoding property.
 | ||||||
|         Fonts[name].properties = { |         var font = Fonts.lookup(name); | ||||||
|  |         font.properties = { | ||||||
|           encoding: data[name].encoding |           encoding: data[name].encoding | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         // Call `Font.prototype.bindDOM` to make the font get loaded on the page.
 |         // Call `Font.prototype.bindDOM` to make the font get loaded on the page.
 | ||||||
|         Font.prototype.bindDOM.call( |         Font.prototype.bindDOM.call( | ||||||
|           Fonts[name], |           font, | ||||||
|           data[name].str, |           data[name].str, | ||||||
|           // IsLoadedCallback.
 |           // IsLoadedCallback.
 | ||||||
|           this.$handleFontLoadedCallback |           this.$handleFontLoadedCallback | ||||||
| @ -84,19 +85,9 @@ FontWorker.prototype = { | |||||||
|         continue; |         continue; | ||||||
|       } |       } | ||||||
|      |      | ||||||
|       // Store only the data on Fonts that is needed later on, such that we
 |       // Register the font but don't pass in any real data. The idea is to
 | ||||||
|       // hold track on as lease memory as possible.
 |       // store as less data as possible to reduce memory usage.
 | ||||||
|       Fonts[font.name] = { |       Fonts.registerFont(font.name, Object.create(null), Object.create(null)); | ||||||
|         name:       font.name, |  | ||||||
|         mimetype:   font.mimetype, |  | ||||||
|         // This is set later on the worker replay. For some fonts, the encoding
 |  | ||||||
|         // is calculated during the conversion process happening on the worker
 |  | ||||||
|         // and therefore is not available right now.
 |  | ||||||
|         // properties: {
 |  | ||||||
|         //   encoding:  font.properties.encoding
 |  | ||||||
|         // },
 |  | ||||||
|         cache:      Object.create(null) |  | ||||||
|       }; |  | ||||||
| 
 | 
 | ||||||
|       // Mark this font to be handled later.
 |       // Mark this font to be handled later.
 | ||||||
|       notLoaded.push(font); |       notLoaded.push(font); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user