Esempio n. 1
0
        public static Stroke GetStroke(IGraphPath path)
        {
            Pen       pen1   = null;
            string    text1  = AttributeFunc.ParseAttribute("stroke", (SvgElement)path, false).ToString();
            Color     color1 = Color.Empty;
            ISvgBrush brush1 = new SolidColor(Color.Empty);

            if ((text1 != null) || (text1 != string.Empty))
            {
                brush1 = BrushManager.Parsing(text1, ((SvgElement)path).OwnerDocument);
            }
            text1 = AttributeFunc.ParseAttribute("stroke-opacity", (SvgElement)path, false).ToString();
            float single1 = 1f;

            if ((text1 != string.Empty) && (text1 != null))
            {
                single1 = Math.Max((float)0f, Math.Min((float)255f, ItopVector.Core.Func.Number.ParseFloatStr(text1)));
            }
            if (single1 > 1f)
            {
                single1 /= 255f;
            }
            single1 = Math.Min(path.Opacity, path.StrokeOpacity);
            float  single2 = 1f;
            object obj1    = AttributeFunc.ParseAttribute("stroke-width", (SvgElement)path, false);

            if (obj1 is float)
            {
                single2 = (float)obj1;
            }
            pen1           = new Pen(Color.Empty, single2);
            pen1.Alignment = PenAlignment.Outset;
            string text2 = AttributeFunc.FindAttribute("stroke-linecap", (SvgElement)path).ToString();

            if (text2 == "round")
            {
                LineCap cap1;
                pen1.EndCap   = cap1 = LineCap.Round;
                pen1.StartCap = cap1;
            }
            else if (text2 == "square")
            {
                LineCap cap2;
                pen1.EndCap   = cap2 = LineCap.Square;
                pen1.StartCap = cap2;
            }
            else
            {
                LineCap cap3;
                pen1.EndCap   = cap3 = LineCap.Flat;
                pen1.StartCap = cap3;
            }
            string text3 = AttributeFunc.FindAttribute("stroke-linejoin", (SvgElement)path).ToString();

            if (text3 == "round")
            {
                pen1.LineJoin = LineJoin.Round;
            }
            else if (text3 == "bevel")
            {
                pen1.LineJoin = LineJoin.Bevel;
            }
            else
            {
                pen1.LineJoin = LineJoin.Miter;
            }
            string text4 = AttributeFunc.FindAttribute("stroke-miterlimit", (SvgElement)path).ToString();

            if (text4 == "")
            {
                text4 = "4";
            }
            float single3 = ItopVector.Core.Func.Number.parseToFloat(text4, (SvgElement)path, SvgLengthDirection.Horizontal);

            if (single3 < 1f)
            {
                throw new Exception("stroke-miterlimit " + ItopVector.Core.Config.Config.GetLabelForName("notlowerstr") + " 1:" + text4);
            }
            pen1.MiterLimit = single3;
            string text5 = AttributeFunc.FindAttribute("stroke-dasharray", (SvgElement)path).ToString();

            if ((text5 != "") && (text5 != "none"))
            {
                Regex regex1 = new Regex(@"[\s\,]+");
                text5 = regex1.Replace(text5, ",");
                char[] chArray1 = new char[1] {
                    ','
                };
                string[] textArray1   = text5.Split(chArray1);
                float[]  singleArray1 = new float[textArray1.GetLength(0)];
                for (int num1 = 0; num1 < textArray1.GetLength(0); num1++)
                {
                    singleArray1[num1] = ItopVector.Core.Func.Number.ParseFloatStr(textArray1[num1]) / pen1.Width;
                }
                if ((singleArray1.GetLength(0) % 2) == 1)
                {
                    float[] singleArray2 = new float[singleArray1.GetLength(0) * 2];
                    singleArray1.CopyTo(singleArray2, 0);
                    singleArray1.CopyTo(singleArray2, singleArray1.GetLength(0));
                    singleArray1 = singleArray2;
                }
                pen1.DashPattern = singleArray1;
            }
            string text6   = AttributeFunc.FindAttribute("stroke-dashoffset", (SvgElement)path).ToString();
            float  single4 = 0f;

            if (text6 != "")
            {
                single4 = ItopVector.Core.Func.Number.parseToFloat(text6, (SvgElement)path, SvgLengthDirection.Horizontal);
            }
            float single5 = Math.Abs((float)AnimFunc.GetAnimateValue((SvgElement)path, "stroke-dashoffset", DomType.SvgNumber, single4)) / pen1.Width;

            pen1.DashOffset = single5 / single2;
            if (brush1 != null)
            {
                brush1.Pen = pen1;
            }
            Stroke stroke1 = new Stroke(brush1);

            stroke1.Opacity = single1;
            return(stroke1);
        }
