Commit 97c9d86a authored by Ryan LeFevre's avatar Ryan LeFevre

Add layer comp parsing

parent fe58a3f6
var PSD = require('../');
PSD.open('./examples/images/example.psd').then(function (psd) {
console.log(psd.resources.resource('layerComps').export());
});
\ No newline at end of file
Util = require './util.coffee'
module.exports = class Resource
@Section: require('./resource_section.coffee')
constructor: (@file) ->
@id = null
@type = null
@length = 0
parse: ->
@type = @file.readString(4)
@id = @file.readShort()
nameLength = Util.pad2(@file.readByte() + 1) - 1
@name = @file.readString(nameLength)
@length = Util.pad2(@file.readInt())
\ No newline at end of file
_ = require 'lodash'
module.exports = class ResourceSection
RESOURCES = [
require('./resources/layer_comps.coffee')
]
@factory: (resource) ->
for Section in RESOURCES
continue unless Section::id is resource.id
return _.tap new Section(resource), (s) -> s.parse()
null
\ No newline at end of file
Resource = require './resource.coffee'
module.exports = class Resources module.exports = class Resources
constructor: (@file) -> constructor: (@file) ->
@resources = {} @resources = {}
...@@ -10,4 +12,30 @@ module.exports = class Resources ...@@ -10,4 +12,30 @@ module.exports = class Resources
parse: -> parse: ->
@length = @file.readInt() @length = @file.readInt()
@file.seek @length, true finish = @length + @file.tell()
\ No newline at end of file
while @file.tell() < finish
resource = new Resource(@file)
resource.parse()
resourceEnd = @file.tell() + resource.length
section = Resource.Section.factory(resource)
unless section?
@file.seek(resourceEnd)
continue
@resources[section.id] = section
@typeIndex[section.name] = section.id if section.name?
@file.seek resourceEnd
@file.seek finish
resource: (search) ->
if typeof(search) is 'string'
@byType(search)
else
@resources[search]
byType: (name) -> @resources[@typeIndex[name]]
\ No newline at end of file
Descriptor = require '../descriptor.coffee'
module.exports = class LayerComps
id: 1065
name: 'layerComps'
@visibilityCaptured: (comp) ->
comp.capturedInfo & parseInt('001', 2) > 0
@positionCaptured: (comp) ->
comp.positionCaptured & parseInt('010', 2) > 0
@appearanceCaptured: (comp) ->
comp.appearanceCaptured & parseInt('100', 2) > 0
constructor: (@resource) ->
@file = @resource.file
parse: ->
@file.seek 4, true
@data = new Descriptor(@file).parse()
names: -> @data.list.map (comp) -> comp['Nm ']
export: ->
@data.list.map (comp) ->
id: comp.compID
name: comp['Nm ']
capturedInfo: comp.capturedInfo
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment