ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Line break if text is bigger then width

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Tobias van Kempen
Line break if text is bigger then width
on Jul 10, 2017 at 9:06:19 am

Hey

I'm currently trying to make a text box element that can be used with live text in premiere.
I tried tweaking the code that makes a line break after a fixed number of characters. ( https://forums.creativecow.net/thread/227/34484 )

But the problem I get is that after it reaches the max width, it makes a line break after one word.
Is there a way that it always breaks the sentence after it reaches the max width, so that you can have for lines breaks in total?



I hope you guys can help.


Kind regards,
Tobias van Kempen

txt = value;
s = thisLayer;
n = 455;
outStr = "";
newLine = ""
splt = txt.split(" ")

for (i = 0; i &lt; splt.length; i++){
if ((s.sourceRectAtTime(time-s.inPoint,true).width / i ) > n){
if (outStr != "") outStr += "\r";
outStr += newLine;
newLine = splt[i];
}else{
if (newLine != "") newLine += " ";
newLine += splt[i];
}
}
if (newLine != ""){
if (outStr != "") outStr += "\r";
outStr += newLine;
}
outStr;


Return to posts index

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