better HDPI support

update packages
This commit is contained in:
Anton Lavrenov 2016-02-28 16:57:15 +08:00
parent 8b23ae64df
commit 3c1e2804de
21 changed files with 94 additions and 119 deletions

View File

@ -26,7 +26,7 @@
"no-empty": 2,
"no-empty-class": 0,
"no-empty-character-class": 2,
"no-empty-label": 2,
"no-labels": 2,
"no-eq-null": 2,
"no-eval": 2,
"no-ex-assign": 2,
@ -45,7 +45,6 @@
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 0,
"no-loop-func": 2,
@ -106,12 +105,11 @@
"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
"camelcase": 1,
"comma-dangle": [2, "never"],
"comma-spacing": 2,
"comma-style": 0,
"complexity": [1, 11],
"computed-property-spacing": [0, "never"],
"consistent-return": 2,
"consistent-return": 1,
"consistent-this": [0, "that"],
"curly": [2, "all"],
"default-case": 0,
@ -156,11 +154,11 @@
"space-in-brackets": [0, "never"],
"space-in-parens": [0, "never"],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"keyword-spacing": 1,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": 0,
"spaced-line-comment": [0, "always"],
"strict": 2,
"strict": [2, "function"],
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
@ -176,5 +174,5 @@
"assert": false,
"addStage": false,
"suite": false
}
}
}

View File

@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## Fixed
- repair `cancelBubble` event property behaviour
- fix wrong `Path` `getClientRect()` calculation
- better HDPI support
## [0.11.1][2016-01-16]

View File

