1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 01:28:06 +02:00

Fuzzy-match the fontName, for TrueType Collection fonts, where the "name"-table is wrong (issue 13193)

The fontName, as defined in the PDF document, cannot be found in *any* of the "name"-tables in the TrueType Collection font. To work-around that, this patch adds a *fallback* code-path to allow using an approximately matching fontName rather than outright failing.
This commit is contained in:
Jonas Jenwald 2021-04-07 14:06:22 +02:00
parent 6ddc297170
commit f986ccdf0e
4 changed files with 37 additions and 2 deletions

View file

@ -1554,6 +1554,8 @@ var Font = (function FontClosure() {
function readTrueTypeCollectionData(ttc, fontName) {
const { numFonts, offsetTable } = readTrueTypeCollectionHeader(ttc);
const fontNameParts = fontName.split("+");
let fallbackData;
for (let i = 0; i < numFonts; i++) {
ttc.pos = (ttc.start || 0) + offsetTable[i];
@ -1569,16 +1571,42 @@ var Font = (function FontClosure() {
for (let j = 0, jj = nameTable.length; j < jj; j++) {
for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
const nameEntry = nameTable[j][k];
if (nameEntry && nameEntry.replace(/\s/g, "") === fontName) {
const nameEntry =
nameTable[j][k] && nameTable[j][k].replace(/\s/g, "");
if (!nameEntry) {
continue;
}
if (nameEntry === fontName) {
return {
header: potentialHeader,
tables: potentialTables,
};
}
if (fontNameParts.length < 2) {
continue;
}
for (const part of fontNameParts) {
if (nameEntry === part) {
fallbackData = {
name: part,
header: potentialHeader,
tables: potentialTables,
};
}
}
}
}
}
if (fallbackData) {
warn(
`TrueType Collection does not contain "${fontName}" font, ` +
`falling back to "${fallbackData.name}" font instead.`
);
return {
header: fallbackData.header,
tables: fallbackData.tables,
};
}
throw new FormatError(
`TrueType Collection does not contain "${fontName}" font.`
);