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

Refactor annotation flags code #6672

Merged
merged 1 commit into from
Nov 22, 2015

Conversation

timvandermeij
Copy link
Contributor

This patch makes it possible to set and get all possible flags that the PDF specification defines. Even though we do not support all possible annotation types and not all possible annotation flags yet, this general framework makes it easy to access all flags for each annotation such that annotation type implementations can use this information.

We add constants for all possible annotation flags such that we do not need to hardcode the flags in the code anymore. The isViewable() and isPrintable() methods are now easier to read. Additionally, unit tests have been added to ensure correct behavior.

This is another part of #5218.

I have tested this patch, both with displaying and with printing, with a corpus of 23 PDF files with different annotation types and annotation flags in them and observed no difference with the current master.

* @see {@link shared/util.js}
*/
setFlags: function Annotation_setFlags(flags) {
if (flags === (flags | 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: it might be a tiny bit simpler to understand this line if isInt is used here :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in the new commit.

@timvandermeij timvandermeij force-pushed the annotation-flags branch 2 times, most recently from 536e1ca to 2ef2af3 Compare November 21, 2015 22:59
@Snuffleupagus
Copy link
Collaborator

Unfortunately the simplifications of isPrintable is regressing issue4914.pdf, but the regression tests doesn't pick up on that. It appears that since some parts of the annotation code is placed in the viewer, we're not actually testing all aspects of annotations.

We might need to do something similar to PR #6619, but for annotations, in order to get better test-coverage.

Edit: Another PDF that's not currently working as intended in the regression tests is annotation-border-styles.pdf. It's obviously not the fault of this patch, but I just realized that our annotation testing is lacking quite a bit unfortunately.

@timvandermeij timvandermeij force-pushed the annotation-flags branch 2 times, most recently from 04a5d7c to 011b620 Compare November 21, 2015 23:50
This patch makes it possible to set and get all possible flags that the PDF specification defines. Even though we do not support all possible annotation types and not all possible annotation flags yet, this general framework makes it easy to access all flags for each annotation such that annotation type implementations can use this information.

We add constants for all possible annotation flags such that we do not need to hardcode the flags in the code anymore. The `isViewable()` and `isPrintable()` methods are now easier to read. Additionally, unit tests have been added to ensure correct behavior.

This is another part of mozilla#5218.
@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

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

@timvandermeij
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/588c1e0133bbfa1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/63129c9427608a3/output.txt

if (data.fieldType === 'Sig') {
warn('unimplemented annotation type: Widget signature');
this.setFlags(AnnotationFlag.HIDDEN);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a nice simplification, compared to the previous code!

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/63129c9427608a3/output.txt

Total script time: 18.51 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/588c1e0133bbfa1/output.txt

Total script time: 19.51 mins

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

Snuffleupagus added a commit that referenced this pull request Nov 22, 2015
@Snuffleupagus Snuffleupagus merged commit 97cb7ff into mozilla:master Nov 22, 2015
@Snuffleupagus
Copy link
Collaborator

Looks good, thanks for the patch!

@timvandermeij timvandermeij deleted the annotation-flags branch November 22, 2015 12:37
*/
setFlags: function Annotation_setFlags(flags) {
if (isInt(flags)) {
this.flags = flags;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this.flags instead of this.data.flags?
Only the data object is exposed with Page.getAnnotationsData method so this will remove the ability to read annotation flags from viewer/third-party code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be addressed by #6677.

iamkhush pushed a commit to iamkhush/pdf.js that referenced this pull request Dec 26, 2015
This PDF file (see issue 4914) originally regressed in PR 4318, and was subsequently fixed in PR 4915.

I added the PDF file as a (linked) test-case in PR 6481, in an effort to prevent regressions. Since we at that time didn't have the necessary framework in place, in order to correctly test annotations, this almost regressed *again* in PR mozilla#6672 (comment).

In that PDF file, some of the annotations are both printable and hidden, and should definitely *not* be visible on normal display. Hence this patch, which adds the `annotations` flag to the manifest in order to ensure that those annotations won't be rendered when `intent === 'display'`.
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.

4 participants