Class: PSD::Renderer::Canvas

Inherits:
Object
  • Object
show all
Defined in:
lib/psd/renderer/canvas.rb

Direct Known Subclasses

MaskCanvas

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, width = nil, height = nil, opts = {}) ⇒ Canvas

Returns a new instance of Canvas.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/psd/renderer/canvas.rb', line 9

def initialize(node, width = nil, height = nil, opts = {})
  @node = node
  @opts = opts
  @pixel_data = @node.group? ? [] : @node.image.pixel_data
  
  @width = (width || @node.width).to_i
  @height = (height || @node.height).to_i

  @opacity = @node.opacity.to_f
  @fill_opacity = @node.fill_opacity.to_f

  initialize_canvas
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



40
41
42
# File 'lib/psd/renderer/canvas.rb', line 40

def method_missing(method, *args, &block)
  @canvas.send(method, *args, &block)
end

Instance Attribute Details

#canvasObject

Returns the value of attribute canvas.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def canvas
  @canvas
end

#fill_opacityObject (readonly)

Returns the value of attribute fill_opacity.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def fill_opacity
  @fill_opacity
end

#heightObject (readonly)

Returns the value of attribute height.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def height
  @height
end

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def node
  @node
end

#opacityObject (readonly)

Returns the value of attribute opacity.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def opacity
  @opacity
end

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def opts
  @opts
end

#widthObject (readonly)

Returns the value of attribute width.



4
5
6
# File 'lib/psd/renderer/canvas.rb', line 4

def width
  @width
end

Instance Method Details

#paint_to(base) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/psd/renderer/canvas.rb', line 23

def paint_to(base)
  PSD.logger.debug "Painting #{node.name} to #{base.node.debug_name}"

  apply_masks
  apply_clipping_mask
  apply_layer_styles
  apply_layer_opacity

  compose_pixels(base)
end