We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.
I am just wondering how the anchor point of a text layer is calculated. I have reseted my character and paragraph panel and typing out a text "jewelry" (in Times New Roman because that is the Default) and no matter how I align the text with the paragraph tool the Anchor Point at [0,0] never touches the bounding box of the text layer.
So is it known how these x and y coordinates are calculated or where the origin is based?
Text operates based on the em box of each individual letter, meaning the data that defines spacing, leading and kerning, not just the visible data. Has never worked any different. Also AE honors the alignment setting of the text paragraph, so coordinates of 0,0 can still be in the center of the text, if only is set to centered alignment.
So how can I than callculate the center of a text layer is there a way to access the data of these boxes around all letters?
I want to dynamically change the center of the text layer, without having to use a script to recenter the anchor point after every change. Is this possible?
That's what the sourceRectAtTime() expression is for, though ironically it is based on the rasterized pixel data, so you may still need to build in extra offsets to get your anchor point to appear where you want it. The "visual center" still would not necessarily be the absolute center.
Thanks for your help. I have tried it already with the sourceRectAtTime() but it hasn't given me the center of the text layer, because the anchor point doesn't unfortunately start in any of the corners. And with any change to the text the offset values change as well.
Is there a way to get the center of the red bounding box? Or is there a way to fetch those additionally needed offset data to use in an expression?
To clarify, are you using paragraph text, or point text? (drag a box vs click)
While many things work the same, paragraph text can come with a few extra complications.
You've got a variety of functions available to you using sourceRectAtTime, which should allow you to get what you need.
For example, adding this expression to the text layer's Anchor Point will keep it centered on the bounding box, observing multiple lines, line spacing, ascenders/decenders, strokes, etc.
var rect = thisLayer.sourceRectAtTime();
var x = rect.left+rect.width/2;
var y = rect.top+rect.height/2;
Thank you this works perfectly with point text.
Thats great! I was wondering if theres a way to deal with the upper or lower length of letters - like f or g ... or ascender, descender of the letters. The thing im trying is to have the same anchorpoint for words with or without upper or lower length. Basically im trying to get the same centerpoint even it the word is assymetrical in Height.
For example "man" , "Man", "song" or "Song"
Here is how text layers work:
The following expression will always center a shape layer Rectangle/Position behind a text layer that is above it no matter what the justification as long as the position of the text layer is tied to the position of the text layer and the anchor point of the text layer and the shape layer is at the default [0, 0]value:
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, (y + t) * refScale]
I hope that clears up the confusion.
If you want to change the text layer's anchor point and keep a text box below it lined up you just have to tie both the position and the anchor point of the shape layer to the position and anchor point of the text layer with an expression.