Hmm, no this wouldn’t work as it wouldn’t divide the text evenly over the lines. So you might be left with a single word on the last line.
So far we have this which is working great for shorter texts where we only want two lines.
But for longer text, we need it to divide into 3 lines.
function breakInTwo(myString) {
var mid = Math.floor(myString.length / 2);
var before = myString.lastIndexOf(” “, mid);
var after = myString.indexOf(” “, mid + 1);
if (before == -1 || (after != -1 && mid – before >= after – mid)) {
mid = after;
} else {
mid = before;
}
return myString.substring(0, mid) + “\n” + myString.substring(mid + 1);
}
if (text.sourceText.indexOf(“\n”) != -1 || text.sourceText.indexOf(“\r”) != -1 || text.sourceText.length<18) {
value;
} else {
val = breakInTwo(text.sourceText);
style.setFont(comp(“00 Color Control”).layer(“Headline Text Font Style”).text.sourceText).setText(val);
}