Auto-Resize Text based on length

Is there a script and is it possible to: if a particular line of text in a ''box'' is bigger, instead of stretching, the font be automatically resized so it fits in the ''box'', BUT the font be resized only for that particular line, not for all the text.
This pic is like it is now(stretchy):
DVMafvY.png

But this pic is like it would ideally be with the script:
AFca5OY.png

Any help would be appreciated. 🙂
This should help: https://forums.rpgmakerweb.com/index.php?threads/text-cache.1001/
@A-Moonless-Night Sorry, but this doesn's work like what I need.
In some cases, the text exceeds the text ''box'' instead the font size being reduced(in the pic the B from the 2nd Elysium Bird can't be seen):
Zu5zG5Q.png

While in this case, it stretches like it did before:
YejbGRj.png

I need something that makes the text fit into the ''box'', by automatically reducing the font size till it fits or something, not for the text to go outside the ''box''.

EDIT: Or maybe there is some script so I can manually determine the font size for the particular battler's title.
Try this:
Code:
class Window_BattleEnemy < Window_Selectable
  def draw_item(index)
    change_color(normal_color)
    name = $game_troop.alive_members[index].name
    while text_size(name).width >= item_rect_for_text(index).width do
      contents.font.size -= 1
    end
    draw_text(item_rect_for_text(index), name)
    reset_font_settings
  end
end
@A-Moonless-Night thank you, it works flawlessly 😀
When i tried it, enemies with long names like the Morphean Mushroom's letters were cut off. Like instead of Morphean Mushroom B, it says Morphean Mushroom without the letter B.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/auto-resize-text-based-on-length.102797/