1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Remove glyph id's outside the range of valid glyphs.

OTS does not like invalid glyph ids in a camp table.
This commit is contained in:
Brendan Dahl 2015-12-02 16:47:20 -08:00
parent e93512f1eb
commit 87762afec4
4 changed files with 21 additions and 5 deletions

View file

@ -2798,11 +2798,15 @@ var Font = (function FontClosure() {
};
}
function getRanges(glyphs) {
function getRanges(glyphs, numGlyphs) {
// Array.sort() sorts by characters, not numerically, so convert to an
// array of characters.
var codes = [];
for (var charCode in glyphs) {
// Remove an invalid glyph ID mappings to make OTS happy.
if (glyphs[charCode] >= numGlyphs) {
continue;
}
codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
}
codes.sort(function fontGetRangesSort(a, b) {
@ -2831,8 +2835,8 @@ var Font = (function FontClosure() {
return ranges;
}
function createCmapTable(glyphs) {
var ranges = getRanges(glyphs);
function createCmapTable(glyphs, numGlyphs) {
var ranges = getRanges(glyphs, numGlyphs);
var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
var cmap = '\x00\x00' + // version
string16(numTables) + // numTables
@ -4335,7 +4339,7 @@ var Font = (function FontClosure() {
this.toFontChar = newMapping.toFontChar;
tables.cmap = {
tag: 'cmap',
data: createCmapTable(newMapping.charCodeToGlyphId)
data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
};
if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
@ -4473,7 +4477,8 @@ var Font = (function FontClosure() {
builder.addTable('OS/2', createOS2Table(properties,
newMapping.charCodeToGlyphId));
// Character to glyphs mapping
builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
numGlyphs));
// Font header
builder.addTable('head',
'\x00\x01\x00\x00' + // Version number