Copy link to clipboard
Copied
Hi, guys!
I'm trying to make a paragraph text layer that adapts to the lenght of the text - I use the same layer to multiple texts and I need it to be easier to do, sometimes when the text is bigger than the previous, the paragraph layer cuts part of my texts off.
I'm studying the sourceRectAtTime expression to make that happen, but I tried a lot and couldn't find a way to make it work 😞 I have tried anchor point, position and scale settings, but I can't make this "responsiveness" happen. Is there a way to do that?
Copy link to clipboard
Copied
You cannot use sourceRectAtTime to get the size of a Paragraph Text box. There is no way that I know of to access the size of a paragraph text box.
The easiest option would be to add a slider to the text layer, which you could use to adjust the font size until the text fills the box. Unfortunately, you cannot use scale because that would change the Text layer Paragraph Text Block size. The expression to set the font size from 40 to 300 looks like this:
sl = effect("Slider Control")("Slider");
style.setFontSize(clamp(sl,40,300))
That would be your simplest option.
The only fully automatic option I am thinking of that might work would be to create your text box on one text layer, figure the number of pixels inside the box, then add another text layer as a guide layer so it won't render, and use sourceRectAtTime() to determine the size of the text and then use a multiplier to change the font size so that the line of text would always fill approximately the same number of pixels. It would be something like this:
//Not a sample expression
if (sourceRectAtTime.width < 1200){
adjust font size until it does;
}
You can then use a simple thisComp. layer ("Guide Layer Text") .text. Source-text expression to copy the text and resize the font to fit in the box. It might take me the better part of a day to figure out if that was even possible.
The other option would be to use multiple lines of text and put them in a small comp that was the size of the paragraph box you need, then use expressions to make the lines fit inside the box. That solution would be a little clunky, but it would get the job done.
Until Adobe adds the paragraph box size to the properties an expression or script can access, you are stuck with some kind of a make-do solution.