Skip to content

Commit

Permalink
Make layer comps easier to access
Browse files Browse the repository at this point in the history
  • Loading branch information
meltingice committed Aug 6, 2013
1 parent cc51675 commit 9c6a088
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
7 changes: 6 additions & 1 deletion examples/parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
psd.parse!
end

if psd.resources[:layer_comps]
puts "\nLayer Comps:\n===================="
puts psd.resources[:layer_comps].data.names
end

puts "\nVisible Layers:\n===================="
psd.layers.each do |layer|
next if layer.folder? || layer.hidden?
Expand All @@ -16,7 +21,7 @@
puts "Position: top = #{layer.top}, left = #{layer.left}"
puts "Size: width = #{layer.width}, height = #{layer.height}"
puts "Mask: width = #{layer.mask.width}, height = #{layer.mask.height}"
puts "Reference point: #{layer.ref_x}, #{layer.ref_y}"
puts "Reference point: #{layer.reference_point.x}, #{layer.reference_point.y}"

puts ""
end
Expand Down
11 changes: 6 additions & 5 deletions lib/psd/layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ def parse_blending_ranges
# not UTF-8. Luckily Ruby kicks ass at character conversion.
def parse_legacy_layer_name
@legacy_name_start = @file.tell
len = Util.pad4 @file.read(1).unpack('C')[0]
@legacy_name = @file.read(len).encode('UTF-8', 'MacRoman').delete("\000")

len = Util.pad4 @file.read(1).bytes.to_a[0]
@legacy_name = @file.read_string(len)

@legacy_name_end = @file.tell
end

Expand All @@ -302,7 +304,7 @@ def parse_extra_data
@file.seek 4, IO::SEEK_CUR

# Key, very important
key = @file.read(4).unpack('A4')[0]
key = @file.read_string(4)
@info_keys << key

length = Util.pad2 @file.read_int
Expand All @@ -329,14 +331,13 @@ def parse_extra_data
end

if !info_parsed
PSD.logger.debug "SKIPPING: key = #{key}, length = #{length}"
PSD.logger.debug "Skipping: key = #{key}, pos = #{@file.tell}, length = #{length}"
@file.seek pos + length
end

@file.seek pos + length if @file.tell != (pos + length)
end

# puts "Layer = #{name}, Parsed = #{@info_keys - PSD.keys.uniq}, Unparsed = #{PSD.keys.uniq - @info_keys}"
@extra_data_end = @file.tell
end

Expand Down
12 changes: 11 additions & 1 deletion lib/psd/resources/layer_comps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ def self.name; :layer_comps; end
def parse
# Descriptor version
@file.seek 4, IO::SEEK_CUR
@resource.data = Descriptor.new(@file).parse

@data = Descriptor.new(@file).parse
@resource.data = self
end

def names
@data['list'].map { |c| c['Nm '] }
end

def [](val)
@data[val]
end
end
end
Expand Down

0 comments on commit 9c6a088

Please sign in to comment.