Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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.`
);
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added test/pdfs/issue13193.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down