Class: Rabbit::ImageManipulable::Base

Inherits:
Object
  • Object
show all
Extended by:
ModuleLoader
Defined in:
lib/rabbit/image/base.rb

Direct Known Subclasses

Default, Dia, EPS, GIMP, PDF, SVG

Constant Summary

Constants included from ModuleLoader

ModuleLoader::LOADERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ModuleLoader

extend_object, find_loader, loaders, push_loader, unshift_loader

Constructor Details

#initialize(filename, props) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
# File 'lib/rabbit/image/base.rb', line 15

def initialize(filename, props)
  @filename = filename
  @props = normalize_props(props)
  @animation = nil
  @animation_iterator = nil
  @animation_timeout = nil
  update_size
  @original_width = @width
  @original_height = @height
end

Instance Attribute Details

#animationObject (readonly)

Returns the value of attribute animation.



13
14
15
# File 'lib/rabbit/image/base.rb', line 13

def animation
  @animation
end

#heightObject (readonly)

Returns the value of attribute height.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def height
  @height
end

#original_heightObject (readonly)

Returns the value of attribute original_height.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def original_height
  @original_height
end

#original_widthObject (readonly)

Returns the value of attribute original_width.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def original_width
  @original_width
end

#widthObject (readonly)

Returns the value of attribute width.



12
13
14
# File 'lib/rabbit/image/base.rb', line 12

def width
  @width
end

Instance Method Details

#[](key) ⇒ Object



26
27
28
# File 'lib/rabbit/image/base.rb', line 26

def [](key)
  @props[normalize_prop_key(key)]
end

#[]=(key, value) ⇒ Object



30
31
32
# File 'lib/rabbit/image/base.rb', line 30

def []=(key, value)
  @props[normalize_prop_key(key)] = value
end

#draw(canvas, x, y, params = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rabbit/image/base.rb', line 67

def draw(canvas, x, y, params={})
  default_params = {
    :width => width,
    :height => height,
  }
  target_pixbuf = pixbuf
  if @animation_iterator
    @animation_iterator.advance
    target_pixbuf = @animation_iterator.pixbuf
    update_animation_timeout(canvas)
  end
  canvas.draw_pixbuf(target_pixbuf, x, y, default_params.merge(params))
end

#keep_ratioObject



34
35
36
# File 'lib/rabbit/image/base.rb', line 34

def keep_ratio
  self["keep_ratio"]
end

#keep_ratio=(value) ⇒ Object



38
39
40
# File 'lib/rabbit/image/base.rb', line 38

def keep_ratio=(value)
  self["keep_ratio"] = value
end

#pixbufObject



42
43
44
# File 'lib/rabbit/image/base.rb', line 42

def pixbuf
  @pixbuf
end

#resize(w, h) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rabbit/image/base.rb', line 46

def resize(w, h)
  if w.nil? and h.nil?
    return
  elsif keep_ratio
    if w and h.nil?
      h = (original_height * w.to_f / original_width).ceil
    elsif w.nil? and h
      w = (original_width * h.to_f / original_height).ceil
    end
  else
    w ||= width
    h ||= height
  end
  w = w.ceil if w
  h = h.ceil if h
  if w and w > 0 and h and h > 0 and [w, h] != [width, height]
    @width = w
    @height = h
  end
end