Class: PDF::Wrapper::TextCell
- Inherits:
-
Object
- Object
- PDF::Wrapper::TextCell
- Defined in:
- lib/pdf/wrapper/text_cell.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#height ⇒ Object
Returns the value of attribute height.
-
#max_width ⇒ Object
readonly
Returns the value of attribute max_width.
-
#min_width ⇒ Object
readonly
Returns the value of attribute min_width.
-
#natural_width ⇒ Object
readonly
Returns the value of attribute natural_width.
- #options ⇒ Object
-
#width ⇒ Object
Returns the value of attribute width.
-
#wrapper ⇒ Object
readonly
Returns the value of attribute wrapper.
Instance Method Summary collapse
- #calculate_height(wrapper) ⇒ Object
- #calculate_width_range(wrapper) ⇒ Object
- #draw(wrapper, x, y) ⇒ Object
-
#initialize(str) ⇒ TextCell
constructor
A new instance of TextCell.
- #text_options ⇒ Object
- #text_options_without_markup ⇒ Object
Constructor Details
#initialize(str) ⇒ TextCell
Returns a new instance of TextCell.
11 12 13 14 |
# File 'lib/pdf/wrapper/text_cell.rb', line 11 def initialize(str) @data = str.to_s @options = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/pdf/wrapper/text_cell.rb', line 7 def data @data end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/pdf/wrapper/text_cell.rb', line 8 def height @height end |
#max_width ⇒ Object (readonly)
Returns the value of attribute max_width.
7 8 9 |
# File 'lib/pdf/wrapper/text_cell.rb', line 7 def max_width @max_width end |
#min_width ⇒ Object (readonly)
Returns the value of attribute min_width.
7 8 9 |
# File 'lib/pdf/wrapper/text_cell.rb', line 7 def min_width @min_width end |
#natural_width ⇒ Object (readonly)
Returns the value of attribute natural_width.
7 8 9 |
# File 'lib/pdf/wrapper/text_cell.rb', line 7 def natural_width @natural_width end |
#options ⇒ Object
44 45 46 |
# File 'lib/pdf/wrapper/text_cell.rb', line 44 def @options ||= {} end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/pdf/wrapper/text_cell.rb', line 8 def width @width end |
#wrapper ⇒ Object (readonly)
Returns the value of attribute wrapper.
7 8 9 |
# File 'lib/pdf/wrapper/text_cell.rb', line 7 def wrapper @wrapper end |
Instance Method Details
#calculate_height(wrapper) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/pdf/wrapper/text_cell.rb', line 35 def calculate_height(wrapper) raise "Cannot calculate height until cell width is set" if self.width.nil? @wrapper = wrapper padding = [:padding] || 3 @height = wrapper.text_height(self.data, self.width - (padding * 2), ) + (padding * 2) end |
#calculate_width_range(wrapper) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pdf/wrapper/text_cell.rb', line 22 def calculate_width_range(wrapper) @wrapper = wrapper padding = [:padding] || 3 if [:markup] == :pango str = self.data.dup.gsub(/<.+?>/,"").gsub("&","&").gsub("<","<").gsub(">",">") else str = self.data.dup end @min_width = wrapper.text_width(str.gsub(/\b|\B/,"\n"), ) + (padding * 4) @natural_width = wrapper.text_width(str, ) + (padding * 4) end |
#draw(wrapper, x, y) ⇒ Object
16 17 18 19 20 |
# File 'lib/pdf/wrapper/text_cell.rb', line 16 def draw(wrapper, x, y) @wrapper = wrapper wrapper.cell(self.data, x, y, self.width, self.height, self.) end |
#text_options ⇒ Object
48 49 50 |
# File 'lib/pdf/wrapper/text_cell.rb', line 48 def self..only(wrapper..keys) end |
#text_options_without_markup ⇒ Object
52 53 54 |
# File 'lib/pdf/wrapper/text_cell.rb', line 52 def self..only(wrapper..keys).except(:markup) end |