Skip to main content
July 29, 2014
Answered

Set different font sizes for portions of text layer?

  • July 29, 2014
  • 2 replies
  • 1363 views

I'm a novice as far as AE goes, but am working on a script to dynamically modify a project.

The project in question has a text layer has a single string, but with variable font size (the text is a price, where the cents portion is a smaller font with different baseline).   I want to use a script to change that text, but simply setting a new text document doesn't retain the variable formatting - all digits end up with the same font size.

From the scripting guide, I see that the font size of a text document object is accessible, but only in very limited form - setting the value sets it for the entire document, with no options to set it for a range of characters.  Would I be correct to assume that programmatically creating/updating a document with multiple font sizes is not possible?

If that's the case, what would be my best options to achieve the same effect?  If the project is changed to have multiple layers/documents, is there a way to adjust the positioning to maintain proper spacing/kerning between the independent strings?  (I also have a dollar sign with yet another font size preceding the price, so I would actually have three pieces of text to position in my script and can't just right/left justify the two strings). 

Thanks for any advice!

This topic has been closed for replies.
Correct answer Dan Ebberts

As far as I know, there's not practical way for a script to maintain multiple font sizes once it modifies a text document.

You can however, use sourceRectAtTime() to get the actual extents of the text in a text layer, so positioning three text layers to get the spacing you want isn't difficult.

Dan

2 replies

Inspiring
August 5, 2014

For something like this, as long as the typeface is the same, I would use text animators and expressions.  Apply an animator to modify scale, position, and tracking, set it to apply based on character index, set the range selector start to 0, end to 2, and then apply an expression to the offset based on the length of the total price string (text.sourceText.length-2 will grab just the last two characters, for example).

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
July 29, 2014

As far as I know, there's not practical way for a script to maintain multiple font sizes once it modifies a text document.

You can however, use sourceRectAtTime() to get the actual extents of the text in a text layer, so positioning three text layers to get the spacing you want isn't difficult.

Dan

July 30, 2014

Thanks Dan!  sourceRectAtTime() looks like just the thing I need, though I haven't figured out what coordinate system that rect is using - it doesn't appear to be relative to the layer itself, but I think I can figure that out (or it may not even matter as long as I know how much it increases/decreases).

It also looks like I need to take transform properties into account to determine the actual rendered location - it took me a while to figure out why the text was actually bigger than the source rect, but I think the scaling applied on the text explains that.