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

[api-minor] Remove the default factories, used to initialize various layers, in the viewer #15811

Merged
merged 9 commits into from
Dec 18, 2022

Conversation

Snuffleupagus
Copy link
Collaborator

The purpose of this patch series is to reduce indirection, and the amount of code that we need to maintain, related to the various layers used in the viewer. Please refer to the individual commit messages for additional details.

@Snuffleupagus Snuffleupagus marked this pull request as ready for review December 12, 2022 13:57
@Snuffleupagus Snuffleupagus force-pushed the rm-web-default-factory branch 2 times, most recently from e2b128d to 9c26a6e Compare December 14, 2022 14:33
@mozilla mozilla deleted a comment from pdfjsbot Dec 14, 2022
@mozilla mozilla deleted a comment from pdfjsbot Dec 14, 2022
@mozilla mozilla deleted a comment from pdfjsbot Dec 14, 2022
@mozilla mozilla deleted a comment from pdfjsbot Dec 14, 2022
@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/e1efd4165691eb0/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/8d2ec2b6fbbff17/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/8d2ec2b6fbbff17/output.txt

Total script time: 25.70 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 6
  different first/second rendering: 1

Image differences available at: http://54.241.84.105:8877/8d2ec2b6fbbff17/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/e1efd4165691eb0/output.txt

Total script time: 31.81 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 17
  different first/second rendering: 1

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

@timvandermeij
Copy link
Contributor

timvandermeij commented Dec 17, 2022

I'm happy about getting rid of this what I also experienced as unnecessary indirection. I'll do my best to review this during the weekend. Am I correct that third-party users should now simply set the relevant TextLayerMode/AnnotationMode settings in order to toggle text/annotation (and therefore struct tree/XFA/editor) layers since it cannot be toggled via the component constructor anymore?

I'm a little bit concerned about if this will break third party usage since we also had to edit the component examples here, so I'll have to think about if [api-minor] is appropriate here since the components were intended to be more stable than the regular viewer. I would feel much better about this patch if we could replace the factory endpoints with dummies that only issue a deprecation warning for let's say a release or two and simply do nothing else. That way at least current usages don't outright break. Note that that would allow us to remove everything else (interfaces and internal usage) but only keep the externally-facing objects used in the component constructor with a deprecation warning for the time being.

@Snuffleupagus
Copy link
Collaborator Author

I'm happy about getting rid of this what I also experienced as unnecessary indirection. I'll do my best to review this during the weekend.

Thank you!

Am I correct that third-party users should now simply set the relevant TextLayerMode/AnnotationMode settings in order to toggle text/annotation (and therefore struct tree/XFA/editor) layers since it cannot be toggled via the component constructor anymore?

Correct, but please note that it only applies to the "pageviewer" example and that the "simpleviewer"/"singlepageviewer" examples are completely unaffected here.
Furthermore, note how PDFPageView currently needs both options and factories specified in order for things to work; see

* @property {IPDFTextLayerFactory} [textLayerFactory]
* @property {number} [textLayerMode] - Controls if the text layer used for
* selection and searching is created. The constants from {TextLayerMode}
* should be used. The default value is `TextLayerMode.ENABLE`.
* @property {number} [annotationMode] - Controls if the annotation layer is
* created, and if interactive form elements or `AnnotationStorage`-data are
* being rendered. The constants from {@link AnnotationMode} should be used;
* see also {@link RenderParameters} and {@link GetOperatorListParameters}.
* The default value is `AnnotationMode.ENABLE_FORMS`.
* @property {IPDFAnnotationLayerFactory} [annotationLayerFactory]
* @property {IPDFAnnotationEditorLayerFactory} [annotationEditorLayerFactory]
* @property {IPDFXfaLayerFactory} [xfaLayerFactory]
* @property {IPDFStructTreeLayerFactory} [structTreeLayerFactory]
* @property {Object} [textHighlighterFactory]

