+ dx += space_advance
+ word_break = true
+ end
+
+ # End of a word?
+ if word_break then
+ # If we care about line width, check for overflow
+ if max_width != null then
+ # Calculate the length of the next word
+ var prev_w = null
+ var word_len = 0.0
+ for wi in [i+1..text.length[ do
+ var w = text[wi]
+
+ if w == '\n' or w == pld or w == plu or w.is_whitespace then break
+ word_len += advance(prev_w, w)
+ prev_w = w
+ end
+
+ # Would the line be too long?
+ if dx + word_len > max_width then
+ if text_sprites.wrap then
+ # Wrap
+ justify(line_sprites, text_sprites.align, dx)
+ dy -= line_height
+ if max_height != null and max_height < -dy + line_height then break
+ dx = 0.0
+ else
+ # Cut short
+ justify(line_sprites, text_sprites.align, dx)
+ dy -= line_height
+ if max_height != null and max_height < -dy + line_height then break
+ dx = 0.0
+ while c != '\n' and i < text.length - 1 do
+ i += 1
+ c = text[i]
+ end
+ end
+ end
+ end
+