Class: Prawn::Table::Cell::Text
- Inherits:
-
Prawn::Table::Cell
- Object
- Prawn::Table::Cell
- Prawn::Table::Cell::Text
- Defined in:
- lib/prawn/table/cell/text.rb
Overview
A Cell that contains text. Has some limited options to set font family, size, and style.
Constant Summary collapse
- TextOptions =
[:inline_format, :kerning, :size, :style, :align, :valign, :rotate, :rotate_around, :leading, :single_line, :skip_encoding, :overflow, :min_font_size]
Constants inherited from Prawn::Table::Cell
Instance Attribute Summary collapse
-
#font ⇒ Object
Returns the font that will be used to draw this cell.
-
#text_color ⇒ Object
writeonly
Sets the attribute text_color.
Attributes inherited from Prawn::Table::Cell
#background_color, #border_color, #border_width, #borders, #content, #height, #max_width, #min_width, #padding
Instance Method Summary collapse
-
#draw_content ⇒ Object
Draws the text content into its bounding box.
-
#initialize(pdf, point, options = {}) ⇒ Text
constructor
A new instance of Text.
-
#natural_content_height ⇒ Object
Returns the natural height of this block of text, wrapped to the preset width.
-
#natural_content_width ⇒ Object
Returns the width of this text with no wrapping.
Methods inherited from Prawn::Table::Cell
#content_height, #content_width, #draw, make, #width, #width=, #x, #x=, #y, #y=
Constructor Details
#initialize(pdf, point, options = {}) ⇒ Text
Returns a new instance of Text.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prawn/table/cell/text.rb', line 28 def initialize(pdf, point, ={}) @text_options = {} super # 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 end |
Instance Attribute Details
#font ⇒ Object
Returns the font that will be used to draw this cell.
41 42 43 |
# File 'lib/prawn/table/cell/text.rb', line 41 def font with_font { @pdf.font } end |
#text_color=(value) ⇒ Object (writeonly)
Sets the attribute text_color
26 27 28 |
# File 'lib/prawn/table/cell/text.rb', line 26 def text_color=(value) @text_color = value end |
Instance Method Details
#draw_content ⇒ Object
Draws the text content into its bounding box.
65 66 67 68 69 70 71 72 73 74 |
# 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 |
#natural_content_height ⇒ Object
Returns the natural height of this block of text, wrapped to the preset width.
55 56 57 58 59 60 61 |
# 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 end end |
#natural_content_width ⇒ Object
Returns the width of this text with no wrapping. This will be far off from the final width if the text is long.
48 49 50 |
# File 'lib/prawn/table/cell/text.rb', line 48 def natural_content_width [styled_width_of(@content), @pdf.bounds.width].min end |