I'm a little bit concerned about if this will break third party usage since we also had to edit the component examples here, so I'll have to think about if [api-minor] is appropriate here since the components were intended to be more stable than the regular viewer.

That's a fair comment; although it (as mentioned above) only applies to the "pageviewer" example.

I would feel much better about this patch if we could replace the factory endpoints with dummies that only issue a deprecation warning for let's say a release or two and simply do nothing else. That way at least current usages don't outright break.

OK, how about if I just add dummy factories in the pdf_viewer.component.js file where we simply throw when they're invoked (since that can't be missed and forces users to adjust)?

@timvandermeij
Copy link
Contributor

timvandermeij commented Dec 18, 2022

OK, how about if I just add dummy factories in the pdf_viewer.component.js file where we simply throw when they're invoked (since that can't be missed and forces users to adjust)?

Let's do that so that if this is being used (and fortunately that should be very limited given that only one of the examples is affected by this, and I therefore agree that this is [api-minor]) that we at least give out a useful error message that suggests how users should adapt their code. This can then be removed after a couple of releases, but it does give users a bit more pointers on how to change their code since I'm afraid not doing so could lead to e.g. issues being opened here with questions about the disappearance of those factories.

…and into `PDFPageView`

By moving this code the "pageviewer"-component example will become slightly more usable on its own, it may simplify a future addition of XFA Foreground document support, and finally also serves as preparation for the following patches.
Currently we'll only initialize and render the `annotationEditorLayer` once the regular `annotationLayer` has been rendered.
While it obviously makes sense to render the `annotationEditorLayer` *last*, the way that the code is currently written means that if a third-party user disables the `annotationLayer` then the editing-functionality indirectly becomes disabled as well.
Given that this seems like a somewhat arbitrary limitation, this patch simply decouples these two layers while still keeping the rendering order consistent.
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `annotationEditorLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `annotationLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `structTreeLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `textHighlighterFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `textLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
Please note that this functionality has never really mattered for the Firefox PDF Viewer, the GENERIC viewer, or even the "simpleviewer"/"singlepageviewer" component-examples. Hence, in practice this means that only the "pageviewer" component-example[1] have ever really utilized this.

Using factories to initialize various layers in the viewer, rather than simply invoking the relevant code directly, seems (at least to me) like a somewhat roundabout way of doing things.
Not only does this lead to more code, both to write and maintain, but since many of the layers have common parameters (e.g. an `AnnotationStorage`-instance) there's also some duplication.

Hence this patch, which removes the `xfaLayerFactory` and instead uses a lookup-function in the `PDFPageView`-class to access the external viewer-properties as necessary.
Note that this should even be an improvement for the "pageviewer" component-example, since most layers will now work by default rather than require manual configuration.

---
[1] In practice we generally suggest using the "simpleviewer", or "singlepageviewer", since it does *most* things out-of-the-box and given that a lot of functionality really require *a viewer* and not just a single page in order to work.
This uses a simple version number check, to prevent breakage if the example is used with older PDF.js versions.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/6cf574df125849d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/6cf574df125849d/output.txt

Total script time: 1.25 mins

Published

@timvandermeij
Copy link
Contributor

/botio integrationtest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/93704e70ee9da6e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/23d6d07720bbe76/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/93704e70ee9da6e/output.txt

Total script time: 4.29 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/23d6d07720bbe76/output.txt

Total script time: 11.97 mins

  • Integration Tests: FAILED

@timvandermeij timvandermeij merged commit 6a9a567 into mozilla:master Dec 18, 2022
@timvandermeij
Copy link
Contributor

Looks really good to me; thank you for simplifying this!

@Snuffleupagus Snuffleupagus deleted the rm-web-default-factory branch December 18, 2022 23:43
@Snuffleupagus
Copy link
Collaborator Author

Looks really good to me; thank you for simplifying this!

Thanks for the review!

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.

3 participants