From 357ee6cbb2e27208b994749e8530234873e2f503 Mon Sep 17 00:00:00 2001 From: Mike Corbin Date: Sat, 16 May 2015 14:18:36 +0100 Subject: [PATCH] viewer: Support Retina/HiDPI thumbnails Reuse the existing getOutputScale() machinery to render and/or rescale thumbnail images to the native display resolution. Fixes blurry thumbnails on HiDPI displays making it a lot easier to make out the content. --- web/pdf_thumbnail_view.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js index d83d30d1f..e446b685c 100644 --- a/web/pdf_thumbnail_view.js +++ b/web/pdf_thumbnail_view.js @@ -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'; @@ -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}}')); @@ -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() { @@ -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) {