Add a simpler path for cmap format 0 to cmap format 4
This commit is contained in:
		
							parent
							
								
									4275a68e29
								
							
						
					
					
						commit
						3cc9912acd
					
				
							
								
								
									
										47
									
								
								fonts.js
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								fonts.js
									
									
									
									
									
								
							| @ -533,6 +533,7 @@ var Font = (function Font() { | |||||||
|     } |     } | ||||||
|      |      | ||||||
|     // Removes duplicate ranges
 |     // Removes duplicate ranges
 | ||||||
|  | /* | ||||||
|     for (var i = ranges.length - 1; i > 0; i--) { |     for (var i = ranges.length - 1; i > 0; i--) { | ||||||
|       var range = ranges[i]; |       var range = ranges[i]; | ||||||
|       var prevRange = ranges[i - 1]; |       var prevRange = ranges[i - 1]; | ||||||
| @ -541,12 +542,12 @@ var Font = (function Font() { | |||||||
|         ranges.splice(i - 1, 1); |         ranges.splice(i - 1, 1); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | */ | ||||||
|      |      | ||||||
|     return ranges; |     return ranges; | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   function createCMapTable(glyphs) { |   function createCMapTable(glyphs, deltas) { | ||||||
|     glyphs.push({ unicode: 0x0000 }); |  | ||||||
|     var ranges = getRanges(glyphs); |     var ranges = getRanges(glyphs); | ||||||
| 
 | 
 | ||||||
|     var numTables = 1; |     var numTables = 1; | ||||||
| @ -573,18 +574,17 @@ var Font = (function Font() { | |||||||
|       var range = ranges[i]; |       var range = ranges[i]; | ||||||
|       var start = range[0]; |       var start = range[0]; | ||||||
|       var end = range[1]; |       var end = range[1]; | ||||||
|       var delta = (bias - start) & 0xffff; | 			var offset = (segCount - i) * 2 + bias * 2; | ||||||
|       bias += (end - start + 1); |       bias += (end - start + 1); | ||||||
| 
 | 
 | ||||||
|       startCount += string16(start); |       startCount += string16(start); | ||||||
|       endCount += string16(end); |       endCount += string16(end); | ||||||
|       idDeltas += string16(delta); |       idDeltas += string16(0); | ||||||
|       idRangeOffsets += string16(0); |       idRangeOffsets += string16(offset); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|       for (var j = start; j <= end; j++) { |     for (var i = 0; i < glyphs.length; i++) | ||||||
|         glyphsIds += string16(j); |       glyphsIds += string16(deltas ? deltas[i] : i + 1); | ||||||
|       } |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     endCount += '\xFF\xFF'; |     endCount += '\xFF\xFF'; | ||||||
|     startCount += '\xFF\xFF'; |     startCount += '\xFF\xFF'; | ||||||
| @ -832,30 +832,15 @@ var Font = (function Font() { | |||||||
|             // under this limit they will not be displayed so let's rewrite the
 |             // under this limit they will not be displayed so let's rewrite the
 | ||||||
|             // CMap.
 |             // CMap.
 | ||||||
|             var glyphs = [];            |             var glyphs = [];            | ||||||
|             if (encoding.empty) { |             var deltas = []; | ||||||
|               var orderedGlyphs= []; |             for (var j = 0; j < 256; j++) { | ||||||
|               for ( var j = 0; j < charset.length; j++) { |               var index = font.getByte(); | ||||||
|                 var unicode = GlyphsUnicode[charset[font.getByte()]] || 0; |               if (index) { | ||||||
|                 glyphs.push({ unicode: unicode }); |                 deltas.push(index); | ||||||
|                 orderedGlyphs.push(unicode); |                 glyphs.push({ unicode : j }); | ||||||
|               } |  | ||||||
| 
 |  | ||||||
|               orderedGlyphs.sort(function(a, b) { |  | ||||||
|                 return a - b; |  | ||||||
|               }); |  | ||||||
| 
 |  | ||||||
|               for (var p in encoding) { |  | ||||||
|                 if (p != "empty") |  | ||||||
|                   properties.encoding[p] = orderedGlyphs[p - 1]; |  | ||||||
|               } |  | ||||||
|             } else { |  | ||||||
|               for (var j = 0x20; j < 256; j++) { |  | ||||||
|                 // TODO do not hardcode WinAnsiEncoding
 |  | ||||||
|                 var unicode = GlyphsUnicode[Encodings["WinAnsiEncoding"][j]]; |  | ||||||
|                 glyphs.push({ unicode: unicode }); |  | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|             cmap.data = createCMapTable(glyphs); |             cmap.data = createCMapTable(glyphs, deltas); | ||||||
|           } else if (format == 6 && numRecords == 1 && !encoding.empty) { |           } else if (format == 6 && numRecords == 1 && !encoding.empty) { | ||||||
|             // Format 0 alone is not allowed by the sanitizer so let's rewrite
 |             // Format 0 alone is not allowed by the sanitizer so let's rewrite
 | ||||||
|             // that to a 3-1-4 Unicode BMP table
 |             // that to a 3-1-4 Unicode BMP table
 | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								pdf.js
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								pdf.js
									
									
									
									
									
								
							| @ -3722,9 +3722,8 @@ var PartialEvaluator = (function() { | |||||||
|           var baseName = encoding.get('BaseEncoding'); |           var baseName = encoding.get('BaseEncoding'); | ||||||
|           if (baseName) { |           if (baseName) { | ||||||
|             var base = Encodings[baseName.name]; |             var base = Encodings[baseName.name]; | ||||||
|             var index = 0; |  | ||||||
|             for (var j = 0, end = base.length; j < end; j++) |             for (var j = 0, end = base.length; j < end; j++) | ||||||
|               encodingMap[index++] = GlyphsUnicode[base[j]]; |               encodingMap[j] = GlyphsUnicode[base[j]] || 0; | ||||||
|           } else { |           } else { | ||||||
|             TODO('need to load default encoding'); |             TODO('need to load default encoding'); | ||||||
|           } |           } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user