Fixing ToUnicode parsing; workaround for invalid UTF16 encoding
This commit is contained in:
		
							parent
							
								
									7859ef0f04
								
							
						
					
					
						commit
						d50773fb96
					
				@ -620,8 +620,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
 | 
				
			|||||||
              } else {
 | 
					              } else {
 | 
				
			||||||
                // parsing hex UTF-16BE numbers
 | 
					                // parsing hex UTF-16BE numbers
 | 
				
			||||||
                var str = [];
 | 
					                var str = [];
 | 
				
			||||||
                for (var i = 0, ii = token.length; i < ii; i += 4)
 | 
					                for (var k = 0, kk = token.length; k < kk; k += 4) {
 | 
				
			||||||
                  str.push(parseInt(token.substr(i, 4), 16));
 | 
					                  var b = parseInt(token.substr(k, 4), 16);
 | 
				
			||||||
 | 
					                  if (b <= 0x10) {
 | 
				
			||||||
 | 
					                    k += 4;
 | 
				
			||||||
 | 
					                    b = (b << 16) | parseInt(token.substr(k, 4), 16);
 | 
				
			||||||
 | 
					                    b -= 0x10000;
 | 
				
			||||||
 | 
					                    str.push(0xD800 | (b >> 10));
 | 
				
			||||||
 | 
					                    str.push(0xDC00 | (b & 0x3FF));
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                  str.push(b);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                tokens.push(String.fromCharCode.apply(String, str));
 | 
					                tokens.push(String.fromCharCode.apply(String, str));
 | 
				
			||||||
                token = '';
 | 
					                token = '';
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										17
									
								
								src/fonts.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/fonts.js
									
									
									
									
									
								
							@ -823,6 +823,13 @@ var Font = (function FontClosure() {
 | 
				
			|||||||
    else
 | 
					    else
 | 
				
			||||||
      this.rebuildToUnicode(properties);
 | 
					      this.rebuildToUnicode(properties);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.toUnicodeOriginal = this.toUnicode.slice();
 | 
				
			||||||
 | 
					    for (var i = 0, j = 0xE000; i < this.toUnicode.length; i++) {
 | 
				
			||||||
 | 
					      if (typeof this.toUnicode[i] == 'number')
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      this.toUnicode[i] = j++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!file) {
 | 
					    if (!file) {
 | 
				
			||||||
      // The file data is not specified. Trying to fix the font name
 | 
					      // The file data is not specified. Trying to fix the font name
 | 
				
			||||||
      // to be used with the canvas.font.
 | 
					      // to be used with the canvas.font.
 | 
				
			||||||
@ -1778,7 +1785,7 @@ var Font = (function FontClosure() {
 | 
				
			|||||||
        for (var i = 1; i < numGlyphs; i++) {
 | 
					        for (var i = 1; i < numGlyphs; i++) {
 | 
				
			||||||
          var cid = gidToCidMap[i] || i;
 | 
					          var cid = gidToCidMap[i] || i;
 | 
				
			||||||
          var unicode = this.toUnicode[cid];
 | 
					          var unicode = this.toUnicode[cid];
 | 
				
			||||||
          if (!unicode || isSpecialUnicode(unicode) ||
 | 
					          if (!unicode || typeof unicode !== 'number' || isSpecialUnicode(unicode) ||
 | 
				
			||||||
              unicode in usedUnicodes) {
 | 
					              unicode in usedUnicodes) {
 | 
				
			||||||
            unassignedUnicodeItems.push(i);
 | 
					            unassignedUnicodeItems.push(i);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
@ -1825,7 +1832,7 @@ var Font = (function FontClosure() {
 | 
				
			|||||||
            var usedUnicodes = [], unassignedUnicodeItems = [];
 | 
					            var usedUnicodes = [], unassignedUnicodeItems = [];
 | 
				
			||||||
            for (var i = 0, ii = glyphs.length; i < ii; i++) {
 | 
					            for (var i = 0, ii = glyphs.length; i < ii; i++) {
 | 
				
			||||||
              var unicode = toUnicode[i + 1];
 | 
					              var unicode = toUnicode[i + 1];
 | 
				
			||||||
              if (!unicode || unicode in usedUnicodes) {
 | 
					              if (!unicode || typeof unicode !== 'number' || unicode in usedUnicodes) {
 | 
				
			||||||
                unassignedUnicodeItems.push(i);
 | 
					                unassignedUnicodeItems.push(i);
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
@ -1972,7 +1979,7 @@ var Font = (function FontClosure() {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        properties.baseEncoding = encoding;
 | 
					        properties.baseEncoding = encoding;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if (properties.subtype == 'CIDFontType0C') {
 | 
					      if (false && properties.subtype == 'CIDFontType0C') {
 | 
				
			||||||
        var toUnicode = [];
 | 
					        var toUnicode = [];
 | 
				
			||||||
        for (var i = 0; i < charstrings.length; ++i) {
 | 
					        for (var i = 0; i < charstrings.length; ++i) {
 | 
				
			||||||
          var charstring = charstrings[i];
 | 
					          var charstring = charstrings[i];
 | 
				
			||||||
@ -2270,8 +2277,8 @@ var Font = (function FontClosure() {
 | 
				
			|||||||
          break;
 | 
					          break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      var unicodeChars = !('toUnicode' in this) ? charcode :
 | 
					      var unicodeChars = !('toUnicodeOriginal' in this) ? charcode :
 | 
				
			||||||
        this.toUnicode[charcode] || charcode;
 | 
					        this.toUnicodeOriginal[charcode] || charcode;
 | 
				
			||||||
      if (typeof unicodeChars === 'number')
 | 
					      if (typeof unicodeChars === 'number')
 | 
				
			||||||
        unicodeChars = String.fromCharCode(unicodeChars);
 | 
					        unicodeChars = String.fromCharCode(unicodeChars);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user