psd 3.1.5 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/psd/node.rb +2 -0
- data/lib/psd/nodes/layer.rb +19 -4
- data/lib/psd/nodes/layer_comps.rb +93 -0
- data/lib/psd/nodes/search.rb +0 -61
- data/lib/psd/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4bd38eaf1619d328b37f11d93117c313c645bd6
|
4
|
+
data.tar.gz: 4b54b449211063657e903917e20f0c78c5fd3297
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d989a86acfc3b2b3b7f3dcea3bad859aabc0e3cdbf74d7cc165decf5b490d75933368f6aff7ca7d4c9dbb87c0d8d67ed5bb393acc7ed4bc4d9fa75f6cf8de5
|
7
|
+
data.tar.gz: 0d8dc9000a99878c9f2806faba5d82a1dc387f01a6c201263643059154d836702e76b2228d9b4c9bc1daaa1a4ad1d40d9b4629137f6c726863604ce9e719fc50
|
data/lib/psd/node.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'psd/nodes/ancestry'
|
2
2
|
require 'psd/nodes/search'
|
3
|
+
require 'psd/nodes/layer_comps'
|
3
4
|
require 'psd/nodes/build_preview'
|
4
5
|
|
5
6
|
# Internal structure to help us build trees of a Photoshop documents.
|
@@ -10,6 +11,7 @@ class PSD
|
|
10
11
|
include Enumerable
|
11
12
|
include Ancestry
|
12
13
|
include Search
|
14
|
+
include LayerComps
|
13
15
|
include BuildPreview
|
14
16
|
|
15
17
|
# Default properties that all nodes contain
|
data/lib/psd/nodes/layer.rb
CHANGED
@@ -16,18 +16,33 @@ class PSD
|
|
16
16
|
|
17
17
|
# Exports this layer to a Hash.
|
18
18
|
def to_hash
|
19
|
-
super.merge({
|
19
|
+
hash = super.merge({
|
20
20
|
type: :layer,
|
21
21
|
text: @layer.text,
|
22
|
-
ref_x:
|
23
|
-
ref_y:
|
22
|
+
ref_x: reference_point.x,
|
23
|
+
ref_y: reference_point.y,
|
24
24
|
mask: @layer.mask.to_hash,
|
25
25
|
image: {
|
26
26
|
width: @layer.image.width,
|
27
27
|
height: @layer.image.height,
|
28
28
|
channels: @layer.channels_info
|
29
|
-
}
|
29
|
+
},
|
30
|
+
layer_comps: {}
|
30
31
|
})
|
32
|
+
|
33
|
+
root.psd.layer_comps.each do |comp|
|
34
|
+
hash[:layer_comps][comp[:name]] = {
|
35
|
+
visible: visible_in_comp?(comp[:id]),
|
36
|
+
position: position_in_comp(comp[:id])
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
hash
|
41
|
+
end
|
42
|
+
|
43
|
+
# In case the layer doesn't have a reference point
|
44
|
+
def reference_point
|
45
|
+
@layer.reference_point || Struct.new(:x, :y).new(0, 0)
|
31
46
|
end
|
32
47
|
|
33
48
|
# If the method is missing, we blindly send it to the layer.
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class PSD
|
2
|
+
module Node
|
3
|
+
module LayerComps
|
4
|
+
# Given a layer comp ID or name, create a new
|
5
|
+
# tree with layer/group visibility altered based on the layer comp.
|
6
|
+
def filter_by_comp(id)
|
7
|
+
comp = find_comp(id)
|
8
|
+
root = PSD::Node::Root.new(psd)
|
9
|
+
|
10
|
+
# Force layers to be visible if they are enabled for the comp
|
11
|
+
root.descendants.each do |c|
|
12
|
+
set_visibility(comp, c) if Resource::Section::LayerComps.visibility_captured?(comp)
|
13
|
+
set_position(comp, c) if Resource::Section::LayerComps.position_captured?(comp)
|
14
|
+
|
15
|
+
PSD.logger.debug "#{c.path}: visible = #{c.visible?}, position = #{c.left}, #{c.top}"
|
16
|
+
end
|
17
|
+
|
18
|
+
return root
|
19
|
+
end
|
20
|
+
|
21
|
+
def visible_in_comp?(id)
|
22
|
+
determine_visibility(find_comp(id), self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def position_in_comp(id)
|
26
|
+
offset = determine_position_offset(find_comp(id), self)
|
27
|
+
|
28
|
+
{
|
29
|
+
top: top + offset[:y],
|
30
|
+
right: right + offset[:x],
|
31
|
+
bottom: bottom + offset[:y],
|
32
|
+
left: left + offset[:x]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def find_comp(id)
|
39
|
+
comp = if id.is_a?(String)
|
40
|
+
psd.layer_comps.select { |c| c[:name] == id }.first
|
41
|
+
else
|
42
|
+
psd.layer_comps.select { |c| c[:id] == id }.first
|
43
|
+
end
|
44
|
+
|
45
|
+
raise "Layer comp not found" if comp.nil?
|
46
|
+
comp
|
47
|
+
end
|
48
|
+
|
49
|
+
def set_visibility(comp, c)
|
50
|
+
c.force_visible = determine_visibility(comp, c)
|
51
|
+
end
|
52
|
+
|
53
|
+
def determine_visibility(comp, c)
|
54
|
+
visible = true
|
55
|
+
found = false
|
56
|
+
|
57
|
+
c
|
58
|
+
.metadata
|
59
|
+
.data[:layer_comp]['layerSettings'].each do |l|
|
60
|
+
visible = l['enab'] if l.has_key?('enab')
|
61
|
+
found = true and break if l['compList'].include?(comp[:id])
|
62
|
+
end
|
63
|
+
|
64
|
+
found && visible
|
65
|
+
end
|
66
|
+
|
67
|
+
def set_position(comp, c)
|
68
|
+
offset = determine_position_offset(comp, c)
|
69
|
+
|
70
|
+
c.left_offset = offset[:x]
|
71
|
+
c.top_offset = offset[:y]
|
72
|
+
end
|
73
|
+
|
74
|
+
def determine_position_offset(comp, c)
|
75
|
+
x = 0
|
76
|
+
y = 0
|
77
|
+
|
78
|
+
c
|
79
|
+
.metadata
|
80
|
+
.data[:layer_comp]['layerSettings'].each do |l|
|
81
|
+
if l.has_key?('Ofst')
|
82
|
+
x = l['Ofst']['Hrzn']
|
83
|
+
y = l['Ofst']['Vrtc']
|
84
|
+
end
|
85
|
+
|
86
|
+
break if l['compList'].include?(comp[:id])
|
87
|
+
end
|
88
|
+
|
89
|
+
{ x: x, y: y }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/psd/nodes/search.rb
CHANGED
@@ -25,67 +25,6 @@ class PSD
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
alias :children_with_path :children_at_path
|
28
|
-
|
29
|
-
# Given a layer comp ID, name, or :last for last document state, create a new
|
30
|
-
# tree with layer/group visibility altered based on the layer comp.
|
31
|
-
def filter_by_comp(id)
|
32
|
-
if id.is_a?(String)
|
33
|
-
comp = psd.layer_comps.select { |c| c[:name] == id }.first
|
34
|
-
raise "Layer comp not found" if comp.nil?
|
35
|
-
|
36
|
-
id = comp[:id]
|
37
|
-
else
|
38
|
-
comp = psd.layer_comps.select { |c| c[:id] == id }.first
|
39
|
-
raise "Layer comp not found" if comp.nil?
|
40
|
-
end
|
41
|
-
|
42
|
-
root = PSD::Node::Root.new(psd)
|
43
|
-
|
44
|
-
# Force layers to be visible if they are enabled for the comp
|
45
|
-
root.descendants.each do |c|
|
46
|
-
set_visibility(comp, c) if Resource::Section::LayerComps.visibility_captured?(comp)
|
47
|
-
set_position(comp, c) if Resource::Section::LayerComps.position_captured?(comp)
|
48
|
-
|
49
|
-
PSD.logger.debug "#{c.path}: visible = #{c.visible?}, position = #{c.left}, #{c.top}"
|
50
|
-
end
|
51
|
-
|
52
|
-
return root
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def set_visibility(comp, c)
|
58
|
-
visible = true
|
59
|
-
found = false
|
60
|
-
|
61
|
-
c
|
62
|
-
.metadata
|
63
|
-
.data[:layer_comp]['layerSettings'].each do |l|
|
64
|
-
visible = l['enab'] if l.has_key?('enab')
|
65
|
-
found = true and break if l['compList'].include?(comp[:id])
|
66
|
-
end
|
67
|
-
|
68
|
-
c.force_visible = found && visible
|
69
|
-
end
|
70
|
-
|
71
|
-
def set_position(comp, c)
|
72
|
-
x = 0
|
73
|
-
y = 0
|
74
|
-
|
75
|
-
c
|
76
|
-
.metadata
|
77
|
-
.data[:layer_comp]['layerSettings'].each do |l|
|
78
|
-
if l.has_key?('Ofst')
|
79
|
-
x = l['Ofst']['Hrzn']
|
80
|
-
y = l['Ofst']['Vrtc']
|
81
|
-
end
|
82
|
-
|
83
|
-
break if l['compList'].include?(comp[:id])
|
84
|
-
end
|
85
|
-
|
86
|
-
c.left_offset = x
|
87
|
-
c.top_offset = y
|
88
|
-
end
|
89
28
|
end
|
90
29
|
end
|
91
30
|
end
|
data/lib/psd/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan LeFevre
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/psd/nodes/build_preview.rb
|
216
216
|
- lib/psd/nodes/group.rb
|
217
217
|
- lib/psd/nodes/layer.rb
|
218
|
+
- lib/psd/nodes/layer_comps.rb
|
218
219
|
- lib/psd/nodes/root.rb
|
219
220
|
- lib/psd/nodes/search.rb
|
220
221
|
- lib/psd/path_record.rb
|