Char code to unicode conversion
This commit is contained in:
parent
3b72c6063c
commit
94cc2cdb75
@ -505,11 +505,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var items = args[0];
|
var items = args[0];
|
||||||
for (var j = 0, jj = items.length; j < jj; j++) {
|
for (var j = 0, jj = items.length; j < jj; j++) {
|
||||||
if (typeof items[j] === 'string')
|
if (typeof items[j] === 'string')
|
||||||
text += items[j];
|
text += fontCharsToUnicode(items[j], font.translated.properties);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Tj':
|
case 'Tj':
|
||||||
text += args[0];
|
text += fontCharsToUnicode(args[0], font.translated.properties);;
|
||||||
break;
|
break;
|
||||||
} // switch
|
} // switch
|
||||||
|
|
||||||
|
74
src/fonts.js
74
src/fonts.js
@ -723,6 +723,48 @@ function isSpecialUnicode(unicode) {
|
|||||||
unicode < kCmapGlyphOffset + kSizeOfGlyphArea);
|
unicode < kCmapGlyphOffset + kSizeOfGlyphArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fontCharsToUnicode(charCodes, fontProperties) {
|
||||||
|
var toUnicode = fontProperties.toUnicode;
|
||||||
|
var composite = fontProperties.composite;
|
||||||
|
var encoding, differences, cidToUnicode;
|
||||||
|
var result = '';
|
||||||
|
if (composite) {
|
||||||
|
cidToUnicode = fontProperties.cidToUnicode
|
||||||
|
for (var i = 0, ii = charCodes.length; i < ii; i += 2) {
|
||||||
|
var charCode = (charCodes.charCodeAt(i) << 8) | charCodes.charCodeAt(i + 1);
|
||||||
|
if (toUnicode && charCode in toUnicode) {
|
||||||
|
var unicode = toUnicode[charCode];
|
||||||
|
result += typeof unicode !== 'number' ? unicode :
|
||||||
|
String.fromCharCode(unicode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result += String.fromCharCode(!cidToUnicode ? charCode :
|
||||||
|
cidToUnicode[charCode] || charCode)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
differences = fontProperties.differences;
|
||||||
|
encoding = fontProperties.baseEncoding;
|
||||||
|
for (var i = 0, ii = charCodes.length; i < ii; i++) {
|
||||||
|
var charCode = charCodes.charCodeAt(i);
|
||||||
|
if (toUnicode && charCode in toUnicode) {
|
||||||
|
var unicode = toUnicode[charCode];
|
||||||
|
result += typeof unicode !== 'number' ? unicode :
|
||||||
|
String.fromCharCode(unicode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var glyphName = charCode in differences ? differences[charCode] :
|
||||||
|
encoding[charCode];
|
||||||
|
if (glyphName in GlyphsUnicode) {
|
||||||
|
result += String.fromCharCode(GlyphsUnicode[glyphName]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result += String.fromCharCode(charCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Font' is the class the outside world should use, it encapsulate all the font
|
* 'Font' is the class the outside world should use, it encapsulate all the font
|
||||||
* decoding logics whatever type it is (assuming the font type is supported).
|
* decoding logics whatever type it is (assuming the font type is supported).
|
||||||
@ -2098,7 +2140,7 @@ var Font = (function FontClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
charToGlyph: function fonts_charToGlyph(charcode) {
|
charToGlyph: function fonts_charToGlyph(charcode) {
|
||||||
var unicode, width, codeIRQueue;
|
var fontChar, width, codeIRQueue;
|
||||||
|
|
||||||
var width = this.widths[charcode];
|
var width = this.widths[charcode];
|
||||||
|
|
||||||
@ -2106,38 +2148,38 @@ var Font = (function FontClosure() {
|
|||||||
case 'CIDFontType0':
|
case 'CIDFontType0':
|
||||||
if (this.noUnicodeAdaptation) {
|
if (this.noUnicodeAdaptation) {
|
||||||
width = this.widths[this.unicodeToCID[charcode] || charcode];
|
width = this.widths[this.unicodeToCID[charcode] || charcode];
|
||||||
unicode = charcode;
|
fontChar = charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unicode = this.toUnicode[charcode] || charcode;
|
fontChar = this.toUnicode[charcode] || charcode;
|
||||||
break;
|
break;
|
||||||
case 'CIDFontType2':
|
case 'CIDFontType2':
|
||||||
if (this.noUnicodeAdaptation) {
|
if (this.noUnicodeAdaptation) {
|
||||||
width = this.widths[this.unicodeToCID[charcode] || charcode];
|
width = this.widths[this.unicodeToCID[charcode] || charcode];
|
||||||
unicode = charcode;
|
fontChar = charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unicode = this.toUnicode[charcode] || charcode;
|
fontChar = this.toUnicode[charcode] || charcode;
|
||||||
break;
|
break;
|
||||||
case 'Type1':
|
case 'Type1':
|
||||||
var glyphName = this.differences[charcode] || this.encoding[charcode];
|
var glyphName = this.differences[charcode] || this.encoding[charcode];
|
||||||
if (!isNum(width))
|
if (!isNum(width))
|
||||||
width = this.widths[glyphName];
|
width = this.widths[glyphName];
|
||||||
if (this.noUnicodeAdaptation) {
|
if (this.noUnicodeAdaptation) {
|
||||||
unicode = GlyphsUnicode[glyphName] || charcode;
|
fontChar = GlyphsUnicode[glyphName] || charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unicode = this.glyphNameMap[glyphName] ||
|
fontChar = this.glyphNameMap[glyphName] ||
|
||||||
GlyphsUnicode[glyphName] || charcode;
|
GlyphsUnicode[glyphName] || charcode;
|
||||||
break;
|
break;
|
||||||
case 'Type3':
|
case 'Type3':
|
||||||
var glyphName = this.differences[charcode] || this.encoding[charcode];
|
var glyphName = this.differences[charcode] || this.encoding[charcode];
|
||||||
codeIRQueue = this.charProcIRQueues[glyphName];
|
codeIRQueue = this.charProcIRQueues[glyphName];
|
||||||
unicode = charcode;
|
fontChar = charcode;
|
||||||
break;
|
break;
|
||||||
case 'TrueType':
|
case 'TrueType':
|
||||||
if (this.useToUnicode) {
|
if (this.useToUnicode) {
|
||||||
unicode = this.toUnicode[charcode] || charcode;
|
fontChar = this.toUnicode[charcode] || charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var glyphName = this.differences[charcode] || this.encoding[charcode];
|
var glyphName = this.differences[charcode] || this.encoding[charcode];
|
||||||
@ -2146,19 +2188,19 @@ var Font = (function FontClosure() {
|
|||||||
if (!isNum(width))
|
if (!isNum(width))
|
||||||
width = this.widths[glyphName];
|
width = this.widths[glyphName];
|
||||||
if (this.noUnicodeAdaptation) {
|
if (this.noUnicodeAdaptation) {
|
||||||
unicode = GlyphsUnicode[glyphName] || charcode;
|
fontChar = GlyphsUnicode[glyphName] || charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!this.hasEncoding) {
|
if (!this.hasEncoding) {
|
||||||
unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
|
fontChar = this.useToUnicode ? this.toUnicode[charcode] : charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.hasShortCmap && false) {
|
if (this.hasShortCmap && false) {
|
||||||
var j = Encodings.MacRomanEncoding.indexOf(glyphName);
|
var j = Encodings.MacRomanEncoding.indexOf(glyphName);
|
||||||
unicode = j >= 0 ? j :
|
fontChar = j >= 0 ? j :
|
||||||
this.glyphNameMap[glyphName];
|
this.glyphNameMap[glyphName];
|
||||||
} else {
|
} else {
|
||||||
unicode = glyphName in GlyphsUnicode ?
|
fontChar = glyphName in GlyphsUnicode ?
|
||||||
GlyphsUnicode[glyphName] :
|
GlyphsUnicode[glyphName] :
|
||||||
this.glyphNameMap[glyphName];
|
this.glyphNameMap[glyphName];
|
||||||
}
|
}
|
||||||
@ -2168,15 +2210,15 @@ var Font = (function FontClosure() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var unicodeChars = !('toUnicode' in this) ? charcode :
|
var unicodeChars = !('toUnicode' in this) ? fontChar :
|
||||||
this.toUnicode[charcode] || charcode;
|
this.toUnicode[charcode] || fontChar;
|
||||||
if (typeof unicodeChars === 'number')
|
if (typeof unicodeChars === 'number')
|
||||||
unicodeChars = String.fromCharCode(unicodeChars);
|
unicodeChars = String.fromCharCode(unicodeChars);
|
||||||
|
|
||||||
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
|
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fontChar: String.fromCharCode(unicode),
|
fontChar: String.fromCharCode(fontChar),
|
||||||
unicode: unicodeChars,
|
unicode: unicodeChars,
|
||||||
width: width,
|
width: width,
|
||||||
codeIRQueue: codeIRQueue
|
codeIRQueue: codeIRQueue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user