/// <summary> /// The way how object like lines and shapes get filled. /// </summary> /// <param name="InitialVersion">The version of the Swf file using this object.</param> public FillStyle(byte InitialVersion) : base(InitialVersion) { this._color = new Rgb(this._SwfVersion); this._gradientMatrix = new Matrix(this._SwfVersion); this._gradient = new Gradient(this._SwfVersion); this._bitmapMatrix = new Matrix(this._SwfVersion); this._caller = TagTypes.DefineShape; }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="caller"></param> public void Parse( Stream input, TagTypes caller ) { BinaryReader br = new BinaryReader(input); this._ratio = br.ReadByte(); if (caller.Equals(TagTypes.DefineShape3) || caller.Equals(TagTypes.DefineShape4)) { this._color = new Rgba(this._SwfVersion); this._color.Parse(input); } else { this._color = new Rgb(this._SwfVersion); this._color.Parse(input); } }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="caller"></param> public virtual void Parse(Stream input, TagTypes caller) { BinaryReader br = new BinaryReader(input); this._width = br.ReadUInt16(); if (caller.Equals(TagTypes.DefineShape) || caller.Equals(TagTypes.DefineShape2)) { this._color = new Rgb(this._SwfVersion); try { this._color.Parse(input); } catch(SwfFormatException e) { throw e; } } else if (caller.Equals(TagTypes.DefineShape3)) { this._color = new Rgba(this._SwfVersion); try { this._color.Parse(input); } catch (SwfFormatException e) { throw e; } } else { SwfFormatException e = new SwfFormatException("LineStyle was called by illegal TagType (" + caller.ToString() +")."); Log.Error(this, e.Message); } }
// TODO: sometimes index out of bounds exception occurs here. Reheck /// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="colorTableSize"></param> /// <param name="imageDataSize"></param> public virtual void Parse( Stream input, byte colorTableSize, UInt32 imageDataSize ) { //Log.Debug(this, "Image data size is:" + imageDataSize + ". Color table size is: " + colorTableSize ); Rgb temp = null; for ( byte i = 0; i <= colorTableSize; i++ ) // because we need BitmapColorTableSize + 1 elements { temp = new Rgb( this._SwfVersion ); temp.Parse( input ); _colorTableRGB.Add( temp ); } try { this._colormapPixelData = new byte[(Int32)imageDataSize]; input.Read(this._colormapPixelData, 0, (Int32)imageDataSize); } catch (IndexOutOfRangeException e) { Log.Error(this, e.Message); throw e; } }
/// <summary> /// Parses this object out of a stream /// </summary> public void Parse(Stream input, TagTypes caller, byte glyphBits, byte advancedBits, byte firstByte) { this._textRecordType = GetBit(firstByte, 0); bool reserved1 = GetBit(firstByte, 1); bool reserved2 = GetBit(firstByte, 2); bool reserved3 = GetBit(firstByte, 3); this._StyleFlagsHasFont = GetBit(firstByte, 4); this._StyleFlagsHasColor = GetBit(firstByte, 5); this._StyleFlagsHasYOffset = GetBit(firstByte, 6); this._StyleFlagsHasXOffset = GetBit(firstByte, 7); if (!this._textRecordType || (reserved1 || reserved2 || reserved3)) { SwfFormatException e = new SwfFormatException("The first four bits have to have the static values {1,0,0,0} but set different."); Log.Error(this, e.Message); throw e; } BinaryReader br = new BinaryReader(input); if (this._StyleFlagsHasFont) { this._fontID = br.ReadUInt16(); } if (this._StyleFlagsHasColor) { if (caller.Equals(TagTypes.DefineFont2) || caller.Equals(TagTypes.DefineText2)) { this._textColor = new Rgba(this._SwfVersion); this._textColor.Parse(input); } else { this._textColor.Parse(input); } } if (this._StyleFlagsHasXOffset) { this._xOffset = br.ReadInt16(); } if (this._StyleFlagsHasYOffset) { this._yOffset = br.ReadInt16(); } if (this._StyleFlagsHasFont) { this._textHeight = br.ReadUInt16(); } this._glyphCount = br.ReadByte(); BitStream bits = new BitStream(input); GlyphEntry tempGlyph = null; for (int i = 0; i < this._glyphCount; i++) { tempGlyph = new GlyphEntry(this._SwfVersion); tempGlyph.Parse(bits, glyphBits, advancedBits); this._glyphEntries.Add(tempGlyph); } }
/// <summary> /// A TEXTRECORD sets text styles for subsequent characters. /// </summary> /// <param name="InitialVersion">The version of the Swf file using this object.</param> public TextRecord(byte InitialVersion) : base(InitialVersion) { this._textColor = new Rgb(this._SwfVersion); this._glyphEntries = new List<GlyphEntry>(); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="caller"></param> public void Parse(Stream input, TagTypes caller) { BinaryReader br = new BinaryReader(input); this._caller = caller; this._fillStyleType = (FillStyleType)br.ReadByte(); if (this._fillStyleType.Equals(FillStyleType.SolidFill)) { if (caller.Equals(TagTypes.DefineShape3) ) { this._color = new Rgba(this._SwfVersion); try { this._color.Parse(input); //Log.InfoFormat("Valid fill style type. FillstyleType: 0x{0:X2} at address: 0x{1:X2} in {2}", (Int32)this._fillStyleType, ((Int32)input.Position) - 1, caller); } catch (SwfFormatException e) { throw e; } } else if (caller.Equals(TagTypes.DefineShape4)) { this._color = new Rgba(this._SwfVersion); try { this._color.Parse(input); } catch (SwfFormatException e) { throw e; } } else { this._color = new Rgb(this._SwfVersion); try { this._color.Parse(input); } catch (SwfFormatException e) { throw e; } } } else if (this._fillStyleType.Equals(FillStyleType.LinearGradientFill) || this._fillStyleType.Equals(FillStyleType.RadialGradientFill)) { this._gradientMatrix = new Matrix(this._SwfVersion); try { this._gradientMatrix.Parse(input); } catch (SwfFormatException e) { throw e; } this._gradient = new Gradient(this._SwfVersion); try { this._gradient.Parse(input, caller); //Log.InfoFormat("Valid fill style type. FillstyleType: 0x{0:X2} at address: 0x{1:X4} in {2}", (Int32)this._fillStyleType, ((Int32)input.Position) - 1, caller); } catch (SwfFormatException e) { throw e; } } else if (this._fillStyleType.Equals(FillStyleType.FocalRadialGradientFill)) { if (this._SwfVersion >= 8) { this._gradientMatrix = new Matrix(this._SwfVersion); try { this._gradientMatrix.Parse(input); } catch(SwfFormatException e) { throw e; } this._gradient = new FocalGradient(this._SwfVersion); try { this._gradient.Parse(input, caller); //Log.InfoFormat("Valid fill style type. FillstyleType: 0x{0:X2} at address: 0x{1:X4} in {2}", (Int32)this._fillStyleType, ((Int32)input.Position) - 1, caller); } catch (SwfFormatException e) { throw e; } } else { SwfFormatException e = new SwfFormatException("Focal gradients are supported by Swf 8 and later only. This version is: " + this._SwfVersion.ToString()); Log.Error(this, e); } } else if (this._fillStyleType.Equals(FillStyleType.RepeatingBitmapFill) || this._fillStyleType.Equals(FillStyleType.ClippedBitmapFill) || this._fillStyleType.Equals(FillStyleType.NonSmoothedRepeatingBitmap) || this._fillStyleType.Equals(FillStyleType.NonSmoothedClippedBitmap)) { this._bitmapID = br.ReadUInt16(); this._bitmapMatrix = new Matrix(this._SwfVersion); try { this._bitmapMatrix.Parse(input); //Log.InfoFormat("Valid fill style type. FillstyleType: 0x{0:X2} at address: 0x{1:X4} in {2}", (Int32)this._fillStyleType, ((Int32)input.Position) - 1, caller); } catch (SwfFormatException e) { throw e; } } else { SwfFormatException e = new SwfFormatException("Invalid fill style type! (" + this._fillStyleType +")" +" caller: " + caller.ToString()); Log.Error(this, e); throw e; } }
/// <summary> /// A line style represents a width and color of a line. /// </summary> /// <param name="InitialVersion">The version of the Swf file using this objct</param> public LineStyle(byte InitialVersion) : base(InitialVersion) { this._width = 0; this._color = new Rgb(this._SwfVersion); }