Commit fe58a3f6 authored by Ryan LeFevre's avatar Ryan LeFevre

Finish Descriptor implementation

parent 91584282
...@@ -13,4 +13,5 @@ task 'compile', 'Compile with browserify for the web', -> ...@@ -13,4 +13,5 @@ task 'compile', 'Compile with browserify for the web', ->
.bundle (err, src) -> .bundle (err, src) ->
return console.log(err) if err? return console.log(err) if err?
fs.writeFile './dist/psd.js', src, -> fs.writeFile './dist/psd.js', src, ->
console.log "Compiled to ./dist/psd.js" fs.stat './dist/psd.js', (err, stats) ->
\ No newline at end of file console.log "Compiled to ./dist/psd.js - #{Math.round(stats.size / 1024)}KB"
\ No newline at end of file
This diff is collapsed.
...@@ -7,7 +7,7 @@ module.exports = class Descriptor ...@@ -7,7 +7,7 @@ module.exports = class Descriptor
numItems = @file.readInt() numItems = @file.readInt()
for i in [0...numItems] for i in [0...numItems]
id, value = @parseKeyItem() [id, value] = @parseKeyItem()
@data[id] = value @data[id] = value
@data @data
...@@ -23,7 +23,7 @@ module.exports = class Descriptor ...@@ -23,7 +23,7 @@ module.exports = class Descriptor
parseKeyItem: -> parseKeyItem: ->
id = @parseId() id = @parseId()
value = @parseItem() value = @parseItem()
return id, value return [id, value]
parseItem: (type = null) -> parseItem: (type = null) ->
type = @file.readString(4) unless type? type = @file.readString(4) unless type?
...@@ -94,3 +94,58 @@ module.exports = class Descriptor ...@@ -94,3 +94,58 @@ module.exports = class Descriptor
items items
parseObjectArray: -> parseObjectArray: ->
throw "Descriptor object array not implemented yet @ #{@file.tell()}"
parseRawData: ->
len = @file.readInt()
@file.read(len)
parseReference: ->
numItems = @file.readInt()
items = []
for i in [0...numItems]
type = @file.readString(4)
value = switch type
when 'prop' then @parseProperty()
when 'Clss' then @parseClass()
when 'Enmr' then @parseEnumReference()
when 'Idnt' then @parseIdentifier()
when 'indx' then @parseIndex()
when 'name' then @file.readUnicodeString()
when 'rele' then @parseOffset()
items.push type: type, value: value
items
parseUnitDouble: ->
unitId = @file.readString(4)
unit = switch unitId
when '#Ang' then 'Angle'
when '#Rsl' then 'Density'
when '#Rlt' then 'Distance'
when '#Nne' then 'None'
when '#Prc' then 'Percent'
when '#Pxl' then 'Pixels'
when '#Mlm' then 'Millimeters'
when '#Pnt' then 'Points'
value = @file.readDouble()
id: unitId, unit: unit, value: value
parseUnitFloat: ->
unitId = @file.readString(4)
unit = switch unitId
when '#Ang' then 'Angle'
when '#Rsl' then 'Density'
when '#Rlt' then 'Distance'
when '#Nne' then 'None'
when '#Prc' then 'Percent'
when '#Pxl' then 'Pixels'
when '#Mlm' then 'Millimeters'
when '#Pnt' then 'Points'
value = @file.readFloat()
id: unitId, unit: unit, value: value
\ 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