Dynamicly changing font size

hey guys! i`m searching for a possibility to fit a text (maxChars = 13) into a dynamic textfield.
the more characters are entered, the smaller the font size should be! 1 char - size 40, 2 chars - size 36, 3 chars - size 32…! Thx for your ideas!