mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
added new getTextSize(), getTextWidth(), and getTextHeight() methods
This commit is contained in:
@@ -36,9 +36,8 @@ Kinetic.Text = function(config) {
|
||||
var context = this.getContext();
|
||||
context.font = this.fontStyle + ' ' + this.fontSize + 'pt ' + this.fontFamily;
|
||||
context.textBaseline = 'middle';
|
||||
var metrics = context.measureText(this.text);
|
||||
var textHeight = textHeight = parseInt(this.fontSize, 10);
|
||||
var textWidth = metrics.width;
|
||||
var textHeight = this.getTextHeight();
|
||||
var textWidth = this.getTextWidth();
|
||||
var p = this.padding;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
@@ -227,6 +226,32 @@ Kinetic.Text.prototype = {
|
||||
*/
|
||||
getText: function() {
|
||||
return this.text;
|
||||
},
|
||||
/**
|
||||
* get text width in pixels
|
||||
*/
|
||||
getTextWidth: function() {
|
||||
return this.getTextSize().width;
|
||||
},
|
||||
/**
|
||||
* get text height in pixels
|
||||
*/
|
||||
getTextHeight: function() {
|
||||
return this.getTextSize().height;
|
||||
},
|
||||
/**
|
||||
* get text size in pixels
|
||||
*/
|
||||
getTextSize: function() {
|
||||
var context = this.getContext();
|
||||
context.save();
|
||||
context.font = this.fontStyle + ' ' + this.fontSize + 'pt ' + this.fontFamily;
|
||||
var metrics = context.measureText(this.text);
|
||||
context.restore();
|
||||
return {
|
||||
width: metrics.width,
|
||||
height: parseInt(this.fontSize, 10)
|
||||
};
|
||||
}
|
||||
};
|
||||
// extend Shape
|
||||
|
Reference in New Issue
Block a user