Prawn::Table::Cell::Text

A Cell that contains text. Has some limited options to set font family, size, and style.

Constants

TextOptions

Attributes

font[W]
text_color[W]

Public Class Methods

new(pdf, point, options={}) click to toggle source
    # File lib/prawn/table/cell/text.rb, line 28
28:         def initialize(pdf, point, options={})
29:           @text_options = {}
30:           super
31:         end

Public Instance Methods

draw_content() click to toggle source

Draws the text content into its bounding box.

    # File lib/prawn/table/cell/text.rb, line 66
66:         def draw_content
67:           with_font do 
68:             @pdf.move_down((@pdf.font.line_gap + @pdf.font.descender)/2)
69:             with_text_color do
70:               text_box(:width => content_width + FPTolerance, 
71:                        :height => content_height + FPTolerance,
72:                        :at => [0, @pdf.cursor]).render
73:             end
74:           end
75:         end
font() click to toggle source

Returns the font that will be used to draw this cell.

    # File lib/prawn/table/cell/text.rb, line 35
35:         def font
36:           with_font { @pdf.font }
37:         end
font_style=(style) click to toggle source

Sets the style of the font in use. Equivalent to the Text::Box style option, but we already have a style method.

    # File lib/prawn/table/cell/text.rb, line 42
42:         def font_style=(style)
43:           @text_options[:style] = style
44:         end
natural_content_height() click to toggle source

Returns the natural height of this block of text, wrapped to the preset width.

    # File lib/prawn/table/cell/text.rb, line 56
56:         def natural_content_height
57:           with_font do
58:             b = text_box(:width => content_width + FPTolerance)
59:             b.render(:dry_run => true)
60:             b.height + b.line_gap
61:           end
62:         end
natural_content_width() click to toggle source

Returns the width of this text with no wrapping. This will be far off from the final width if the text is long.

    # File lib/prawn/table/cell/text.rb, line 49
49:         def natural_content_width
50:           [styled_width_of(@content), @pdf.bounds.width].min
51:         end

Protected Instance Methods

set_width_constraints() click to toggle source
    # File lib/prawn/table/cell/text.rb, line 79
79:         def set_width_constraints
80:           # Sets a reasonable minimum width. If the cell has any content, make
81:           # sure we have enough width to be at least one character wide. This is
82:           # a bit of a hack, but it should work well enough.
83:           min_content_width = [natural_content_width, styled_width_of("M")].min
84:           @min_width ||= padding_left + padding_right + min_content_width
85:           super
86:         end
styled_width_of(text) click to toggle source

Returns the width of text under the given text options.

     # File lib/prawn/table/cell/text.rb, line 123
123:         def styled_width_of(text)
124:           with_font do
125:             options = {}
126:             options[:size] = @text_options[:size] if @text_options[:size]
127: 
128:             @pdf.font.compute_width_of(text, options)
129:           end
130:         end
text_box(extra_options={}) click to toggle source
     # File lib/prawn/table/cell/text.rb, line 107
107:         def text_box(extra_options={})
108:           if @text_options[:inline_format]
109:             options = @text_options.dup
110:             options.delete(:inline_format)
111: 
112:             array = ::Prawn::Text::Formatted::Parser.to_array(@content)
113:             ::Prawn::Text::Formatted::Box.new(array,
114:               options.merge(extra_options).merge(:document => @pdf))
115:           else
116:             ::Prawn::Text::Box.new(@content, @text_options.merge(extra_options).
117:                merge(:document => @pdf))
118:           end
119:         end
with_font() click to toggle source
    # File lib/prawn/table/cell/text.rb, line 88
88:         def with_font
89:           @pdf.save_font do
90:             options = {}
91:             options[:style] = @text_options[:style] if @text_options[:style]
92: 
93:             @pdf.font(@font || @pdf.font.name, options)
94: 
95:             yield
96:           end
97:         end
with_text_color() click to toggle source
     # File lib/prawn/table/cell/text.rb, line 99
 99:         def with_text_color
100:           old_color = @pdf.fill_color || '000000'
101:           @pdf.fill_color(@text_color) if @text_color
102:           yield
103:         ensure
104:           @pdf.fill_color(old_color)
105:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.