|
44 | 44 | * @param {Number} options.width - width to be applied to node before rendering.
|
45 | 45 | * @param {Number} options.height - height to be applied to node before rendering.
|
46 | 46 | * @param {Object} options.style - an object whose properties to be copied to node's style before rendering.
|
47 |
| - * @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only), defaults to 1.0. |
| 47 | + * @param {Number} options.quality - a Number between 0 and 1 indicating image quality (applicable to JPEG only), |
| 48 | + defaults to 1.0. |
| 49 | + * @param {Number} options.scale - scale factor for image quality rendering (to unblurry JPEG and PNG output), |
| 50 | + default = unset = no scaling applied = 1.0. |
48 | 51 | * @param {String} options.imagePlaceholder - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
|
49 | 52 | * @param {Boolean} options.cacheBust - set to true to cache bust by appending the time to the request url
|
50 | 53 | * @return {Promise} - A promise that is fulfilled with a SVG image data URL
|
|
155 | 158 | .then(function (image) {
|
156 | 159 | var canvas = newCanvas(domNode);
|
157 | 160 | var ctx = canvas.getContext('2d');
|
158 |
| - ctx.scale(window.devicePixelRatio, window.devicePixelRatio); |
| 161 | + if (options.scale) { |
| 162 | + ctx.scale(options.scale, options.scale); |
| 163 | + } |
159 | 164 | ctx.drawImage(image, 0, 0);
|
160 | 165 | return canvas;
|
161 | 166 | });
|
162 | 167 |
|
163 | 168 | function newCanvas(domNode) {
|
164 | 169 | var canvas = document.createElement('canvas');
|
165 |
| - canvas.width = options.width || window.devicePixelRatio * util.width(domNode); |
166 |
| - canvas.height = options.height || window.devicePixelRatio * util.height(domNode); |
| 170 | + if (options.scale) { |
| 171 | + canvas.width = options.width || options.scale * util.width(domNode); |
| 172 | + canvas.height = options.height || options.scale * util.height(domNode); |
| 173 | + } |
| 174 | + else { |
| 175 | + canvas.width = options.width || util.width(domNode); |
| 176 | + canvas.height = options.height || util.height(domNode); |
| 177 | + } |
167 | 178 |
|
168 | 179 | if (options.bgcolor) {
|
169 | 180 | var ctx = canvas.getContext('2d');
|
|
0 commit comments