Skip to content

Commit

Permalink
Merge branch 'hotfix/1.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
jondavidjohn committed Jul 27, 2014
2 parents bdf7577 + 9e5afd4 commit 220b8ba
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
= 1.0.8
* Fix issue with lineWidth handling in stroke (#14)

= 1.0.7
* Better fix for pixel ratio being 1

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.7",
"version": "1.0.8",
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
"authors": [
"Jonathan Johnson <[email protected]>"
Expand Down
10 changes: 9 additions & 1 deletion dist/hidpi-canvas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* HiDPI Canvas Polyfill (1.0.7)
* HiDPI Canvas Polyfill (1.0.8)
*
* Author: Jonathan D. Johnson (http://jondavidjohn.com)
* Homepage: https://github.com/jondavidjohn/hidpi-canvas-polyfill
Expand Down Expand Up @@ -69,6 +69,14 @@
})(prototype[key]);
});

// Stroke lineWidth adjustment
prototype.stroke = (function(_super) {
var args = Array.prototype.slice.call(arguments);
this.lineWidth *= pixelRatio;
_super.apply(this, args);
this.lineWidth /= pixelRatio;
})(prototype.stroke);

// Text
//
prototype.fillText = (function(_super) {
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.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
ctx.beginPath();
for(var i=0;i<4;i++){
for(var j=0;j<3;j++){
ctx.beginPath();
var x = 225+j*50; // x coordinate
var y = 225+i*50; // y coordinate
var radius = 20; // Arc radius
var startAngle = 0; // Starting point on circle
var endAngle = Math.PI+(Math.PI*j)/2; // End point on circle
var anticlockwise = i%2==0 ? false : true; // clockwise or anticlockwise

ctx.beginPath();
ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);

if (i>1){
Expand All @@ -59,6 +59,7 @@
ctx.beginPath();
ctx.moveTo(250,150);
ctx.arcTo(350,50,350,100,50);
ctx.lineWidth = 10;
ctx.stroke();
ctx.closePath();

Expand Down
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.7",
"version": "1.0.8",
"license": "Apache 2.0",
"homepage": "https://github.com/jondavidjohn/hidpi-canvas-polyfill",
"bugs": "https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues",
Expand Down
8 changes: 8 additions & 0 deletions src/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
})(prototype[key]);
});

// Stroke lineWidth adjustment
prototype.stroke = (function(_super) {
var args = Array.prototype.slice.call(arguments);
this.lineWidth *= pixelRatio;
_super.apply(this, args);
this.lineWidth /= pixelRatio;
})(prototype.stroke);

// Text
//
prototype.fillText = (function(_super) {
Expand Down
18 changes: 18 additions & 0 deletions test/CanvasRenderingContext2DTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ test('the font size remains unchanged after every text call', function() {
context.fillText("Some More Text",10,450);
equal(context.font, font_value);
});

test('the lineWidth property remains unchanged after every stroke call', function() {
var line_width_value = 12,
canvas = document.getElementById('test_canvas'),
context = canvas.getContext('2d');

context.lineWidth = line_width_value;

context.moveTo(250,150);
context.arcTo(350,50,350,100,50);
context.stroke();
equal(context.lineWidth, line_width_value);

context.moveTo(10,15);
context.arcTo(30,50,30,10,50);
context.stroke();
equal(context.lineWidth, line_width_value);
});

0 comments on commit 220b8ba

Please sign in to comment.