Esempio n. 2
0
        public void Paint(GraphicsPath path, Graphics g, int time, float opacity)
        {
            int num1 = 0;
            int num2 = 0;

            AnimFunc.CreateAnimateValues(this, time, out num1, out num2);
            path.FillMode   = FillMode.Alternate;
            g.SmoothingMode = base.OwnerDocument.SmoothingMode;
            SpreadMethods methods1 = this.SpreadMethod;
            bool          flag1    = this.Units == Units.UserSpaceOnUse;
            float         single1  = this.CX;
            float         single2  = this.CY;
            float         single3  = this.R;
            float         single4  = this.FX;
            float         single5  = this.FY;

            PointF[] tfArray2 = new PointF[7] {
                new PointF(single1, single2), new PointF(single1 + single3, single2), new PointF(single1 + (single3 * ((float)Math.Sin(1.8325957145940459))), single2 + (single3 * ((float)Math.Cos(1.8325957145940459)))), new PointF(single1 + (single3 * ((float)Math.Sin(1.3089969389957472))), single2 + (single3 * ((float)Math.Cos(1.3089969389957472)))), new PointF(single1, single2 + single3), PointF.Empty, PointF.Empty
            };
            this.boundsPoints = tfArray2;
            GraphicsPath path1 = this.gradientpath;

            path1.Reset();
            path1.AddEllipse((float)(single1 - single3), (float)(single2 - single3), (float)(2f * single3), (float)(2f * single3));
            RectangleF ef1 = RectangleF.Empty;
            RectangleF ef2 = PathFunc.GetBounds(path);
            RectangleF ef3 = RectangleF.Empty;

            this.coord.Reset();
            if (flag1)
            {
                ef3 = ((SVG)base.OwnerDocument.DocumentElement).ViewPort;
            }
            else
            {
                ef2 = new RectangleF(0f, 0f, 1f, 1f);
                ef3 = ef2;
                ef1 = PathFunc.GetBounds(path);
                this.coord.Translate(ef1.X, ef1.Y);
                this.coord.Scale(ef1.Width, ef1.Height);
            }
            //if (this.stops.Count==0)return;

            ColorBlend blend1 = new ColorBlend(this.Stops.Count);

            Color[] colorArray1              = new Color[this.Stops.Count];
            float[] singleArray1             = new float[this.Stops.Count];
            SvgElementCollection collection1 = this.Stops;

            for (int num3 = 0; num3 < collection1.Count; num3++)
            {
                GradientStop stop1 = (GradientStop)collection1[num3];
                AnimFunc.CreateAnimateValues(stop1, time, out num1, out num2);
                int num4 = 0xff;
                if ((stop1.Opacity >= 0f) && (stop1.Opacity <= 255f))
                {
                    if (stop1.Opacity <= 1f)
                    {
                        num4 = (int)(stop1.Opacity * 255f);
                    }
                    else
                    {
                        num4 = (int)stop1.Opacity;
                    }
                }
                num4 = (int)Math.Min((float)(opacity * 255f), (float)num4);
                Color color1  = stop1.Color;
                float single6 = Math.Min((float)1f, Math.Max((float)0f, stop1.ColorOffset));
                colorArray1[num3]  = Color.FromArgb(num4, color1.R, color1.G, color1.B);
                singleArray1[num3] = single6;
            }
            float[] singleArray2 = (float[])singleArray1.Clone();
            Color[] colorArray2  = (Color[])colorArray1.Clone();
            Array.Sort(singleArray2, colorArray2);
            Color color2 = colorArray2[0];
            Color color3 = colorArray2[colorArray2.Length - 1];

            if (singleArray2[0] != 0f)
            {
                float[] singleArray3 = (float[])singleArray2.Clone();
                Color[] colorArray3  = (Color[])colorArray2.Clone();
                singleArray2 = new float[singleArray2.Length + 1];
                colorArray2  = new Color[colorArray2.Length + 1];
                colorArray3.CopyTo(colorArray2, 1);
                singleArray3.CopyTo(singleArray2, 1);
                singleArray2[0] = 0f;
                colorArray2[0]  = color2;
            }
            if (singleArray2[singleArray2.Length - 1] != 1f)
            {
                float[] singleArray4 = (float[])singleArray2.Clone();
                Color[] colorArray4  = (Color[])colorArray2.Clone();
                singleArray2 = new float[singleArray2.Length + 1];
                singleArray4.CopyTo(singleArray2, 0);
                singleArray2[singleArray2.Length - 1] = 1f;
                colorArray2 = new Color[colorArray2.Length + 1];
                colorArray4.CopyTo(colorArray2, 0);
                colorArray2[colorArray2.Length - 1] = color3;
            }
            if (methods1 == SpreadMethods.Pad)
            {
                float single7  = Math.Min((float)(single1 - single3), ef2.X);
                float single8  = Math.Min((float)(single2 - single3), ef2.Y);
                float single9  = Math.Max(single3, (float)(ef2.Width / 2f));
                float single10 = this.cx - single3;
                float single11 = this.r;
                for (int num5 = 0; num5 < singleArray2.Length; num5++)
                {
                    singleArray2[num5] = ((single10 + (single11 * singleArray2[num5])) - single7) / single9;
                }
                if (singleArray2[0] != 0f)
                {
                    float[] singleArray5 = (float[])singleArray2.Clone();
                    Color[] colorArray5  = (Color[])colorArray2.Clone();
                    singleArray2 = new float[singleArray2.Length + 1];
                    colorArray2  = new Color[colorArray2.Length + 1];
                    colorArray5.CopyTo(colorArray2, 1);
                    singleArray5.CopyTo(singleArray2, 1);
                    singleArray2[0] = 0f;
                    colorArray2[0]  = color2;
                }
                if (singleArray2[singleArray2.Length - 1] != 1f)
                {
                    float[] singleArray6 = (float[])singleArray2.Clone();
                    Color[] colorArray6  = (Color[])colorArray2.Clone();
                    singleArray2 = new float[singleArray2.Length + 1];
                    singleArray6.CopyTo(singleArray2, 0);
                    singleArray2[singleArray2.Length - 1] = 1f;
                    colorArray2 = new Color[colorArray2.Length + 1];
                    colorArray6.CopyTo(colorArray2, 0);
                    colorArray2[colorArray2.Length - 1] = color3;
                }
            }
            Array.Reverse(colorArray2);
            Array.Reverse(singleArray2);
            for (int num6 = 0; num6 < singleArray2.Length; num6++)
            {
                singleArray2[num6] = 1f - singleArray2[num6];
            }
            Matrix matrix1 = this.Transform.Matrix.Clone();

            path1 = (GraphicsPath)this.gradientpath.Clone();
            path1.Transform(matrix1);
            this.brush       = new PathGradientBrush(path1);
            blend1.Colors    = colorArray2;
            blend1.Positions = singleArray2;
            this.brush.InterpolationColors = blend1;
            if (methods1 == SpreadMethods.Reflect)
            {
                this.brush.WrapMode = WrapMode.Tile;
            }
            else if (methods1 == SpreadMethods.Repeat)
            {
                this.brush.WrapMode = WrapMode.TileFlipXY;
            }
            else
            {
                this.brush.WrapMode = WrapMode.Clamp;
            }
            if (AttributeFunc.FindAttribute("fx", this).ToString() == string.Empty)
            {
                single4 = this.CX;
            }
            if (AttributeFunc.FindAttribute("fy", this).ToString() == string.Empty)
            {
                single5 = this.CY;
            }
            PointF[] tfArray3 = new PointF[1] {
                new PointF(single4, single5)
            };
            PointF[] tfArray1 = tfArray3;
            matrix1.TransformPoints(tfArray1);
            this.brush.CenterPoint = tfArray1[0];
            g.FillPath(new SolidBrush(colorArray2[0]), path);
            GraphicsContainer container1 = g.BeginContainer();

            g.Transform = this.coord;
            Matrix matrix2 = this.coord.Clone();

            matrix2.Invert();
            GraphicsPath path2 = (GraphicsPath)path.Clone();

            path2.Transform(matrix2);
            g.FillPath(this.brush, path2);
            g.EndContainer(container1);
            this.pretime = -1;
        }