Class: TnPDF::PageSection::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/tn_pdf/box.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Box

Returns a new instance of Box.



9
10
11
# File 'lib/tn_pdf/box.rb', line 9

def initialize(options)
  parse_options(options)
end

Instance Attribute Details

#image_fileObject (readonly)

Returns the value of attribute image_file.



5
6
7
# File 'lib/tn_pdf/box.rb', line 5

def image_file
  @image_file
end

#image_optionsObject (readonly)

Returns the value of attribute image_options.



5
6
7
# File 'lib/tn_pdf/box.rb', line 5

def image_options
  @image_options
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/tn_pdf/box.rb', line 6

def text
  @text
end

#text_optionsObject (readonly)

Returns the value of attribute text_options.



6
7
8
# File 'lib/tn_pdf/box.rb', line 6

def text_options
  @text_options
end

#widthObject

Returns the value of attribute width.



7
8
9
# File 'lib/tn_pdf/box.rb', line 7

def width
  @width
end

Instance Method Details

#has_image?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/tn_pdf/box.rb', line 35

def has_image?
  !image_file.nil?
end

#has_text?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/tn_pdf/box.rb', line 39

def has_text?
  !text.nil?
end

#render(document, pos, height = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tn_pdf/box.rb', line 13

def render(document, pos, height=nil)
  options_hash = { :width => width }
  options_hash[:height] = height unless height.nil?

  document.bounding_box(pos, options_hash) do
    if has_image?
      image_args = [image_file]
      image_args << image_options unless image_options.empty?
      document.image(*image_args)
    end

    if has_text?
      text_args = [text]
      text_options.merge!({:inline_format => true})
      text_args << text_options
      document.font(text_options[:font], text_options[:font_options]) do
        document.text(*text_args)
      end
    end
  end
end