Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SourceRectAtTime not working

Community Beginner ,
Jul 05, 2021 Jul 05, 2021

I've been trying to make SourceRectAtTime working for a long time, and I can't understand why it's not working properly. Everywhere I look, be it on this forum or on tutorials, no one seem to have this problem--which suggests I'm missing something really obvious about the way it should work.

 

First off, when I connect the shape layer to the text, the shape layer gets like 10 times too long. Fine, I resize it in the contents menu and while that kind of works, it seems to be off by some pixels, the longer the text the more it's off.

 

This is what I write on size:

s = thisComp.layer("text").sourceRectAtTime();
w = s.width;

[w,value[1]]

I've tried to add and subtract the "left" parameter to this, but then it just work for some letters.

martinj27319522_0-1625484485675.pngmartinj27319522_1-1625484503560.png

martinj27319522_3-1625484587353.png

 

Look at the last "e"

martinj27319522_2-1625484527355.png

English is not my first language by the way, sorry for the poor explanation. Thanks in advance.

TOPICS
Expressions
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2021 Jul 05, 2021

My guess is After Effects is calculating the width, but it can't take into account exact character width.  How about adding a correction value to the text width, something:

 

w = s.width + s.width*0.01

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 05, 2021 Jul 05, 2021

Thank you for your reply! 0.01 was too much, but I will keep on experimenting with the decimals and see if I'll get it right eventually.

 

Just out of curiosity, if it doesn't measure character width, what is it measuring?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2021 Jul 05, 2021

Impossible to know without any actual info about your font formatting and other details. That said, of course there will be minor discrepancies due to quantization errors. Even on large text some internal font values will end up as tiny fractions like 0.00001 em and wil lsimply be rounded up or down since ultimately the engine has to make a determination on whether a pixel is visible or not. As suggested by the cactus, sinmply figure this into your planning and also don't mess too much with custom kerning, scaling character widths and so on to minimize those artifacts. Also find alternate fonts. Many fonts these days have specific screen-optimized variants that avoid a lot of the issues just like generally better balnced, commercial fonts may work better than stock system fonts or free fonts from the Internet.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 05, 2021 Jul 05, 2021

Thank you for your reply and thorough explanation! I hadn't taken all those things into consideration, obviously. I realise it can't be exact to the point of a 100th of a pixel, but something like 1 pixel off by 200 seemed a bit too much. Maybe I'm just being overly-faddish. And ofcourse a reasonable padding will hide most of these faults. Cheers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2021 Jul 05, 2021
LATEST

The layer scale is not taken into consideration. Make sure that you have not inadvertently scaled the layer. That will foul it up, but it can be compensated for. 

 

Try adding these expressions to the appropriate properties of a rectangle that is just below a text layer:

 

//Contents/Rectangle 1/Rectangle Path 1/Size;
src=thisComp.layer(index - 1);
ref = sRc.sourceRectAtTime();
refScale = sRc.scale * .01;
x = ref.width;
y = ref.height;

[x * refScale[0], y * refScale[1]]

//Contents/Rectangle 1/Rectangle Path 1/Position;
src=thisComp.layer(index - 1);
box = src.sourceRectAtTime();
refScale = src.scale * .01;
x = box.width / 2;
y = box.height / 2;
t = box.top;
l = box.left;

[(x + l) * refScale[0], (y + t) * refScale[1]]

//Shape Layer/Transform/Position;
src=thisComp.layer(index - 1);
src.position;

 

You have to make sure all of the other shape layer properties are at their default position.

 

The shape layer will perfectly line up with the text layer no matter what the paragraph justification is and no matter where the text layer is in the comp as long as the anchor point of the text layer has not been fiddled with.

SourceRectAtTime.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines