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.`
);

View File

@ -385,6 +385,7 @@
!issue9278.pdf
!annotation-text-without-popup.pdf
!annotation-underline.pdf
!issue13193.pdf
!annotation-underline-without-appearance.pdf
!issue269_2.pdf
!annotation-strikeout.pdf

BIN
test/pdfs/issue13193.pdf Normal file

Binary file not shown.

View File

@ -3095,6 +3095,12 @@
"link": true,
"type": "eq"
},
{ "id": "issue13193",
"file": "pdfs/issue13193.pdf",
"md5": "38cf058f58b7dc5dc54e1602580936a7",
"rounds": 1,
"type": "eq"
},
{ "id": "issue1655",
"file": "pdfs/issue1655r.pdf",
"md5": "569f48449ba57c15c4f9ade151a651c5",