else
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++;
- }
+ this.toFontChar = this.buildToFontChar(this.toUnicode);
if (!file) {
// The file data is not specified. Trying to fix the font name
var unassignedUnicodeItems = [];
for (var i = 1; i < numGlyphs; i++) {
var cid = gidToCidMap[i] || i;
- var unicode = this.toUnicode[cid];
+ var unicode = this.toFontChar[cid];
if (!unicode || typeof unicode !== 'number' || isSpecialUnicode(unicode) ||
unicode in usedUnicodes) {
unassignedUnicodeItems.push(i);
if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea)
break;
var unicode = unusedUnicode++;
- this.toUnicode[cid] = unicode;
+ this.toFontChar[cid] = unicode;
usedUnicodes[unicode] = true;
glyphs.push({ unicode: unicode, code: cid });
ids.push(i);
var glyphs = cmapTable.glyphs;
var ids = cmapTable.ids;
var hasShortCmap = !!cmapTable.hasShortCmap;
- var toUnicode = this.toUnicode;
+ var toFontChar = this.toFontChar;
- if (toUnicode && toUnicode.length > 0) {
+ if (toFontChar && toFontChar.length > 0) {
// checking if cmap is just identity map
var isIdentity = true;
for (var i = 0, ii = glyphs.length; i < ii; i++) {
break;
}
}
- // if it is, replacing with meaningful toUnicode values
+ // if it is, replacing with meaningful toFontChar values
if (isIdentity) {
var usedUnicodes = [], unassignedUnicodeItems = [];
for (var i = 0, ii = glyphs.length; i < ii; i++) {
- var unicode = toUnicode[i + 1];
+ var unicode = toFontChar[i + 1];
if (!unicode || typeof unicode !== 'number' || unicode in usedUnicodes) {
unassignedUnicodeItems.push(i);
continue;
unusedUnicode++;
var cid = i + 1;
// override only if unicode mapping is not specified
- if (!(cid in toUnicode))
- toUnicode[cid] = unusedUnicode;
+ if (!(cid in toFontChar))
+ toFontChar[cid] = unusedUnicode;
glyphs[i].unicode = unusedUnicode++;
}
- this.useToUnicode = true;
+ this.useToFontChar = true;
}
}
properties.baseEncoding = encoding;
}
if (false && properties.subtype == 'CIDFontType0C') {
- var toUnicode = [];
+ var toFontChar = [];
for (var i = 0; i < charstrings.length; ++i) {
var charstring = charstrings[i];
- toUnicode[charstring.code] = charstring.unicode;
+ toFontChar[charstring.code] = charstring.unicode;
}
- this.toUnicode = toUnicode;
+ this.toFontChar = toFontChar;
}
var fields = {
return stringToArray(otf.file);
},
+ buildToFontChar: function font_buildToFontChar(toUnicode) {
+ var result = [];
+ var unusedUnicode = kCmapGlyphOffset;
+ for (var i = 0, ii = toUnicode.length; i < ii; i++) {
+ var unicode = toUnicode[i];
+ var fontCharCode = typeof unicode === 'object' ? unusedUnicode++ :
+ unicode;
+ result.push(fontCharCode);
+ }
+ return result;
+ },
+
rebuildToUnicode: function font_rebuildToUnicode(properties) {
var firstChar = properties.firstChar, lastChar = properties.lastChar;
var map = [];
},
charToGlyph: function fonts_charToGlyph(charcode) {
- var unicode, width, codeIRQueue;
+ var fontCharCode, width, codeIRQueue;
var width = this.widths[charcode];
case 'CIDFontType0':
if (this.noUnicodeAdaptation) {
width = this.widths[this.unicodeToCID[charcode] || charcode];
- unicode = mapPrivateUseChars(charcode);
+ fontCharCode = mapPrivateUseChars(charcode);
break;
}
- unicode = this.toUnicode[charcode] || charcode;
+ fontCharCode = this.toFontChar[charcode] || charcode;
break;
case 'CIDFontType2':
if (this.noUnicodeAdaptation) {
width = this.widths[this.unicodeToCID[charcode] || charcode];
- unicode = mapPrivateUseChars(charcode);
+ fontCharCode = mapPrivateUseChars(charcode);
break;
}
- unicode = this.toUnicode[charcode] || charcode;
+ fontCharCode = this.toFontChar[charcode] || charcode;
break;
case 'Type1':
var glyphName = this.differences[charcode] || this.encoding[charcode];
if (!isNum(width))
width = this.widths[glyphName];
if (this.noUnicodeAdaptation) {
- unicode = mapPrivateUseChars(GlyphsUnicode[glyphName] || charcode);
+ fontCharCode = mapPrivateUseChars(GlyphsUnicode[glyphName] ||
+ charcode);
break;
}
- unicode = this.glyphNameMap[glyphName] ||
+ fontCharCode = this.glyphNameMap[glyphName] ||
GlyphsUnicode[glyphName] || charcode;
break;
case 'Type3':
var glyphName = this.differences[charcode] || this.encoding[charcode];
codeIRQueue = this.charProcIRQueues[glyphName];
- unicode = charcode;
+ fontCharCode = charcode;
break;
case 'TrueType':
- if (this.useToUnicode) {
- unicode = this.toUnicode[charcode] || charcode;
+ if (this.useToFontChar) {
+ fontCharCode = this.toFontChar[charcode] || charcode;
break;
}
var glyphName = this.differences[charcode] || this.encoding[charcode];
if (!isNum(width))
width = this.widths[glyphName];
if (this.noUnicodeAdaptation) {
- unicode = GlyphsUnicode[glyphName] || charcode;
+ fontCharCode = GlyphsUnicode[glyphName] || charcode;
break;
}
if (!this.hasEncoding || this.isSymbolicFont) {
- unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
+ fontCharCode = this.useToFontChar ? this.toFontChar[charcode] :
+ charcode;
break;
}
// MacRoman encoding address by re-encoding the cmap table
- unicode = glyphName in this.glyphNameMap ?
+ fontCharCode = glyphName in this.glyphNameMap ?
this.glyphNameMap[glyphName] : GlyphsUnicode[glyphName];
break;
default:
break;
}
- var unicodeChars = !('toUnicodeOriginal' in this) ? charcode :
- this.toUnicodeOriginal[charcode] || charcode;
+ var unicodeChars = !('toUnicode' in this) ? charcode :
+ this.toUnicode[charcode] || charcode;
if (typeof unicodeChars === 'number')
unicodeChars = String.fromCharCode(unicodeChars);
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
return {
- fontChar: String.fromCharCode(unicode),
+ fontChar: String.fromCharCode(fontCharCode),
unicode: unicodeChars,
width: width,
codeIRQueue: codeIRQueue