Skip to content

Commit 1f2e9f0

Browse files
committed
Merge branch 'release/1.0.2'
2 parents b4d3286 + fb16886 commit 1f2e9f0

File tree

9 files changed

+64
-15
lines changed

9 files changed

+64
-15
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
= 1.0.2
2+
* Fix bug with font scaling with multiple text calls (Issue #4)
3+
* Add a few tests
4+
15
= 1.0.1
26
* Fixed Bug detecting the webkit backingStore
37
* General code cleanup

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ Good Pull Requests include:
7171

7272
A few things it currently lacks that I'd like to see improved
7373

74-
- Better touch support
75-
- Responsive interactivity
76-
- Better handling of a large number of "bubbles"
74+
- More complete canvas context method coverage.
75+
- Figure out how to test this stuff.

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
ctx.font="20px Arial";
7878
ctx.fillText("Am I Sharp?",10,300);
79+
ctx.fillText("Am I Sharp Also?",10,450);
7980
})();
8081
</script>
8182
</body>

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.1",
4+
"version": "1.0.2",
55
"license": "Apache 2.0",
66
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
77
"bugs": "https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues",

src/CanvasRenderingContext2D.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
'isPointinStroke': 'all',
3535
'quadraticCurveTo': 'all',
3636
'rect': 'all',
37-
'translate': 'all'
37+
'translate': 'all',
38+
'createRadialGradient': 'all'
3839
};
3940

4041
forEach(ratioArgs, function(value, key) {
@@ -77,7 +78,14 @@
7778
}
7879
);
7980

80-
return _super.apply(this, args);
81+
_super.apply(this, args);
82+
83+
this.font = this.font.replace(
84+
/(\d+)(px|em|rem|pt)/g,
85+
function(w, m, u) {
86+
return (m / ratio) + u;
87+
}
88+
);
8189
};
8290
})(prototype.fillText);
8391

@@ -96,7 +104,14 @@
96104
}
97105
);
98106

99-
return _super.apply(this, args);
107+
_super.apply(this, args);
108+
109+
this.font = this.font.replace(
110+
/(\d+)(px|em|rem|pt)/g,
111+
function(w, m, u) {
112+
return (m / ratio) + u;
113+
}
114+
);
100115
};
101116
})(prototype.strokeText);
102117
})(CanvasRenderingContext2D.prototype);

test/CanvasRenderingContext2D.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body>
99
<div id="qunit"></div>
1010
<div id="qunit-fixture">
11-
<canvas id="canvas" height="300" width="500"></canvas>
11+
<canvas id="test_canvas"></canvas>
1212
</div>
1313
<script src="qunit/qunit/qunit.js"></script>
1414
<script src="../dist/hidpi-canvas.js"></script>
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
module('CanvasRenderingContext2D Tests');
1+
module('CanvasRenderingContext2D Tests', {
2+
setup: function() {
3+
window.devicePixelRatio = 2;
4+
}
5+
});
6+
7+
test('the font size remains unchanged after every text call', function() {
8+
var font_value = '12px Helvetica',
9+
canvas = document.getElementById('test_canvas'),
10+
context = canvas.getContext('2d');
11+
12+
context.font = font_value;
13+
14+
context.fillText("Some Text",10,300);
15+
equal(context.font, font_value);
216

3-
test('something', function() {
4-
equal(true, true);
17+
context.fillText("Some More Text",10,450);
18+
equal(context.font, font_value);
519
});

test/HTMLCanvasElement.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body>
99
<div id="qunit"></div>
1010
<div id="qunit-fixture">
11-
<canvas id="canvas" height="300" width="500"></canvas>
11+
<canvas id="test_canvas"></canvas>
1212
</div>
1313
<script src="qunit/qunit/qunit.js"></script>
1414
<script src="../dist/hidpi-canvas.js"></script>

test/HTMLCanvasElementTests.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1-
module('HTMLCanvasElement Tests');
1+
module('HTMLCanvasElement Tests', {
2+
setup: function() {
3+
window.devicePixelRatio = 2;
4+
}
5+
});
6+
7+
test('canvas dimensions scale to device pixel ratio', function() {
8+
var canvas = document.getElementById('test_canvas'),
9+
context;
10+
11+
canvas.height = 100;
12+
canvas.width = 200;
13+
14+
context = canvas.getContext('2d');
15+
16+
equal(canvas.height, 200);
17+
equal(canvas.width, 400);
218

3-
test('something', function() {
4-
equal(true, true);
19+
equal(canvas.style.height, '100px');
20+
equal(canvas.style.width, '200px');
521
});

0 commit comments

Comments
 (0)