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 65 def draw_content with_font do @pdf.move_down((@pdf.font.line_gap + @pdf.font.descender)/2) with_text_color do text_box(:width => content_width + FPTolerance, :height => content_height + FPTolerance, :at => [0, @pdf.cursor]).render end end end
Returns the font that will be used to draw this cell.
# File lib/prawn/table/cell/text.rb, line 34 def font with_font { @pdf.font } 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 41 def font_style=(style) @text_options[:style] = style end
Returns the natural height of this block of text, wrapped to the preset width.
# File lib/prawn/table/cell/text.rb, line 55 def natural_content_height with_font do b = text_box(:width => content_width + FPTolerance) b.render(:dry_run => true) b.height + b.line_gap end end
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 48 def natural_content_width [styled_width_of(@content), @pdf.bounds.width].min end
# File lib/prawn/table/cell/text.rb, line 76 def set_width_constraints # Sets a reasonable minimum width. If the cell has any content, make # sure we have enough width to be at least one character wide. This is # a bit of a hack, but it should work well enough. min_content_width = [natural_content_width, styled_width_of("M")].min @min_width ||= padding_left + padding_right + min_content_width super end
Returns the width of text under the given text options.
# File lib/prawn/table/cell/text.rb, line 122 def styled_width_of(text) with_font do options = {} options[:size] = @text_options[:size] if @text_options[:size] @pdf.font.compute_width_of(text, options) end end
# File lib/prawn/table/cell/text.rb, line 106 def text_box(extra_options={}) if @text_options[:inline_format] options = @text_options.dup options.delete(:inline_format) array = ::Prawn::Text::Formatted::Parser.to_array(@content) ::Prawn::Text::Formatted::Box.new(array, options.merge(extra_options).merge(:document => @pdf)) else ::Prawn::Text::Box.new(@content, @text_options.merge(extra_options). merge(:document => @pdf)) end end
Generated with the Darkfish Rdoc Generator 2.