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

Slightly refactor the fontRef handling in PartialEvaluator_loadFont (issue 7403 and issue 7402) #7347

Merged
merged 3 commits into from
Jul 23, 2016
Merged

Slightly refactor the fontRef handling in PartialEvaluator_loadFont (issue 7403 and issue 7402) #7347

merged 3 commits into from
Jul 23, 2016

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented May 23, 2016

Originally, I was just going to change this code to use Ref_toString in a couple more places. When I started reading the code, I figured that it wouldn't hurt to clean up a couple of comments. While doing this, I noticed that the logic for the (rare) isDict(fontRef) case could do with a few improvements.

There should be no functional changes with this patch, but given the added reference checks, we will now avoid bogus Refs when resolving font aliases. In practice, I don't think the current code has caused issues, but it seems good to clean this up to prevent any future problems. As issue #7403 shows, there're issues with the current code.

Note that the only thing that this patch will change, is the font.loadedName in the case where a fontRef is a reference and the font doesn't have a descriptor. Previously for fontRef = Ref(4, 0) we'd get font.loadedName = 'g_d0_f4_0', and with this patch font.loadedName = g_d0_f4R, which is actually one character shorted in most cases. (Given that Ref_toString contains an optimization for the gen === 0 case, which is by far the most common gen value.)

In the already existing fallback case, where the fontName is used to when creating the font.loadedName, we allow any alphanumeric character. Hence I don't see how (as mentioned above) e.g. font.loadedName = g_d0_f4R would be an issue here.

Edit: This also fixes #7403 and #7402.

@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/e8857c99c118ed5/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/9f6d1be36b6075f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/e8857c99c118ed5/output.txt

Total script time: 21.35 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/9f6d1be36b6075f/output.txt

Total script time: 27.62 mins

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

@Snuffleupagus
Copy link
Collaborator Author

/botio-linux lint

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/9e739d778b4dccf/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/9e739d778b4dccf/output.txt

Total script time: 1.21 mins

  • Lint: Passed

@Snuffleupagus Snuffleupagus changed the title Slightly refactor the fontRef handling in PartialEvaluator_loadFont Slightly refactor the fontRef handling in PartialEvaluator_loadFont (issue 7403) Jun 11, 2016
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/4c32a3f426453c4/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/dc36290a342a652/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/4c32a3f426453c4/output.txt

Total script time: 22.51 mins

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

Image differences available at: http://107.22.172.223:8877/4c32a3f426453c4/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/dc36290a342a652/output.txt

Total script time: 27.80 mins

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

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

@Snuffleupagus Snuffleupagus changed the title Slightly refactor the fontRef handling in PartialEvaluator_loadFont (issue 7403) Slightly refactor the fontRef handling in PartialEvaluator_loadFont (issue 7403 and issue 7402) Jun 17, 2016
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/5ad3d68f90815c1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/b1a39b6d552852a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/b1a39b6d552852a/output.txt

Total script time: 21.93 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/5ad3d68f90815c1/output.txt

Total script time: 27.82 mins

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

@timvandermeij
Copy link
Contributor

@brendandahl Do you have time to review this PR?

@Snuffleupagus
Copy link
Collaborator Author

@brendandahl Do you have time to review this PR?

I'd guess that both Brendan and Yury are currently at https://wiki.mozilla.org/All_Hands/2016_London, so if anyone else wants to review this, feel free to :-)

@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/e0cf8d88de4824c/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/310cbb64ac3adba/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/310cbb64ac3adba/output.txt

Total script time: 21.97 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/e0cf8d88de4824c/output.txt

Total script time: 27.71 mins

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

@Snuffleupagus
Copy link
Collaborator Author

The PR was rebased to fix a merge conflict in test/pdfs/.gitignore.

…t` (issue 7403 and issue 7402)

Originally, I was just going to change this code to use `Ref_toString` in a couple more places. When I started reading the code, I figured that it wouldn't hurt to clean up a couple of comments. While doing this, I noticed that the logic for the (rare) `isDict(fontRef)` case could do with a few improvements.

There should be no functional changes with this patch, but given the added reference checks, we will now avoid bogus `Ref`s when resolving font aliases. In practice, as issue 7403 shows, the current code can break certain PDF files even if it's very rare.

Note that the only thing that this patch will change, is the `font.loadedName` in the case where a `fontRef` is a reference *and* the font doesn't have a descriptor. Previously for `fontRef = Ref(4, 0)` we'd get `font.loadedName = 'g_d0_f4_0'`, and with this patch `font.loadedName = g_d0_f4R`, which is actually one character shorted in most cases. (Given that `Ref_toString` contains an optimization for the `gen === 0` case, which is by far the most common `gen` value.)

In the already existing fallback case, where the `fontName` is used to when creating the `font.loadedName`, we allow any alphanumeric character. Hence I don't see how (as mentioned above) e.g. `font.loadedName = g_d0_f4R` would be an issue here.
…osed to `Ref`s, to prevent re-rendering after `cleanup` from breaking (issue 7403 and issue 7402)

Fonts that are not referenced by `Ref`s are very uncommon in practice, but it can unfortunately happen. In this case, we're currently not caching them in the usual way, i.e. by `Ref`, which leads to failures when a page is rendered after `cleanup` has run.
The simplest solution would have been to remove the `font.translated` workaround, but since this would have meant loading these kind of fonts over and over, the patch attempts to be a bit clever about this situation.

Note that if we instead loaded fonts per *page*, instead of per document, this issue wouldn't have existed.
@Snuffleupagus
Copy link
Collaborator Author

The PR was rebased to fix a merge conflict in test/pdfs/.gitignore.

@brendandahl
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/ac1028e9e801155/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/795021fb44cb055/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/795021fb44cb055/output.txt

Total script time: 22.73 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/ac1028e9e801155/output.txt

Total script time: 27.02 mins

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

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

Successfully merging this pull request may close these issues.

Text glyphs are scrambled
4 participants