Class: PSD::Renderer

Inherits:
Object
  • Object
show all
Includes:
CanvasManagement
Defined in:
lib/psd/renderer.rb,
lib/psd/renderer/mask.rb,
lib/psd/renderer/canvas.rb,
lib/psd/renderer/blender.rb,
lib/psd/renderer/mask_canvas.rb,
lib/psd/renderer/vector_shape.rb,
lib/psd/renderer/cairo_helpers.rb,
lib/psd/renderer/clipping_mask.rb,
lib/psd/renderer/canvas_management.rb

Defined Under Namespace

Modules: CairoHelpers, CanvasManagement Classes: Blender, Canvas, ClippingMask, Mask, MaskCanvas, VectorShape

Instance Method Summary collapse

Methods included from CanvasManagement

#active_canvas, #create_group_canvas, #pop_canvas, #push_canvas, #stack_inspect

Constructor Details

#initialize(node, opts = {}) ⇒ Renderer

Returns a new instance of Renderer.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/psd/renderer.rb', line 14

def initialize(node, opts = {})
  @root_node = node
  @opts = opts
  @render_hidden = opts.delete(:render_hidden)

  # Our canvas always starts as the full document size because
  # all measurements are relative to this size. We can later crop
  # the image if needed.
  @width = @root_node.document_dimensions[0].to_i
  @height = @root_node.document_dimensions[1].to_i

  @canvas_stack = []
  @node_stack = [@root_node]

  @rendered = false
end

Instance Method Details

#execute_pipelineObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/psd/renderer.rb', line 43

def execute_pipeline
  PSD.logger.debug "Executing pipeline on #{active_node.debug_name}"
  children.reverse.each do |child|
    # We skip over hidden nodes unless explicitly set otherwise.
    # If rendering a single PSD::Node::Layer, this is automatically
    # set so that hidden layers will render.
    next if !@render_hidden && !child.visible?

    if child.group?
      push_node(child)

      if child.passthru_blending?
        PSD.logger.debug "#{child.name} is a group with passthru blending"
        execute_pipeline
      else
        PSD.logger.debug "#{child.name} is a group with #{child.blending_mode} blending"
        
        create_group_canvas(child)
        execute_pipeline
        
        child_canvas = pop_canvas
        child_canvas.paint_to active_canvas
      end

      pop_node and next
    end

    canvas = Canvas.new(child, nil, nil, @opts)
    canvas.paint_to active_canvas
  end
end

#render!Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/psd/renderer.rb', line 31

def render!
  PSD.logger.debug "Beginning render process"

  # Create our base canvas
  create_group_canvas(active_node, active_node.width, active_node.height, base: true)

  # Begin the rendering process
  execute_pipeline

  @rendered = true
end

#to_pngObject



75
76
77
78
# File 'lib/psd/renderer.rb', line 75

def to_png
  render! unless @rendered
  active_canvas.canvas
end