ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Adding line breaks to a block of text based on character length

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
TIneke van Schalkwyk
Adding line breaks to a block of text based on character length
on Jul 31, 2020 at 4:09:09 am

I'm trying to automatically break headline text into 2 or 3 lines EVENLY.
The parameters would be something like:
If text length > 40 characters add line break to 1/2 way (not breaking words)
If text length > 20 but < 40 characters split txt equally into 3 lines


Return to posts index

Brice Munn
Re: Adding line breaks to a block of text based on character length
on Jul 31, 2020 at 4:08:09 pm

Would a text bounding box work? Just click and drag with the type tool to create a rectangular text box like you would make in word processing or graphics software. Then you can use the normal settings in the Character and Paragraph windows to control the typesetting.


Return to posts index

TIneke van Schalkwyk
Re: Adding line breaks to a block of text based on character length
on Aug 2, 2020 at 12:10:34 pm

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);
}


Return to posts index


Tomas Bumbulevičius
Re: Adding line breaks to a block of text based on character length
on Aug 4, 2020 at 11:22:42 am

Hey Tineke, just wondering - lines still remains not perfectly equal in sizes, due to different letters width. Is that an issue or not at all for you?

Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH


Return to posts index

TIneke van Schalkwyk
Re: Adding line breaks to a block of text based on character length
on Aug 4, 2020 at 12:04:27 pm

No that doesn’t matter to me.


Return to posts index

Tomas Bumbulevičius
Re: Adding line breaks to a block of text based on character length
on Aug 5, 2020 at 11:42:18 am

Tineke - then caps lock in the first post on 'evenly' does not really make sense.

Reason - IF you have a superlongtextinoneline this won't work nicely ! (:

Find out more:
Motion Graphics Design & After Effects Tutorials
On YT
On VH


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]