psd 2.1.2 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/psd.rb +8 -6
  4. data/lib/psd/blend_mode.rb +46 -38
  5. data/lib/psd/channel_image.rb +9 -5
  6. data/lib/psd/descriptor.rb +39 -16
  7. data/lib/psd/header.rb +33 -32
  8. data/lib/psd/image_formats/rle.rb +4 -10
  9. data/lib/psd/image_modes/rgb.rb +4 -4
  10. data/lib/psd/layer.rb +1 -15
  11. data/lib/psd/layer/blend_modes.rb +12 -12
  12. data/lib/psd/layer/helpers.rb +8 -10
  13. data/lib/psd/layer/info.rb +9 -7
  14. data/lib/psd/layer/position_and_channels.rb +0 -4
  15. data/lib/psd/layer_info.rb +0 -4
  16. data/lib/psd/layer_info/blend_clipping_elements.rb +4 -2
  17. data/lib/psd/layer_info/blend_interior_elements.rb +4 -2
  18. data/lib/psd/layer_info/fill_opacity.rb +4 -2
  19. data/lib/psd/layer_info/layer_group.rb +4 -2
  20. data/lib/psd/layer_info/layer_id.rb +4 -2
  21. data/lib/psd/layer_info/layer_name_source.rb +4 -2
  22. data/lib/psd/layer_info/layer_section_divider.rb +4 -2
  23. data/lib/psd/layer_info/legacy_typetool.rb +5 -3
  24. data/lib/psd/layer_info/locked.rb +4 -2
  25. data/lib/psd/layer_info/metadata_setting.rb +4 -2
  26. data/lib/psd/layer_info/object_effects.rb +4 -2
  27. data/lib/psd/layer_info/pattern.rb +14 -0
  28. data/lib/psd/layer_info/placed_layer.rb +4 -2
  29. data/lib/psd/layer_info/reference_point.rb +4 -2
  30. data/lib/psd/layer_info/sheet_color.rb +18 -0
  31. data/lib/psd/layer_info/solid_color.rb +36 -0
  32. data/lib/psd/layer_info/typetool.rb +4 -2
  33. data/lib/psd/layer_info/unicode_name.rb +4 -2
  34. data/lib/psd/layer_info/vector_mask.rb +4 -2
  35. data/lib/psd/layer_info/vector_origination.rb +14 -0
  36. data/lib/psd/layer_info/vector_stroke.rb +4 -2
  37. data/lib/psd/layer_info/vector_stroke_content.rb +4 -2
  38. data/lib/psd/layer_mask.rb +2 -8
  39. data/lib/psd/lazy_execute.rb +5 -1
  40. data/lib/psd/node.rb +112 -48
  41. data/lib/psd/nodes/ancestry.rb +80 -75
  42. data/lib/psd/nodes/build_preview.rb +4 -4
  43. data/lib/psd/nodes/group.rb +35 -0
  44. data/lib/psd/nodes/layer.rb +40 -0
  45. data/lib/psd/nodes/root.rb +90 -0
  46. data/lib/psd/nodes/search.rb +19 -19
  47. data/lib/psd/path_record.rb +1 -71
  48. data/lib/psd/renderer.rb +6 -5
  49. data/lib/psd/renderer/blender.rb +10 -5
  50. data/lib/psd/renderer/cairo_helpers.rb +46 -0
  51. data/lib/psd/renderer/canvas.rb +39 -19
  52. data/lib/psd/renderer/canvas_management.rb +2 -2
  53. data/lib/psd/renderer/clipping_mask.rb +5 -4
  54. data/lib/psd/renderer/compose.rb +61 -68
  55. data/lib/psd/renderer/layer_styles.rb +15 -5
  56. data/lib/psd/renderer/layer_styles/color_overlay.rb +46 -27
  57. data/lib/psd/renderer/mask.rb +26 -22
  58. data/lib/psd/renderer/mask_canvas.rb +12 -0
  59. data/lib/psd/renderer/vector_shape.rb +239 -0
  60. data/lib/psd/resource_section.rb +4 -7
  61. data/lib/psd/resources.rb +4 -19
  62. data/lib/psd/resources/base.rb +27 -0
  63. data/lib/psd/resources/guides.rb +6 -4
  64. data/lib/psd/resources/layer_comps.rb +6 -4
  65. data/lib/psd/resources/slices.rb +7 -5
  66. data/lib/psd/version.rb +1 -1
  67. data/psd.gemspec +1 -2
  68. data/spec/files/blendmodes.psd +0 -0
  69. data/spec/hierarchy_spec.rb +5 -0
  70. metadata +27 -26
  71. data/lib/psd/layer_info/vector_mask_2.rb +0 -10
  72. data/lib/psd/node_exporting.rb +0 -20
  73. data/lib/psd/node_group.rb +0 -86
  74. data/lib/psd/node_layer.rb +0 -81
  75. data/lib/psd/node_root.rb +0 -93
  76. data/lib/psd/nodes/has_children.rb +0 -13
  77. data/lib/psd/nodes/lock_to_origin.rb +0 -7
  78. data/lib/psd/nodes/parse_layers.rb +0 -18
  79. data/lib/psd/renderer/layer_styles/drop_shadow.rb +0 -75
  80. data/lib/psd/section.rb +0 -26
