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.


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rabbit/image/base.rb', line 34

def initialize(filename, props)
  @filename = filename
  @properties = Properties.new(props)
  initialize_keep_ratio
  @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.


32
33
34
# File 'lib/rabbit/image/base.rb', line 32

def animation
  @animation
end

#filenameObject (readonly)

Returns the value of attribute filename.


28
29
30
# File 'lib/rabbit/image/base.rb', line 28

def filename
  @filename
end

#original_heightObject (readonly)

Returns the value of attribute original_height.


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

def original_height
  @original_height
end

#original_widthObject (readonly)

Returns the value of attribute original_width.


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

def original_width
  @original_width
end

#propertiesObject (readonly)

Returns the value of attribute properties.


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

def properties
  @properties
end

Instance Method Details

#[](key) ⇒ Object


46
47
48
# File 'lib/rabbit/image/base.rb', line 46

def [](key)
  @properties[key]
end

#[]=(key, value) ⇒ Object


50
51
52
# File 'lib/rabbit/image/base.rb', line 50

def []=(key, value)
  @properties[key] = value
end

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


115
116
117
118
119
120
121
122
123
124
# File 'lib/rabbit/image/base.rb', line 115

def draw(canvas, x, y, params={})
  default_params = default_draw_params(x, y)
  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

#heightObject


73
74
75
76
# File 'lib/rabbit/image/base.rb', line 73

def height
  (relative_clip_height&.resolve(@height) || @height) -
    (relative_clip_y&.resolve(@height) || 0)
end

#keep_ratio=(value) ⇒ Object


60
61
62
# File 'lib/rabbit/image/base.rb', line 60

def keep_ratio=(value)
  @properties.keep_ratio = value
end

#keep_ratio?Boolean Also known as: keep_ratio

Returns:

  • (Boolean)

54
55
56
# File 'lib/rabbit/image/base.rb', line 54

def keep_ratio?
  @properties.keep_ratio
end

#pixbufObject


64
65
66
# File 'lib/rabbit/image/base.rb', line 64

def pixbuf
  @pixbuf
end

#relative_clip_heightObject


90
91
92
# File 'lib/rabbit/image/base.rb', line 90

def relative_clip_height
  @properties.get_relative_size("relative_clip_height", @filename)
end

#relative_clip_widthObject


86
87
88
# File 'lib/rabbit/image/base.rb', line 86

def relative_clip_width
  @properties.get_relative_size("relative_clip_width", @filename)
end

#relative_clip_xObject


78
79
80
# File 'lib/rabbit/image/base.rb', line 78

def relative_clip_x
  @properties.get_relative_size("relative_clip_x", @filename)
end

#relative_clip_yObject


82
83
84
# File 'lib/rabbit/image/base.rb', line 82

def relative_clip_y
  @properties.get_relative_size("relative_clip_y", @filename)
end

#resize(w, h) ⇒ Object


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/rabbit/image/base.rb', line 94

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

#widthObject


68
69
70
71
# File 'lib/rabbit/image/base.rb', line 68

def width
  (relative_clip_width&.resolve(@width) || @width) -
    (relative_clip_x&.resolve(@width) || 0)
end