Object
# File lib/prawn/text/box.rb, line 349
349: def wrap_line(line, options)
350: @document = options[:document]
351: @size = options[:size]
352: @kerning = options[:kerning]
353: @width = options[:width]
354: @accumulated_width = 0
355: @output = ""
356:
357: scan_pattern = @document.font.unicode? ? /\S+|\s+/ : /\S+|\s+/
358: space_scan_pattern = @document.font.unicode? ? /\s/ : /\s/
359:
360: line.scan(scan_pattern).each do |segment|
361: # yes, this block could be split out into another method, but it is
362: # called on every word printed, so I'm keeping it here for speed
363:
364: segment_width = @document.width_of(segment,
365: :size => @size,
366: :kerning => @kerning)
367:
368: if @accumulated_width + segment_width <= @width
369: @accumulated_width += segment_width
370: @output << segment
371: else
372: # if the line contains white space, don't split the
373: # final word that doesn't fit, just return what fits nicely
374: break if @output =~ space_scan_pattern
375: wrap_by_char(segment)
376: break
377: end
378: end
379: @output
380: end
# File lib/prawn/text/box.rb, line 396
396: def append_char(char)
397: @accumulated_width += @document.width_of(char,
398: :size => @size,
399: :kerning => @kerning)
400: if @accumulated_width >= @width
401: false
402: else
403: @output << char
404: true
405: end
406: end
# File lib/prawn/text/box.rb, line 384
384: def wrap_by_char(segment)
385: if @document.font.unicode?
386: segment.unpack("U*").each do |char_int|
387: return unless append_char([char_int].pack("U"))
388: end
389: else
390: segment.each_char do |char|
391: return unless append_char(char)
392: end
393: end
394: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.