Here’s an attempt at it. It is breaking a paragraph onto lines after a certain number of letters that depends on the width of the rectangle. It’s not that accurate, as the number of letters doesn’t necessarily correspond to length of line, but it is something. Using this, all text should be the same size and there should be no line breaks in the original source text.
Comp has a rectangle named “Rect” and a text layer that covers the maximum size of the rectangle.
Code for source text:
txt = value;
done = 0;
esc = 0;
len =0;
row = Math.floor(thisComp.layer("Rect").sourceRectAtTime(time).width*thisComp.layer("Rect").scale[0]/1220);//divisor depends on type size
while (done == 0){
esc ++;
len+=row;
if (txt.length >= len+1){
for (i = len; i > len-row; i--) if (txt[i] == " ") break;
if (i > len-row){
txt=txt.substr(0,i) + "\r" + txt.substr(i+1,9999);
}
}
len = i;
if (esc>100){done=1}
}
txt