HiDPI Canvas Polyfill
This is a drop-in polyfill to scale canvas appropriately to maintain sharpness in browsers that currently do not provide the appropriately scaled backing store to do this automatically.
As of this writing Safari is the only browser that accounts for this.
The goal of this drop-in is to make this behavior consistent accross all browsers, without having to modify any of your canvas code.
Scope
Currently this plugin handles most general cross browser drawing functions, but feel free to send Pull Requests as you find functions you need supported.
If the function simply needs all or some of its arguments multiplied by the ratio,
it should simply require you to add it to the ratioArgs
object, following the proper
pattern.
It currently leaves images alone, so to retinize images on your canvas, simply duplicate the getPixelRatio function in your code and divide your image dimensions by the provided ratio.
var { var backingStore = contextbackingStorePixelRatio || contextwebkitBackingStorePixelRatio || contextmozBackingStorePixelRatio || contextmsBackingStorePixelRatio || contextoBackingStorePixelRatio || contextbackingStorePixelRatio || 1; return windowdevicePixelRatio || 1 / backingStore;};
Usage
To use this module, simply include it before any of your canvas code
... ...
Bower
This module is also installable via bower
bower install hidpi-canvas
TODO
- More Complete context function coverage
- Figure out how to write tests for this type of thing
Development
See CONTRIBUTING.md