Fix wrong dict data offset when there is many charstrings
This commit is contained in:
		
							parent
							
								
									1cf4fc8782
								
							
						
					
					
						commit
						4a320705c0
					
				
							
								
								
									
										24
									
								
								fonts.js
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								fonts.js
									
									
									
									
									
								
							@ -1848,7 +1848,7 @@ CFF.prototype = {
 | 
				
			|||||||
    if (count == 0)
 | 
					    if (count == 0)
 | 
				
			||||||
      return '\x00\x00\x00';
 | 
					      return '\x00\x00\x00';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var data = String.fromCharCode(count >> 8, count & 0xff);
 | 
					    var data = String.fromCharCode((count >> 8) & 0xFF, count & 0xff);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Next byte contains the offset size use to reference object in the file
 | 
					    // Next byte contains the offset size use to reference object in the file
 | 
				
			||||||
    // Actually we're using 0x04 to be sure to be able to store everything
 | 
					    // Actually we're using 0x04 to be sure to be able to store everything
 | 
				
			||||||
@ -1881,9 +1881,7 @@ CFF.prototype = {
 | 
				
			|||||||
             String.fromCharCode((value >> 8) & 0xFF) +
 | 
					             String.fromCharCode((value >> 8) & 0xFF) +
 | 
				
			||||||
             String.fromCharCode(value & 0xFF);
 | 
					             String.fromCharCode(value & 0xFF);
 | 
				
			||||||
    } else if (value >= (-2147483648) && value <= 2147483647) {
 | 
					    } else if (value >= (-2147483648) && value <= 2147483647) {
 | 
				
			||||||
      value ^= 0xffffffff;
 | 
					      return '\x1d' +
 | 
				
			||||||
      value += 1;
 | 
					 | 
				
			||||||
      return '\xff' +
 | 
					 | 
				
			||||||
             String.fromCharCode((value >> 24) & 0xFF) +
 | 
					             String.fromCharCode((value >> 24) & 0xFF) +
 | 
				
			||||||
             String.fromCharCode((value >> 16) & 0xFF) +
 | 
					             String.fromCharCode((value >> 16) & 0xFF) +
 | 
				
			||||||
             String.fromCharCode((value >> 8) & 0xFF) +
 | 
					             String.fromCharCode((value >> 8) & 0xFF) +
 | 
				
			||||||
@ -2021,8 +2019,8 @@ CFF.prototype = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      'topDict': (function topDict(self) {
 | 
					      'topDict': (function topDict(self) {
 | 
				
			||||||
        return function() {
 | 
					        return function() {
 | 
				
			||||||
 | 
					          var header = '\x00\x01\x01\x01';
 | 
				
			||||||
          var dict =
 | 
					          var dict =
 | 
				
			||||||
              '\x00\x01\x01\x01\x30' +
 | 
					 | 
				
			||||||
              '\xf8\x1b\x00' + // version
 | 
					              '\xf8\x1b\x00' + // version
 | 
				
			||||||
              '\xf8\x1c\x01' + // Notice
 | 
					              '\xf8\x1c\x01' + // Notice
 | 
				
			||||||
              '\xf8\x1d\x02' + // FullName
 | 
					              '\xf8\x1d\x02' + // FullName
 | 
				
			||||||
@ -2037,19 +2035,29 @@ CFF.prototype = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          var offset = fields.header.length +
 | 
					          var offset = fields.header.length +
 | 
				
			||||||
                       fields.names.length +
 | 
					                       fields.names.length +
 | 
				
			||||||
                       (dict.length + (4 + 4 + 7)) +
 | 
					                       (header.length + 1) +
 | 
				
			||||||
 | 
					                       (dict.length + (4 + 4)) +
 | 
				
			||||||
                       fields.strings.length +
 | 
					                       fields.strings.length +
 | 
				
			||||||
                       fields.globalSubrs.length;
 | 
					                       fields.globalSubrs.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // If the offset if over 32767, encodeNumber is going to return
 | 
				
			||||||
 | 
					          // 5 bytes to encode the position instead of 3.
 | 
				
			||||||
 | 
					          if ((offset + fields.charstrings.length) > 32767) {
 | 
				
			||||||
 | 
					            offset += 9;
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            offset += 7;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          dict += self.encodeNumber(offset) + '\x0f'; // Charset
 | 
					          dict += self.encodeNumber(offset) + '\x0f'; // Charset
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          offset = offset + (glyphs.length * 2) + 1;
 | 
					          offset = offset + (glyphs.length * 2) + 1;
 | 
				
			||||||
          dict += self.encodeNumber(offset) + '\x11'; // Charstrings
 | 
					          dict += self.encodeNumber(offset) + '\x11'; // Charstrings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          dict += self.encodeNumber(fields.private.length);
 | 
					 | 
				
			||||||
          offset = offset + fields.charstrings.length;
 | 
					          offset = offset + fields.charstrings.length;
 | 
				
			||||||
 | 
					          dict += self.encodeNumber(fields.private.length);
 | 
				
			||||||
          dict += self.encodeNumber(offset) + '\x12'; // Private
 | 
					          dict += self.encodeNumber(offset) + '\x12'; // Private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          return dict;
 | 
					          return header + String.fromCharCode(dict.length + 1) + dict;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
      })(this),
 | 
					      })(this),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								pdf.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								pdf.js
									
									
									
									
									
								
							@ -4294,6 +4294,10 @@ var PartialEvaluator = (function() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (fontDict.has('ToUnicode')) {
 | 
					        if (fontDict.has('ToUnicode')) {
 | 
				
			||||||
          encodingMap['empty'] = true;
 | 
					          encodingMap['empty'] = true;
 | 
				
			||||||
 | 
					          var glyphsMap = {};
 | 
				
			||||||
 | 
					          for (var p in glyphMap)
 | 
				
			||||||
 | 
					            glyphsMap[glyphMap[p]] = encodingMap[p];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode'));
 | 
					          var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode'));
 | 
				
			||||||
          if (IsName(cmapObj)) {
 | 
					          if (IsName(cmapObj)) {
 | 
				
			||||||
            error('ToUnicode file cmap translation not implemented');
 | 
					            error('ToUnicode file cmap translation not implemented');
 | 
				
			||||||
@ -4425,16 +4429,12 @@ var PartialEvaluator = (function() {
 | 
				
			|||||||
          glyphWidths[unicode++] = widths[i];
 | 
					          glyphWidths[unicode++] = widths[i];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      var glyphsMap = {};
 | 
					 | 
				
			||||||
      for (var p in glyphMap)
 | 
					 | 
				
			||||||
        glyphsMap[glyphMap[p]] = encodingMap[p];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      var properties = {
 | 
					      var properties = {
 | 
				
			||||||
        type: subType.name,
 | 
					        type: subType.name,
 | 
				
			||||||
        subtype: fileType,
 | 
					        subtype: fileType,
 | 
				
			||||||
        widths: glyphWidths,
 | 
					        widths: glyphWidths,
 | 
				
			||||||
        encoding: encodingMap,
 | 
					        encoding: encodingMap,
 | 
				
			||||||
        glyphs: glyphsMap,
 | 
					        glyphs: glyphsMap || GlyphsUnicode,
 | 
				
			||||||
        builtInEncoding: builtInEncoding,
 | 
					        builtInEncoding: builtInEncoding,
 | 
				
			||||||
        charset: charset,
 | 
					        charset: charset,
 | 
				
			||||||
        firstChar: fontDict.get('FirstChar'),
 | 
					        firstChar: fontDict.get('FirstChar'),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user