ccoa's UMS FIT_WINDOW_TO_TEXT Patch

ccoa's UMS FIT_WINDOW_TO_TEXT Patch​

Introduction
ccoa's Universal Message System (UMS) FIT_WINDOW_TO_TEXT mode adds extra space from escape codes and make the window unnecessary longer.
I had Chaucer fix it and I'd like to share the fix with anyone want to remove the gap as well.

Since ccoa does not allow to redistribute the script, so I can only show the parts need changing only.

Script
- Replace line 1195 width = [width, self.contents.text_size(line).width].max
with width = [width, text_width(line)].max

- Add these at line 1290 (above reset_window)
Spoiler: text_width method
Ruby:
def text_width ( text )
    width = 0;

    text = text.gsub( "\030" ) do "" end
    text = text.gsub( "\031" ) do "" end
    text = text.gsub( "\000" ) { "" }
    text = text.gsub( /\001[.*?]/ ) { "" }
    text = text.gsub( "\002" ) { "" }
    text = text.gsub( /\026[.*?]/ ) { "" }
    text = text.gsub( "\003" ) { "" }
    text = text.gsub( "\023" ) { "" }
    text = text.gsub( /\024[.*?]/ ) { "" }
    text = text.gsub( /\025[.*?]/ ) { "" }
    text = text.gsub( "\004" ) { "" }
    text = text.gsub( "\005" ) { "" }
    text = text.gsub( "\006" ) { "" }
    text = text.gsub( /\007\[(.*?)\]/ ) { "" }
    text = text.gsub( /\010\[.*?\]/ ) { "" }
    text = text.gsub( /\011\[.*?\]/ ) { "" }
    text = text.gsub( /\013\[[0-9]+\]/ ) { "" }
    text = text.gsub( /\014\[[0-9]+\]\s\s/ ) {
      width += 24;
      ""
    }
    text = text.gsub( /\015\[[0-9]+\]\s\s/ ) {
      width += 24;
      ""
    }
    text = text.gsub( /\016\[[0-9]+\]\s\s/ ) {
      width += 24;
      ""
    }
    text = text.gsub( /\017\[[0-9]+\]\s\s/ ) {
      width += 24;
      ""
    }
    text = text.gsub( /\027\[.*?\]/ ) {
      width += 24;
      ""
    }
    text = text.gsub( "\020" ) { "" }
    text = text.gsub( "\021" ) { "" }
    text = text.gsub( "\022" ) { "" }

    width += self.contents.text_size( text ).width;

    return width;

  end

Credit and Thanks
- Chaucer
- Credit is optional

Original thread: https://forums.rpgmakerweb.com/threads/ccoas-ums-fit_window_to_text-patch.159688/