Skip to content

Commit

Permalink
Merge branch 'hotfix/1.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jondavidjohn committed Jul 9, 2014
2 parents d296b27 + 0cc94d3 commit bdf7577
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
= 1.0.7
* Better fix for pixel ratio being 1

= 1.0.6
* Performance improvement, early bail if pixel ratio is 1 (#13)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hidpi-canvas",
"version": "1.0.6",
"version": "1.0.7",
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
"authors": [
"Jonathan Johnson <[email protected]>"
Expand Down
43 changes: 17 additions & 26 deletions dist/hidpi-canvas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* HiDPI Canvas Polyfill (1.0.6)
* HiDPI Canvas Polyfill (1.0.7)
*
* Author: Jonathan D. Johnson (http://jondavidjohn.com)
* Homepage: https://github.com/jondavidjohn/hidpi-canvas-polyfill
Expand All @@ -8,9 +8,7 @@
*/
(function(prototype) {

var func, value,

getPixelRatio = function(context) {
var pixelRatio = (function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
Expand All @@ -19,7 +17,7 @@
context.backingStorePixelRatio || 1;

return (window.devicePixelRatio || 1) / backingStore;
},
})(prototype),

forEach = function(obj, func) {
for (var p in obj) {
Expand Down Expand Up @@ -47,23 +45,22 @@
'createLinearGradient': 'all'
};

if (pixelRatio === 1) return;

forEach(ratioArgs, function(value, key) {
prototype[key] = (function(_super) {
return function() {
var i, len,
ratio = getPixelRatio(this),
args = Array.prototype.slice.call(arguments);

if (ratio === 1) return _super.apply(this, args);

if (value === 'all') {
args = args.map(function(a) {
return a * ratio;
return a * pixelRatio;
});
}
else if (Array.isArray(value)) {
for (i = 0, len = value.length; i < len; i++) {
args[value[i]] *= ratio;
args[value[i]] *= pixelRatio;
}
}

Expand All @@ -76,18 +73,15 @@
//
prototype.fillText = (function(_super) {
return function() {
var ratio = getPixelRatio(this),
args = Array.prototype.slice.call(arguments);

if (ratio === 1) return _super.apply(this, args);
var args = Array.prototype.slice.call(arguments);

args[1] *= ratio; // x
args[2] *= ratio; // y
args[1] *= pixelRatio; // x
args[2] *= pixelRatio; // y

this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m * ratio) + u;
return (m * pixelRatio) + u;
}
);

Expand All @@ -96,26 +90,23 @@
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m / ratio) + u;
return (m / pixelRatio) + u;
}
);
};
})(prototype.fillText);

prototype.strokeText = (function(_super) {
return function() {
var ratio = getPixelRatio(this),
args = Array.prototype.slice.call(arguments);

if (ratio === 1) return _super.apply(this, args);
var args = Array.prototype.slice.call(arguments);

args[1] *= ratio; // x
args[2] *= ratio; // y
args[1] *= pixelRatio; // x
args[2] *= pixelRatio; // y

this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m * ratio) + u;
return (m * pixelRatio) + u;
}
);

Expand All @@ -124,7 +115,7 @@
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m / ratio) + u;
return (m / pixelRatio) + u;
}
);
};
Expand Down
4 changes: 2 additions & 2 deletions dist/hidpi-canvas.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hidpi-canvas",
"description": "A JavaScript drop-in module to polyfill consistent and automatic HiDPI Canvas support.",
"version": "1.0.6",
"version": "1.0.7",
"license": "Apache 2.0",
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
"bugs": "https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues",
Expand Down
41 changes: 16 additions & 25 deletions src/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
(function(prototype) {

var func, value,

getPixelRatio = function(context) {
var pixelRatio = (function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
Expand All @@ -11,7 +9,7 @@
context.backingStorePixelRatio || 1;

return (window.devicePixelRatio || 1) / backingStore;
},
})(prototype),

forEach = function(obj, func) {
for (var p in obj) {
Expand Down Expand Up @@ -39,23 +37,22 @@
'createLinearGradient': 'all'
};

if (pixelRatio === 1) return;

forEach(ratioArgs, function(value, key) {
prototype[key] = (function(_super) {
return function() {
var i, len,
ratio = getPixelRatio(this),
args = Array.prototype.slice.call(arguments);

if (ratio === 1) return _super.apply(this, args);

if (value === 'all') {
args = args.map(function(a) {
return a * ratio;
return a * pixelRatio;
});
}
else if (Array.isArray(value)) {
for (i = 0, len = value.length; i < len; i++) {
args[value[i]] *= ratio;
args[value[i]] *= pixelRatio;
}
}

Expand All @@ -68,18 +65,15 @@
//
prototype.fillText = (function(_super) {
return function() {
var ratio = getPixelRatio(this),
args = Array.prototype.slice.call(arguments);

if (ratio === 1) return _super.apply(this, args);
var args = Array.prototype.slice.call(arguments);

args[1] *= ratio; // x
args[2] *= ratio; // y
args[1] *= pixelRatio; // x
args[2] *= pixelRatio; // y

this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m * ratio) + u;
return (m * pixelRatio) + u;
}
);

Expand All @@ -88,26 +82,23 @@
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m / ratio) + u;
return (m / pixelRatio) + u;
}
);
};
})(prototype.fillText);

prototype.strokeText = (function(_super) {
return function() {
var ratio = getPixelRatio(this),
args = Array.prototype.slice.call(arguments);

if (ratio === 1) return _super.apply(this, args);
var args = Array.prototype.slice.call(arguments);

args[1] *= ratio; // x
args[2] *= ratio; // y
args[1] *= pixelRatio; // x
args[2] *= pixelRatio; // y

this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m * ratio) + u;
return (m * pixelRatio) + u;
}
);

Expand All @@ -116,7 +107,7 @@
this.font = this.font.replace(
/(\d+)(px|em|rem|pt)/g,
function(w, m, u) {
return (m / ratio) + u;
return (m / pixelRatio) + u;
}
);
};
Expand Down

0 comments on commit bdf7577

Please sign in to comment.