diff --git a/.gitignore b/.gitignore index 07e6e47..727118b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /node_modules +npm-debug.log \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 5b5ce9c..3948f8c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "test/qunit"] path = test/qunit - url = git@github.com:jquery/qunit.git + url = https://github.com/jquery/qunit.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..587bd3e --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: node_js diff --git a/CHANGELOG b/CHANGELOG index db17284..e652d2b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ += 1.0.10 + * Fixed iOS 10 API deprication (#17) + * Add Travis CI + * Include minified build in release + = 1.0.9 * True fix for issue with lineWidth handling in stroke (#14) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6e170e7..bd51bf7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ Yay, you're interested in helping this thing suck less. Good for you! Some things you should be familiar with before getting started - Unit testing (with [QUnit](http://qunitjs.com)) - - [Grunt](http://gruntjs.org) (available via `npm install -g grunt-cli`) + - [Grunt](http://gruntjs.org) - [Node/NPM](https://npmjs.org/) (available via homebrew) ## Project Layout @@ -17,15 +17,15 @@ Some things you should be familiar with before getting started ## Development -Once you have NPM and Grunt installed, clone the repository (with `--recursive` to also clone all submodules) and install all dependencies +Once you have npm installed, clone the repository (with `--recursive` to also clone all submodules) and install all dependencies git clone git@.....hidpi-canvas-polyfill.git --recursive cd hidpi-canvas-polyfill npm install -Then to build a distribution run this grunt task +Then to build a distribution run - grunt dist + npm run build This will generate the compiled (and minified) sourc in your `dist/` directory along with a distributable zip archive. @@ -35,7 +35,7 @@ need to re-run this command. You can also use - grunt watch + npm run watch to automatically reconcat the unminified file everytime you change any of the `src/**/*.js` files. @@ -49,7 +49,7 @@ sure to organize and produce tests that fit the patterns present. ### Running Tests - grunt test + npm test ## On Contribution diff --git a/README.md b/README.md index ddd2905..613efe5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # HiDPI Canvas Polyfill +[![Build Status](https://travis-ci.org/jondavidjohn/hidpi-canvas-polyfill.svg?branch=master)](https://travis-ci.org/jondavidjohn/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. @@ -14,7 +16,7 @@ without having to modify any of your canvas code. 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 it's arguments multiplied by the ratio, +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. diff --git a/bower.json b/bower.json index 785a604..eb4e3b9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "hidpi-canvas", - "version": "1.0.9", + "version": "1.0.10", "homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill", "authors": [ "Jonathan Johnson " @@ -13,7 +13,7 @@ "polyfill" ], "main": "dist/hidpi-canvas.js", - "license": "Apache 2.0", + "license": "Apache-2.0", "ignore": [ "**/.*", "node_modules", diff --git a/dist/hidpi-canvas.js b/dist/hidpi-canvas.js index 2f94a38..3d1f1ba 100644 --- a/dist/hidpi-canvas.js +++ b/dist/hidpi-canvas.js @@ -1,15 +1,17 @@ /** - * HiDPI Canvas Polyfill (1.0.9) + * HiDPI Canvas Polyfill (1.0.10) * * Author: Jonathan D. Johnson (http://jondavidjohn.com) * Homepage: https://github.com/jondavidjohn/hidpi-canvas-polyfill * Issue Tracker: https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues - * License: Apache 2.0 + * License: Apache-2.0 */ (function(prototype) { - var pixelRatio = (function(context) { - var backingStore = context.backingStorePixelRatio || + var pixelRatio = (function() { + var canvas = document.createElement('canvas'), + context = canvas.getContext('2d'), + backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || @@ -17,7 +19,7 @@ context.backingStorePixelRatio || 1; return (window.devicePixelRatio || 1) / backingStore; - })(prototype), + })(), forEach = function(obj, func) { for (var p in obj) { diff --git a/dist/hidpi-canvas.min.js b/dist/hidpi-canvas.min.js index 687149e..5447c71 100644 --- a/dist/hidpi-canvas.min.js +++ b/dist/hidpi-canvas.min.js @@ -1,9 +1,9 @@ /** - * HiDPI Canvas Polyfill (1.0.9) + * HiDPI Canvas Polyfill (1.0.10) * * Author: Jonathan D. Johnson (http://jondavidjohn.com) * Homepage: https://github.com/jondavidjohn/hidpi-canvas-polyfill * Issue Tracker: https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues - * License: Apache 2.0 + * License: Apache-2.0 */ -!function(a){var b=function(a){var b=a.backingStorePixelRatio||a.webkitBackingStorePixelRatio||a.mozBackingStorePixelRatio||a.msBackingStorePixelRatio||a.oBackingStorePixelRatio||a.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/b}(a),c=function(a,b){for(var c in a)a.hasOwnProperty(c)&&b(a[c],c)},d={fillRect:"all",clearRect:"all",strokeRect:"all",moveTo:"all",lineTo:"all",arc:[0,1,2],arcTo:"all",bezierCurveTo:"all",isPointinPath:"all",isPointinStroke:"all",quadraticCurveTo:"all",rect:"all",translate:"all",createRadialGradient:"all",createLinearGradient:"all"};1!==b&&(c(d,function(c,d){a[d]=function(a){return function(){var d,e,f=Array.prototype.slice.call(arguments);if("all"===c)f=f.map(function(a){return a*b});else if(Array.isArray(c))for(d=0,e=c.length;e>d;d++)f[c[d]]*=b;return a.apply(this,f)}}(a[d])}),a.stroke=function(a){return function(){this.lineWidth*=b,a.apply(this,arguments),this.lineWidth/=b}}(a.stroke),a.fillText=function(a){return function(){var c=Array.prototype.slice.call(arguments);c[1]*=b,c[2]*=b,this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c*b+d}),a.apply(this,c),this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c/b+d})}}(a.fillText),a.strokeText=function(a){return function(){var c=Array.prototype.slice.call(arguments);c[1]*=b,c[2]*=b,this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c*b+d}),a.apply(this,c),this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c/b+d})}}(a.strokeText))}(CanvasRenderingContext2D.prototype),function(a){a.getContext=function(a){return function(b){var c,d,e=a.call(this,b);return"2d"===b&&(c=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1,d=(window.devicePixelRatio||1)/c,d>1&&(this.style.height=this.height+"px",this.style.width=this.width+"px",this.width*=d,this.height*=d)),e}}(a.getContext)}(HTMLCanvasElement.prototype); \ No newline at end of file +!function(a){var b=function(){var a=document.createElement("canvas"),b=a.getContext("2d"),c=b.backingStorePixelRatio||b.webkitBackingStorePixelRatio||b.mozBackingStorePixelRatio||b.msBackingStorePixelRatio||b.oBackingStorePixelRatio||b.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/c}(),c=function(a,b){for(var c in a)a.hasOwnProperty(c)&&b(a[c],c)},d={fillRect:"all",clearRect:"all",strokeRect:"all",moveTo:"all",lineTo:"all",arc:[0,1,2],arcTo:"all",bezierCurveTo:"all",isPointinPath:"all",isPointinStroke:"all",quadraticCurveTo:"all",rect:"all",translate:"all",createRadialGradient:"all",createLinearGradient:"all"};1!==b&&(c(d,function(c,d){a[d]=function(a){return function(){var d,e,f=Array.prototype.slice.call(arguments);if("all"===c)f=f.map(function(a){return a*b});else if(Array.isArray(c))for(d=0,e=c.length;e>d;d++)f[c[d]]*=b;return a.apply(this,f)}}(a[d])}),a.stroke=function(a){return function(){this.lineWidth*=b,a.apply(this,arguments),this.lineWidth/=b}}(a.stroke),a.fillText=function(a){return function(){var c=Array.prototype.slice.call(arguments);c[1]*=b,c[2]*=b,this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c*b+d}),a.apply(this,c),this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c/b+d})}}(a.fillText),a.strokeText=function(a){return function(){var c=Array.prototype.slice.call(arguments);c[1]*=b,c[2]*=b,this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c*b+d}),a.apply(this,c),this.font=this.font.replace(/(\d+)(px|em|rem|pt)/g,function(a,c,d){return c/b+d})}}(a.strokeText))}(CanvasRenderingContext2D.prototype),function(a){a.getContext=function(a){return function(b){var c,d,e=a.call(this,b);return"2d"===b&&(c=e.backingStorePixelRatio||e.webkitBackingStorePixelRatio||e.mozBackingStorePixelRatio||e.msBackingStorePixelRatio||e.oBackingStorePixelRatio||e.backingStorePixelRatio||1,d=(window.devicePixelRatio||1)/c,d>1&&(this.style.height=this.height+"px",this.style.width=this.width+"px",this.width*=d,this.height*=d)),e}}(a.getContext)}(HTMLCanvasElement.prototype); \ No newline at end of file diff --git a/package.json b/package.json index 94f91de..b20aee3 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "hidpi-canvas", "description": "A JavaScript drop-in module to polyfill consistent and automatic HiDPI Canvas support.", - "version": "1.0.9", - "license": "Apache 2.0", + "version": "1.0.10", + "license": "Apache-2.0", "homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill", "bugs": "https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues", "repository": { @@ -23,6 +23,8 @@ }, "scripts": { "test": "grunt", - "prepublish": "grunt dist" + "watch": "grunt watch", + "build": "grunt dist", + "prepublish": "npm run build" } } diff --git a/src/CanvasRenderingContext2D.js b/src/CanvasRenderingContext2D.js index ac077c1..589abc8 100644 --- a/src/CanvasRenderingContext2D.js +++ b/src/CanvasRenderingContext2D.js @@ -1,7 +1,9 @@ (function(prototype) { - var pixelRatio = (function(context) { - var backingStore = context.backingStorePixelRatio || + var pixelRatio = (function() { + var canvas = document.createElement('canvas'), + context = canvas.getContext('2d'), + backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || @@ -9,7 +11,7 @@ context.backingStorePixelRatio || 1; return (window.devicePixelRatio || 1) / backingStore; - })(prototype), + })(), forEach = function(obj, func) { for (var p in obj) {