Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How area texts are pushed into a new line?

  • How area texts are pushed into a new line?

    Posted by Tomas Bumbulevičius on October 13, 2021 at 12:55 pm

    Hey guys, I wonder is there a way to figure out whether text is moved into a next line inside area text box, by splitting contents of a layer by some special character?

    Idea is as follows – if we have a phrase in one line, but make area-text-box region smaller, it pushes overbleeding text into next line. Is there a way to detect that through expressions?

    I thought maybe it under the hood adds return carriage or “\x03” – but splitting phrase in a temporary layer by various options doesn’t provide that information.

    Cheers!

    Andrei Popa replied 4 years, 6 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 13, 2021 at 11:09 pm

    I don’t know that there’s a way to do it based on characters, but it seems like you could compare sourceRectAtTime(time).height to the font size to see if there’s more than one line.

  • Tomas Bumbulevičius

    October 27, 2021 at 6:19 am

    Hey Dan, thanks a lot for your response. This could be a workaround for this indeed, but there is a catch I think.

    Do you happen to know the overall logic of how paragraph bounding box works? What is interesting, that sourceRectAtTime is not capable of reading actual text inside the box – it reads whole height of paragraph, disregarding of how many lines there are. I might have confused calling this thing “area text” in the headline 🙂 Thanks!

  • Andrei Popa

    October 27, 2021 at 7:48 am

    Hi Tomas. sourceRectAtTime reads only the text size if used with false value for include extents. Like this sourceRectAtTime(time, false).height;

    If all you want is to know how many lines there are, you can use this function for that.

    //L=layer, T=time

    function getNumRows(L, T) {

    var H = L.sourceRectAtTime(L.sourceTime(T), false).height;

    var myStyle = L.text.sourceText.style;

    myFontSize = myStyle.fontSize;

    myLeading = myStyle.autoLeading ? myFontSize * 1.2 : myStyle.leading;

    return Math.ceil((H - myFontSize*0.5) / myLeading);

    }

    getNumRows(thisLayer,0);

  • Tomas Bumbulevičius

    October 27, 2021 at 3:04 pm

    Thanks a lot Andrei! I always thought true/false for extents is only for shapes!

    Could you please elaborate on the “1.2” multiplication? Can this value vary depending on the font chosen?

  • Andrei Popa

    October 28, 2021 at 6:46 am

    Autoleading is equal to 1.2 of the size of the font. However, if the autoleading is selected, myStyle.leading returns the value that the leading had before autoleading. So if your font is 100 px and leading 80 and you decide to set autoleading, the paragraph looks as if the leading would be 120. But myStyle.leading still returns 80. So that is why that line is there.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy