PSD解析工具實現(六)

接着解析圖層的adjustmentData部分信息: ide

第一個signature是固定的8BIM spa

第二個是標示下面的data內容所屬類型的key code

第三個是內容長度。 ip

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來舉例。 unicode

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;
	}
}
相關文章
相關標籤/搜索