接着解析图层的adjustmentData部分信息:
第一个signature是固定的8BIM
第二个是标示下面的data内容所属类型的key
第三个是内容长度。
var ba:ByteArray = new ByteArray();
var signature:String = adjustmentData.readUTFBytes(4); //always 8BIM
if("" == signature)
{
throw new Error("解析文件错误了");
return;
}
var key:String = adjustmentData.readUTFBytes(4);
key值有很多种,这里只用了标示文本内容的TySh跟图层类型的lsct来举例。
switch(key)
{
case "TySh": //文本内容
{ len = adjustmentData.readUnsignedInt();
adjustmentData.readBytes(ba, 0, len);
var version:int = ba.readShort();
ba.position += 48;//跳过
var ver1:int = ba.readShort();
var ver2:int = ba.readInt();
//descriptor
len = ba.readInt()*2; //the string of unicode values, two bytes per character
ba.position += len;
len = ba.readInt();
if(0 == len)
{
ba.position += 4;
}
var numOfItems:int = ba.readInt();
var descripterKey:String;
var typeTxt:String;
for (var i:int = 0; i < numOfItems; i++)
{
descripterKey = ba.readUTFBytes(4);
if("" == descripterKey)
{
descripterKey = ba.readUTFBytes(4);
}
typeTxt = ba.readUTFBytes(4);
switch(descripterKey)
{
case 'Txt ':
textContent = parseUnicodeString(ba);
labelSheetVo = PsdUtil.psdVo.labelSheetDict[layerName];
isText = true;
break;
}
}
break;
}
case "lsct": //文件夹判断
{
len = adjustmentData.readUnsignedInt();
adjustmentData.readBytes(ba, 0, len);
//0 = any other type of layer, 1 = open “folder”, 2 = closed “folder”, 3 = bounding section divider, hidden in the UI
var type:int = ba.readUnsignedInt();
_isFolder = (1 == type || 2 == type);
break;
}
//这几个在长度上有特殊的去读要求
case "lrFX": //Effects Layer info
case "lfx2": //Object Based Effects Layer info
case "Patt": //Patterns ase "Anno": //Annotations
{
len = adjustmentData.readUnsignedInt();
mode = len%4;
if(0 != mode)
{
adjustmentData.readBytes(ba, 0, len + 4 - mode);
}
else
{
adjustmentData.readBytes(ba, 0, len);
}
break;
}
default:
{
len = adjustmentData.readUnsignedInt();
adjustmentData.readBytes(ba, 0, len);
break;
}
}