ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Adjusting line space based on the text layer scale

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Ken Kwong
Adjusting line space based on the text layer scale
on Sep 30, 2019 at 10:44:20 pm
Last Edited By Ken Kwong on Oct 2, 2019 at 1:18:36 am

Hey Guys! Feeling great to be here, I am currently working on a project, and trying to develop some expressions to help myself work smarter. And here are some details of what I am trying to achieve:

I have applied the following expression to the [b][i]scale[/i][/b] of a regular Point Text layer, then when the content you type in is wider then 500 pixels, it will scale down the layer so it won’t exceed 500 pixels

s=thisLayer;
scl=500;
x=s.sourceRectAtTime(time,false).width;
if (x>scl)
{[scl/x*value[0],scl/x*value[1]]}
else
{value}



















It’s working pretty nice.

But when I input line return to the text: since the expression scales the whole layer, including the vertical scale, the result is not visually what I want:


















I hope to keep the line spacing between lines visually the same even after the scale expression scales down the whole layer:



















So I developed the following expression, and put on the [i][b]line space[/b][/i]

TextHeight=sourceRectAtTime(time,false).height;
BeforeHeight=TextHeight;
AfterHeight=TextHeight*scale[1]/100;
LineSpace=(BeforeHeight-AfterHeight)/4*100/scale[1];
[value[0],LineSpace]


This expression kind of works when I change the preview resolution to force the preview refresh, or use Edit>Purge>Image Cache Memory, but sometimes both ways won’t work




















I assume the reason is because the line space expression makes it react to the layer height, but when the line spacing increases, the layer height will also increase, then the expression will make the line space to react to that again… which creates a “loop” and confuses the AE.

If that’s the case, I am wondering if that’s other way to achieve the line spacing purpose without creating that “loop”, or maybe a better/ easier way to force refresh the preview so it can work every time?

Any help will be greatly appreciated!

Attached with the AE file to better illustrate the situation:
https://www.dropbox.com/s/k8fbfsnxmgfuyrp/LineSpaceReactToScaling_Sample.ae...


Return to posts index

Tomas Bumbulevičius
Re: Adjusting line space based on the text layer scale
on Oct 6, 2019 at 9:09:07 am

Hey Ken, I am pretty sure that this is a bug, due to the fact that resolution change shoudln't make any affect on visuals, apart from quality loss.

Anyways, try applying expression below to anchorpoint and see if it works for your favour.

sourceSize = thisLayer.sourceRectAtTime(time, false);
T = sourceSize.top;
L = sourceSize.left;
W = sourceSize.width;
H = sourceSize.height;
([L+ W/2,T+H/2])


Seeing you do this for Shakr Media, I would recommend not to hardcode numbers into expressions like you did in scale. Instead, pick thisComp.width, and find divider which works for your scenario (/2, for example). Then, if in the future you need to adapt the same approach for different resolution, it will auto-adjust, instead of manual change 'magic numbers'. Cheers!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

Ken Kwong
Re: Adjusting line space based on the text layer scale
on Oct 6, 2019 at 9:53:01 am

Hi Tomas,

Thank you for the kind help!
Will definitely try the auto-adjust solution you suggests!


To illustrate my question better, please see the attached images:
I have applied the following expression on the Scale of the following text layer

s=thisLayer;
scl=500;
x=s.sourceRectAtTime(time,false).width;
if (x>scl)
{[scl/x*value[0],scl/x*value[1]]}
else
{value}





When I type more content to the text layer and exceeds the maximum width I set, it will scale down the whole layer.
And if there are more than one line of content in a single text layer, it results like this:



What I hope to achieve is that when the scale expression scales down the whole text layer contains multiple lines,
the line space can increase itself base on the scaling rate, in order to make the text layer visually remain the same height as before the scale expression:



which I developed the following expression:
TextHeight=sourceRectAtTime(time,false).height;
BeforeHeight=TextHeight;
AfterHeight=TextHeight*scale[1]/100;
LineSpace=(BeforeHeight-AfterHeight)/4*100/scale[1];
[value[0],LineSpace]

but it leads to the "bug" you mentioned. And I believe the reason is this expression created a dependent loop and messed up the result.

So I am wondering if theres other expression that can do the same purpose (increase line space in order to keep the text layer height visually the same after the scale expression) without creating this "bug"?

Greatly appreciate your help!



Attached with my AE file
https://dl.dropboxusercontent.com/s/k8fbfsnxmgfuyrp/LineSpaceReactToScaling...


Return to posts index


Tomas Bumbulevičius
Re: Adjusting line space based on the text layer scale
on Oct 13, 2019 at 2:00:10 pm

Hey Ken, sorry for my late response. There are few things to consider:

1. When you sourceRect for lines spacing, it kind of overrides resizing, this is why you can't successfully increase distance between the lines.
2. Line spacing works in this way:
~Disregarding how many lines of text there are, it only uses single line height in pixels.

SO, calculation to find proper distance between the lines would be as follows:
~ ([maxHeight] / [numOfLines-1]) - [singleLineDistance] = Resulting line height

To get number of lines, change animator's range to index, and change it to lines.

This should get it going to expand titles in fixed ranges. Might require some tweaks, but should be somewhat it.

let us know if it works!

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index

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