Merge pull request #4055 from Snuffleupagus/fix-thumbnail-rotation-regression

Fix thumbnail rotation regression
This commit is contained in:
Brendan Dahl 2014-01-02 10:39:13 -08:00
commit d005353115
2 changed files with 18 additions and 13 deletions

View File

@ -29,7 +29,7 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport) {
this.pdfPage = undefined; this.pdfPage = undefined;
this.viewport = defaultViewport; this.viewport = defaultViewport;
this.pdfPageRotate = defaultViewport.rotate; this.pdfPageRotate = defaultViewport.rotation;
this.rotation = 0; this.rotation = 0;
this.pageWidth = this.viewport.width; this.pageWidth = this.viewport.width;
@ -66,20 +66,16 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport) {
this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) { this.setPdfPage = function thumbnailViewSetPdfPage(pdfPage) {
this.pdfPage = pdfPage; this.pdfPage = pdfPage;
this.pdfPageRotate = pdfPage.rotate; this.pdfPageRotate = pdfPage.rotate;
this.viewport = pdfPage.getViewport(1); var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
this.viewport = pdfPage.getViewport(1, totalRotation);
this.update(); this.update();
}; };
this.update = function thumbnailViewUpdate(rot) { this.update = function thumbnailViewUpdate(rotation) {
if (!this.pdfPage) { if (rotation !== undefined) {
return; this.rotation = rotation;
} }
var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
if (rot !== undefined) {
this.rotation = rot;
}
var totalRotation = (this.rotation + this.pdfPage.rotate) % 360;
this.viewport = this.viewport.clone({ this.viewport = this.viewport.clone({
scale: 1, scale: 1,
rotation: totalRotation rotation: totalRotation
@ -179,8 +175,17 @@ var ThumbnailView = function thumbnailView(container, id, defaultViewport) {
}; };
this.setImage = function thumbnailViewSetImage(img) { this.setImage = function thumbnailViewSetImage(img) {
if (this.hasImage || !img) if (!this.pdfPage) {
var promise = PDFView.getPage(this.id);
promise.then(function(pdfPage) {
this.setPdfPage(pdfPage);
this.setImage(img);
}.bind(this));
return; return;
}
if (this.hasImage || !img) {
return;
}
this.renderingState = RenderingStates.FINISHED; this.renderingState = RenderingStates.FINISHED;
var ctx = this.getPageDrawContext(); var ctx = this.getPageDrawContext();
ctx.drawImage(img, 0, 0, img.width, img.height, ctx.drawImage(img, 0, 0, img.width, img.height,

View File

@ -1371,7 +1371,7 @@ var PDFView = {
div.removeChild(div.lastChild); div.removeChild(div.lastChild);
}, },
rotatePages: function pdfViewPageRotation(delta) { rotatePages: function pdfViewRotatePages(delta) {
this.pageRotation = (this.pageRotation + 360 + delta) % 360; this.pageRotation = (this.pageRotation + 360 + delta) % 360;