@@ -1,10 +1,12 @@
1
1
  class PSD
2
2
  class Resource
3
- class Section
3
+ module Section
4
4
  def self.factory(file, resource)
5
5
  Section.constants.each do |c|
6
+ next if c == :Base
7
+
6
8
  section = Section.const_get(c)
7
- next unless section.id == resource.id
9
+ next unless section.resource_id == resource.id
8
10
 
9
11
  section.new(file, resource).parse
10
12
  return section.name
@@ -12,11 +14,6 @@ class PSD
12
14
 
13
15
  return nil
14
16
  end
15
-
16
- def initialize(file, resource)
17
- @file = file
18
- @resource = resource
19
- end
20
17
  end
21
18
  end
22
19
  end
data/lib/psd/resources.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  class PSD
2
2
  # Parses and reads all of the Resource records in the document.
3
3
  class Resources
4
- include Section
5
-
6
4
  attr_reader :resources
7
5
  alias :data :resources
8
6
 
@@ -15,14 +13,9 @@ class PSD
15
13
 
16
14
  # Parses each Resource and stores them.
17
15
  def parse
18
- start_section
19
-
20
- n = length
21
- start = @file.tell
22
-
23
- while n > 0
24
- pos = @file.tell
16
+ finish = length + @file.tell
25
17
 
18
+ while @file.tell < finish
26
19
  resource = Resource.new(@file)
27
20
  resource.parse
28
21
 
@@ -33,14 +26,9 @@ class PSD
33
26
  @type_index[name] = resource.id unless name.nil?
34
27
 
35
28
  @file.seek resource_end
36
- n -= @file.tell - pos
37
29
  end
38
30
 
39
- unless n == 0
40
- @file.seek start + length
41
- end
42
-
43
- end_section
31
+ @file.seek finish if @file.tell != finish
44
32
  end
45
33
 
46
34
  def skip
@@ -59,11 +47,8 @@ class PSD
59
47
  @resources[@type_index[id]]
60
48
  end
61
49
 
62
- private
63
-
64
50
  def length
65
- return @length unless @length.nil?
66
- @length = @file.read_int
51
+ @length ||= @file.read_int
67
52
  end
68
53
  end
69
54
  end
@@ -0,0 +1,27 @@
1
+ require 'psd/resources/base'
2
+
3
+ class PSD
4
+ class Resource
5
+ module Section
6
+ class Base
7
+ def self.resource_id(id = nil)
8
+ @resource_id = id unless id.nil?
9
+ @resource_id
10
+ end
11
+
12
+ def self.name(name = nil)
13
+ @name = name unless name.nil?
14
+ @name
15
+ end
16
+
17
+ def initialize(file, resource)
18
+ @file = file
19
+ @resource = resource
20
+ end
21
+
22
+ def resource_id; self.class.resource_id; end
23
+ def name; self.class.name; end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,11 @@
1
+ require 'psd/resources/base'
2
+
1
3
  class PSD
