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

Fix bad truetype loca tables. #12186

Merged
merged 1 commit into from
Aug 11, 2020
Merged

Conversation

brendandahl
Copy link
Contributor

@brendandahl brendandahl commented Aug 7, 2020

Some fonts have loca tables that aren't sorted or use 0 as an offset to
signal a missing glyph. This fixes the bad loca tables by sorting them
and then rewriting the loca table and potentially re-ordering the glyf
table to match.

Fixes #11131, #11561
and
https://bugzilla.mozilla.org/show_bug.cgi?id=1650302
https://bugzilla.mozilla.org/show_bug.cgi?id=846014
https://bugzilla.mozilla.org/show_bug.cgi?id=844092

@brendandahl
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Aug 7, 2020

From: Bot.io (Linux m4)


Received

Command cmd_test from @brendandahl received. Current queue size: 0

Live output at: http://54.67.70.0:8877/51f7b098febb263/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 7, 2020

From: Bot.io (Windows)


Received

Command cmd_test from @brendandahl received. Current queue size: 0

Live output at: http://54.215.176.217:8877/d27ba7b7c878286/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 7, 2020

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/51f7b098febb263/output.txt

Total script time: 27.20 mins

  • Font tests: Passed
  • Unit tests: FAILED
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/51f7b098febb263/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Aug 7, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/d27ba7b7c878286/output.txt

Total script time: 30.13 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/d27ba7b7c878286/reftest-analyzer.html#web=eq.log

@Snuffleupagus
Copy link
Collaborator

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Aug 8, 2020

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/4aee4742d547f8a/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 8, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/4aee4742d547f8a/output.txt

Total script time: 3.46 mins

Published

Comment on lines 2075 to 2081
// Now the offsets are sorted, calculate the end offset of each glyph.
for (i = 0; i < numGlyphs; i++) {
locaEntries[i].endOffset = locaEntries[i + 1].offset;
}
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Aug 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean that the last loca-table entry will always have a zero endOffset, i.e. locaEntries[numGlyphs].endOffset === 0; is that not a problem?

Unless I'm overlooking something here, this means that sanitizeGlyph will just reject the glyph since it's deemed empty!?


Edit: Naively, I'd expect that adding something like the below might work, but I could also be completely wrong :-)
locaEntries[numGlyphs].endOffset = oldGlyfDataLength - locaEntries[numGlyphs].offset;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing since there are numGlyphs + 1 loca entries. Down below we don't iterate over the last loca entry (i < numGlyphs), but it's data is effectively saved in the previous entry when endOffset is read here.

I think I'll add some more comments, and maybe change the above i <= numGlyphs to i < numGlyphs + 1 to make it more explicit.


// The spec says the offsets should be in ascending order, however
// this is not true for some fonts or they use the offset of 0 to mark a
// glyph as missing. OTS requires the offsets in order and not to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Looks like a missing "to be" here, i.e. it probably should read:
// glyph as missing. OTS requires the offsets to be in order and not to

Some fonts have loca tables that aren't sorted or use 0 as an offset to
signal a missing glyph. This fixes the bad loca tables by sorting them
and then rewriting the loca table and potentially re-ordering the glyf
table to match.

Fixes mozilla#11131 and bug 1650302.
@brendandahl
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @brendandahl received. Current queue size: 0

Live output at: http://54.215.176.217:8877/bf371e99f6beef8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @brendandahl received. Current queue size: 0

Live output at: http://54.67.70.0:8877/48a6fbd7d69dca4/output.txt

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, with passing tests; really nice work fixing a bunch of font bugs all at once!

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/48a6fbd7d69dca4/output.txt

Total script time: 27.03 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/48a6fbd7d69dca4/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/bf371e99f6beef8/output.txt

Total script time: 29.11 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/bf371e99f6beef8/reftest-analyzer.html#web=eq.log

@brendandahl
Copy link
Contributor Author

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @brendandahl received. Current queue size: 0

Live output at: http://54.67.70.0:8877/2c9ac166d2bdae6/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @brendandahl received. Current queue size: 0

Live output at: http://54.215.176.217:8877/72c9b95dea13939/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/2c9ac166d2bdae6/output.txt

Total script time: 25.25 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/72c9b95dea13939/output.txt

Total script time: 29.73 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@brendandahl brendandahl merged commit 7fb01f9 into mozilla:master Aug 11, 2020
@brendandahl
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Certain PDF displays with Scrambled Text in PDF.js
4 participants