/// <summary> /// swf tag code property /// </summary> public TagCodeEnum GetTagCode() { TagCodeEnum val = TagCodeEnum.Unknown; if (this.TagCode != -1) { val = TagCodeEnum.DefineBits; val = (TagCodeEnum)System.Enum.Parse(val.GetType(), this.TagCode.ToString()); } return(val); }
/// <summary> /// Writes to a binary writer. /// </summary> /// <param name="writer">Writer.</param> /// <param name="buttonType">Button type.</param> public void WriteTo(BufferedBinaryWriter writer, TagCodeEnum buttonType) { writer.WriteUBits(0, 4); writer.WriteBoolean(buttonStateHitTest); writer.WriteBoolean(buttonStateDown); writer.WriteBoolean(buttonStateOver); writer.WriteBoolean(buttonStateUp); writer.Write(this.characterId); writer.Write(this.placeDepth); if (placeMatrix != null) { placeMatrix.WriteTo(writer); } if (colorTransform != null && buttonType == TagCodeEnum.DefineButton2) { colorTransform.WriteTo(writer); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="firstByte">First byte.</param> /// <param name="buttonType">Button type.</param> public void ReadData(BufferedBinaryReader binaryReader, byte firstByte, TagCodeEnum buttonType) { BitArray ba = BitParser.GetBitValues(new byte[1] { firstByte }); buttonStateHitTest = ba.Get(4); buttonStateDown = ba.Get(5); buttonStateOver = ba.Get(6); buttonStateUp = ba.Get(7); characterId = binaryReader.ReadUInt16(); placeDepth = binaryReader.ReadUInt16(); placeMatrix = new Matrix(); placeMatrix.ReadData(binaryReader); colorTransform = null; if (buttonType == TagCodeEnum.DefineButton2) { colorTransform = new CXFormWithAlphaData(); colorTransform.ReadData(binaryReader); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="endOfRecordsFlag">End of records flag.</param> /// <param name="tagCodeEnum">Tag code enum.</param> public void ReadData(BufferedBinaryReader binaryReader, ref bool endOfRecordsFlag, TagCodeEnum tagCodeEnum) { binaryReader.SynchBits(); bool textRecordType = binaryReader.ReadBoolean(); binaryReader.ReadUBits(3); bool styleFlagsHasFont = binaryReader.ReadBoolean(); bool styleFlagsHasColor = binaryReader.ReadBoolean(); bool styleFlagsHasYOffset = binaryReader.ReadBoolean(); bool styleFlagsHasXOffset = binaryReader.ReadBoolean(); if (textRecordType == false) { endOfRecordsFlag = true; return; } fontId = 0; if (styleFlagsHasFont) fontId = binaryReader.ReadUInt16(); textColor = null; if (styleFlagsHasColor) { if (tagCodeEnum == TagCodeEnum.DefineText2) { textColor = new RGBA(); textColor.ReadData(binaryReader); } else { textColor = new RGB(); textColor.ReadData(binaryReader); } } xOffset = 0; if (styleFlagsHasXOffset) xOffset = binaryReader.ReadInt16(); yOffset = 0; if (styleFlagsHasYOffset) yOffset = binaryReader.ReadInt16(); textHeight = 0; if (styleFlagsHasFont) textHeight = binaryReader.ReadUInt16(); byte glyphCount = binaryReader.ReadByte(); if (glyphCount > 0) { if (glyphEntries == null) glyphEntries = new GlyphEntryCollection(); else glyphEntries.Clear(); for (int i = 0; i < glyphCount; i++) { GlyphEntry glyphEntry = new GlyphEntry(); glyphEntry.ReadData(binaryReader); glyphEntries.Add(glyphEntry); } } }
/// <summary> /// Writes to a binary writer. /// </summary> /// <param name="writer">Writer.</param> /// <param name="buttonType">Button type.</param> public void WriteTo(BufferedBinaryWriter writer, TagCodeEnum buttonType) { writer.WriteUBits(0, 4); writer.WriteBoolean(buttonStateHitTest); writer.WriteBoolean(buttonStateDown); writer.WriteBoolean(buttonStateOver); writer.WriteBoolean(buttonStateUp); writer.Write(this.characterId); writer.Write(this.placeDepth); if (placeMatrix != null) placeMatrix.WriteTo(writer); if (colorTransform != null && buttonType == TagCodeEnum.DefineButton2) colorTransform.WriteTo(writer); }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="firstByte">First byte.</param> /// <param name="buttonType">Button type.</param> public void ReadData(BufferedBinaryReader binaryReader, byte firstByte, TagCodeEnum buttonType) { BitArray ba = BitParser.GetBitValues(new byte[1]{firstByte}); buttonStateHitTest = ba.Get(4); buttonStateDown = ba.Get(5); buttonStateOver = ba.Get(6); buttonStateUp = ba.Get(7); characterId = binaryReader.ReadUInt16(); placeDepth = binaryReader.ReadUInt16(); placeMatrix = new Matrix(); placeMatrix.ReadData(binaryReader); colorTransform = null; if (buttonType == TagCodeEnum.DefineButton2) { colorTransform = new CXFormWithAlphaData(); colorTransform.ReadData(binaryReader); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="endOfRecordsFlag">End of records flag.</param> /// <param name="tagCodeEnum">Tag code enum.</param> public void ReadData(BufferedBinaryReader binaryReader, ref bool endOfRecordsFlag, TagCodeEnum tagCodeEnum) { binaryReader.SynchBits(); bool textRecordType = binaryReader.ReadBoolean(); binaryReader.ReadUBits(3); bool styleFlagsHasFont = binaryReader.ReadBoolean(); bool styleFlagsHasColor = binaryReader.ReadBoolean(); bool styleFlagsHasYOffset = binaryReader.ReadBoolean(); bool styleFlagsHasXOffset = binaryReader.ReadBoolean(); if (textRecordType == false) { endOfRecordsFlag = true; return; } fontId = 0; if (styleFlagsHasFont) { fontId = binaryReader.ReadUInt16(); } textColor = null; if (styleFlagsHasColor) { if (tagCodeEnum == TagCodeEnum.DefineText2) { textColor = new RGBA(); textColor.ReadData(binaryReader); } else { textColor = new RGB(); textColor.ReadData(binaryReader); } } xOffset = 0; if (styleFlagsHasXOffset) { xOffset = binaryReader.ReadInt16(); } yOffset = 0; if (styleFlagsHasYOffset) { yOffset = binaryReader.ReadInt16(); } textHeight = 0; if (styleFlagsHasFont) { textHeight = binaryReader.ReadUInt16(); } byte glyphCount = binaryReader.ReadByte(); if (glyphCount > 0) { if (glyphEntries == null) { glyphEntries = new GlyphEntryCollection(); } else { glyphEntries.Clear(); } for (int i = 0; i < glyphCount; i++) { GlyphEntry glyphEntry = new GlyphEntry(); glyphEntry.ReadData(binaryReader); glyphEntries.Add(glyphEntry); } } }
override protected BaseTag ReadTag() { long posBefore = br.BaseStream.Position; RecordHeader rh = ReadRecordHeader(); int offset = (int)(br.BaseStream.Position - posBefore); br.BaseStream.Position = posBefore; TagCodeEnum tag = (TagCodeEnum)rh.TagCode; //if (tag != TagCodeEnum.End) Console.WriteLine("Tag: " + (TagCodeEnum)rh.TagCode); switch (tag) { //-- Parse sub-clips case TagCodeEnum.DefineSprite: return(ReadDefineSpriteTag()); case TagCodeEnum.ExportAssets: case TagCodeEnum.SymbolClass: return(ReadExportTag(offset)); case TagCodeEnum.DoABCDefine: return(new AbcTag(br.ReadBytes(rh.TagLength + offset), offset, true)); case TagCodeEnum.DoABC: return(new AbcTag(br.ReadBytes(rh.TagLength + offset), offset, false)); case TagCodeEnum.FrameLabel: return(ReadFrameTag(offset)); case TagCodeEnum.MetaData: return(ReadMetaDataTag(offset)); case TagCodeEnum.DefineFont2: case TagCodeEnum.DefineFont3: return(new DefineFontTag(br.ReadBytes(rh.TagLength + offset), offset, rh.TagCode)); /*case TagCodeEnum.DefineFontName: * br.BaseStream.Position += offset; * byte b; * Console.WriteLine(tag); * for (int i = 0; i < Math.Min(256, rh.TagLength); i++) * { * b = br.ReadByte(); * Console.Write((b >= 32) ? ((char)b).ToString() : "[" + b.ToString() + "]"); * } * Console.WriteLine(); * br.BaseStream.Position = posBefore; * return new BaseTag(br.ReadBytes(rh.TagLength + offset), rh.TagCode);*/ default: // Dump tag /*br.BaseStream.Position += offset; * byte b; * Console.WriteLine(tag); * for (int i = 0; i < rh.TagLength; i++) * { * b = br.ReadByte(); * Console.Write((b >= 32) ? ((char)b).ToString() :"[" + b.ToString() + "]"); * } * Console.WriteLine(); * br.BaseStream.Position = posBefore;*/ return(new BaseTag(br.ReadBytes(rh.TagLength + offset), rh.TagCode)); } }