Skip to content

Commit

Permalink
Merge pull request #6025 from mcorb/retina-thumbnails
Browse files Browse the repository at this point in the history
viewer: Support Retina/HiDPI thumbnails
  • Loading branch information
timvandermeij committed May 19, 2015
2 parents b5de3dc + 357ee6c commit 82536f8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions web/pdf_thumbnail_view.js
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals mozL10n, RenderingStates, Promise */
/* globals mozL10n, RenderingStates, Promise, getOutputScale */

'use strict';

Expand Down Expand Up @@ -177,12 +177,11 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
/**
* @private
*/
_getPageDrawContext: function PDFThumbnailView_getPageDrawContext() {
_getPageDrawContext:
function PDFThumbnailView_getPageDrawContext(noCtxScale) {
var canvas = document.createElement('canvas');
canvas.id = this.renderingId;

canvas.width = this.canvasWidth;
canvas.height = this.canvasHeight;
canvas.className = 'thumbnailImage';
canvas.setAttribute('aria-label', mozL10n.get('thumb_page_canvas',
{page: this.id}, 'Thumbnail of Page {{page}}'));
Expand All @@ -191,7 +190,16 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
this.div.setAttribute('data-loaded', true);
this.ring.appendChild(canvas);

return canvas.getContext('2d');
var ctx = canvas.getContext('2d');
var outputScale = getOutputScale(ctx);
canvas.width = (this.canvasWidth * outputScale.sx) | 0;
canvas.height = (this.canvasHeight * outputScale.sy) | 0;
canvas.style.width = this.canvasWidth + 'px';
canvas.style.height = this.canvasHeight + 'px';
if (!noCtxScale && outputScale.scaled) {
ctx.scale(outputScale.sx, outputScale.sy);
}
return ctx;
},

draw: function PDFThumbnailView_draw() {
Expand Down Expand Up @@ -274,7 +282,7 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
this.hasImage = true;
this.renderingState = RenderingStates.FINISHED;

var ctx = this._getPageDrawContext();
var ctx = this._getPageDrawContext(true);
var canvas = ctx.canvas;

if (img.width <= 2 * canvas.width) {
Expand Down

0 comments on commit 82536f8

Please sign in to comment.