2
4
  class Resource
3
- class Section
4
- class Guides < Section
5
- def self.id; 1032; end
6
- def self.name; :guides; end
5
+ module Section
6
+ class Guides < Base
7
+ resource_id 1032
8
+ name :guides
7
9
 
8
10
  def parse
9
11
  # Descriptor version
@@ -1,9 +1,11 @@
1
+ require 'psd/resources/base'
2
+
1
3
  class PSD
2
4
  class Resource
3
- class Section
4
- class LayerComps < Section
5
- def self.id; 1065; end
6
- def self.name; :layer_comps; end
5
+ module Section
6
+ class LayerComps < Base
7
+ resource_id 1065
8
+ name :layer_comps
7
9
 
8
10
  def self.visibility_captured?(comp)
9
11
  comp[:captured_info] & 0b001 > 0
@@ -1,11 +1,13 @@
1
+ require 'psd/resources/base'
2
+
1
3
  class PSD
2
4
  class Resource
3
- class Section
4
- class Slices < Section
5
- attr_reader :data, :version
5
+ module Section
6
+ class Slices < Base
7
+ resource_id 1050
8
+ name :slices
6
9
 
7
- def self.id; 1050; end
8
- def self.name; :slices; end
10
+ attr_reader :data, :version
9
11
 
10
12
  def parse
11
13
  @version = @file.read_int
data/lib/psd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class PSD
2
- VERSION = "2.1.2"
2
+ VERSION = "3.1.2"
3
3
  end
data/psd.gemspec CHANGED
@@ -19,10 +19,9 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency 'rake'
22
- gem.add_dependency 'bindata'
23
22
  gem.add_dependency 'psd-enginedata', '~> 1.0'
24
-
25
23
  gem.add_dependency 'chunky_png'
24
+ gem.add_dependency 'activesupport', '~> 3.2.7'
26
25
 
27
26
  gem.test_files = Dir.glob("spec/**/*")
28
27
  gem.add_development_dependency 'rspec'
Binary file
@@ -71,6 +71,11 @@ describe "Hierarchy" do
71
71
  expect(node.path).to eq('Version A/Matte')
72
72
  end
73
73
 
74
+ it "should be able to return a path as an array" do
75
+ node = @tree.children_at_path('Version A/Matte').first
76
+ expect(node.path(:as_array)).to eq(['Version A', 'Matte'])
77
+ end
78
+
74
79
  describe "Searching" do
75
80
  it "should find a node given a path" do
76
81
  expect(@tree.children_at_path('Version A/Matte')).to be_an_instance_of(Array)
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: 2.1.2
4
+ version: 3.1.2
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-03-07 00:00:00.000000000 Z
12
+ date: 2014-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: bindata
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - '>='
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - '>='
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: psd-enginedata
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +53,20 @@ dependencies:
67
53
  - - '>='
68
54
  - !ruby/object:Gem::Version
69
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: activesupport
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 3.2.7
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.2.7
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -181,12 +181,15 @@ files:
181
181
  - lib/psd/layer_info/locked.rb
182
182
  - lib/psd/layer_info/metadata_setting.rb
183
183
  - lib/psd/layer_info/object_effects.rb
184
+ - lib/psd/layer_info/pattern.rb
184
185
  - lib/psd/layer_info/placed_layer.rb
185
186
  - lib/psd/layer_info/reference_point.rb
187
+ - lib/psd/layer_info/sheet_color.rb
188
+ - lib/psd/layer_info/solid_color.rb
186
189
  - lib/psd/layer_info/typetool.rb
187
190
  - lib/psd/layer_info/unicode_name.rb
188
191
  - lib/psd/layer_info/vector_mask.rb
189
- - lib/psd/layer_info/vector_mask_2.rb
192
+ - lib/psd/layer_info/vector_origination.rb
190
193
  - lib/psd/layer_info/vector_stroke.rb
191
194
  - lib/psd/layer_info/vector_stroke_content.rb
