Class: PDF::Wrapper::TextCell

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/wrapper/text_cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/pdf/wrapper/text_cell.rb', line 7

def data
  @data
end

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/pdf/wrapper/text_cell.rb', line 8

def height
  @height
end

#max_widthObject (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_widthObject (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_widthObject (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

#optionsObject



44
45
46
# File 'lib/pdf/wrapper/text_cell.rb', line 44

def options
  @options ||= {}
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/pdf/wrapper/text_cell.rb', line 8

def width
  @width
end

#wrapperObject (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 = options[:padding] || 3
  @height = wrapper.text_height(self.data, self.width - (padding * 2), text_options) + (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 = options[:padding] || 3
  if options[:markup] == :pango
    str = self.data.dup.gsub(/<.+?>/,"").gsub("&amp;","&").gsub("&lt;","<").gsub("&gt;",">")
  else
    str = self.data.dup
  end
  @min_width  = wrapper.text_width(str.gsub(/\b|\B/,"\n"), text_options_without_markup) + (padding * 4)
  @natural_width = wrapper.text_width(str, text_options_without_markup) + (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.options)
end

#text_optionsObject



48
49
50
# File 'lib/pdf/wrapper/text_cell.rb', line 48

def text_options
  self.options.only(wrapper.default_text_options.keys)
end

#text_options_without_markupObject



52
53
54
# File 'lib/pdf/wrapper/text_cell.rb', line 52

def text_options_without_markup
  self.options.only(wrapper.default_text_options.keys).except(:markup)
end