-
Paragraph Alignment Detection
Hey folks,
what are your workflows for detecting a text layer’s paragraph alignment, since you can’t directly access it via expressions?
I found a solution to my case yesterday, which might be a little specific, but I thought I’d share it anyway.
My setup consists of a text layer where one line is text, and the next line is a pipe character stretched into a box. Changing the paragraph alignment on this would only reposition the text, and not the pipe character, since that one is stretched in the opposite direction with a scaling animator.
But now, knowing that only one part of the layer moves, we can measure it against the other part, and got something tangible to detect the paragraph alignment with. SourceRectAtTime seemed perfect for this, so the following code on anchor point grouping alignment made the stretched pipe character always follow the first line’s position:
const a = sourceRectAtTime(-3);
const b = sourceRectAtTime(-1);
if (a.left > b.left) {
rightAligned = [50, 0];
} else if (a.width < b.width) {
leftAligned = [-50, 0];
} else {
centered = [0, 0];
}
One important thing to mention here is that the part we want to compare the changes in alignment to needs to remain static at all times, which means that we need to isolate its bounding box using a scaling animator set to [0, 0] (I did it at time == -3), leaving only the stretched pipe character.
The negative time 1 in the other sourceRect is just a workaround for some minor bugs that can occur when you leave the parentheses empty.
Another drawback is that this isn’t optimized for keyframing sourceText yet, which I found to be a little glitchy as well. Apart from that, it’s pretty solid!
Thrilled to hear your thoughts & ideas!