192
195
  - lib/psd/layer_mask.rb
@@ -194,34 +197,32 @@ files:
194
197
  - lib/psd/logger.rb
195
198
  - lib/psd/mask.rb
196
199
  - lib/psd/node.rb
197
- - lib/psd/node_exporting.rb
198
- - lib/psd/node_group.rb
199
- - lib/psd/node_layer.rb
200
- - lib/psd/node_root.rb
201
200
  - lib/psd/nodes/ancestry.rb
202
201
  - lib/psd/nodes/build_preview.rb
203
- - lib/psd/nodes/has_children.rb
204
- - lib/psd/nodes/lock_to_origin.rb
205
- - lib/psd/nodes/parse_layers.rb
202
+ - lib/psd/nodes/group.rb
203
+ - lib/psd/nodes/layer.rb
204
+ - lib/psd/nodes/root.rb
206
205
  - lib/psd/nodes/search.rb
207
206
  - lib/psd/path_record.rb
208
207
  - lib/psd/renderer.rb
209
208
  - lib/psd/renderer/blender.rb
209
+ - lib/psd/renderer/cairo_helpers.rb
210
210
  - lib/psd/renderer/canvas.rb
211
211
  - lib/psd/renderer/canvas_management.rb
212
212
  - lib/psd/renderer/clipping_mask.rb
213
213
  - lib/psd/renderer/compose.rb
214
214
  - lib/psd/renderer/layer_styles.rb
215
215
  - lib/psd/renderer/layer_styles/color_overlay.rb
216
- - lib/psd/renderer/layer_styles/drop_shadow.rb
217
216
  - lib/psd/renderer/mask.rb
217
+ - lib/psd/renderer/mask_canvas.rb
218
+ - lib/psd/renderer/vector_shape.rb
218
219
  - lib/psd/resource.rb
219
220
  - lib/psd/resource_section.rb
220
221
  - lib/psd/resources.rb
222
+ - lib/psd/resources/base.rb
221
223
  - lib/psd/resources/guides.rb
222
224
  - lib/psd/resources/layer_comps.rb
223
225
  - lib/psd/resources/slices.rb
224
- - lib/psd/section.rb
225
226
  - lib/psd/util.rb
226
227
  - lib/psd/version.rb
227
228
  - psd.gemspec