@ -3,7 +3,7 @@
* Konva JavaScript Framework v0.11.1
* http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Fri Feb 05 2016
* Date: Sun Feb 28 2016
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
@ -200,29 +200,29 @@
UA: undefined
};
var global =
var glob =
typeof window !== 'undefined' ? window :
typeof global !== 'undefined' ? global :
typeof WorkerGlobalScope !== 'undefined' ? self : {};
Konva.UA = Konva._parseUA((global.navigator && global.navigator.userAgent) || '');
Konva.UA = Konva._parseUA((glob.navigator && glob.navigator.userAgent) || '');
if (global.Konva) {
if (glob.Konva) {
console.error(
'Konva instance is already exist in current eviroment. ' +
'Please use only one instance.'
);
}
global.Konva = Konva;
Konva.global = global;
glob.Konva = Konva;
Konva.global = glob;
if( typeof exports === 'object') {
// runtime-check for browserify and nw.js (node-webkit)
if(global.window && global.window.document) {
Konva.document = global.window.document;
Konva.window = global.window;
if(glob.window && glob.window.document) {
Konva.document = glob.window.document;
Konva.window = glob.window;
} else {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
@ -1847,10 +1847,6 @@
args = _simplifyArray(Array.prototype.slice.call(arguments, 0));
ret = origMethod.apply(that, arguments);
if (methodName === 'clearRect') {
args[2] = args[2] / that.canvas.getPixelRatio();
args[3] = args[3] / that.canvas.getPixelRatio();
}
that._trace({
method: methodName,
args: args
@ -2530,10 +2526,10 @@
maxY = Math.max(maxY, transformed.y);
});
return {
x: Math.round(minX),
y: Math.round(minY),
width: Math.round(maxX - minX),
height: Math.round(maxY - minY)
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY
};
},
_drawCachedSceneCanvas: function(context) {
@ -7406,15 +7402,16 @@
drawFunc.call(this, bufferContext);
bufferContext.restore();
var ratio = bufferCanvas.pixelRatio;
if (hasShadow && !canvas.hitCanvas) {
context.save();
context._applyShadow(this);
context._applyOpacity(this);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
context.restore();
} else {
context._applyOpacity(this);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
}
}
// if buffer canvas is not needed
@ -9260,10 +9257,8 @@
// the buffer canvas pixel ratio must be 1 because it is used as an
// intermediate canvas before copying the result onto a scene canvas.
// not setting it to 1 will result in an over compensation
this.bufferCanvas = new Konva.SceneCanvas({
pixelRatio: 1
});
this.bufferHitCanvas = new Konva.HitCanvas();
this.bufferCanvas = new Konva.SceneCanvas();
this.bufferHitCanvas = new Konva.HitCanvas({pixelRatio: 1});
this._resizeDOM();
},
@ -10145,8 +10140,8 @@
len = animations.length,
n;
for(n = 0; n < len; n++) {
if(animations[n].id === this.id) {
for (n = 0; n < len; n++) {
if (animations[n].id === this.id) {
return true;
}
}

12
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -4,22 +4,23 @@
"author": "Anton Lavrenov",
"scripts": {
"start": "gulp",
"full-build": "gulp lint test build"
"full-build": "gulp lint test build",
"test": "gulp test"
},
"devDependencies": {
"chai": "3.2.0",
"chai": "3.5.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-connect": "^2.2.0",
"gulp-eslint": "^1.0.0",
"gulp-jscpd": "0.0.4",
"gulp-connect": "^3.0.0",
"gulp-eslint": "^2.0.0",
"gulp-jscpd": "0.0.6",
"gulp-jsdoc": "^0.1.4",
"gulp-mocha-phantomjs": "^0.9.0",
"gulp-mocha-phantomjs": "^0.11.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^1.3.0",
"gulp-util": "^3.0.6",
"mocha": "2.2.5"
"mocha": "2.4.5"
},
"keywords": [
"canvas",

View File

@ -140,8 +140,8 @@
len = animations.length,
n;
for(n = 0; n < len; n++) {
if(animations[n].id === this.id) {
for (n = 0; n < len; n++) {
if (animations[n].id === this.id) {
return true;
}
}

View File

@ -402,10 +402,6 @@
args = _simplifyArray(Array.prototype.slice.call(arguments, 0));
ret = origMethod.apply(that, arguments);
if (methodName === 'clearRect') {
args[2] = args[2] / that.canvas.getPixelRatio();
args[3] = args[3] / that.canvas.getPixelRatio();
}
that._trace({
method: methodName,
args: args

View File

@ -200,29 +200,29 @@
UA: undefined
};
var global =
var glob =
typeof window !== 'undefined' ? window :
typeof global !== 'undefined' ? global :
typeof WorkerGlobalScope !== 'undefined' ? self : {};
Konva.UA = Konva._parseUA((global.navigator && global.navigator.userAgent) || '');
Konva.UA = Konva._parseUA((glob.navigator && glob.navigator.userAgent) || '');
if (global.Konva) {
if (glob.Konva) {
console.error(
'Konva instance is already exist in current eviroment. ' +
'Please use only one instance.'
);
}
global.Konva = Konva;
Konva.global = global;
glob.Konva = Konva;
Konva.global = glob;
if( typeof exports === 'object') {
// runtime-check for browserify and nw.js (node-webkit)
if(global.window && global.window.document) {
Konva.document = global.window.document;
Konva.window = global.window;
if(glob.window && glob.window.document) {
Konva.document = glob.window.document;
Konva.window = glob.window;
} else {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,

View File

@ -293,10 +293,10 @@
maxY = Math.max(maxY, transformed.y);
});
return {
x: Math.round(minX),
y: Math.round(minY),
width: Math.round(maxX - minX),
height: Math.round(maxY - minY)
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY
};
},
_drawCachedSceneCanvas: function(context) {

View File

@ -279,15 +279,16 @@
drawFunc.call(this, bufferContext);
bufferContext.restore();
var ratio = bufferCanvas.pixelRatio;
if (hasShadow && !canvas.hitCanvas) {
context.save();
context._applyShadow(this);
context._applyOpacity(this);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
context.restore();
} else {
context._applyOpacity(this);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.drawImage(bufferCanvas._canvas, 0, 0, bufferCanvas.width / ratio, bufferCanvas.height / ratio);
}
}
// if buffer canvas is not needed

View File

@ -698,10 +698,8 @@
// the buffer canvas pixel ratio must be 1 because it is used as an
// intermediate canvas before copying the result onto a scene canvas.
// not setting it to 1 will result in an over compensation
this.bufferCanvas = new Konva.SceneCanvas({
pixelRatio: 1
});
this.bufferHitCanvas = new Konva.HitCanvas();
this.bufferCanvas = new Konva.SceneCanvas();
this.bufferHitCanvas = new Konva.HitCanvas({pixelRatio: 1});
this._resizeDOM();
},

View File

@ -38,4 +38,4 @@ suite('Canvas', function() {
layer.draw();
});
});
});

View File

@ -388,19 +388,8 @@ suite('Caching', function() {
layer.add(group);
stage.add(layer);
var canvas = createCanvas();
var context = canvas.getContext('2d');
context.translate(100, 50);
context.rotate(Math.PI / 4);
context.beginPath();
context.rect(0, 0, 100, 50);
context.closePath();
context.fillStyle = 'green';
context.fill();
if (!window.isPhantomJS) {
compareLayerAndCanvas(layer, canvas, 150);
cloneAndCompareLayer(layer, 150);
cloneAndCompareLayer(layer, 200);
}
});
@ -738,7 +727,7 @@ suite('Caching', function() {
group.add(circle);
group.cache();
stage.draw();
cloneAndCompareLayer(layer, 150);
});
});

View File

@ -314,7 +314,7 @@ suite('Node', function() {
assert.equal(image.width(), stage.width() * 2, 'image has double size');
layer2.add(image);
layer2.draw();
compareLayers(layer, layer2);
compareLayers(layer, layer2, 50);
Konva.pixelRatio = oldRatio;
done();
}
@ -2128,7 +2128,7 @@ suite('Node', function() {
var bufferTrace = stage.bufferCanvas.getContext().getTrace();
//console.log(bufferTrace);
assert.equal(sceneTrace, 'clearRect(0,0,578,200);save();globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();');
assert.equal(sceneTrace, 'clearRect(0,0,578,200);save();globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0,578,200);restore();');
assert.equal(bufferTrace, 'clearRect(0,0,578,200);save();transform(1,0,0,1,289,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=20;strokeStyle=black;stroke();restore();');
});

View File

@ -17,9 +17,9 @@ suite('Shape', function() {
stage.add(layer);
assert.equal(rect.intersects({
x: 200,
y: 100
}), true, '(200,100) should intersect the shape');
x: 201,
y: 101
}), true, '(201,101) should intersect the shape');
assert.equal(rect.intersects({
x: 197,
@ -544,18 +544,17 @@ suite('Shape', function() {
var canvas = createCanvas();
var context = canvas.getContext('2d');
context.globalAlpha = 0.5;
context.globalAlpha = 0.1;
// draw shadow
var offset = 200;
context.save();
context.beginPath();
context.rect(95 - offset, 45 - offset, 110, 60);
context.rect(95, 45, 110, 60);
context.closePath();
context.shadowColor = 'grey';
context.shadowBlur = 1;
context.shadowOffsetX = 20 + offset;
context.shadowOffsetY = 20 + offset;
context.shadowOffsetX = 20;
context.shadowOffsetY = 20;
context.fillStyle = 'black';
context.fill();
context.restore();
@ -585,12 +584,12 @@ suite('Shape', function() {
// don't test in PhantomJS as it use old chrome engine
// it it has opacity + shadow bug
if (!window.mochaPhantomJS) {
compareLayerAndCanvas(layer, canvas, 210);
compareLayerAndCanvas(layer, canvas, 200);
}
var trace = layer.getContext().getTrace();
//console.log(trace);
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(128,128,128,1);shadowBlur=1;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();restore();');
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(128,128,128,1);shadowBlur=1;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0,578,200);restore();restore();');
});
@ -648,11 +647,13 @@ suite('Shape', function() {
context.fillStyle = 'green';
context.fillText('Test TEXT', 50, 75);
context.lineWidth = 2;
context.lineWidth = 2;
context.strokeStyle = 'black';
context.strokeText('Test TEXT', 50, 75);
compareLayerAndCanvas(layer, canvas, 50);
if (!window.isPhantomJS) {
compareLayerAndCanvas(layer, canvas, 254);
}
});

View File

@ -36,8 +36,8 @@ suite('Stage', function() {
});
assert.equal(stage.bufferCanvas.getPixelRatio(), 1);
assert.equal(stage.bufferHitCanvas.getPixelRatio(), 2);
assert.equal(stage.bufferCanvas.getPixelRatio(), 2);
assert.equal(stage.bufferHitCanvas.getPixelRatio(), 1);
// reset
Konva.pixelRatio = 1;
@ -138,8 +138,8 @@ suite('Stage', function() {
assert.equal(stage.getSize().height, 155);
assert.equal(stage.getContent().style.width, '333px');
assert.equal(stage.getContent().style.height, '155px');
assert.equal(layer.getCanvas()._canvas.width, 333);
assert.equal(layer.getCanvas()._canvas.height, 155);
assert.equal(layer.getCanvas()._canvas.width, 333 * layer.getCanvas().getPixelRatio());
assert.equal(layer.getCanvas()._canvas.height, 155 * layer.getCanvas().getPixelRatio());
});
// ======================================================

View File

@ -5,7 +5,7 @@ suite('RGB', function() {
var imageObj = new Image();
imageObj.onload = function() {
var layer = new Konva.Layer();
darth = new Konva.Image({
x: 10,
@ -23,7 +23,7 @@ suite('RGB', function() {
layer.draw();
// Assert fails even though '[255,0,128] = [255,0,128]'
//assert.equal(darth.getFilterColorizeColor(), [255,0,128]);
// assert.deepEqual(darth.getFilterColorizeColor(), [255,0,128]);
done();
};
@ -37,7 +37,7 @@ suite('RGB', function() {
var imageObj = new Image();
imageObj.onload = function() {
var layer = new Konva.Layer();
darth = new Konva.Image({
x: 10,
@ -55,7 +55,7 @@ suite('RGB', function() {
darth.red(0).green(255).blue(0);
layer.draw();
// assert.equal(darth.getFilterColorizeColor(), [0,255,0]);
// assert.deepEqual(darth.getFilterColorizeColor(), [0,255,0]);
done();
@ -87,7 +87,7 @@ suite('RGB', function() {
for( i=0; i<l; i+=1 ){
var imageObj = new Image();
imageObj.onload = (function(color,x){ return function() {
var darth = new Konva.Image({
x: x,
y: 32,

View File

@ -2,12 +2,6 @@ suite('RGBA', function() {
// ======================================================
test('colorize basic', function(done) {
var data = [
{
color: '#ff0000',
filter: [170, 170, 170, 0.5],
// Actually 212 but in tests rounding half up
result: [213, 85, 85, 255]
},
{
color: '#2a6511',
filter: [242, 193, 168, 0.33],
@ -67,11 +61,9 @@ suite('RGBA', function() {
var a0 = imageDataToArray(0);
var a1 = imageDataToArray(1);
var a2 = imageDataToArray(2);
assert.deepEqual(a0, data[0].result);
assert.deepEqual(a1, data[1].result);
assert.deepEqual(a2, data[2].result);
done();
});

View File

@ -119,6 +119,7 @@ suite('RegularPolygon', function() {
});
test('polygon cache', function() {
Konva.pixelRatio = 1;
var stage = addStage();
var layer = new Konva.Layer();
@ -128,7 +129,7 @@ suite('RegularPolygon', function() {
sides: 5,
radius: 50,
fill: 'green',
stroke: 'blue',
stroke: 'black',
strokeWidth: 5,
name: 'foobar'
});
@ -143,8 +144,10 @@ suite('RegularPolygon', function() {
width : 100
});
if (!window.isPhantomJS) {
cloneAndCompareLayer(layer, 200);
cloneAndCompareLayer(layer, 254);
}
Konva.pixelRatio = undefined;
});
});

View File

@ -96,6 +96,6 @@ suite('Ellipse', function(){
context.fill();
context.lineWidth = 8;
context.stroke();
compareLayerAndCanvas(layer, canvas, 50);
compareLayerAndCanvas(layer, canvas, 80);
});
});
});

View File

@ -305,7 +305,7 @@ suite('Image', function(){
var trace = layer.getContext().getTrace();
//console.log(trace);
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(0,0,0,0.5);shadowBlur=10;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0);restore();restore();');
assert.equal(trace, 'clearRect(0,0,578,200);save();save();shadowColor=rgba(0,0,0,0.5);shadowBlur=10;shadowOffsetX=20;shadowOffsetY=20;globalAlpha=0.5;drawImage([object HTMLCanvasElement],0,0,578,200);restore();restore();');
done();