Class: Prawn::Text::Formatted::Box

Inherits:
Box
  • Object
show all
Includes:
Core::Text::Formatted::Wrap
Defined in:
lib/prawn/text/formatted/box.rb

Overview

Generally, one would use the Prawn::Text::Formatted#formatted_text_box convenience method. However, using Text::Formatted::Box.new in conjunction with #render(:dry_run => true) enables one to do look-ahead calculations prior to placing text on the page, or to determine how much vertical space was consumed by the printed text

Instance Attribute Summary

Attributes inherited from Box

#ascender, #at, #descender, #leading, #line_height, #text

Instance Method Summary collapse

Methods included from Core::Text::Formatted::Wrap

#wrap

Methods inherited from Box

#available_width, #draw_line, extensions, inherited, #render, #valid_options

Methods included from Core::Text::Wrap

#wrap

Constructor Details

#initialize(array, options = {}) ⇒ Box

Returns a new instance of Box.



100
101
102
103
104
105
106
# File 'lib/prawn/text/formatted/box.rb', line 100

def initialize(array, options={})
  super(array, options)
  if @overflow == :ellipses
    raise NotImplementedError, "ellipses overflow unavailable with" +
      "formatted box"
  end
end

Instance Method Details

#draw_fragment(fragment, accumulated_width = 0, line_width = 0, word_spacing = 0) ⇒ Object

fragment is a Prawn::Text::Formatted::Fragment object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/prawn/text/formatted/box.rb', line 117

def draw_fragment(fragment, accumulated_width=0, line_width=0, word_spacing=0) #:nodoc:
  case(@align)
  when :left, :justify
    x = @at[0]
  when :center
    x = @at[0] + @width * 0.5 - line_width * 0.5
  when :right
    x = @at[0] + @width - line_width
  end

  x += accumulated_width

  y = @at[1] + @baseline_y

  y += fragment.y_offset

  fragment.left = x
  fragment.baseline = y

  draw_fragment_underlays(fragment)

  if @inked
    if @align == :justify
      @document.word_spacing(word_spacing) {
        @document.draw_text!(fragment.text, :at => [x, y],
                             :kerning => @kerning)
      }
    else
      @document.draw_text!(fragment.text, :at => [x, y],
                           :kerning => @kerning)
    end

    draw_fragment_overlays(fragment)
  end
end

#heightObject

The height actually used during the previous render



110
111
112
113
# File 'lib/prawn/text/formatted/box.rb', line 110

def height
  return 0 if @baseline_y.nil? || @descender.nil?
  @baseline_y.abs + @line_height - @ascender
end