refactored the whole _setTextData method of Kinetic.Text, added a 'wrapping' option.

Performances should improve.
Also, the text should not overflow anymore from the defined width like it sometimes did.
This commit is contained in:
Louis Jolibois
2013-03-15 15:40:30 +01:00
parent 5ca21992de
commit c58db11a2a
3 changed files with 146 additions and 67 deletions

File diff suppressed because one or more lines are too long

View File

@@ -356,5 +356,40 @@ Test.Modules.Text = {
//console.log(layer.toDataURL());
warn(layer.toDataURL() === dataUrls['text stroke disabled'], 'should be text with blue fill and no stroke');
},
'wrapped text': function (containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var txt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
arr = [txt, txt];
var layer = new Kinetic.Layer();
var text = new Kinetic.Text({
x: 0,
y: 0,
width: 578,
text: arr.join(''),
fontSize: 15,
fontFamily: 'Calibri',
fill: '#000',
wrapping: 'word'
});
layer.add(text);
stage.add(layer);
warn(layer.toDataURL() === dataUrls['wrapped text']['wrapping to words'], 'text should be wrapped to words');
text.setWrapping('none');
layer.draw();
warn(layer.toDataURL() === dataUrls['wrapped text']['no wrapping'], 'text should not be wrapped');
text.setWrapping('char');
layer.draw();
warn(layer.toDataURL() === dataUrls['wrapped text']['wrapping to chars'], 'text should be wrapped to chars');
}
};