ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Automatic font size on text based on its width

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Svetlin Aleksandrov
Automatic font size on text based on its width
on Jun 30, 2020 at 5:30:25 pm

Hello,
I'm trying to make text that decrease its font size depending on its length if its bigger than certain value. I'm trying to use while statement but with no success.

The idea is lets say we have a text with font size 75 and when you are typing text and the text width reach lets say 500 we want font size to start going down.

tWidth = thisLayer.sourceRectAtTime().width;
fSize = 75;

while(tWidth > 500){
fSize--;
thisLayer.text.sourceText.style.setFontSize(fSize);
tWidth = thisLayer.sourceRectAtTime().width;
};

text.sourceText;


Return to posts index

Andrei Popa
Re: Automatic font size on text based on its width
on Jul 1, 2020 at 11:12:22 am

Is there a particular reason why you don't decrease the size? If you want to decrease the scale, you can use this as an expression, applied to scale:


maxWidth = 500;
thisWidth = sourceRectAtTime(time,false).width;
ratio = Math.min(maxWidth/thisWidth,1);
value*ratio


Andrei
My Envato portfolio.


Return to posts index

Svetlin Aleksandrov
Re: Automatic font size on text based on its width
on Jul 1, 2020 at 4:37:54 pm

Thanks, that worked in my case. :)


Return to posts index


David Avila
Re: Automatic font size on text based on its width
on Jul 1, 2020 at 4:45:34 pm

speaking of font expressions, is there a way to have a text layer reference another layer, and have its own type of font-style-expression? like

thisComp.layer("Main").text.sourceText.style.setFauxBold(1).setFauxItalic(1).setFontSize(900)


Return to posts index

Andrei Popa
Re: Automatic font size on text based on its width
on Jul 1, 2020 at 4:59:52 pm

Something like

style.setFauxBold(1).setFauxItalic(1).setFontSize(900).setText(thisComp.layer("Main").text.sourceText.value)

Andrei
My Envato portfolio.


Return to posts index

David Avila
Re: Automatic font size on text based on its width
on Jul 1, 2020 at 5:09:37 pm

Ahh, thanks.

I needed to also do it for a long else-if statement. I figured it was the same way, setting the style and the text result in each of the "else if" outputs.


Return to posts index

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