Swf 8 and later supports up to 15 gradient control points, spread modes and a new

interpolation type.

Note that for the DefineShape, DefineShape2 or DefineShape3 tags, the SpreadMode and

InterpolationMode fields must be 0, and the NumGradients field can not exceed 8.

Source: Adobe[swf_file_format_spec_v10.pdf]

Inheritance: AbstractSwfElement
Exemple #1
0
 /// <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;
 }
Exemple #2
0
        /// <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;
            }
        }