Ejemplo 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);
        }