mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Convert uniXXXX
glyph names to proper ones when building the charCodeToGlyphId
map for TrueType fonts (bug 1132849, issue 6893, issue 6894)
This patch adds a `getUnicodeForGlyph` helper function, which is used to recover Unicode values for non-standard glyph names. Some PDF generators, e.g. Scribus PDF, use improper `uniXXXX` glyph names which breaks the glyph mapping. We can avoid this by converting them to "standard" glyph names instead. Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1132849. Fixes 6893. Fixes 6894.
This commit is contained in:
parent
147598417c
commit
dfe9015a43
6 changed files with 96 additions and 10 deletions
|
@ -65,6 +65,36 @@
|
|||
return code;
|
||||
}
|
||||
|
||||
function getUnicodeForGlyph(name, glyphsUnicodeMap) {
|
||||
var unicode = glyphsUnicodeMap[name];
|
||||
if (unicode !== undefined) {
|
||||
return unicode;
|
||||
}
|
||||
if (!name) {
|
||||
return -1;
|
||||
}
|
||||
// Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
|
||||
if (name[0] === 'u') {
|
||||
var nameLen = name.length, hexStr;
|
||||
|
||||
if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
|
||||
hexStr = name.substr(3);
|
||||
} else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
|
||||
hexStr = name.substr(1);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
// Check for upper-case hexadecimal characters, to avoid false positives.
|
||||
if (hexStr === hexStr.toUpperCase()) {
|
||||
unicode = parseInt(hexStr, 16);
|
||||
if (unicode >= 0) {
|
||||
return unicode;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
var UnicodeRanges = [
|
||||
{ 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
|
||||
{ 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
|
||||
|
@ -1612,4 +1642,5 @@
|
|||
exports.reverseIfRtl = reverseIfRtl;
|
||||
exports.getUnicodeRangeFor = getUnicodeRangeFor;
|
||||
exports.getNormalizedUnicodes = getNormalizedUnicodes;
|
||||
exports.getUnicodeForGlyph = getUnicodeForGlyph;
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue