Auto-squeeze text (shrink x scale) if any line over n characters


#1

Thanks to the fantastic help on here, I’ve been able to dial in scripts for auto height and auto-placement of text, but not quite sure how to do the following:

IF
one or more lines of text are over n characters

THEN
shrink the x scale value by a given factor depending on how many characters over it is. Letters can’t be any closer together due to caps, etc… so tests show shrinking x scale looks best overall.

In other words, if 20 characters is the ideal size, then I don’t want to stretch the text all lines are below that, but I do need the entire text block to fit within the text safe margins, so if ANY line is above 20, then multiply the y scale value by some constant times the number of characters over from the longest line.

So, if I had lines of 15, 21, 23, 18, then the greatest overage would be 3, so I’d multiply 3 by whatever constant ends up being the closest fit.

I get the logical operators, but not sure how to interface with the character count, or how to extract the overage only from the longest line… or if perhaps there is some other better metric to use instead of character count that gives a better approximation of width.