continue;
}
- var unicode = glyph.unicode;
- var char = (unicode >= 0x10000) ?
- String.fromCharCode(0xD800 | ((unicode - 0x10000) >> 10),
- 0xDC00 | (unicode & 0x3FF)) : String.fromCharCode(unicode);
-
+ var char = glyph.fontChar;
ctx.fillText(char, width, 0);
width += glyph.width * fontSize * 0.001 + charSpacing;
+
+ // TODO actual characters can be extracted from the glyph.unicode
}
current.x += width;
error('Encoding is not a Name nor a Dict');
}
}
+
properties.differences = differences;
properties.baseEncoding = baseEncoding;
properties.hasEncoding = hasEncoding;
}
} else if (byte == 0x3E) {
if (token.length) {
- // parsing hex number
- tokens.push(parseInt(token, 16));
- token = '';
+ if (token.length <= 4) {
+ // parsing hex number
+ tokens.push(parseInt(token, 16));
+ token = '';
+ } else {
+ // parsing hex UTF-16BE numbers
+ var str = [];
+ for (var i = 0, ii = token.length; i < ii; i += 4)
+ str.push(parseInt(token.substr(i, 4), 16));
+ tokens.push(String.fromCharCode.apply(String, str));
+ token = '';
+ }
}
} else {
token += String.fromCharCode(byte);
this.widths = properties.widths;
this.defaultWidth = properties.defaultWidth;
this.composite = properties.composite;
- this.toUnicode = properties.toUnicode;
this.hasEncoding = properties.hasEncoding;
this.fontMatrix = properties.fontMatrix;
// Trying to fix encoding using glyph CIDSystemInfo.
this.loadCidToUnicode(properties);
+ if (properties.toUnicode)
+ this.toUnicode = properties.toUnicode;
+ else
+ this.rebuildToUnicode(properties);
+
if (!file) {
// The file data is not specified. Trying to fix the font name
// to be used with the canvas.font.
return stringToArray(otf.file);
},
+ rebuildToUnicode: function font_rebuildToUnicode(properties) {
+ var map = [];
+ if (properties.composite) {
+ for (var i = properties.firstChar, ii = properties.lastChar; i <= ii; i++) {
+ // TODO missing map the character according font's CMap
+ var cid = i;
+ map[i] = this.cidToUnicode[cid];
+ }
+ } else {
+ for (var i = properties.firstChar, ii = properties.lastChar; i <= ii; i++) {
+ var glyph = properties.differences[i];
+ if (!glyph)
+ glyph = properties.baseEncoding[i];
+ if (!!glyph && (glyph in GlyphsUnicode))
+ map[i] = GlyphsUnicode[glyph]
+ }
+ }
+ this.toUnicode = map;
+ this.refreshToUnicode = function refreshToUnicode() {
+ this.font_rebuildToUnicode(properties);
+ };
+ },
+
loadCidToUnicode: function font_loadCidToUnicode(properties) {
if (properties.cidToGidMap) {
this.cidToUnicode = properties.cidToGidMap;
warn('Unsupported font type: ' + this.type);
break;
}
+
+ var unicodeChars = this.toUnicode ? this.toUnicode[charcode] : charcode;
+ if (typeof unicodeChars === 'number') {
+ unicodeChars = (unicodeChars >= 0x10000) ?
+ String.fromCharCode(0xD800 | ((unicodeChars - 0x10000) >> 10),
+ 0xDC00 | (unicodeChars & 0x3FF)) : String.fromCharCode(unicodeChars);
+ // TODO we probably don't need convert high/low surrogate... keeping for now
+ }
+
return {
- unicode: unicode,
+ fontChar: String.fromCharCode(unicode),
+ unicode: unicodeChars,
width: isNum(width) ? width : this.defaultWidth,
codeIRQueue: codeIRQueue
};