Class: PDFGen::Image

Inherits:
BaseRegion show all
Defined in:
lib/image.rb

Instance Attribute Summary collapse

Attributes inherited from BaseRegion

#parent

Attributes included from BaseAttributes

#background_color, #border_bottom, #border_color, #border_left, #border_right, #border_style, #border_top, #border_width, #height, #is_breakable, #pad_bottom, #pad_left, #pad_right, #pad_top, #page_pad_top, #width

Instance Method Summary collapse

Methods inherited from BaseRegion

#check_fit_in_height, #document, #minimal_height, #value

Methods included from BaseAttributes

#av_width, #border=, #border_params, #breakable?, included, #paddings=, #var_init

Methods included from BaseAttributes::ClassMethods

#common_setter

Constructor Details

#initialize(parent, image_res) ⇒ Image

Returns a new instance of Image.



9
10
11
12
13
14
# File 'lib/image.rb', line 9

def initialize(parent, image_res)
  super(parent)

  @image = image_res
  @info = PDF::Writer::Graphics::ImageInfo.new(@image)
end

Instance Attribute Details

#imageObject

Returns the value of attribute image.



16
17
18
# File 'lib/image.rb', line 16

def image
  @image
end

Instance Method Details

#render(pos, av_height, test = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/image.rb', line 32

def render(pos, av_height, test=false)
  self.check_fit_in_height
  if av_height >= self.height
    document.pdf.add_image(@image, pos[0] + pad_left, pos[1] - height + pad_bottom,
                           width - pad_left - pad_right, height-pad_top - pad_bottom)
    super
    [self.height, true]
  else
    [0, false]
  end
end

#set_properties(props = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/image.rb', line 18

def set_properties(props = {})
  super

  if width.zero? && height.zero?
    self.width = @info.width
    self.height = @info.height
  elsif width.zero?
    self.width = height / @info.height.to_f * @info.width
  elsif height.zero?
    self.height = width * @info.height / @info.width.to_f
  end
  self.height = self.height - pad_top - pad_bottom
end