Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression to change line spacing based on above or below baseline characters

  • Expression to change line spacing based on above or below baseline characters

    Posted by Adam Greenberg on March 28, 2023 at 3:26 pm

    HI everyone, I have a simple task, but I imagine the expression is complicated to write,

    I`d like to add an expression to the y value of the line spacing property of a texts property that will do the following to a multiline text.

    It will look at any above or below baseline characters for every line of text and adjust the spacing so that these characters never overlap.

    so in this photo, the first example is how I want the result to be when no above or below baseline characters are used.

    the 2 second example is what I want after effects to do in the case where those characters may appear.

    And if possible, the 3rd secnerio would be ideal, where as when those characters do not interfere with each other we keep the distance closer then the 2nd example, but still no overlap.

    Has anyone ever done anything like this before ?

    thanks everyone

    Adam Greenberg replied 2 months ago 2 Members · 13 Replies
  • 13 Replies
  • Filip Vandueren

    March 29, 2023 at 5:46 am

    Hey Adam, by multiline text, do you mean, more than 2 lines?

    I can’t immediately think of a way to achieve the third case with more than 2 layers.

    Both the 2nd and 3rd are not very simple to implement with expressions while they take just a few seconds to do manually, so is it just an academic question of wether it is possible, or is it vital to be implemented in a template ?

    Another question is, are you sure this is a desirable layout ?

  • Filip Vandueren

    March 29, 2023 at 6:45 am

    It seems like you are asking for the “line by line” look, which I don’t immediately know how to do with expressions, and is ugly (IMO).

    Is the “global” look OK ?
    So the entire text gets the minimum line-spacing (+ 10px margin) so no ascenders and descenders intersect anywhere?

  • Adam Greenberg

    March 29, 2023 at 2:19 pm

    Hi Flip, so yes it is for a template, and it is 1 text layer with hard returns ( if thats possible )

    The reason is…. the text is all caps but in french.

    And the look we are going for is the text almost touching each other, but we want the text to have a bigger gap between lines only when there are characters that pose a problem, such as;

    É È Ç Î À Â

    those characteres sort of ruin the look but we have no choice but prevent them from overlapping. so I am sure there is a way to get this in the line spacing property as opposed to the leading, which we cannot write expressions in.

  • Filip Vandueren

    March 29, 2023 at 5:04 pm

    Sure, but do you want that uneven look ?

    Because, minimizing it line by line looks like this:

  • Filip Vandueren

    March 30, 2023 at 11:23 am

    I made a project-file:

    https://we.tl/t-RgqaPEuSxo

    Can you check if this does what you need ?

    https://imgur.com/a/a7FZtRV

    View post on imgur.com

  • Adam Greenberg

    March 30, 2023 at 2:34 pm

    Amazing Filip.

    I see your point with the variable spacing per line but most texts will fall on only 2 lines, so this would not really be an issue.

    Is it possible to have this work on 1 layer only, without using source text property to reference another layer. I ask only because the users would need per character control in the character palette sometimes. But if not, I can always add a note to the template for those cases.

    thanks again Filip.

  • Filip Vandueren

    March 30, 2023 at 3:02 pm

    It’s less stable if I implement it on 1 layer, but I’ll post a version later.

    They would have to disable an expression before editing otherwise it would be very slow to edit the text.

  • Filip Vandueren

    March 30, 2023 at 3:05 pm

    Also, if there are text animators on the text too that can move the letters around, then it’s much better to do the analyzing of the text on a second hidden layer.

  • Filip Vandueren

    March 30, 2023 at 4:50 pm

    I can’t get it to work on one layer.

    Best I can do is: it tells you the linespacing value you have to enter manually for minimal overlap. Could be easily scripted too, but just a preset with expressions on 1 layer is unreliable.

    https://imgur.com/a/MeVAek5

    It’s really neat how with a bit of kerning you can minimize the height by nudging the accents and descenders into nooks and crannies 🙂

    View post on imgur.com

  • Filip Vandueren

    March 31, 2023 at 8:06 am

    Hey Adam, go it working on 1 text-layer. But I’m not doing anything else with the layer (animating, text-animators,…) which could break it.

    https://we.tl/t-gpWLxdbh0g

    I recommend unchecking the checkbox before editing text, then re-enabling.

    And a funny caveat in the image…

    A good way to add some extra safety margin is to add a stroke of the background color around the text (black in my example image) . The “extra pixels” control that I added only looks vertical, while a stroke would also ensure a minimal horizontal distance of a few pixels to avoid.

    Of course, in a capitalized french text with accents, you’ll never get as extreme of an example as here.

    Also, very important, forgot to mention: this needs 16bpc precision, so in an 8bpc project, it’ll collapse.

Page 1 of 2

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