10 Replies Latest reply on Oct 5, 2008 9:31 PM by Mylenium

    Center text horizontally and vertically on composition?

    theboyk Level 1
      Hello,

      I'm working on a short projects (15 minutes length). Every 30 seconds a title fade in/out against a blank (grey) composition. How do I go about easily centering the text (single word) on the composition both horizontally and vertically? I know I can horizontally center via the paragraphs pallet, but how do I center on the vertical at the same time?

      Right now I'm modifying the Anchor Point of the text so it's in the center (visually) of the text, and then set the Position to the center of the composition, but every time I increase the type size, I have to go through this all over again...and with different titles coming up every 30 seconds or so, a simple text size change turns into a lot of work.

      I can only image there's a better way to do this and would appreciate any advice for an AE newb!

      Thanks,
      Kristin.
        • 1. Re: Center text horizontally and vertically on composition?
          Mylenium Most Valuable Participant
          No. Text alignment is determined by the properties of the text layer, meaning that the actual rendered pixels are derived from the contours in relation to the glyph bounding box and kerning info found in the font file. Hence the placement of the anchor point or other text-specific stuff is derived from the true typographical data, which in effect means that the anchor point will almost never be placed in the vertical center because the text engine will respect baseline settings and line spacing. Therefore aligning text automatically is not even possible with the Align&Distribute palette. You could only coerce AE by creating the text in Photoshop and importing the pixel data. In that case you could use Align&Distribute to center the text by creating a comp size solid as reference. You can always convert such text to editable text later.

          Mylenium
          • 2. Re: Center text horizontally and vertically on composition?
            theboyk Level 1
            A, bummer.<br />Well, here's to hoping CS4 will bring better text box options from InDesign... (I know, I won't hold my breathe... <G>).<br />Thanks!<br />k.
            • 3. Re: Center text horizontally and vertically on composition?
              A. Cobb Level 3
              It is possible to do this via scripting, but it won't be "live", i.e. you would have to run a script to grab the dimensions of the text layer each time you want to update its vertical alignment.

              It is also possible to roughly align text vertically using expressions given three limitations:

              1) You'll have to be willing to consider the height of the text layer to only extend from the cap height of the first line to the baseline of the last line, meaning descenders and ascenders wouldn't be counted as part of the height of the text layer.

              2) You'll have to manually locate the center of the first line of text.

              3) You'll have to be happy with a consistent point size and line spacing throughout.

              Given those limitations, vertical alignment can be done as follows:

              Add a Position animator to your text layer. Delete the default range selector you won't need it. Next add the Line Spacing property to the newly-created animator (using its "Add" menu). In the Character panel, set your text layer's line spacing to 0 (it will really be set to .01, but the difference shouldn't be noticeable once we're done). In the Line Spacing animator, set the desired line spacing (unfortunately, "Auto" isn't an option).

              Now set your Text layer's anchor point such that it falls in the center of the text's cap height (the height of a capital letter with no ascender or descenders).

              Next, add the following expression to the Position property of the text animator (NOT the Position property of the text layer's Transform group):

              >STA = text.sourceText.split("\r");

              >value - [0, (STA.length-1)*propertyGroup(countUp = 2).property.lineSpacing[1]]/2

              The second line should be all one line, but the forum insists on wrapping it. Be aware that if you later decide to change the point size of the font, you'll need to temporarily disable the text animator and center up the anchor point again.

              You can also use this method to force the text layer to shift up to accommodate new lines by deleting the "/2" at the end of the second line of the expression.
              • 4. Re: Center text horizontally and vertically on composition?
                (Steve_Patterson) Level 1
                Nice, Aaron. It looks like you've done this one before. :)
                • 6. Re: Center text horizontally and vertically on composition?
                  Mylenium Most Valuable Participant
                  BTW, for all folks interested: CS4 scripting will introduce some new methods (not for expressions, unfortunately) that deal with matters of getting the text bounding box, setting font sizes and a few other things, so this might become a bit easier.

                  Mylenium
                  • 7. Re: Center text horizontally and vertically on composition?
                    A. Cobb Level 3
                    Where'd you hear about the scripting additions? Is there any information on the web?
                    • 8. Re: Center text horizontally and vertically on composition?
                      Todd_Kopriva Level 8
                      > Where'd you hear about the scripting additions?

                      A little bird that works in my building probably told him.

                      > Is there any information on the web?

                      That same little bird is working on a summary of changes to scripting for After Effects CS4. Stay tuned.
                      • 10. Re: Center text horizontally and vertically on composition?
                        Mylenium Most Valuable Participant
                        Todd is in a funny mood today... ;-)

                        Mylenium