A Cell that contains text. Has some limited options to set font family, size, and style.
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
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
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
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
# 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
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
# 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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.