Method: Core.multiline

Defined in:
lib/core.rb

.multiline(text, width, font) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/core.rb', line 73

def self.multiline(text, width, font)
  ret = []
  lines = text.split("\n")
  lines.each { |line|
    ary = line.split(" ")
    str = ""
    ary.each { |word|
      if font.text_width(str + word) < width - 18
        str += "#{word} "
      else
        str.rstrip!
        if str != ""
          ret.push(str)
        end
        str = "#{word} "
      end
      if word == ary.last
        str.rstrip!
        ret.push(str)
      end
    }
  }
  return ret
end