Sha256: 7234885e972d04e4b760d28e519335e9392045144f522eb19566f8bd45a34089

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

require_relative 'nodes/ancestry'
require_relative 'nodes/search'

# Internal structure to help us build trees of a Photoshop documents.
# A lot of method names borrowed from the Ruby ancestry gem.
class PSD
  class Node
    include Ancestry
    include Search
    include BuildPreview

    # Default properties that all nodes contain
    PROPERTIES = [:name, :left, :right, :top, :bottom, :height, :width]

    attr_accessor :parent, :children, :layer, :force_visible

    def initialize(layers=[])
      @children = []
      layers.each do |layer|
        layer.parent = self
        @children << layer
      end

      @force_visible = false
    end

    def hidden?
      !visible?
    end

    def visible?
      force_visible || @layer.visible?
    end

    def psd
      parent.psd
    end

    def layer?
      is_a?(PSD::Node::Layer)
    end

    def group?
      is_a?(PSD::Node::Group) || is_a?(PSD::Node::Root)
    end

    def to_hash
      hash = {
        type: nil,
        visible: visible?,
        opacity: @layer.opacity / 255.0,
        blending_mode: @layer.blending_mode
      }

      PROPERTIES.each do |p|
        hash[p] = self.send(p)
      end

      hash
    end

    def document_dimensions
      @parent.document_dimensions
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
psd-1.5.0 lib/psd/node.rb
psd-1.4.5 lib/psd/node.rb
psd-1.4.4 lib/psd/node.rb
psd-1.4.3 lib/psd/node.rb
psd-1.4.2 lib/psd/node.rb