Moving CID-0 encoding hack to fonts.js
This commit is contained in:
parent
078433fecd
commit
ab391c318d
60
fonts.js
60
fonts.js
@ -429,6 +429,9 @@ var Font = (function Font() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trying to fix encoding using glyph widths and CIDSystemInfo
|
||||||
|
this.fixWidths(properties);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
// The file data is not specified. Trying to fix the font name
|
// The file data is not specified. Trying to fix the font name
|
||||||
// to be used with the canvas.font.
|
// to be used with the canvas.font.
|
||||||
@ -1403,6 +1406,63 @@ var Font = (function Font() {
|
|||||||
return stringToArray(otf.file);
|
return stringToArray(otf.file);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fixWidths: function font_fixWidths(properties) {
|
||||||
|
var encoding = properties.encoding;
|
||||||
|
if (encoding[0])
|
||||||
|
return;
|
||||||
|
var glyphsWidths = properties.widths;
|
||||||
|
if (!glyphsWidths)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var cidSystemInfo = properties.cidSystemInfo;
|
||||||
|
var cidToUnicode;
|
||||||
|
if (cidSystemInfo) {
|
||||||
|
cidToUnicode = CIDToUnicodeMaps[cidSystemInfo.registry +
|
||||||
|
'-' + cidSystemInfo.ordering];
|
||||||
|
}
|
||||||
|
if (!cidToUnicode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
encoding[0] = { unicode: 0, width: 0 };
|
||||||
|
var glyph = 1, i, j;
|
||||||
|
for (i = 0; i < cidToUnicode.length; ++i) {
|
||||||
|
var unicode = cidToUnicode[i];
|
||||||
|
if (isArray(unicode)) {
|
||||||
|
var length = unicode.length;
|
||||||
|
if (glyph in glyphsWidths) {
|
||||||
|
for (j = 0; j < length; j++) {
|
||||||
|
encoding[unicode[j]] = {
|
||||||
|
unicode: unicode[j],
|
||||||
|
width: glyphsWidths[glyph]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glyph++;
|
||||||
|
} else if (typeof unicode === 'object') {
|
||||||
|
var fillLength = unicode.f;
|
||||||
|
if (fillLength) {
|
||||||
|
unicode = unicode.c;
|
||||||
|
for (j = 0; j < fillLength; ++j) {
|
||||||
|
if (!(glyph in glyphsWidths))
|
||||||
|
continue;
|
||||||
|
encoding[unicode] = {
|
||||||
|
unicode: unicode,
|
||||||
|
width: glyphsWidths[glyph]
|
||||||
|
};
|
||||||
|
unicode++;
|
||||||
|
glyph++;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
glyph += unicode.s;
|
||||||
|
} else if (unicode) {
|
||||||
|
encoding[unicode] = {
|
||||||
|
unicode: unicode,
|
||||||
|
width: glyphsWidths[glyph++]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
bindWorker: function font_bindWorker(data) {
|
bindWorker: function font_bindWorker(data) {
|
||||||
postMessage({
|
postMessage({
|
||||||
action: 'font',
|
action: 'font',
|
||||||
|
59
pdf.js
59
pdf.js
@ -4472,56 +4472,19 @@ var PartialEvaluator = (function partialEvaluator() {
|
|||||||
// Glyph ids are big-endian 2-byte values
|
// Glyph ids are big-endian 2-byte values
|
||||||
encoding = properties.encoding;
|
encoding = properties.encoding;
|
||||||
|
|
||||||
|
// CIDSystemInfo might help to match width and glyphs
|
||||||
|
var cidSystemInfo = dict.get('CIDSystemInfo');
|
||||||
|
if (isDict(cidSystemInfo)) {
|
||||||
|
properties.cidSystemInfo = {
|
||||||
|
registry: cidSystemInfo.get('Registry'),
|
||||||
|
ordering: cidSystemInfo.get('Ordering'),
|
||||||
|
supplement: cidSystemInfo.get('Supplement')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var cidToGidMap = dict.get('CIDToGIDMap');
|
var cidToGidMap = dict.get('CIDToGIDMap');
|
||||||
if (!cidToGidMap || !isRef(cidToGidMap)) {
|
if (!cidToGidMap || !isRef(cidToGidMap)) {
|
||||||
// trying to guess encoding from CIDSystemInfo
|
|
||||||
var cidSystemInfo = dict.get('CIDSystemInfo');
|
|
||||||
var cidToUnicode;
|
|
||||||
if (isDict(cidSystemInfo)) {
|
|
||||||
cidToUnicode = CIDToUnicodeMaps[
|
|
||||||
cidSystemInfo.get('Registry') + '-' +
|
|
||||||
cidSystemInfo.get('Ordering')];
|
|
||||||
}
|
|
||||||
if (cidToUnicode) {
|
|
||||||
encoding[0] = { unicode: 0, width: 0 };
|
|
||||||
var glyph = 1, i, j;
|
|
||||||
for (i = 0; i < cidToUnicode.length; ++i) {
|
|
||||||
var unicode = cidToUnicode[i];
|
|
||||||
if (isArray(unicode)) {
|
|
||||||
var length = unicode.length;
|
|
||||||
if (glyph in glyphsWidths) {
|
|
||||||
for (j = 0; j < length; j++) {
|
|
||||||
encoding[unicode[j]] = {
|
|
||||||
unicode: unicode[j],
|
|
||||||
width: glyphsWidths[glyph]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glyph++;
|
|
||||||
} else if (typeof unicode === 'object') {
|
|
||||||
var fillLength = unicode.f;
|
|
||||||
if (fillLength) {
|
|
||||||
unicode = unicode.c;
|
|
||||||
for (j = 0; j < fillLength; ++j) {
|
|
||||||
if (!(glyph in glyphsWidths))
|
|
||||||
continue;
|
|
||||||
encoding[unicode] = {
|
|
||||||
unicode: unicode,
|
|
||||||
width: glyphsWidths[glyph]
|
|
||||||
};
|
|
||||||
unicode++;
|
|
||||||
glyph++;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
glyph += unicode.s;
|
|
||||||
} else if (unicode) {
|
|
||||||
encoding[unicode] = {
|
|
||||||
unicode: unicode,
|
|
||||||
width: glyphsWidths[glyph++]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.create(GlyphsUnicode);
|
return Object.create(GlyphsUnicode);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user