Fit Text to Object?
Posted: Wed May 18, 2022 5:57 pm
Hi all,
I am trying to resize the text of a text frame (text frame sizes will vary) so that it does not exceed the width or height of the frame. My code starts the text size at 1pt and then increases it by 1pt (via a repeat routine) until the formattedWidth reaches the width of the frame. This works. Then (and if needed), I need the text size reduced until the formattedHeight does not exceed the height of the field. The width portion seems to work but not the height. I'm sure it's something silly I am missing. Here's my code:
Anyone have any ideas?
Thank you,
Jon
I am trying to resize the text of a text frame (text frame sizes will vary) so that it does not exceed the width or height of the frame. My code starts the text size at 1pt and then increases it by 1pt (via a repeat routine) until the formattedWidth reaches the width of the frame. This works. Then (and if needed), I need the text size reduced until the formattedHeight does not exceed the height of the field. The width portion seems to work but not the height. I'm sure it's something silly I am missing. Here's my code:
Code: Select all
on mouseUp
put true into ttt
put 1 into t2
repeat while ttt
add 1 to t2
set the textsize of field "Tester" to t2
if the formattedWidth of field "Tester" > the width of field "Tester" then
put false into ttt
set textsize of field "Tester" to (t2 - 1)
end if
end repeat
put textSize of field "Tester" into t2
repeat until the formattedHeight of field "Tester" < the height of field "Tester"
set textSize of field "Tester" to (t2 - 1)
end repeat
end mouseUp
Thank you,
Jon
