Recurity.Swf.FillStyle.Parse C# (CSharp) Method

Parse() public method

public Parse ( Stream input, TagTypes caller ) : void
input Stream
caller TagTypes
return void
        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;
            }
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="caller"></param>
        public virtual void Parse( Stream input, TagTypes caller )
        {
            BinaryReader br = new BinaryReader(input);

            this._fillStyleCount = br.ReadByte();

            if (this._fillStyleCount.Equals(0xFF))
            {
                if (caller.Equals(TagTypes.DefineShape2) || caller.Equals(TagTypes.DefineShape3))
                {
                    this._fillStyleCountExtended = br.ReadUInt16();

                    //Log.InfoFormat("{0}(0x{0:x4}) fillstyles will be parsed", (int)this._fillStyleCountExtended);

                    for (UInt16 i = 0; i < this._fillStyleCountExtended; i++)
                    {
                        FillStyle temp = new FillStyle(this._SwfVersion);
                        try
                        {
                            temp.Parse(input, caller);
                            this._fillStyles.Add(temp);
                        }
                        catch (SwfFormatException e)
                        {
                           Log.Error(this, e.Message);
                        }
                    }
                }
                else
                {
                    SwfFormatException e = new SwfFormatException("Extended count of fill styles supported only for Shape2 and Shape3.");
                   Log.Error(this, e.Message);
                    throw e;
                }
            }
            else
            {
                //Log.InfoFormat("{0}(0x{0:x4}) fillstyles will be parsed", (int)this._fillStyleCount);

                for (byte i = 0; i < this._fillStyleCount; i++)
                {
                    FillStyle temp = new FillStyle(this._SwfVersion);
                    try
                    {
                        temp.Parse(input, caller);
                    }
                    catch (SwfFormatException e)
                    {
                        throw e;
                    }

                    this._fillStyles.Add( temp);
                }
            }
        }