From 439b8bcdf3949353b03062958929065c2c6a3cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bj=C3=B8rnskov?= Date: Thu, 14 Feb 2013 11:49:47 +0100 Subject: [PATCH] [WebProfilerBundle] Draw retina canvas if devicePixelRatio is bigger than 1 --- .../Resources/views/Collector/time.html.twig | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig index b8853213f3..aab88b5c01 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig @@ -194,7 +194,10 @@ h = space, x = request.left * ratio + space, // position canvas = cache.get(elementId) || cache.set(elementId, document.getElementById(elementId)), - ctx = canvas.getContext("2d"); + ctx = canvas.getContext("2d"), + backingStoreRatio, + scaleRatio, + devicePixelRatio; // Filter events whose total time is below the threshold. drawableEvents = request.events.filter(function(event) { @@ -203,8 +206,20 @@ canvasHeight += gapPerEvent * drawableEvents.length; - canvas.width = width; - canvas.height = canvasHeight; + // For retina displays so text and boxes will be crisp + devicePixelRatio = window.devicePixelRatio == "undefined" ? 1 : window.devicePixelRatio; + backingStoreRatio = ctx.webkitBackingStorePixelRatio == "undefined" ? 1 : ctx.webkitBackingStorePixelRatio; + scaleRatio = devicePixelRatio / 1; + + canvasHeight += gapPerEvent * drawableEvents.length; + + canvas.width = width * scaleRatio; + canvas.height = canvasHeight * scaleRatio; + + canvas.style.width = width + 'px'; + canvas.style.height = canvasHeight + 'px'; + + ctx.scale(scaleRatio, scaleRatio); ctx.textBaseline = "middle"; ctx.lineWidth = 0;