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

Fixed #5927 - Now remembers page rotation on reload #5949

Closed
wants to merge 1 commit into from
Closed

Fixed #5927 - Now remembers page rotation on reload #5949

wants to merge 1 commit into from

Conversation

mbbaig
Copy link
Contributor

@mbbaig mbbaig commented Apr 19, 2015

Fix for #5927

@timvandermeij
Copy link
Contributor

/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/4b6e97818553124/output.txt

@@ -1786,7 +1789,8 @@ window.addEventListener('updateviewarea', function () {
'page': location.pageNumber,
'zoom': location.scale,
'scrollLeft': location.left,
'scrollTop': location.top
'scrollTop': location.top,
'pageRotation': PDFViewerApplication.pdfViewer.pagesRotation
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should add rotation: this._pagesRotation at pdf_viewer.js#L572 instead, and change this line to 'rotation': location.rotation.

@Snuffleupagus
Copy link
Collaborator

When testing this locally, and in the preview, the following is printed in the console:

"pdfViewSetScale: '0' is an unknown zoom value." viewer.js:4483:1

@@ -902,6 +902,9 @@ var PDFViewerApplication = {
var left = store.get('scrollLeft', '0');
var top = store.get('scrollTop', '0');

self.pageRotation = store.get('pageRotation', '0');
self.pdfViewer.pagesRotation = self.pageRotation;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately this won't work, since it breaks the thumbnails (and it's probably related to the console error). I believe that you need to use PDFViewerApplication.rotatePages instead, see viewer.js#L1326.

Edit: To avoid unnecessary operations, you should probably do e.g.

var rotation = store.get('rotation', '0');
if (rotation !== self.pageRotation) {
  self.rotatePages(rotation);
}

Edit2: Also, just calling PDFViewerApplication.rotatePages here would cause unnecessary rendering/scrolling, so we might want to modify that function slightly to be able to avoid that.

@Snuffleupagus
Copy link
Collaborator

A more general question: I'm well aware that rotation isn't specified in the "Open parameters", but do we want to expose it as a hash parameter?

@mbbaig
Copy link
Contributor Author

mbbaig commented Apr 20, 2015

I made all of the changes mentioned.

I changed the PDFViewerApplication.rotatePages function to the following:

rotatePages: function pdfViewRotatePages(delta) {
    this.pageRotation = (this.pageRotation + 360 + delta) % 360;
    this.pdfViewer.pagesRotation = this.pageRotation;
    this.pdfThumbnailViewer.pagesRotation = this.pageRotation;

    this.forceRendering();
  }

As for the error. It occurs because this._currentScaleValue is set to '0'. Here is the location pdf_viewer.js#L201

I can't see where that is being set to '0'.

@mbbaig
Copy link
Contributor Author

mbbaig commented Apr 20, 2015

@Snuffleupagus I think exposing the rotation as a parameter couldn't hurt. It would also make the code consistent here viewer.js#905. We could simply add rotation into storedHash

@@ -197,7 +197,6 @@ var PDFViewer = (function pdfViewer() {
var page = this.pages[i];
page.update(page.scale, rotation);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is unrelated to the patch, please revert it.

@Snuffleupagus
Copy link
Collaborator

I changed the PDFViewerApplication.rotatePages function to the following:

I'm sorry, but changing it in this way will first of all break other functionality, and second of all not actually achieve the desired goal! What you should do is e.g. something like this:

rotatePages: function pdfViewRotatePages(delta, noRendering) {
  var pageNumber = this.page;
  this.pageRotation = (this.pageRotation + 360 + delta) % 360;
  this.pdfViewer.pagesRotation = this.pageRotation;
  this.pdfThumbnailViewer.pagesRotation = this.pageRotation;

  if (!noRendering) {
    this.forceRendering();

    this.pdfViewer.scrollPageIntoView(pageNumber);
  }
},

Then you can call self.rotatePage(rotation, true) when you've read the parameter from storage.


As for the error. It occurs because this._currentScaleValue is set to '0'. Here is the location pdf_viewer.js#L201
I can't see where that is being set to '0'.

You are probably trying to change the rotation before the document/viewer has been properly initialized.

@mbbaig
Copy link
Contributor Author

mbbaig commented Apr 20, 2015

@Snuffleupagus updated to code to your specifications moved to code to after init so no more error.

@Snuffleupagus
Copy link
Collaborator

moved to code to after init so no more error.

Unfortunately I don't think that is going to work correctly either, since I still believe that you need to set the rotation before setInitialView/setHash is called for the position to actually be correct. More investigation/debugging seems necessary here, unfortunately.

@@ -901,6 +902,12 @@ var PDFViewerApplication = {
store.get('zoom', self.pdfViewer.currentScale);
var left = store.get('scrollLeft', '0');
var top = store.get('scrollTop', '0');
rotation = store.get('rotation', '0');

self.setScale(DEFAULT_SCALE, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am now setting the scale and moved the code back to its original spot. There is no error. Can this be considered a viable solution?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be considered a viable solution?

In my opinion, no. This patch tries to add a minor feature, hence I don't think that unconditionally triggering an unnecessary rendering operation during every document load is a particularly good thing to do.

Given that the error isn't really a breaking error, but just a console message, I'd remove this line and try something else instead: Try changing https://github.com/mozilla/pdf.js/blob/master/web/pdf_viewer.js#L201 to

if (this._currentScale !== UNKNOWN_SCALE)
  this._setScale(this._currentScaleValue, true);
}

If this seem to work: please make sure that you test the patch thoroughly, to ensure first of all that it does not regress other functionality, and second of all that the rotation works as intended!

@mbbaig
Copy link
Contributor Author

mbbaig commented Apr 24, 2015

updated and tested. seems to work fine with no errors

var rotation = store.get('rotation', '0') | 0;

if (rotation !== self.pageRotation) {
self.rotatePages(rotation,true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add a space after the ,, i.e., self.rotatePages(rotation, true);

Optimized code for rotation bug
@xlc
Copy link
Contributor

xlc commented Jun 9, 2015

@Snuffleupagus Can you have a look and maybe merge this?

@@ -198,7 +198,9 @@ var PDFViewer = (function pdfViewer() {
page.update(page.scale, rotation);
}

this._setScale(this._currentScaleValue, true);
if (this._currentScale !== UNKNOWN_SCALE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change needed?

@brendandahl
Copy link
Contributor

Needs a rebase and comments addressed.

@timvandermeij
Copy link
Contributor

Closing in favor of #6980.

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.

None yet

6 participants