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

Check that TrueType (3, 0) cmap tables, for symbolic fonts, are sorted correctly (issue 13626) #13628

Merged
merged 2 commits into from
Jun 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,18 @@ class Font {
}
} else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
useTable = true;
canBreak = true;

let correctlySorted = true;
if (i < numTables - 1) {
const nextBytes = file.peekBytes(2),
nextPlatformId = int16(nextBytes[0], nextBytes[1]);
if (nextPlatformId < platformId) {
correctlySorted = false;
}
}
if (correctlySorted) {
canBreak = true;
}
}

if (useTable) {
Expand Down Expand Up @@ -1529,7 +1540,14 @@ class Font {
};
}

function sanitizeMetrics(file, header, metrics, numGlyphs, dupFirstEntry) {
function sanitizeMetrics(
file,
header,
metrics,
headTable,
numGlyphs,
dupFirstEntry
) {
if (!header) {
if (metrics) {
metrics.data = null;
Expand All @@ -1548,19 +1566,24 @@ class Font {
file.pos += 2; // max_extent
file.pos += 2; // caret_slope_rise
file.pos += 2; // caret_slope_run
file.pos += 2; // caret_offset
const caretOffset = file.getUint16();
file.pos += 8; // reserved
file.pos += 2; // format
let numOfMetrics = file.getUint16();

if (caretOffset !== 0) {
const macStyle = int16(headTable.data[44], headTable.data[45]);
if (!(macStyle & 2)) {
// Suppress OTS warnings about the `caretOffset` in the hhea-table.
header.data[22] = 0;
header.data[23] = 0;
}
}

if (numOfMetrics > numGlyphs) {
info(
"The numOfMetrics (" +
numOfMetrics +
") should not be " +
"greater than the numGlyphs (" +
numGlyphs +
")"
`The numOfMetrics (${numOfMetrics}) should not be ` +
`greater than the numGlyphs (${numGlyphs}).`
);
// Reduce numOfMetrics if it is greater than numGlyphs
numOfMetrics = numGlyphs;
Expand Down Expand Up @@ -2446,6 +2469,7 @@ class Font {
font,
tables.hhea,
tables.hmtx,
tables.head,
numGlyphsOut,
dupFirstEntry
);
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue13626.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/mozilla/pdf.js/files/6715502/test.pdf
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,13 @@
"rounds": 1,
"type": "eq"
},
{ "id": "issue13626",
"file": "pdfs/issue13626.pdf",
"md5": "68bc1c2459d56e8c33f5a12a88c9df7d",
"link": true,
"rounds": 1,
"type": "eq"
},
{ "id": "simpletype3font-text",
"file": "pdfs/simpletype3font.pdf",
"md5": "b374c7543920840c61999e9e86939f99",
Expand Down