-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Implement support for line annotations #8228
Conversation
/botio-linux preview |
/botio test |
The reference failures are expected since the border width is now taken into account when creating the container.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not really had time to review this properly yet, so I'm just adding quick drive-by comments for now.
The reference failures are expected since the border width is now taken into account when creating the container.
I'm not sure that I follow why this is expected, since you're still removing the border (but now in the display
layer instead). It seems to me that currently we're ignoring the border before any rendering occurs, but with this patch you are now doing it after instead, meaning that all of this code is now being (unnecessarily?) run: https://github.com/mozilla/pdf.js/blob/master/src/display/annotation_layer.js#L168.
Would it not make more sense to do e.g. something like this following diff instead: https://gist.github.com/Snuffleupagus/437b3073c3e587d8fca6507a30a574d5?
I might be totally off, but don't really understand the first patch!
TEST-UNEXPECTED-FAIL | test failed chrome has not responded in 120s
at the end of the test run is not expected and is likely to be related to #8217.
Hmm, this is a bit problematic and I think it points to Chrome having issues with (probably the SVG) added in this PR, since that's where the timeout occurs. Hence we need Chrome updated on the bot first, before we can move forward with this PR.
src/core/annotation.js
Outdated
@@ -956,6 +959,7 @@ var PopupAnnotation = (function PopupAnnotationClosure() { | |||
} | |||
|
|||
this.data.parentId = dict.getRaw('Parent').toString(); | |||
this.data.parentType = dict.get('Parent').get('Subtype').name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that parentItem
is defined just above, you can use that instead of getting the Parent
again here :-)
Also, in issue #7446 we learned that the Subtype
can be missing (or incorrect), hence it would be a good idea to some validation here to prevent bugs, e.g. like this instead:
var parentSubtype = parentItem.get('Subtype');
this.data.parentType = isName(parentSubtype) ? parentSubtype.name : null;
src/display/annotation_layer.js
Outdated
@@ -697,7 +704,7 @@ var PopupAnnotationElement = (function PopupAnnotationElementClosure() { | |||
|
|||
var selector = '[data-annotation-id="' + this.data.parentId + '"]'; | |||
var parentElement = this.layer.querySelector(selector); | |||
if (!parentElement) { | |||
if (!parentElement || IGNORE_TYPES.indexOf(this.data.parentType) >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible idea for a (general) follow-up PR:
Convert the code-base to use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes, and similarly for strings, to make these kind of checks easier to read in cases where you don't care about the index (with suitable polyfills of course).
Thank you for the comments! You raised some valid points and I agree that this may be improved, so I'll definitely look into that. |
The display layer is responsible for creating the HTML elements for the annotations from the core layer. If we need to ignore border styling for the containers of certain elements, the display layer should do so and not the core layer. I noticed this during the implementation of line annotations, for which we actually need the original border width in the display layer, even though we ignore it for the container. If we set the border style to zero in the core layer, this becomes impossible. To prevent this, this patch moves the container border removal code from the core layer to the display layer. This makes the core layer output the unchanged annotation data and lets the display layer remove any border styling if necessary.
313c177
to
e581240
Compare
/botio-linux preview |
/botio test |
I have resolved all the comments you added. The Chrome update also fixed the timeout issue, so I think we're good. Note that the remaining Linux failure is a known intermittent issue after the Chrome update which has nothing to do with this patch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay here!
I wanted some time to look through the surrounding code, to consider if there's a solution that didn't require using IGNORE_TYPES
(which feels slightly hacky). However, it seems that you already thought about this, since I'm not able to come up with something better :-)
r=me, with one optional comment, since the general approach seem fine to me. Thanks for the patch!
src/display/annotation_layer.js
Outdated
@@ -697,7 +706,7 @@ var PopupAnnotationElement = (function PopupAnnotationElementClosure() { | |||
|
|||
var selector = '[data-annotation-id="' + this.data.parentId + '"]'; | |||
var parentElement = this.layer.querySelector(selector); | |||
if (!parentElement) { | |||
if (!parentElement || IGNORE_TYPES.indexOf(this.data.parentType) >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Perhaps a micro-optimization, but how about moving the IGNORE_TYPES
check before doing querySelector
to avoid a potentially useless element look-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find! Fixed in the new commit.
@@ -955,6 +958,8 @@ var PopupAnnotation = (function PopupAnnotationClosure() { | |||
return; | |||
} | |||
|
|||
var parentSubtype = parentItem.get('Subtype'); | |||
this.data.parentType = isName(parentSubtype) ? parentSubtype.name : null; | |||
this.data.parentId = dict.getRaw('Parent').toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is completely out-of-scope for this PR, but it's something that I noticed which we might want try and address in a future PR.
Given that there are bad PDF files where annotations are not Ref
s, see e.g. PR #7570, this probably doesn't work very well in that (rare) case. Ideally I think that we probably want to somehow tap into the id
as generated above, but it might not be entirely simple given that annotations can be ordered arbitrarily.
Anyway, probably worth looking into later...
This patch implements support for line annotations. Other viewers only show the popup annotation when hovering over the line, which may have any orientation. To make this possible, we render an invisible line (SVG element) over the line on the canvas that acts as the trigger for the popup annotation. This invisible line has the same starting coordinates, ending coordinates and width of the line on the canvas.
e581240
to
e15a2ec
Compare
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/3ce5d85721b25eb/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/3ce5d85721b25eb/output.txt Total script time: 2.85 mins Published |
/botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/89c27df2a73b1da/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/b68d37e74c5a069/output.txt |
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/b68d37e74c5a069/output.txt Total script time: 23.14 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/89c27df2a73b1da/output.txt Total script time: 30.50 mins
|
/botio makeref |
From: Bot.io (Linux)ReceivedCommand cmd_makeref from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/90f0f4be58c00ac/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/c73e0a326145108/output.txt |
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/c73e0a326145108/output.txt Total script time: 22.51 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/90f0f4be58c00ac/output.txt Total script time: 28.78 mins
|
Implement support for line annotations
The commit messages contain more information about the changes.
Other unimplemented annotation types will require similar code. To prepare for this, https://github.com/mozilla/pdf.js/pull/8228/files#diff-1097e3b131ba22f8e8a6c2f20e3ab5ecR687 is an array.