mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Convert cid to Unicode when rebuilding Type 2 CID fonts encoded with non-Identity CMap
This commit is contained in:
parent
3131c7bfdb
commit
96f6fcf8ba
3 changed files with 36 additions and 16 deletions
44
src/fonts.js
44
src/fonts.js
|
@ -3903,9 +3903,10 @@ var Font = (function FontClosure() {
|
|||
|
||||
var usedUnicodes = [];
|
||||
var unassignedUnicodeItems = [];
|
||||
var toFontChar = this.cidToFontChar || this.toFontChar;
|
||||
for (var i = 1; i < numGlyphs; i++) {
|
||||
var cid = gidToCidMap[i] || i;
|
||||
var unicode = this.toFontChar[cid];
|
||||
var unicode = toFontChar[cid];
|
||||
if (!unicode || typeof unicode !== 'number' ||
|
||||
isSpecialUnicode(unicode) || unicode in usedUnicodes) {
|
||||
unassignedUnicodeItems.push(i);
|
||||
|
@ -3915,21 +3916,25 @@ var Font = (function FontClosure() {
|
|||
glyphs.push({ unicode: unicode, code: cid });
|
||||
ids.push(i);
|
||||
}
|
||||
// trying to fit as many unassigned symbols as we can
|
||||
// in the range allocated for the user defined symbols
|
||||
var unusedUnicode = CMAP_GLYPH_OFFSET;
|
||||
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
|
||||
var i = unassignedUnicodeItems[j];
|
||||
var cid = gidToCidMap[i] || i;
|
||||
while (unusedUnicode in usedUnicodes)
|
||||
unusedUnicode++;
|
||||
if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE)
|
||||
break;
|
||||
var unicode = unusedUnicode++;
|
||||
this.toFontChar[cid] = unicode;
|
||||
usedUnicodes[unicode] = true;
|
||||
glyphs.push({ unicode: unicode, code: cid });
|
||||
ids.push(i);
|
||||
// unassigned codepoints will never be used for non-Identity CMap
|
||||
// because the input will be Unicode
|
||||
if (!this.cidToFontChar) {
|
||||
// trying to fit as many unassigned symbols as we can
|
||||
// in the range allocated for the user defined symbols
|
||||
var unusedUnicode = CMAP_GLYPH_OFFSET;
|
||||
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
|
||||
var i = unassignedUnicodeItems[j];
|
||||
var cid = gidToCidMap[i] || i;
|
||||
while (unusedUnicode in usedUnicodes)
|
||||
unusedUnicode++;
|
||||
if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE)
|
||||
break;
|
||||
var unicode = unusedUnicode++;
|
||||
this.toFontChar[cid] = unicode;
|
||||
usedUnicodes[unicode] = true;
|
||||
glyphs.push({ unicode: unicode, code: cid });
|
||||
ids.push(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.useToFontChar = true;
|
||||
|
@ -4394,6 +4399,11 @@ var Font = (function FontClosure() {
|
|||
if (cidEncoding.indexOf('Identity-') !== 0) {
|
||||
// input is already Unicode for non-Identity CMap encodings.
|
||||
this.cidToUnicode = [];
|
||||
// For CIDFontType2, however, we need cid-to-Unicode conversion
|
||||
// to rebuild cmap.
|
||||
if (properties.type == 'CIDFontType2') {
|
||||
this.cidToFontChar = cidToUnicodeMap;
|
||||
}
|
||||
} else {
|
||||
// We don't have to do reverse conversions if the string is
|
||||
// already CID.
|
||||
|
@ -4494,6 +4504,8 @@ var Font = (function FontClosure() {
|
|||
var cid = this.unicodeToCID[charcode] || charcode;
|
||||
width = this.widths[cid];
|
||||
vmetric = this.vmetrics && this.vmetrics[cid];
|
||||
fontCharCode = charcode;
|
||||
break;
|
||||
}
|
||||
fontCharCode = this.toFontChar[charcode] || charcode;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue