Sure, suppose you want to have a sourceRect for a textlayer, but you want that sourcerect to be tall enough to contain descenders, even if there aren’t any in the current text. (useful if you want to line up multiple
Choose a character for your current font that has a full height both above and below the baseline, for example the pipe symbol “|” is good in many fonts. (Or you can use a character that doesn’t have any ascenders or descenders like “x” , but then add a margin you know will be enough for the font)
Add a “character value” textanimator to your text, with this expression:
"|".codePointAt(0);
You’ll see all the characters change to |. If you would take the top and height of the sourceRect of the layer now, you’ll get the margin of the descenders.
But if you change the expression to:
time < 0 ? "|".codePointAt(0) : 0;
Everything is normal again, the text will only be changed to |||| when the time <0.
So now you can do this:
sr1 = sourceRectAtTime(time);
sr2 = sourceRectAtTime(-1);
l = sr1.left;
w = sr1.width;
t = sr2.top;
h = sr2.height;
The horizontal parameters are based on the actual text, the vertical parameters are based on the text as it exists (hidden) in negative time: every character replaced by “|”
You may want to add an extra margin because stuff like Á is taller than |
I hope that’s clear.