-
Adjust Text Position Animator with Expression that parses Source Text
Hello!
I’ve been toying with a peculiar issue in After Effects with text layers. For some reason the spacing/kerning changes for many fonts between the first character and anchor point when numbers are typed. When numbers are typed they seem to shift an additional 3.5 pixels to the right of the anchor point. I don’t know why this only happens when numbers are typed and it doesn’t seem to be an restricted to any particular font because I tested several and the numbers always seem to shift to the right. In the attached screenshot both text fields have the same font, kerning (set to optical), and font size but you’ll notice the numbers are shifted more to the right even though the only thing that changed was changing letters to numbers.

https://images.creativecow.net/312740/textshift.pngI’m looking for an expression that can check the source text layer for any numbers and change the X value of a position animator to compensate for this shift. If no numbers are detected in the source text the position doesn’t change. The reason I’m looking for a solution to this is because when using sourceRectAtTime numbers often throw off the even spacing of the rectangle created behind the text.
I’ve been playing with the expression below but my lacking javascript knowledge is keeping me from figuring out a way to make this work. This works fine when I type all the numbers. But I can’t quite figure out how to script the expression to not be conditional on all the numbers being present. I want it to work and change position if any numbers are present in the source text. Any ideas?
If anyone could help me figure this one out I’d greatly appreciate it!
Best,
Qinput = thisComp.layer(“TEXT”).text.sourceText;
if (input == “0123456789”) xPos = 0 else xPos = -3.5;
y = 0;
[xPos, y]