text.getWidth() and getHeight() now return calculated width and height. Removed getBoxWidth() and getBoxHeight() methods

This commit is contained in:
Eric Rowell
2012-10-11 20:00:13 -07:00
parent 353cd939bd
commit d636afb6fe
4 changed files with 35 additions and 35 deletions

26
dist/kinetic-core.js vendored
View File

@@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Oct 10 2012
* Date: Oct 11 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@@ -4910,8 +4910,8 @@ Kinetic.Text.prototype = {
drawFunc: function(context) {
// draw rect
context.beginPath();
var boxWidth = this.getBoxWidth();
var boxHeight = this.getBoxHeight();
var boxWidth = this.getWidth();
var boxHeight = this.getHeight();
if(this.attrs.cornerRadius === 0) {
// simple rect - don't bother doing all that complicated maths stuff.
@@ -4960,10 +4960,10 @@ Kinetic.Text.prototype = {
// horizontal alignment
context.save();
if(this.attrs.align === 'right') {
context.translate(this.getBoxWidth() - this._getTextSize(text).width - p * 2, 0);
context.translate(this.getWidth() - this._getTextSize(text).width - p * 2, 0);
}
else if(this.attrs.align === 'center') {
context.translate((this.getBoxWidth() - this._getTextSize(text).width - p * 2) / 2, 0);
context.translate((this.getWidth() - this._getTextSize(text).width - p * 2) / 2, 0);
}
this.fillText(context, text);
@@ -4985,23 +4985,23 @@ Kinetic.Text.prototype = {
this.setAttr('text', str);
},
/**
* get box width
* @name getBoxWidth
* get width
* @name getWidth
* @methodOf Kinetic.Text.prototype
*/
getBoxWidth: function() {
getWidth: function() {
return this.attrs.width === 'auto' ? this.getTextWidth() + this.attrs.padding * 2 : this.attrs.width;
},
/**
* get box height
* @name getBoxHeight
* get height
* @name getHeight
* @methodOf Kinetic.Text.prototype
*/
getBoxHeight: function() {
getHeight: function() {
return this.attrs.height === 'auto' ? (this.getTextHeight() * this.textArr.length * this.attrs.lineHeight) + this.attrs.padding * 2 : this.attrs.height;
},
/**
* get text width in pixels
* get text width
* @name getTextWidth
* @methodOf Kinetic.Text.prototype
*/
@@ -5009,7 +5009,7 @@ Kinetic.Text.prototype = {
return this.textWidth;
},
/**
* get text height in pixels
* get text height
* @name getTextHeight
* @methodOf Kinetic.Text.prototype
*/

File diff suppressed because one or more lines are too long

View File

@@ -47,8 +47,8 @@ Kinetic.Text.prototype = {
drawFunc: function(context) {
// draw rect
context.beginPath();
var boxWidth = this.getBoxWidth();
var boxHeight = this.getBoxHeight();
var boxWidth = this.getWidth();
var boxHeight = this.getHeight();
if(this.attrs.cornerRadius === 0) {
// simple rect - don't bother doing all that complicated maths stuff.
@@ -97,10 +97,10 @@ Kinetic.Text.prototype = {
// horizontal alignment
context.save();
if(this.attrs.align === 'right') {
context.translate(this.getBoxWidth() - this._getTextSize(text).width - p * 2, 0);
context.translate(this.getWidth() - this._getTextSize(text).width - p * 2, 0);
}
else if(this.attrs.align === 'center') {
context.translate((this.getBoxWidth() - this._getTextSize(text).width - p * 2) / 2, 0);
context.translate((this.getWidth() - this._getTextSize(text).width - p * 2) / 2, 0);
}
this.fillText(context, text);
@@ -122,23 +122,23 @@ Kinetic.Text.prototype = {
this.setAttr('text', str);
},
/**
* get box width
* @name getBoxWidth
* get width
* @name getWidth
* @methodOf Kinetic.Text.prototype
*/
getBoxWidth: function() {
getWidth: function() {
return this.attrs.width === 'auto' ? this.getTextWidth() + this.attrs.padding * 2 : this.attrs.width;
},
/**
* get box height
* @name getBoxHeight
* get height
* @name getHeight
* @methodOf Kinetic.Text.prototype
*/
getBoxHeight: function() {
getHeight: function() {
return this.attrs.height === 'auto' ? (this.getTextHeight() * this.textArr.length * this.attrs.lineHeight) + this.attrs.padding * 2 : this.attrs.height;
},
/**
* get text width in pixels
* get text width
* @name getTextWidth
* @methodOf Kinetic.Text.prototype
*/
@@ -146,7 +146,7 @@ Kinetic.Text.prototype = {
return this.textWidth;
},
/**
* get text height in pixels
* get text height
* @name getTextHeight
* @methodOf Kinetic.Text.prototype
*/

View File

@@ -2781,7 +2781,7 @@ Test.prototype.tests = {
});
// center text box
text.setOffset(text.getBoxWidth() / 2, text.getBoxHeight() / 2);
text.setOffset(text.getWidth() / 2, text.getHeight() / 2);
layer.add(text);
stage.add(layer);
@@ -2810,8 +2810,8 @@ Test.prototype.tests = {
test(text.getCornerRadius() === 10, 'text box corner radius should be 10');
test(text.getDraggable() === true, 'text should be draggable');
test(text.getBoxWidth() === 400, 'box width should be 400');
test(text.getBoxHeight() === 100, 'box height should be 100');
test(text.getWidth() === 400, 'box width should be 400');
test(text.getHeight() === 100, 'box height should be 100');
test(text.getTextWidth() > 0, 'text width should be greater than 0');
test(text.getTextHeight() > 0, 'text height should be greater than 0');
@@ -3045,8 +3045,8 @@ Test.prototype.tests = {
detectionType: 'path'
});
var width = text.getBoxWidth();
var height = text.getBoxHeight();
var width = text.getWidth();
var height = text.getHeight();
layer.add(text);
stage.add(layer);
@@ -3054,8 +3054,8 @@ Test.prototype.tests = {
text.setFontSize(30);
layer.draw();
test(text.getBoxWidth() > width, 'text box width should have increased.');
test(text.getBoxHeight() > height, 'text box height should have increased.');
test(text.getWidth() > width, 'text box width should have increased.');
test(text.getHeight() > height, 'text box height should have increased.');
},
'SHAPE - get shape name': function(containerId) {