Add support for TrueType format 12 cmaps (issue 14881)
				
					
				
			This is, as far as I can tell, the first case we've seen of a format 12 `cmap`. Please see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html
This commit is contained in:
		
							parent
							
								
									cfac6fa511
								
							
						
					
					
						commit
						6e7e9d83d8
					
				| @ -1499,14 +1499,14 @@ class Font { | |||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       const format = file.getUint16(); |       const format = file.getUint16(); | ||||||
|       file.skip(2 + 2); // length + language
 |  | ||||||
| 
 |  | ||||||
|       let hasShortCmap = false; |       let hasShortCmap = false; | ||||||
|       const mappings = []; |       const mappings = []; | ||||||
|       let j, glyphId; |       let j, glyphId; | ||||||
| 
 | 
 | ||||||
|       // TODO(mack): refactor this cmap subtable reading logic out
 |       // TODO(mack): refactor this cmap subtable reading logic out
 | ||||||
|       if (format === 0) { |       if (format === 0) { | ||||||
|  |         file.skip(2 + 2); // length + language
 | ||||||
|  | 
 | ||||||
|         for (j = 0; j < 256; j++) { |         for (j = 0; j < 256; j++) { | ||||||
|           const index = file.getByte(); |           const index = file.getByte(); | ||||||
|           if (!index) { |           if (!index) { | ||||||
| @ -1519,6 +1519,8 @@ class Font { | |||||||
|         } |         } | ||||||
|         hasShortCmap = true; |         hasShortCmap = true; | ||||||
|       } else if (format === 2) { |       } else if (format === 2) { | ||||||
|  |         file.skip(2 + 2); // length + language
 | ||||||
|  | 
 | ||||||
|         const subHeaderKeys = []; |         const subHeaderKeys = []; | ||||||
|         let maxSubHeaderKey = 0; |         let maxSubHeaderKey = 0; | ||||||
|         // Read subHeaderKeys. If subHeaderKeys[i] === 0, then i is a
 |         // Read subHeaderKeys. If subHeaderKeys[i] === 0, then i is a
 | ||||||
| @ -1568,6 +1570,8 @@ class Font { | |||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       } else if (format === 4) { |       } else if (format === 4) { | ||||||
|  |         file.skip(2 + 2); // length + language
 | ||||||
|  | 
 | ||||||
|         // re-creating the table in format 4 since the encoding
 |         // re-creating the table in format 4 since the encoding
 | ||||||
|         // might be changed
 |         // might be changed
 | ||||||
|         const segCount = file.getUint16() >> 1; |         const segCount = file.getUint16() >> 1; | ||||||
| @ -1630,6 +1634,8 @@ class Font { | |||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       } else if (format === 6) { |       } else if (format === 6) { | ||||||
|  |         file.skip(2 + 2); // length + language
 | ||||||
|  | 
 | ||||||
|         // Format 6 is a 2-bytes dense mapping, which means the font data
 |         // Format 6 is a 2-bytes dense mapping, which means the font data
 | ||||||
|         // lives glue together even if they are pretty far in the unicode
 |         // lives glue together even if they are pretty far in the unicode
 | ||||||
|         // table. (This looks weird, so I can have missed something), this
 |         // table. (This looks weird, so I can have missed something), this
 | ||||||
| @ -1647,6 +1653,26 @@ class Font { | |||||||
|             glyphId, |             glyphId, | ||||||
|           }); |           }); | ||||||
|         } |         } | ||||||
|  |       } else if (format === 12) { | ||||||
|  |         file.skip(2 + 4 + 4); // reserved + length + language
 | ||||||
|  | 
 | ||||||
|  |         const nGroups = file.getInt32() >>> 0; | ||||||
|  |         for (j = 0; j < nGroups; j++) { | ||||||
|  |           const startCharCode = file.getInt32() >>> 0; | ||||||
|  |           const endCharCode = file.getInt32() >>> 0; | ||||||
|  |           let glyphCode = file.getInt32() >>> 0; | ||||||
|  | 
 | ||||||
|  |           for ( | ||||||
|  |             let charCode = startCharCode; | ||||||
|  |             charCode <= endCharCode; | ||||||
|  |             charCode++ | ||||||
|  |           ) { | ||||||
|  |             mappings.push({ | ||||||
|  |               charCode, | ||||||
|  |               glyphId: glyphCode++, | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|       } else { |       } else { | ||||||
|         warn("cmap table has unsupported format: " + format); |         warn("cmap table has unsupported format: " + format); | ||||||
|         return { |         return { | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -18,6 +18,7 @@ | |||||||
| !issue2391-2.pdf | !issue2391-2.pdf | ||||||
| !issue14046.pdf | !issue14046.pdf | ||||||
| !issue7891_bc1.pdf | !issue7891_bc1.pdf | ||||||
|  | !issue14881.pdf | ||||||
| !issue3214.pdf | !issue3214.pdf | ||||||
| !issue4665.pdf | !issue4665.pdf | ||||||
| !issue4684.pdf | !issue4684.pdf | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								test/pdfs/issue14881.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/pdfs/issue14881.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -4630,6 +4630,12 @@ | |||||||
|        "password": "\u00E6\u00F8\u00E5", |        "password": "\u00E6\u00F8\u00E5", | ||||||
|        "about": "The password (æøå) is UTF8 encoded." |        "about": "The password (æøå) is UTF8 encoded." | ||||||
|     }, |     }, | ||||||
|  |     {  "id": "issue14881", | ||||||
|  |        "file": "pdfs/issue14881.pdf", | ||||||
|  |        "md5": "1aa3f2c7929eaf4502fcf6488ff31b5f", | ||||||
|  |        "rounds": 1, | ||||||
|  |        "type": "eq" | ||||||
|  |     }, | ||||||
|     {  "id": "High-Pressure-Measurement-WP-001287", |     {  "id": "High-Pressure-Measurement-WP-001287", | ||||||
|        "file": "pdfs/High-Pressure-Measurement-WP-001287.pdf", |        "file": "pdfs/High-Pressure-Measurement-WP-001287.pdf", | ||||||
|        "md5": "aeba7e47bbe50cbf08bb8bdff78fec8c", |        "md5": "aeba7e47bbe50cbf08bb8bdff78fec8c", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user