Convert cid to Unicode when rebuilding Type 2 CID fonts encoded with non-Identity CMap
This commit is contained in:
parent
3131c7bfdb
commit
96f6fcf8ba
44
src/fonts.js
44
src/fonts.js
@ -3903,9 +3903,10 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
var usedUnicodes = [];
|
var usedUnicodes = [];
|
||||||
var unassignedUnicodeItems = [];
|
var unassignedUnicodeItems = [];
|
||||||
|
var toFontChar = this.cidToFontChar || this.toFontChar;
|
||||||
for (var i = 1; i < numGlyphs; i++) {
|
for (var i = 1; i < numGlyphs; i++) {
|
||||||
var cid = gidToCidMap[i] || i;
|
var cid = gidToCidMap[i] || i;
|
||||||
var unicode = this.toFontChar[cid];
|
var unicode = toFontChar[cid];
|
||||||
if (!unicode || typeof unicode !== 'number' ||
|
if (!unicode || typeof unicode !== 'number' ||
|
||||||
isSpecialUnicode(unicode) || unicode in usedUnicodes) {
|
isSpecialUnicode(unicode) || unicode in usedUnicodes) {
|
||||||
unassignedUnicodeItems.push(i);
|
unassignedUnicodeItems.push(i);
|
||||||
@ -3915,21 +3916,25 @@ var Font = (function FontClosure() {
|
|||||||
glyphs.push({ unicode: unicode, code: cid });
|
glyphs.push({ unicode: unicode, code: cid });
|
||||||
ids.push(i);
|
ids.push(i);
|
||||||
}
|
}
|
||||||
// trying to fit as many unassigned symbols as we can
|
// unassigned codepoints will never be used for non-Identity CMap
|
||||||
// in the range allocated for the user defined symbols
|
// because the input will be Unicode
|
||||||
var unusedUnicode = CMAP_GLYPH_OFFSET;
|
if (!this.cidToFontChar) {
|
||||||
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
|
// trying to fit as many unassigned symbols as we can
|
||||||
var i = unassignedUnicodeItems[j];
|
// in the range allocated for the user defined symbols
|
||||||
var cid = gidToCidMap[i] || i;
|
var unusedUnicode = CMAP_GLYPH_OFFSET;
|
||||||
while (unusedUnicode in usedUnicodes)
|
for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
|
||||||
unusedUnicode++;
|
var i = unassignedUnicodeItems[j];
|
||||||
if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE)
|
var cid = gidToCidMap[i] || i;
|
||||||
break;
|
while (unusedUnicode in usedUnicodes)
|
||||||
var unicode = unusedUnicode++;
|
unusedUnicode++;
|
||||||
this.toFontChar[cid] = unicode;
|
if (unusedUnicode >= CMAP_GLYPH_OFFSET + GLYPH_AREA_SIZE)
|
||||||
usedUnicodes[unicode] = true;
|
break;
|
||||||
glyphs.push({ unicode: unicode, code: cid });
|
var unicode = unusedUnicode++;
|
||||||
ids.push(i);
|
this.toFontChar[cid] = unicode;
|
||||||
|
usedUnicodes[unicode] = true;
|
||||||
|
glyphs.push({ unicode: unicode, code: cid });
|
||||||
|
ids.push(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.useToFontChar = true;
|
this.useToFontChar = true;
|
||||||
@ -4394,6 +4399,11 @@ var Font = (function FontClosure() {
|
|||||||
if (cidEncoding.indexOf('Identity-') !== 0) {
|
if (cidEncoding.indexOf('Identity-') !== 0) {
|
||||||
// input is already Unicode for non-Identity CMap encodings.
|
// input is already Unicode for non-Identity CMap encodings.
|
||||||
this.cidToUnicode = [];
|
this.cidToUnicode = [];
|
||||||
|
// For CIDFontType2, however, we need cid-to-Unicode conversion
|
||||||
|
// to rebuild cmap.
|
||||||
|
if (properties.type == 'CIDFontType2') {
|
||||||
|
this.cidToFontChar = cidToUnicodeMap;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// We don't have to do reverse conversions if the string is
|
// We don't have to do reverse conversions if the string is
|
||||||
// already CID.
|
// already CID.
|
||||||
@ -4494,6 +4504,8 @@ var Font = (function FontClosure() {
|
|||||||
var cid = this.unicodeToCID[charcode] || charcode;
|
var cid = this.unicodeToCID[charcode] || charcode;
|
||||||
width = this.widths[cid];
|
width = this.widths[cid];
|
||||||
vmetric = this.vmetrics && this.vmetrics[cid];
|
vmetric = this.vmetrics && this.vmetrics[cid];
|
||||||
|
fontCharCode = charcode;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
fontCharCode = this.toFontChar[charcode] || charcode;
|
fontCharCode = this.toFontChar[charcode] || charcode;
|
||||||
break;
|
break;
|
||||||
|
1
test/pdfs/ohkubo-SS04.pdf.link
Normal file
1
test/pdfs/ohkubo-SS04.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://www.sapid.org/html2/PDF-ja/ohkubo-SS04.pdf
|
@ -930,6 +930,13 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "ohkubo-ss04",
|
||||||
|
"file": "pdfs/ohkubo-SS04.pdf",
|
||||||
|
"md5": "b8c334073ff5be74fac1f36130943ea5",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "sfaa_japanese",
|
{ "id": "sfaa_japanese",
|
||||||
"file": "pdfs/SFAA_Japanese.pdf",
|
"file": "pdfs/SFAA_Japanese.pdf",
|
||||||
"md5": "b961bbc0d05bdd6d91041bca60ec8e8b",
|
"md5": "b961bbc0d05bdd6d91041bca60ec8e8b",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user