@@ -1,10 +0,0 @@
1
- require_relative 'vector_mask'
2
-
3
- class PSD
4
- # Identical to VectorMask, except with a different key. This
5
- # exists in Photoshop >= CS6. If this key exists, then there
6
- # is also a vscg key.
7
- class VectorMask2 < VectorMask
8
- @key = 'vsms'
9
- end
10
- end
@@ -1,20 +0,0 @@
1
- class PSD
2
- module NodeExporting #:nodoc:
3
- def export_node(node, path)
4
- hide_all_nodes
5
- node.show!
6
- node.lock_to_origin
7
-
8
- width_difference_factor = @header.cols.to_f / node.width
9
- height_difference_factor = @header.rows.to_f / node.height
10
- @header.cols, @header.rows = node.width, node.height
11
-
12
- node.scale_path_components(width_difference_factor, height_difference_factor)
13
- export path
14
- end
15
-
16
- def hide_all_nodes
17
- tree.descendants.map(&:hide!)
18
- end
19
- end
20
- end
@@ -1,86 +0,0 @@
1
- require_relative 'node'
2
-
3
- class PSD::Node
4
- # Represents a group, or folder, in the PSD document. It can have
5
- # zero or more children nodes.
6
- class Group < PSD::Node
7
- include PSD::HasChildren
8
- include PSD::Node::LockToOrigin
9
-
10
- attr_reader :name, :top, :left, :bottom, :right
11
-
12
- # Parses the descendant tree structure and figures out the bounds
13
- # of the layers within this folder.
14
- def initialize(folder)
15
- @name = folder[:name]
16
- @layer = folder[:layer]
17
-
18
- super(folder[:layers])
19
- get_dimensions
20
- end
21
-
22
- # Calculated height of this folder.
23
- def rows
24
- @bottom - @top
25
- end
26
- alias :height :rows
27
-
28
- # Calculated width of this folder.
29
- def cols
30
- @right - @left
31
- end
32
- alias :width :cols
33
-
34
- # Attempt to translate this folder and all of the descendants.
35
- def translate(x=0, y=0)
36
- @children.each{ |c| c.translate(x,y) }
37
- end
38
-
39
- # Attempt to hide all children of this layer.
40
- def hide!
41
- @children.each{ |c| c.hide! }
42
- end
43
-
44
- # Attempt to show all children of this layer.
45
- def show!
46
- @children.each{ |c| c.show! }
47
- end
48
-
49
- def passthru_blending?
50
- blending_mode == 'passthru'
51
- end
52
-
53
- def empty?
54
- @children.each do |child|
55
- return false unless child.empty?
56
- end
57
-
58
- return true
59
- end
60
-
61
- # Export this layer and it's children to a hash recursively.
62
- def to_hash
63
- super.merge({
64
- type: :group,
65
- visible: visible?,
66
- children: children.map(&:to_hash)
67
- })
68
- end
69
-
70
- # If the method is missing, we blindly send it to the layer.
71
- # The layer handles the case in which the method doesn't exist.
72
- def method_missing(method, *args, &block)
73
- @layer.send(method, *args, &block)
74
- end
75
-
76
- private
77
-
78
- def get_dimensions
79
- children = @children.reject(&:empty?)
80
- @left = children.map(&:left).min || 0
81
- @top = children.map(&:top).min || 0
82
- @bottom = children.map(&:bottom).max || 0
83
- @right = children.map(&:right).max || 0
84
- end
85
- end
86
- end
@@ -1,81 +0,0 @@
1
- require_relative 'node'
2
-
3
- class PSD::Node
4
- class Layer < PSD::Node
5
- include PSD::Node::LockToOrigin
6
-
7
- attr_reader :layer
8
-
9
- # Stores a reference to the PSD::Layer
10
- def initialize(layer)
11
- @layer = layer
12
- layer.node = self
13
-
14
- super([])
15
- end
16
-
17
- # Delegates some methods to the PSD::Layer
18
- [:text, :ref_x, :ref_y].each do |meth|
19
- define_method meth do
20
- @layer.send(meth)
21
- end
22
-
23
- define_method "#{meth}=" do |val|
24
- @layer.send("#{meth}=", val)
25
- end
26
- end
27
-
28
- # Attempt to translate the layer.
29
- def translate(x=0, y=0)
30
- @layer.translate x, y
31
- end
32
-
33
- # Attempt to scale the path components of the layer.
34
- def scale_path_components(xr, yr)
35
- @layer.scale_path_components(xr, yr)
36
- end
37
-
38
- # Tries to hide the layer by moving it way off canvas.
39
- def hide!
40
- # TODO actually mess with the blend modes instead of
41
- # just putting things way off canvas
42
- return if @hidden_by_kelly
43
- translate(100000, 10000)
44
- @hidden_by_kelly = true
45
- end
46
-
47
- # Tries to re-show the canvas by moving it back to it's original position.
48
- def show!
49
- if @hidden_by_kelly
50
- translate(-100000, -10000)
51
- @hidden_by_kelly = false
52
- end
53
- end
54
-
55
- def empty?
56
- width == 0 || height == 0
57
- end
58
-
59
- # Exports this layer to a Hash.
60
- def to_hash
61
- super.merge({
62
- type: :layer,
63
- text: @layer.text,
64
- ref_x: @layer.reference_point.x,
65
- ref_y: @layer.reference_point.y,
66
- mask: @layer.mask.to_hash,
67
- image: {
68
- width: @layer.image.width,
69
- height: @layer.image.height,
70
- channels: @layer.channels_info
71
- }
72
- })
73
- end
74
-
75
- # If the method is missing, we blindly send it to the layer.
76
- # The layer handles the case in which the method doesn't exist.
77
- def method_missing(method, *args, &block)
78
- @layer.send(method, *args, &block)
79
- end
80
- end
81
- end