-
CenterMultiple Lines of Text Vertically While Ignoring Descenders
I am trying to add an expression to my text layer anchor point to keep the text centered vertically regardless of how many lines of text there are. I don’t want to use sourceRectAtTime because the text moves vertically when there are descenders. I’m trying to use the fontSize and leading to find the center of the layer, but it’s not doing what I expect it to do. I just changed my expressions engine to JavaScript (apparently I was still in ExtendScript) so this syntax is new to me.
Thanks in advance!
Code below:
const layer = thisLayer;
const numLines = layer.text.sourceText.value.split(‘\n’).length;
const { fontSize, leading } = layer.text.sourceText.style;
const xHeight = fontSize / 2;
const height = xHeight + leading * (numLines – 1);
[0, height/2]