/// <summary> /// Reads the text information for the layer. /// </summary> /// <param name="dataReader">The reader to use to read the text data.</param> private void ReadTextLayer(BinaryReverseReader dataReader) { IsTextLayer = true; // read the text layer's text string dataReader.Seek("/Text"); dataReader.ReadBytes(4); Text = dataReader.ReadString(); // read the text justification dataReader.Seek("/Justification "); int justification = dataReader.ReadByte() - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } // read the font size dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red * byte.MaxValue, green * byte.MaxValue, blue * byte.MaxValue, alpha * byte.MaxValue); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); dataReader.ReadBytes(4); FontName = dataReader.ReadString(); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
/// <summary> /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data. /// </summary> /// <param name="reader">The reader containing the PSD file data.</param> /// <param name="psdFile">The PSD file to set as the parent.</param> public Layer(BinaryReverseReader reader, PsdFile psdFile) { Children = new List <Layer>(); PsdFile = psdFile; // read the rect Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; // read the channels int channelCount = reader.ReadUInt16(); Channels = new List <Channel>(); SortedChannels = new SortedList <short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); SortedChannels.Add(channel.ID, channel); } // read the header and verify it if (new string(reader.ReadChars(4)) != "8BIM") { throw new IOException("Layer Channelheader error!"); } // read the blend mode key (unused) (defaults to "norm") reader.ReadChars(4); // read the opacity Opacity = reader.ReadByte(); // read the clipping (unused) (< 0 = base, > 0 = non base) reader.ReadByte(); // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant) flags = new BitVector32(reader.ReadByte()); // skip a padding byte reader.ReadByte(); uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); BlendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // read the name Name = reader.ReadPascalString(); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); AdjustmentInfo = new List <AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo) { if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; dataReader.ReadBytes(3); dataReader.ReadByte(); Name = dataReader.ReadString().TrimEnd(new char[1]); } } reader.BaseStream.Position = num4; }
private void ReadTextLayer(BinaryReverseReader dataReader) { //文档 五 - 4 - 22) -d - 15 IsTextLayer = true; dataReader.Seek("/Text"); byte[] temp = dataReader.ReadBytes(4); Text = dataReader.ReadString();// ( true); dataReader.Seek("/Justification"); int justification = dataReader.ReadByte();// - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red, green, blue, alpha); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); FontName = dataReader.ReadString(); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); byte[] wrapBytes = dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
public Layer(BinaryReverseReader reader, PsdFile psdFile) { //从文档 五 - 4 - 1) 开始读 Children = new List <Layer>(); PsdFile = psdFile; Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; int channelCount = reader.ReadUInt16(); Channels = new List <Channel>(); SortedChannels = new SortedList <short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); SortedChannels.Add(channel.ID, channel); } string head = reader.ReadStringNew(4); if (head != "8BIM") { throw new IOException("Layer Channelheader error!"); } string layerRecordsBlendModeKey = reader.ReadStringNew(4); Opacity = reader.ReadByte(); int Clipping = reader.ReadByte(); _flags = new BitVector32(reader.ReadByte()); int Filler = reader.ReadByte(); _imageTransparent = Convert.ToSingle(Opacity) / byte.MaxValue; //文档 五 - 4 - 13) uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); _blendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // 文档 五 - 4 - 21) Name = reader.ReadPascalString(); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); _adjustmentInfo = new List <AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { _adjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } foreach (AdjustmentLayerInfo adjustmentLayerInfo in _adjustmentInfo) { if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] temp1 = dataReader.ReadBytes(3); byte charCount = dataReader.ReadByte(); //本来 charCount 是文本串的长度,可以传入ReadString()限定读取长度,但Text除串头无文本长度信息,因此改为读一段Unicode字符串 Name = dataReader.ReadString(); if (Name == "") { Name = DefaultLayerName; } } //此处针对字体 图层样式 else if (adjustmentLayerInfo.Key == "lrFX") //样式 相关,对于字体来说,就是描边之类的 { ParseLrfxKeyword(adjustmentLayerInfo); //yanruTODO测试屏蔽 } //仅对于图片的 else if (adjustmentLayerInfo.Key == "lspf") { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] data = dataReader.ReadBytes(4); } else if (adjustmentLayerInfo.Key == "lclr") { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] data = dataReader.ReadBytes(10); } } reader.BaseStream.Position = num4; int deltaL = (int)(MaskData.Rect.x - Rect.x); int deltaR = (int)(Rect.xMax - MaskData.Rect.xMax); int deltaT = (int)(MaskData.Rect.y - Rect.y); int deltaB = (int)(Rect.yMax - MaskData.Rect.yMax); int l = deltaL > 0 ? deltaL : 0; int r = deltaR > 0 ? deltaR : 0; int t = deltaT > 0 ? deltaT : 0; int b = deltaB > 0 ? deltaB : 0; //Unity Document TextureImporter.spriteBorder X=left, Y=bottom, Z=right, W=top. _border = new Vector4(l, b, r, t); //_is9Slice = SLICE_REG.Match(_name).Success; _is9Slice = _name.Contains(SLICE_HEAD); }
/// <summary> /// Reads the text information for the layer. /// </summary> /// <param name="dataReader">The reader to use to read the text data.</param> private void ReadTextLayer(BinaryReverseReader dataReader) { IsTextLayer = true; // read the text layer's text string dataReader.Seek("/Text"); dataReader.ReadBytes(4); Text = dataReader.ReadString(); // read the text justification dataReader.Seek("/Justification "); int justification = dataReader.ReadByte() - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } // read the font size dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red * byte.MaxValue, green * byte.MaxValue, blue * byte.MaxValue, alpha * byte.MaxValue); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); dataReader.ReadBytes(4); FontName = dataReader.ReadString(); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
/// <summary> /// Reads the text information for the layer. /// </summary> /// <param name="dataReader">The reader to use to read the text data.</param> private void ReadTextLayer(BinaryReverseReader dataReader) { IsTextLayer = true; // read the text layer's text string dataReader.Seek("/Text"); byte[] temp = dataReader.ReadBytes(4); //注意:解析的起点是对的,但是终点不对 //Debug.Log("text layer temp[0]=" + temp[0] + ",temp[1]=" + temp[1] + ",temp[2]=" + temp[2]+",temp[3]=" + temp[3]); Text = dataReader.ReadString(); // ( true); // read the text justification dataReader.Seek("/Justification"); int justification = dataReader.ReadByte();// - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } //Debug.Log("text layer justification=" + justification); // read the font size dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); //Debug.Log("text layer FontSize=" + FontSize); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red, green, blue, alpha); //Debug.Log("text text="+ Text + ",red=" + red + ",green=" + green + ",blue=" + blue+ ",alpha="+ alpha+",position="+dataReader.BaseStream.Position+ ", byte.MaxValue=" + byte.MaxValue); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); FontName = dataReader.ReadString(); //Debug.Log("text layer FontName=" + FontName); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); byte [] wrapBytes = dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
/// <summary> /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data. /// </summary> /// <param name="reader">The reader containing the PSD file data.</param> /// <param name="psdFile">The PSD file to set as the parent.</param> public Layer(BinaryReverseReader reader, PsdFile psdFile) { Children = new List <Layer>(); PsdFile = psdFile; // read the rect Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; // read the channels int channelCount = reader.ReadUInt16(); Channels = new List <Channel>(); SortedChannels = new SortedList <short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); //Debug.Log(Time.time + "channel.ID=" + channel.ID + ",layer=" + this.Name); SortedChannels.Add(channel.ID, channel); } string head = reader.readStringNew(4); //Debug.Log(Time.time + ",head=" + head); // read the header and verify it if (head != "8BIM") { throw new IOException("Layer Channelheader error!"); } // read the blend mode key (unused) (defaults to "norm") //reader.ReadChars(4); string layerRecordsBlendModeKey = reader.readStringNew(4); // read the opacity Opacity = reader.ReadByte(); // read the clipping (unused) (< 0 = base, > 0 = non base) int Clipping = reader.ReadByte(); // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant) flags = new BitVector32(reader.ReadByte()); // skip a padding byte int Filler = reader.ReadByte(); imageTransparent = Convert.ToSingle(Opacity) / byte.MaxValue; Debug.Log("layerRecordsBlendModeKey=" + layerRecordsBlendModeKey + ",Opacity=" + Opacity + ",Clipping=" + Clipping + ",flags=" + flags + ", Filler=" + Filler + ",LayerTransparent=" + imageTransparent); uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); BlendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // read the name Name = reader.ReadPascalString(); //Debug.Log(Time.time + ",read layer Name=" + Name + ".end"); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); //Debug.Log(Time.time + ",read count=" + count + ".end"); AdjustmentInfo = new List <AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } string keyInfo = ""; foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo) { keyInfo += ",key=" + adjustmentLayerInfo.Key + "\n"; if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] temp1 = dataReader.ReadBytes(3); byte charCount = dataReader.ReadByte(); //本来 charCount 是文本串的长度,可以传入ReadString()限定读取长度,但Text除串头无文本长度信息,因此改为读一段Unicode字符串 Name = dataReader.ReadString(); if (Name == "") { Name = defaultLayerName; } } //此处针对字体 图层样式 else if (adjustmentLayerInfo.Key == "lrFX") //样式 相关,对于字体来说,就是描边之类的 { parseLrfxKeyword(adjustmentLayerInfo); //yanruTODO测试屏蔽 } //仅对于图片的 else if (adjustmentLayerInfo.Key == "lspf") { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] data = dataReader.ReadBytes(4); printbytes(data, "lspf data", true); } else if (adjustmentLayerInfo.Key == "lclr") { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] data = dataReader.ReadBytes(10); printbytes(data, "lclr data", true); } } Debug.Log("layer=" + Name + ",Totalkey=\n" + keyInfo); reader.BaseStream.Position = num4; }