Skip to content

Commit 2dd8ef0

Browse files
committed
Merge branch 'hotfix/1.0.3'
2 parents 1f2e9f0 + faa5b20 commit 2dd8ef0

File tree

6 files changed

+194
-2
lines changed

6 files changed

+194
-2
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
= 1.0.3
2+
* Add bower support
3+
* Add built distribution files to the repository
4+
15
= 1.0.2
26
* Fix bug with font scaling with multiple text calls (Issue #4)
37
* Add a few tests

bower.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "hidpi-canvas",
3+
"version": "1.0.3",
4+
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
5+
"authors": [
6+
"Jonathan Johnson <jon@crowdfavorite.com>"
7+
],
8+
"description": "A JavaScript drop-in module to polyfill consistent and automatic HiDPI Canvas support.",
9+
"keywords": [
10+
"canvas",
11+
"retina",
12+
"hidpi",
13+
"polyfill"
14+
],
15+
"license": "Apache 2.0",
16+
"ignore": [
17+
"**/.*",
18+
"node_modules",
19+
"bower_components",
20+
"src",
21+
"test",
22+
"tests"
23+
]
24+
}

dist/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
[^.]*
1+
*.zip
2+
*.gz

dist/hidpi-canvas.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/**
2+
* HiDPI Canvas Polyfill (1.0.3)
3+
*
4+
* Author: Jonathan D. Johnson (http://jondavidjohn.com)
5+
* Homepage: https://github.com/jondavidjohn/hidpi-canvas-polyfill
6+
* Issue Tracker: https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues
7+
* License: Apache 2.0
8+
*/
9+
(function(prototype) {
10+
11+
var func, value,
12+
13+
getPixelRatio = function(context) {
14+
var backingStore = context.backingStorePixelRatio ||
15+
context.webkitBackingStorePixelRatio ||
16+
context.mozBackingStorePixelRatio ||
17+
context.msBackingStorePixelRatio ||
18+
context.oBackingStorePixelRatio ||
19+
context.backingStorePixelRatio || 1;
20+
21+
return (window.devicePixelRatio || 1) / backingStore;
22+
},
23+
24+
forEach = function(obj, func) {
25+
for (var p in obj) {
26+
if (obj.hasOwnProperty(p)) {
27+
func(obj[p], p);
28+
}
29+
}
30+
},
31+
32+
ratioArgs = {
33+
'fillRect': 'all',
34+
'clearRect': 'all',
35+
'strokeRect': 'all',
36+
'moveTo': 'all',
37+
'lineTo': 'all',
38+
'arc': [0,1,2],
39+
'arcTo': 'all',
40+
'bezierCurveTo': 'all',
41+
'isPointinPath': 'all',
42+
'isPointinStroke': 'all',
43+
'quadraticCurveTo': 'all',
44+
'rect': 'all',
45+
'translate': 'all',
46+
'createRadialGradient': 'all'
47+
};
48+
49+
forEach(ratioArgs, function(value, key) {
50+
prototype[key] = (function(_super) {
51+
return function() {
52+
var i, len,
53+
ratio = getPixelRatio(this),
54+
args = Array.prototype.slice.call(arguments);
55+
56+
if (value === 'all') {
57+
args = args.map(function(a) {
58+
return a * ratio;
59+
});
60+
}
61+
else if (Array.isArray(value)) {
62+
for (i = 0, len = value.length; i < len; i++) {
63+
args[value[i]] *= ratio;
64+
}
65+
}
66+
67+
return _super.apply(this, args);
68+
};
69+
})(prototype[key]);
70+
});
71+
72+
// Text
73+
//
74+
prototype.fillText = (function(_super) {
75+
return function() {
76+
var ratio = getPixelRatio(this),
77+
args = Array.prototype.slice.call(arguments);
78+
79+
args[1] *= ratio; // x
80+
args[2] *= ratio; // y
81+
82+
this.font = this.font.replace(
83+
/(\d+)(px|em|rem|pt)/g,
84+
function(w, m, u) {
85+
return (m * ratio) + u;
86+
}
87+
);
88+
89+
_super.apply(this, args);
90+
91+
this.font = this.font.replace(
92+
/(\d+)(px|em|rem|pt)/g,
93+
function(w, m, u) {
94+
return (m / ratio) + u;
95+
}
96+
);
97+
};
98+
})(prototype.fillText);
99+
100+
prototype.strokeText = (function(_super) {
101+
return function() {
102+
var ratio = getPixelRatio(this),
103+
args = Array.prototype.slice.call(arguments);
104+
105+
args[1] *= ratio; // x
106+
args[2] *= ratio; // y
107+
108+
this.font = this.font.replace(
109+
/(\d+)(px|em|rem|pt)/g,
110+
function(w, m, u) {
111+
return (m * ratio) + u;
112+
}
113+
);
114+
115+
_super.apply(this, args);
116+
117+
this.font = this.font.replace(
118+
/(\d+)(px|em|rem|pt)/g,
119+
function(w, m, u) {
120+
return (m / ratio) + u;
121+
}
122+
);
123+
};
124+
})(prototype.strokeText);
125+
})(CanvasRenderingContext2D.prototype);
126+
;(function(prototype) {
127+
prototype.getContext = (function(_super) {
128+
return function(type) {
129+
var backingStore, ratio,
130+
context = _super.call(this, type);
131+
132+
if (type === '2d') {
133+
134+
backingStore = context.backingStorePixelRatio ||
135+
context.webkitBackingStorePixelRatio ||
136+
context.mozBackingStorePixelRatio ||
137+
context.msBackingStorePixelRatio ||
138+
context.oBackingStorePixelRatio ||
139+
context.backingStorePixelRatio || 1;
140+
141+
ratio = (window.devicePixelRatio || 1) / backingStore;
142+
143+
if (ratio > 1) {
144+
this.style.height = this.height + 'px';
145+
this.style.width = this.width + 'px';
146+
this.width *= ratio;
147+
this.height *= ratio;
148+
}
149+
}
150+
151+
return context;
152+
};
153+
})(prototype.getContext);
154+
})(HTMLCanvasElement.prototype);

dist/hidpi-canvas.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hidpi-canvas",
33
"description": "A JavaScript drop-in module to polyfill consistent and automatic HiDPI Canvas support.",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"license": "Apache 2.0",
66
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
77
"bugs": "https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues",

0 commit comments

Comments
 (0)