2012-11-14 13:37:28 +08:00
Test . Modules . Text = {
2013-01-01 04:45:32 +08:00
'add text with shadows' : function ( containerId ) {
2012-11-24 06:54:32 +08:00
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var layer = new Kinetic . Layer ( ) ;
2013-01-01 04:45:32 +08:00
var rect = new Kinetic . Rect ( {
2012-11-24 06:54:32 +08:00
x : stage . getWidth ( ) / 2 ,
y : stage . getHeight ( ) / 2 ,
stroke : '#555' ,
strokeWidth : 5 ,
fill : '#ddd' ,
2013-01-01 04:45:32 +08:00
width : 400 ,
height : 100 ,
shadowColor : 'black' ,
shadowBlur : 1 ,
shadowOffset : [ 10 , 10 ] ,
shadowOpacity : 0.2 ,
cornerRadius : 10
} ) ;
var text = new Kinetic . Text ( {
x : stage . getWidth ( ) / 2 ,
y : stage . getHeight ( ) / 2 ,
2012-11-24 06:54:32 +08:00
text : 'Hello World!' ,
fontSize : 50 ,
fontFamily : 'Calibri' ,
fontStyle : 'normal' ,
2013-01-01 04:45:32 +08:00
fill : '#888' ,
stroke : '#333' ,
2012-11-24 06:54:32 +08:00
align : 'right' ,
lineHeight : 1.2 ,
width : 400 ,
height : 100 ,
padding : 10 ,
2013-01-01 04:45:32 +08:00
shadowColor : 'red' ,
2012-12-31 16:45:38 +08:00
shadowBlur : 1 ,
shadowOffset : [ 10 , 10 ] ,
2013-01-01 04:45:32 +08:00
shadowOpacity : 0.2
} ) ;
var group = new Kinetic . Group ( {
2012-11-24 06:54:32 +08:00
draggable : true
} ) ;
// center text box
2013-01-01 04:45:32 +08:00
rect . setOffset ( text . getWidth ( ) / 2 , text . getHeight ( ) / 2 ) ;
2012-11-24 06:54:32 +08:00
text . setOffset ( text . getWidth ( ) / 2 , text . getHeight ( ) / 2 ) ;
2013-01-01 04:45:32 +08:00
group . add ( rect ) ;
group . add ( text ) ;
layer . add ( group ) ;
2012-11-24 06:54:32 +08:00
stage . add ( layer ) ;
2013-03-24 15:14:42 +08:00
2013-05-20 12:48:48 +08:00
test ( text . getClassName ( ) === 'Text' , 'getClassName should be Text' ) ;
2012-11-24 06:54:32 +08:00
} ,
2012-11-14 13:37:28 +08:00
'text getters and setters' : function ( containerId ) {
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var layer = new Kinetic . Layer ( ) ;
var text = new Kinetic . Text ( {
x : stage . getWidth ( ) / 2 ,
y : stage . getHeight ( ) / 2 ,
text : 'Hello World!' ,
fontSize : 50 ,
fontFamily : 'Calibri' ,
fontStyle : 'normal' ,
2013-01-01 04:45:32 +08:00
fill : '#888' ,
stroke : '#333' ,
2012-11-14 13:37:28 +08:00
align : 'right' ,
lineHeight : 1.2 ,
width : 400 ,
height : 100 ,
padding : 10 ,
2012-12-31 16:45:38 +08:00
shadowColor : 'black' ,
shadowBlur : 1 ,
shadowOffset : [ 10 , 10 ] ,
shadowOpacity : 0.2 ,
2012-11-14 13:37:28 +08:00
draggable : true
} ) ;
// center text box
text . setOffset ( text . getWidth ( ) / 2 , text . getHeight ( ) / 2 ) ;
layer . add ( text ) ;
stage . add ( layer ) ;
/ *
* test getters and setters
* /
test ( text . getX ( ) === stage . getWidth ( ) / 2 , 'text box x should be in center of stage' ) ;
test ( text . getY ( ) === stage . getHeight ( ) / 2 , 'text box y should be in center of stage' ) ;
2013-01-01 04:45:32 +08:00
2012-11-14 13:37:28 +08:00
test ( text . getText ( ) === 'Hello World!' , 'text should be Hello World!' ) ;
test ( text . getFontSize ( ) == 50 , 'font size should 50' ) ;
test ( text . getFontFamily ( ) == 'Calibri' , 'font family should be Calibri' ) ;
test ( text . getFontStyle ( ) == 'normal' , 'font style should be normal' ) ;
2013-01-01 04:45:32 +08:00
test ( text . getFill ( ) == '#888' , 'text fill should be #888' ) ;
test ( text . getStroke ( ) == '#333' , 'text fill should be #333' ) ;
2012-11-14 13:37:28 +08:00
test ( text . getAlign ( ) === 'right' , 'text should be aligned right' ) ;
test ( text . getLineHeight ( ) === 1.2 , 'line height should be 1.2' ) ;
test ( text . getWidth ( ) === 400 , 'width should be 400' ) ;
test ( text . getHeight ( ) === 100 , 'height should be 100' ) ;
test ( text . getPadding ( ) === 10 , 'padding should be 10' ) ;
2012-12-31 16:45:38 +08:00
test ( text . getShadowColor ( ) === 'black' , 'text box shadow color should be black' ) ;
2012-11-14 13:37:28 +08:00
test ( text . getDraggable ( ) === true , 'text should be draggable' ) ;
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' ) ;
text . setX ( 1 ) ;
text . setY ( 2 ) ;
text . setText ( 'bye world!' ) ;
text . setFontSize ( 10 ) ;
text . setFontFamily ( 'Arial' ) ;
text . setFontStyle ( 'bold' ) ;
2013-01-01 04:45:32 +08:00
text . setFill ( 'green' ) ;
text . setStroke ( 'yellow' ) ;
2012-11-14 13:37:28 +08:00
text . setAlign ( 'left' ) ;
text . setWidth ( 300 ) ;
text . setHeight ( 75 ) ;
text . setPadding ( 20 ) ;
2012-12-31 16:45:38 +08:00
text . setShadowColor ( 'green' ) ;
2012-11-14 13:37:28 +08:00
text . setDraggable ( false ) ;
test ( text . getX ( ) === 1 , 'text box x should be 1' ) ;
test ( text . getY ( ) === 2 , 'text box y should be 2' ) ;
test ( text . getText ( ) === 'bye world!' , 'text should be bye world!' ) ;
test ( text . getFontSize ( ) == 10 , 'font size should 10' ) ;
test ( text . getFontFamily ( ) == 'Arial' , 'font family should be Arial' ) ;
test ( text . getFontStyle ( ) == 'bold' , 'font style should be bold' ) ;
2013-01-01 04:45:32 +08:00
test ( text . getFill ( ) == 'green' , 'text fill should be green' ) ;
test ( text . getStroke ( ) == 'yellow' , 'text fill should be yellow' ) ;
2012-11-14 13:37:28 +08:00
test ( text . getAlign ( ) === 'left' , 'text should be aligned left' ) ;
test ( text . getWidth ( ) === 300 , 'width should be 300' ) ;
test ( text . getHeight ( ) === 75 , 'height should be 75' ) ;
test ( text . getPadding ( ) === 20 , 'padding should be 20' ) ;
2012-12-31 16:45:38 +08:00
test ( text . getShadowColor ( ) === 'green' , 'text box shadow color should be green' ) ;
2012-11-14 13:37:28 +08:00
test ( text . getDraggable ( ) === false , 'text draggable should be false' ) ;
// test set text to integer
text . setText ( 5 ) ;
//document.body.appendChild(layer.bufferCanvas.element)
//layer.setListening(false);
2012-11-19 11:50:50 +08:00
layer . drawHit ( ) ;
2012-11-14 13:37:28 +08:00
} ,
'text multi line' : function ( containerId ) {
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var layer = new Kinetic . Layer ( ) ;
2013-03-21 00:02:18 +08:00
var rect = new Kinetic . Rect ( {
x : 10 ,
y : 10 ,
width : 380 ,
height : 300 ,
fill : 'red'
} ) ;
2012-11-14 13:37:28 +08:00
var text = new Kinetic . Text ( {
x : 10 ,
y : 10 ,
2013-04-05 13:22:28 +08:00
text : 'HEADING\n\nAll the world\'s a stage, merely players. They have their exits and their entrances; And one man in his time plays many parts.' ,
2012-11-14 13:37:28 +08:00
//text: 'HEADING\n\nThis is a really cool paragraph. \n And this is a footer.',
2013-03-21 00:02:18 +08:00
fontSize : 24 ,
2012-11-14 13:37:28 +08:00
fontFamily : 'Calibri' ,
fontStyle : 'normal' ,
2013-01-01 04:45:32 +08:00
fill : '#555' ,
2012-11-14 13:37:28 +08:00
//width: 20,
width : 380 ,
//width: 200,
2013-04-05 13:22:28 +08:00
padding : 10 ,
2012-11-14 13:37:28 +08:00
align : 'center' ,
2013-03-21 00:17:21 +08:00
draggable : true ,
2013-03-21 00:26:55 +08:00
wrap : 'WORD'
2012-11-14 13:37:28 +08:00
} ) ;
// center text box
//text.setOffset(text.getBoxWidth() / 2, text.getBoxHeight() / 2);
2013-03-21 00:02:18 +08:00
layer . add ( rect ) . add ( text ) ;
2012-11-14 13:37:28 +08:00
stage . add ( layer ) ;
2013-01-27 11:35:53 +08:00
2013-01-02 11:36:13 +08:00
test ( text . getLineHeight ( ) === 1 , 'text line height should be defaulted to 1' ) ;
2012-11-14 13:37:28 +08:00
2013-03-21 00:02:18 +08:00
/ *
2012-11-14 13:37:28 +08:00
text . transitionTo ( {
2013-03-21 00:02:18 +08:00
width : 50 ,
duration : 20
} ) ;
rect . transitionTo ( {
width : 50 ,
duration : 20
2012-11-14 13:37:28 +08:00
} ) ;
* /
2013-03-21 00:02:18 +08:00
2013-03-21 00:17:21 +08:00
2012-11-14 13:37:28 +08:00
} ,
'text multi line with shadows' : function ( containerId ) {
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var layer = new Kinetic . Layer ( ) ;
var text = new Kinetic . Text ( {
x : 10 ,
y : 10 ,
//stroke: '#555',
//strokeWidth: 5,
text : 'HEADING\n\nAll the world\'s a stage, and all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts.' ,
//text: 'HEADING\n\nThis is a really cool paragraph. \n And this is a footer.',
fontSize : 16 ,
fontFamily : 'Calibri' ,
fontStyle : 'normal' ,
2013-01-01 04:45:32 +08:00
fill : '#555' ,
2012-11-14 13:37:28 +08:00
//width: 20,
width : 380 ,
//width: 200,
padding : 20 ,
align : 'center' ,
2012-12-31 16:45:38 +08:00
shadowColor : 'red' ,
shadowBlur : 1 ,
shadowOffset : [ 10 , 10 ] ,
shadowOpacity : 0.5 ,
2013-01-01 04:45:32 +08:00
draggable : true
2012-11-14 13:37:28 +08:00
} ) ;
layer . add ( text ) ;
stage . add ( layer ) ;
2013-01-27 11:35:53 +08:00
2012-11-14 13:37:28 +08:00
} ,
'change font size should update text data' : function ( containerId ) {
var stage = new Kinetic . Stage ( {
container : containerId ,
width : 578 ,
height : 200
} ) ;
var layer = new Kinetic . Layer ( ) ;
var text = new Kinetic . Text ( {
x : 10 ,
y : 10 ,
text : 'Some awesome text' ,
fontSize : 16 ,
fontFamily : 'Calibri' ,
fontStyle : 'normal' ,
2013-01-01 04:45:32 +08:00
fill : '#555' ,
2012-11-14 13:37:28 +08:00
align : 'center' ,
padding : 5 ,
2013-01-01 04:45:32 +08:00
draggable : true
2012-11-14 13:37:28 +08:00
} ) ;
var width = text . getWidth ( ) ;
var height = text . getHeight ( ) ;
2013-03-15 23:33:05 +08:00
2012-11-14 13:37:28 +08:00
layer . add ( text ) ;
stage . add ( layer ) ;
text . setFontSize ( 30 ) ;
layer . draw ( ) ;
2013-03-15 23:33:05 +08:00
//console.log(text.getHeight() + ',' + height);
2012-11-14 13:37:28 +08:00
test ( text . getWidth ( ) > width , 'text box width should have increased.' ) ;
test ( text . getHeight ( ) > height , 'text box height should have increased.' ) ;
}
} ;