Kinetic.Line detection type is now defaulted to pixel since this is the expected detection strategy

This commit is contained in:
Eric Rowell 2012-05-12 15:45:04 -07:00
parent 51258531bf
commit 502115fad7
5 changed files with 30 additions and 48 deletions

13
dist/kinetic-core.js vendored
View File

@ -3603,17 +3603,17 @@ Kinetic.Text.prototype = {
*/ */
getTextSize: function() { getTextSize: function() {
var context = this.getContext(); var context = this.getContext();
/** /**
* if the text hasn't been added a layer yet there * if the text hasn't been added a layer yet there
* will be no associated context. Will have to create * will be no associated context. Will have to create
* a dummy context * a dummy context
*/ */
if (!context) { if(!context) {
var dummyCanvas = document.createElement('canvas'); var dummyCanvas = document.createElement('canvas');
context = dummyCanvas.getContext('2d'); context = dummyCanvas.getContext('2d');
} }
context.save(); context.save();
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily; context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily;
var metrics = context.measureText(this.attrs.text); var metrics = context.measureText(this.attrs.text);
@ -3640,7 +3640,8 @@ Kinetic.Line = function(config) {
this.setDefaultAttrs({ this.setDefaultAttrs({
points: [], points: [],
lineCap: 'butt', lineCap: 'butt',
dashArray: [] dashArray: [],
detectionType: 'pixel'
}); });
this.shapeType = "Line"; this.shapeType = "Line";

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,8 @@ Kinetic.Line = function(config) {
this.setDefaultAttrs({ this.setDefaultAttrs({
points: [], points: [],
lineCap: 'butt', lineCap: 'butt',
dashArray: [] dashArray: [],
detectionType: 'pixel'
}); });
this.shapeType = "Line"; this.shapeType = "Line";

View File

@ -234,17 +234,17 @@ Kinetic.Text.prototype = {
*/ */
getTextSize: function() { getTextSize: function() {
var context = this.getContext(); var context = this.getContext();
/** /**
* if the text hasn't been added a layer yet there * if the text hasn't been added a layer yet there
* will be no associated context. Will have to create * will be no associated context. Will have to create
* a dummy context * a dummy context
*/ */
if (!context) { if(!context) {
var dummyCanvas = document.createElement('canvas'); var dummyCanvas = document.createElement('canvas');
context = dummyCanvas.getContext('2d'); context = dummyCanvas.getContext('2d');
} }
context.save(); context.save();
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily; context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily;
var metrics = context.measureText(this.attrs.text); var metrics = context.measureText(this.attrs.text);

View File

@ -1219,10 +1219,11 @@ Test.prototype.tests = {
}, { }, {
x: 340, x: 340,
y: 23 y: 23
}, { }
x: 500, /*, {
y: 109 x: 500,
}]; y: 109
}*/];
var line = new Kinetic.Line({ var line = new Kinetic.Line({
points: points, points: points,
@ -1233,9 +1234,17 @@ Test.prototype.tests = {
draggable: true draggable: true
}); });
// test that default detection type is pixel
test(line.getDetectionType() === 'pixel', 'dection type should be pixel');
layer.add(line); layer.add(line);
stage.add(layer); stage.add(layer);
line.saveData();
line.on('dragend', function() {
line.saveData();
});
}, },
'SHAPES - add dashed line': function(containerId) { 'SHAPES - add dashed line': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
@ -1936,9 +1945,9 @@ Test.prototype.tests = {
verticalAlign: 'middle' verticalAlign: 'middle'
}); });
// test text width before adding it to stage // test text width before adding it to stage
test(text.getTextWidth() > 0, 'text width should have a value'); test(text.getTextWidth() > 0, 'text width should have a value');
layer.add(text); layer.add(text);
stage.add(layer); stage.add(layer);