Module: Prawn::Core::Text::Formatted::Wrap

Included in:
Text::Formatted::Box
Defined in:
lib/prawn/core/text/formatted/wrap.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#initialize(array, options) ⇒ Object



10
11
12
13
14
# File 'lib/prawn/core/text/formatted/wrap.rb', line 10

def initialize(array, options)
  super(array, options)
  @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
  @arranger = Prawn::Core::Text::Formatted::Arranger.new(@document)
end

#wrap(array) ⇒ Object

See the developer documentation for Prawn::Core::Text#wrap

Formatted#wrap should set some of the variables slightly differently than Text#wrap;

<tt>@line_height</tt>::
     the height of the tallest fragment in the last printed line
<tt>@descender</tt>::
     the descender height of the tallest fragment in the last
     printed line
<tt>@ascender</tt>::
     the ascender heigth of the tallest fragment in the last
     printed line

Returns any formatted text that was not printed



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/prawn/core/text/formatted/wrap.rb', line 32

def wrap(array) #:nodoc:
  initialize_wrap(array)

  move_baseline = true
  while @arranger.unfinished?
    printed_fragments = []

    line_to_print = @line_wrap.wrap_line(:document => @document,
                                         :kerning => @kerning,
                                         :width => available_width,
                                         :arranger => @arranger)

    move_baseline = false
    break unless enough_height_for_this_line?
    move_baseline_down

    accumulated_width = 0
    word_spacing = word_spacing_for_this_line
    while fragment = @arranger.retrieve_fragment
      fragment.word_spacing = word_spacing
      if fragment.text == "\n"
        printed_fragments << "\n" if @printed_lines.last == ""
        break
      end
      printed_fragments << fragment.text
      format_and_draw_fragment(fragment, accumulated_width,
                               @line_wrap.width, word_spacing)
      accumulated_width += fragment.width
    end
    @printed_lines << printed_fragments.join("")
    break if @single_line
    move_baseline = true unless @arranger.finished?
  end
  move_baseline_down if move_baseline
  @text = @printed_lines.join("\n")

  @arranger.unconsumed
end