diff options
author | meltingice <meltingice8917@gmail.com> | 2012-07-17 21:22:18 -0400 |
---|---|---|
committer | meltingice <meltingice8917@gmail.com> | 2012-07-17 21:22:18 -0400 |
commit | e7050bd45708b4e86a26792e849cd3f18692048f (patch) | |
tree | 260fa79cadda575be7b43695180b8aaf383c7ba0 | |
parent | Updated documentation (diff) | |
download | psd.js-e7050bd45708b4e86a26792e849cd3f18692048f.tar.xz psd.js-e7050bd45708b4e86a26792e849cd3f18692048f.zip |
Fix layer name parsing bug and add solid color layer data
-rwxr-xr-x | Cakefile | 1 | ||||
-rw-r--r-- | lib/psd.js | 33 | ||||
-rw-r--r-- | lib/psd.min.js | 11 | ||||
-rw-r--r-- | src/layerdata/solidcolor.coffee | 11 | ||||
-rwxr-xr-x | src/layerdata/typetool.coffee | 4 | ||||
-rwxr-xr-x | src/psdlayer.coffee | 12 |
6 files changed, 56 insertions, 16 deletions
@@ -43,6 +43,7 @@ coffeeFiles = [ "layerdata/levels" "layerdata/posterize" "layerdata/selectivecolor" + "layerdata/solidcolor" "layerdata/threshold" "layerdata/typetool" @@ -307,7 +307,7 @@ var jspack = new JSPack(); ; END DEPENDENCIES */ - var Log, PSD, PSDBrightnessContrast, PSDChannelImage, PSDColor, PSDColorBalance, PSDCurves, PSDDescriptor, PSDDropDownLayerEffect, PSDFile, PSDHeader, PSDHueSaturation, PSDImage, PSDInvert, PSDLayer, PSDLayerEffect, PSDLayerEffectCommonStateInfo, PSDLayerMask, PSDLevels, PSDPosterize, PSDResource, PSDSelectiveColor, PSDThreshold, PSDTypeTool, Root, Util, assert, fs, + var Log, PSD, PSDBrightnessContrast, PSDChannelImage, PSDColor, PSDColorBalance, PSDCurves, PSDDescriptor, PSDDropDownLayerEffect, PSDFile, PSDHeader, PSDHueSaturation, PSDImage, PSDInvert, PSDLayer, PSDLayerEffect, PSDLayerEffectCommonStateInfo, PSDLayerMask, PSDLevels, PSDPosterize, PSDResource, PSDSelectiveColor, PSDSolidColor, PSDThreshold, PSDTypeTool, Root, Util, assert, fs, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -2363,8 +2363,7 @@ var jspack = new JSPack(); ; PSDLayer.prototype.parseLegacyLayerName = function() { var namelen; namelen = Util.pad4(this.file.read(1)[0]); - this.legacyName = Util.decodeMacroman(this.file.read(namelen)).replace(/\u0000/g, ''); - return Log.debug("Layer name: " + this.name); + return this.legacyName = Util.decodeMacroman(this.file.read(namelen)).replace(/\u0000/g, ''); }; PSDLayer.prototype.parseExtraData = function() { @@ -2377,6 +2376,9 @@ var jspack = new JSPack(); ; pos = this.file.tell(); Log.debug("Extra layer info: key = " + key + ", length = " + length); switch (key) { + case "SoCo": + this.adjustments.solidColor = (new PSDSolidColor(this, length)).parse(); + break; case "levl": this.adjustments.levels = (new PSDLevels(this, length)).parse(); break; @@ -2411,7 +2413,8 @@ var jspack = new JSPack(); ; this.adjustments.typeTool = (new PSDTypeTool(this, length)).parse(); break; case "luni": - this.name = this.file.readUnicodeString(); + this.name = this.file.readUnicodeString(Util.pad4); + this.file.seek(pos + length, false); break; case "lyid": this.layerId = this.file.readInt(); @@ -2428,7 +2431,7 @@ var jspack = new JSPack(); ; Log.debug("Skipping additional layer info with key " + key); } if (this.file.tell() !== (pos + length)) { - Log.debug("Error parsing additional layer info with key " + key + " - unexpected end"); + Log.debug("Warning: additional layer info with key " + key + " - unexpected end"); _results.push(this.file.seek(pos + length, false)); } else { _results.push(void 0); @@ -3008,6 +3011,25 @@ var jspack = new JSPack(); ; })(); + PSDSolidColor = (function() { + + function PSDSolidColor(layer, length) { + this.layer = layer; + this.length = length; + this.file = this.layer.file; + } + + PSDSolidColor.prototype.parse = function() { + var version; + version = this.file.readInt(); + assert(version === 16); + return (new PSDDescriptor(this.file)).parse(); + }; + + return PSDSolidColor; + + })(); + PSDThreshold = (function() { function PSDThreshold(layer, length) { @@ -3061,7 +3083,6 @@ var jspack = new JSPack(); ; engineData += String.fromCharCode(char); } this.data.text.EngineData = engineData.replace(/\u0000/g, ""); - Log.debug("Text:", this.data.text); warpVersion = this.file.readShortInt(); assert(warpVersion === 1); descriptorVersion = this.file.readInt(); diff --git a/lib/psd.min.js b/lib/psd.min.js index a920e1a..1d21ce4 100644 --- a/lib/psd.min.js +++ b/lib/psd.min.js @@ -69,7 +69,7 @@ return a;};m.Pack=function(fmt,values) {return this.PackTo(fmt,new Array(this.CalcLength(fmt)),0,values);};m.CalcLength=function(fmt) {var re=new RegExp(this._sPattern,'g'),m,sum=0;while(m=re.exec(fmt)) {sum+=(((m[1]==undefined)||(m[1]==''))?1:parseInt(m[1]))*this._lenLut[m[2]];} -return sum;};};var jspack=new JSPack();;var Log,PSD,PSDBrightnessContrast,PSDChannelImage,PSDColor,PSDColorBalance,PSDCurves,PSDDescriptor,PSDDropDownLayerEffect,PSDFile,PSDHeader,PSDHueSaturation,PSDImage,PSDInvert,PSDLayer,PSDLayerEffect,PSDLayerEffectCommonStateInfo,PSDLayerMask,PSDLevels,PSDPosterize,PSDResource,PSDSelectiveColor,PSDThreshold,PSDTypeTool,Root,Util,assert,fs,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key];}function ctor(){this.constructor=child;}ctor.prototype=parent.prototype;child.prototype=new ctor();child.__super__=parent.prototype;return child;};assert=(function(assert){if(typeof exports!=="undefined"&&exports!==null){return require('assert');} +return sum;};};var jspack=new JSPack();;var Log,PSD,PSDBrightnessContrast,PSDChannelImage,PSDColor,PSDColorBalance,PSDCurves,PSDDescriptor,PSDDropDownLayerEffect,PSDFile,PSDHeader,PSDHueSaturation,PSDImage,PSDInvert,PSDLayer,PSDLayerEffect,PSDLayerEffectCommonStateInfo,PSDLayerMask,PSDLevels,PSDPosterize,PSDResource,PSDSelectiveColor,PSDSolidColor,PSDThreshold,PSDTypeTool,Root,Util,assert,fs,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key];}function ctor(){this.constructor=child;}ctor.prototype=parent.prototype;child.prototype=new ctor();child.__super__=parent.prototype;return child;};assert=(function(assert){if(typeof exports!=="undefined"&&exports!==null){return require('assert');} assert=function(test){if(test!==true){throw"Assertion error";}};assert.equal=function(actual,expected){if(actual!==expected){throw"Assertion error";}};return assert;})(assert);if(typeof exports!=="undefined"&&exports!==null){Root=exports;fs=require('fs');}else{Root=window;} Root.PSD=PSD=(function(){PSD.VERSION="0.4.4";PSD.DEBUG=false;PSD.fromFile=function(file,cb){var data,reader;if(cb==null){cb=function(){};} if(typeof exports!=="undefined"&&exports!==null){data=fs.readFileSync(file);return new PSD(data);}else{reader=new FileReader();reader.onload=function(f){var bytes,psd;bytes=new Uint8Array(f.target.result);psd=new PSD(bytes);return cb(psd);};return reader.readAsArrayBuffer(file);}};PSD.fromURL=function(url,cb){var xhr;if(cb==null){cb=function(){};} @@ -218,8 +218,8 @@ return _results;};PSDLayer.prototype.parseBlendModes=function(){var filler,flags this.blendingMode=this.blendMode.blender;this.opacity=this.blendMode.opacity;this.visible=this.blendMode.visible;return Log.debug("Blending mode:",this.blendMode);};PSDLayer.prototype.parseMaskData=function(){var flags,_ref,_ref1,_ref2,_ref3;this.mask.size=this.file.readInt();assert((_ref=this.mask.size)===36||_ref===20||_ref===0);if(this.mask.size===0){return true;} _ref1=this.file.readf(">llllBB"),this.mask.top=_ref1[0],this.mask.left=_ref1[1],this.mask.bottom=_ref1[2],this.mask.right=_ref1[3],this.mask.defaultColor=_ref1[4],flags=_ref1[5];assert((_ref2=this.mask.defaultColor)===0||_ref2===255);this.mask.width=this.mask.right-this.mask.left;this.mask.height=this.mask.bottom-this.mask.top;this.mask.relative=flags&0x01;this.mask.disabled=(flags&(0x01<<1))>0;this.mask.invert=(flags&(0x01<<2))>0;if(this.mask.size===20){this.file.seek(2);}else{_ref3=this.file.readf(">BB"),flags=_ref3[0],this.mask.defaultColor=_ref3[1];this.mask.relative=flags&0x01;this.mask.disabled=(flags&(0x01<<1))>0;this.mask.invert=(flags&(0x01<<2))>0;this.file.seek(16);} return true;};PSDLayer.prototype.parseBlendingRanges=function(){var i,length,pos,_i,_ref,_results;length=this.file.readInt();this.blendingRanges.grey={source:{black:this.file.readShortInt(),white:this.file.readShortInt()},dest:{black:this.file.readShortInt(),white:this.file.readShortInt()}};pos=this.file.tell();this.blendingRanges.numChannels=(length-8)/8;assert(this.blendingRanges.numChannels>0);this.blendingRanges.channels=[];_results=[];for(i=_i=0,_ref=this.blendingRanges.numChannels;0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){_results.push(this.blendingRanges.channels.push({source:{black:this.file.readShortInt(),white:this.file.readShortInt()},dest:{black:this.file.readShortInt(),white:this.file.readShortInt()}}));} -return _results;};PSDLayer.prototype.parseLegacyLayerName=function(){var namelen;namelen=Util.pad4(this.file.read(1)[0]);this.legacyName=Util.decodeMacroman(this.file.read(namelen)).replace(/\u0000/g,'');return Log.debug("Layer name: "+this.name);};PSDLayer.prototype.parseExtraData=function(){var key,length,pos,signature,_ref,_results;_results=[];while(this.file.tell()<this.layerEnd){_ref=this.file.readf(">4s4s"),signature=_ref[0],key=_ref[1];assert.equal(signature,"8BIM");length=Util.pad2(this.file.readInt());pos=this.file.tell();Log.debug("Extra layer info: key = "+key+", length = "+length);switch(key){case"levl":this.adjustments.levels=(new PSDLevels(this,length)).parse();break;case"curv":this.adjustments.curves=(new PSDCurves(this,length)).parse();break;case"brit":this.adjustments.brightnessContrast=(new PSDBrightnessContrast(this,length)).parse();break;case"blnc":this.adjustments.colorBalance=(new PSDColorBalance(this,length)).parse();break;case"hue2":this.adjustments.hueSaturation=(new PSDHueSaturation(this,length)).parse();break;case"selc":this.adjustments.selectiveColor=(new PSDSelectiveColor(this,length)).parse();break;case"thrs":this.adjustments.threshold=(new PSDThreshold(this,length)).parse();break;case"nvrt":this.adjustments.invert=(new PSDInvert(this,length)).parse();break;case"post":this.adjustments.posterize=(new PSDPosterize(this,length)).parse();break;case"tySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse(true);break;case"TySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse();break;case"luni":this.name=this.file.readUnicodeString();break;case"lyid":this.layerId=this.file.readInt();break;case"lsct":this.readLayerSectionDivider();break;case"lrFX":this.parseEffectsLayer();this.file.read(2);break;default:this.file.seek(length);Log.debug("Skipping additional layer info with key "+key);} -if(this.file.tell()!==(pos+length)){Log.debug("Error parsing additional layer info with key "+key+" - unexpected end");_results.push(this.file.seek(pos+length,false));}else{_results.push(void 0);}} +return _results;};PSDLayer.prototype.parseLegacyLayerName=function(){var namelen;namelen=Util.pad4(this.file.read(1)[0]);return this.legacyName=Util.decodeMacroman(this.file.read(namelen)).replace(/\u0000/g,'');};PSDLayer.prototype.parseExtraData=function(){var key,length,pos,signature,_ref,_results;_results=[];while(this.file.tell()<this.layerEnd){_ref=this.file.readf(">4s4s"),signature=_ref[0],key=_ref[1];assert.equal(signature,"8BIM");length=Util.pad2(this.file.readInt());pos=this.file.tell();Log.debug("Extra layer info: key = "+key+", length = "+length);switch(key){case"SoCo":this.adjustments.solidColor=(new PSDSolidColor(this,length)).parse();break;case"levl":this.adjustments.levels=(new PSDLevels(this,length)).parse();break;case"curv":this.adjustments.curves=(new PSDCurves(this,length)).parse();break;case"brit":this.adjustments.brightnessContrast=(new PSDBrightnessContrast(this,length)).parse();break;case"blnc":this.adjustments.colorBalance=(new PSDColorBalance(this,length)).parse();break;case"hue2":this.adjustments.hueSaturation=(new PSDHueSaturation(this,length)).parse();break;case"selc":this.adjustments.selectiveColor=(new PSDSelectiveColor(this,length)).parse();break;case"thrs":this.adjustments.threshold=(new PSDThreshold(this,length)).parse();break;case"nvrt":this.adjustments.invert=(new PSDInvert(this,length)).parse();break;case"post":this.adjustments.posterize=(new PSDPosterize(this,length)).parse();break;case"tySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse(true);break;case"TySh":this.adjustments.typeTool=(new PSDTypeTool(this,length)).parse();break;case"luni":this.name=this.file.readUnicodeString(Util.pad4);this.file.seek(pos+length,false);break;case"lyid":this.layerId=this.file.readInt();break;case"lsct":this.readLayerSectionDivider();break;case"lrFX":this.parseEffectsLayer();this.file.read(2);break;default:this.file.seek(length);Log.debug("Skipping additional layer info with key "+key);} +if(this.file.tell()!==(pos+length)){Log.debug("Warning: additional layer info with key "+key+" - unexpected end");_results.push(this.file.seek(pos+length,false));}else{_results.push(void 0);}} return _results;};PSDLayer.prototype.parseEffectsLayer=function(){var count,data,effect,effects,left,pos,signature,size,type,v,_ref,_ref1;effects=[];_ref=this.file.readf(">HH"),v=_ref[0],count=_ref[1];while(count-->0){_ref1=this.file.readf(">4s4s"),signature=_ref1[0],type=_ref1[1];size=this.file.readf(">i")[0];pos=this.file.tell();Log.debug("Parsing effect layer with type "+type+" and size "+size);effect=(function(){switch(type){case"cmnS":return new PSDLayerEffectCommonStateInfo(this.file);case"dsdw":return new PSDDropDownLayerEffect(this.file);case"isdw":return new PSDDropDownLayerEffect(this.file,true);}}).call(this);data=effect!=null?effect.parse():void 0;left=(pos+size)-this.file.tell();if(left!==0){Log.debug("Failed to parse effect layer with type "+type);this.file.seek(left);}else{if(type!=="cmnS"){effects.push(data);}}} return this.adjustments.effects=effects;};PSDLayer.prototype.readLayerSectionDivider=function(){var code;code=this.file.readInt();this.layerType=SECTION_DIVIDER_TYPES[code];Log.debug("Layer type:",this.layerType);switch(code){case 1:case 2:return this.isFolder=true;case 3:return this.isHidden=true;}};PSDLayer.prototype.toJSON=function(){var data,section,sections,_i,_len;sections=['name','top','left','bottom','right','channels','rows','cols','channelsInfo','mask','layerType','blendMode','adjustments','visible'];data={};for(_i=0,_len=sections.length;_i<_len;_i++){section=sections[_i];data[section]=this[section];} return data;};return PSDLayer;})();PSDLayerMask=(function(){function PSDLayerMask(file,header,options){this.file=file;this.header=header;this.options=options;this.layers=[];this.mergedAlpha=false;this.globalMask={};this.extras=[];} @@ -261,12 +261,13 @@ _results.push(this.data.records.push(record));} return _results;};return PSDLevels;})();PSDPosterize=(function(){function PSDPosterize(layer,length){this.layer=layer;this.length=length;this.file=this.layer.file;this.data={};} PSDPosterize.prototype.parse=function(){this.data.levels=this.file.readShortInt();assert(this.data.levels>=2&&this.data.levels<=255);this.file.seek(2);return this.data;};return PSDPosterize;})();PSDSelectiveColor=(function(){function PSDSelectiveColor(layer,length){this.layer=layer;this.length=length;this.file=this.layer.file;this.data={cyanCorrection:[],magentaCorrection:[],yellowCorrection:[],blackCorrection:[]};} PSDSelectiveColor.prototype.parse=function(){var i,version,_i;version=this.file.getShortInt();assert(version===1);this.data.correctionMethod=this.file.getShortInt();for(i=_i=0;_i<10;i=++_i){this.data.cyanCorrection.push(this.file.getShortInt());this.data.magentaCorrection.push(this.file.getShortInt());this.data.yellowCorrection.push(this.file.getShortInt());this.data.blackCorrection.push(this.file.getShortInt());} -return this.data;};return PSDSelectiveColor;})();PSDThreshold=(function(){function PSDThreshold(layer,length){this.layer=layer;this.length=length;this.file=this.layer.file;this.data={};} +return this.data;};return PSDSelectiveColor;})();PSDSolidColor=(function(){function PSDSolidColor(layer,length){this.layer=layer;this.length=length;this.file=this.layer.file;} +PSDSolidColor.prototype.parse=function(){var version;version=this.file.readInt();assert(version===16);return(new PSDDescriptor(this.file)).parse();};return PSDSolidColor;})();PSDThreshold=(function(){function PSDThreshold(layer,length){this.layer=layer;this.length=length;this.file=this.layer.file;this.data={};} PSDThreshold.prototype.parse=function(){this.data.level=this.file.readShortInt();assert(this.data.level>=1&&this.data.level<=255);this.file.seek(2);return this.data;};return PSDThreshold;})();PSDTypeTool=(function(){function PSDTypeTool(layer,length){this.layer=layer;this.length=length;this.file=this.layer.file;this.data={};} PSDTypeTool.prototype.parse=function(legacy){var char,descriptorVersion,engineData,textVersion,version,warpVersion,_i,_len,_ref,_ref1,_ref2;if(legacy==null){legacy=false;} version=this.file.readShortInt();assert(version===1);this.data.transformInfo={};_ref=this.file.readf(">6d"),this.data.transformInfo.xx=_ref[0],this.data.transformInfo.xy=_ref[1],this.data.transformInfo.yx=_ref[2],this.data.transformInfo.yy=_ref[3],this.data.transformInfo.tx=_ref[4],this.data.transformInfo.ty=_ref[5];if(legacy){return this.parseLegacy();} textVersion=this.file.readShortInt();assert(textVersion===50);descriptorVersion=this.file.readInt();assert(descriptorVersion===16);this.data.text=(new PSDDescriptor(this.file)).parse();engineData="";_ref1=this.data.text.EngineData;for(_i=0,_len=_ref1.length;_i<_len;_i++){char=_ref1[_i];engineData+=String.fromCharCode(char);} -this.data.text.EngineData=engineData.replace(/\u0000/g,"");Log.debug("Text:",this.data.text);warpVersion=this.file.readShortInt();assert(warpVersion===1);descriptorVersion=this.file.readInt();assert(descriptorVersion===16);this.data.warp=(new PSDDescriptor(this.file)).parse();Log.debug("Warp:",this.data.warp);_ref2=this.file.readf(">4d"),this.data.left=_ref2[0],this.data.top=_ref2[1],this.data.right=_ref2[2],this.data.bottom=_ref2[3];return this.data;};PSDTypeTool.prototype.parseLegacy=function(){var i,j,version,_i,_j,_k,_l,_ref,_ref1,_ref2,_ref3;version=this.file.readShortInt();assert(version===6);this.data.facesCount=this.file.readShortInt();this.data.face=[];for(i=_i=0,_ref=this.data.facesCount;0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){this.data.face[i]={};this.data.face[i].mark=this.file.readShortInt();this.data.face[i].fontType=this.file.readInt();this.data.face[i].fontName=this.file.readLengthWithString();this.data.face[i].fontFamilyName=this.file.readLengthWithString();this.data.face[i].fontStyleName=this.file.readLengthWithString();this.data.face[i].script=this.file.readShortInt();this.data.face[i].numberAxesVector=this.file.readInt();this.data.face[i].vector=[];for(j=_j=0,_ref1=this.data.face[i].numberAxesVector;0<=_ref1?_j<_ref1:_j>_ref1;j=0<=_ref1?++_j:--_j){this.data.face[i].vector[j]=this.file.readInt();}} +this.data.text.EngineData=engineData.replace(/\u0000/g,"");warpVersion=this.file.readShortInt();assert(warpVersion===1);descriptorVersion=this.file.readInt();assert(descriptorVersion===16);this.data.warp=(new PSDDescriptor(this.file)).parse();Log.debug("Warp:",this.data.warp);_ref2=this.file.readf(">4d"),this.data.left=_ref2[0],this.data.top=_ref2[1],this.data.right=_ref2[2],this.data.bottom=_ref2[3];return this.data;};PSDTypeTool.prototype.parseLegacy=function(){var i,j,version,_i,_j,_k,_l,_ref,_ref1,_ref2,_ref3;version=this.file.readShortInt();assert(version===6);this.data.facesCount=this.file.readShortInt();this.data.face=[];for(i=_i=0,_ref=this.data.facesCount;0<=_ref?_i<_ref:_i>_ref;i=0<=_ref?++_i:--_i){this.data.face[i]={};this.data.face[i].mark=this.file.readShortInt();this.data.face[i].fontType=this.file.readInt();this.data.face[i].fontName=this.file.readLengthWithString();this.data.face[i].fontFamilyName=this.file.readLengthWithString();this.data.face[i].fontStyleName=this.file.readLengthWithString();this.data.face[i].script=this.file.readShortInt();this.data.face[i].numberAxesVector=this.file.readInt();this.data.face[i].vector=[];for(j=_j=0,_ref1=this.data.face[i].numberAxesVector;0<=_ref1?_j<_ref1:_j>_ref1;j=0<=_ref1?++_j:--_j){this.data.face[i].vector[j]=this.file.readInt();}} this.data.stylesCount=this.file.readShortInt();this.data.style=[];for(i=_k=0,_ref2=this.data.stylesCount;0<=_ref2?_k<_ref2:_k>_ref2;i=0<=_ref2?++_k:--_k){this.data.style[i]={};this.data.style[i].mark=this.file.readShortInt();this.data.style[i].faceMark=this.file.readShortInt();this.data.style[i].size=this.file.readInt();this.data.style[i].tracking=this.file.readInt();this.data.style[i].kerning=this.file.readInt();this.data.style[i].leading=this.file.readInt();this.data.style[i].baseShift=this.file.readInt();this.data.style[i].autoKern=this.file.readBoolean();this.file.read(1);this.data.style[i].rotate=this.file.readBoolean();} this.data.type=this.file.readShortInt();this.data.scalingFactor=this.file.readInt();this.data.sharacterCount=this.file.readInt();this.data.horzPlace=this.file.readInt();this.data.vertPlace=this.file.readInt();this.data.selectStart=this.file.readInt();this.data.selectEnd=this.file.readInt();this.data.linesCount=this.file.readShortInt();this.data.line=[];for(i=_l=0,_ref3=this.data.linesCount;0<=_ref3?_l<_ref3:_l>_ref3;i=0<=_ref3?++_l:--_l){this.data.line[i].charCount=this.file.readInt();this.data.line[i].orientation=this.file.readShortInt();this.data.line[i].alignment=this.file.readShortInt();this.data.line[i].actualChar=this.file.readShortInt();this.data.line[i].style=this.file.readShortInt();} this.data.color=this.file.readSpaceColor();this.data.antialias=this.file.readBoolean();return this.data;};return PSDTypeTool;})();PSDResource=(function(){var RESOURCE_DESCRIPTIONS;RESOURCE_DESCRIPTIONS={1000:{name:'PS2.0 mode data',parse:function(){var _ref;return _ref=this.file.readf(">5H"),this.channels=_ref[0],this.rows=_ref[1],this.cols=_ref[2],this.depth=_ref[3],this.mode=_ref[4],_ref;}},1001:{name:'Macintosh print record'},1003:{name:'PS2.0 indexed color table'},1005:{name:'ResolutionInfo'},1006:{name:'Names of the alpha channels'},1007:{name:'DisplayInfo'},1008:{name:'Caption',parse:function(){return this.caption=this.file.readLengthWithString();}},1009:{name:'Border information',parse:function(){var units,_ref;_ref=this.file.readf(">fH"),this.width=_ref[0],units=_ref[1];return this.units=(function(){switch(units){case 1:return"inches";case 2:return"cm";case 3:return"points";case 4:return"picas";case 5:return"columns";}})();}},1010:{name:'Background color'},1011:{name:'Print flags',parse:function(){var start,_ref;start=this.file.tell();_ref=this.file.readf(">9B"),this.labels=_ref[0],this.cropMarks=_ref[1],this.colorBars=_ref[2],this.registrationMarks=_ref[3],this.negative=_ref[4],this.flip=_ref[5],this.interpolate=_ref[6],this.caption=_ref[7];return this.file.seek(start+this.size,false);}},1012:{name:'Grayscale/multichannel halftoning info'},1013:{name:'Color halftoning info'},1014:{name:'Duotone halftoning info'},1015:{name:'Grayscale/multichannel transfer function'},1016:{name:'Color transfer functions'},1017:{name:'Duotone transfer functions'},1018:{name:'Duotone image info'},1019:{name:'B&W values for the dot range',parse:function(){var _ref;return _ref=this.file.readf(">H"),this.bwvalues=_ref[0],_ref;}},1021:{name:'EPS options'},1022:{name:'Quick Mask info',parse:function(){var _ref;return _ref=this.file.readf(">HB"),this.quickMaskChannelID=_ref[0],this.wasMaskEmpty=_ref[1],_ref;}},1024:{name:'Layer state info',parse:function(){var _ref;return _ref=this.file.readf(">H"),this.targetLayer=_ref[0],_ref;}},1025:{name:'Working path'},1026:{name:'Layers group info',parse:function(){var info,start,_results;start=this.file.tell();this.layerGroupInfo=[];_results=[];while(this.file.tell()<start+this.size){info=this.file.readf(">H")[0];_results.push(this.layerGroupInfo.push(info));} diff --git a/src/layerdata/solidcolor.coffee b/src/layerdata/solidcolor.coffee new file mode 100644 index 0000000..d1144fd --- /dev/null +++ b/src/layerdata/solidcolor.coffee @@ -0,0 +1,11 @@ +# Photoshop 6.0 +class PSDSolidColor + constructor: (@layer, @length) -> + @file = @layer.file + + parse: -> + version = @file.readInt() + assert version is 16 + + # Just return the descriptor data + (new PSDDescriptor(@file)).parse()
\ No newline at end of file diff --git a/src/layerdata/typetool.coffee b/src/layerdata/typetool.coffee index b375e37..faf964d 100755 --- a/src/layerdata/typetool.coffee +++ b/src/layerdata/typetool.coffee @@ -41,7 +41,9 @@ class PSDTypeTool engineData += String.fromCharCode(char) @data.text.EngineData = engineData.replace /\u0000/g, "" - Log.debug "Text:", @data.text + + # This is a bit verbose + #Log.debug "Text:", @data.text warpVersion = @file.readShortInt() assert warpVersion is 1 diff --git a/src/psdlayer.coffee b/src/psdlayer.coffee index 5e582c0..454163c 100755 --- a/src/psdlayer.coffee +++ b/src/psdlayer.coffee @@ -265,8 +265,6 @@ class PSDLayer namelen = Util.pad4 @file.read(1)[0] @legacyName = Util.decodeMacroman(@file.read(namelen)).replace /\u0000/g, '' - Log.debug "Layer name: #{@name}" - parseExtraData: -> while @file.tell() < @layerEnd [ @@ -282,6 +280,8 @@ class PSDLayer # TODO: many more adjustment layers to implement Log.debug("Extra layer info: key = #{key}, length = #{length}") switch key + when "SoCo" + @adjustments.solidColor = (new PSDSolidColor(@, length)).parse() when "levl" @adjustments.levels = (new PSDLevels(@, length)).parse() when "curv" @@ -305,7 +305,11 @@ class PSDLayer when "TySh" # PS >= 6 @adjustments.typeTool = (new PSDTypeTool(@, length)).parse() when "luni" # PS >= 5.0 - @name = @file.readUnicodeString() + @name = @file.readUnicodeString(Util.pad4) + + # This seems to be padded with null bytes (by 4?), but the easiest + # thing to do is to simply jump to the end of this section. + @file.seek pos + length, false when "lyid" @layerId = @file.readInt() when "lsct" @@ -317,7 +321,7 @@ class PSDLayer Log.debug("Skipping additional layer info with key #{key}") if @file.tell() != (pos + length) - Log.debug "Error parsing additional layer info with key #{key} - unexpected end" + Log.debug "Warning: additional layer info with key #{key} - unexpected end" @file.seek pos + length, false # Attempt to recover parseEffectsLayer: -> |