Пример #1
0
        public static double[] ParseDoubles(string str)
        {
            List <double> valueList = new List <double>();

            foreach (Match m in DoubleRegex.Matches(str))
            {
                if (!string.IsNullOrEmpty(m.Value))
                {
                    valueList.Add(SvgNumber.ParseDouble(m.Value));
                }
            }
            return(valueList.ToArray());
        }
Пример #2
0
        public SvgTransform(string str)
        {
            int    start      = str.IndexOf("(", StringComparison.OrdinalIgnoreCase);
            string type       = str.Substring(0, start);
            string valuesList = (str.Substring(start + 1, str.Length - start - 2)).Trim();           //JR added trim
            Regex  re         = new Regex("[\\s\\,]+");

            valuesList = re.Replace(valuesList, ",");

            string[] valuesStr = valuesList.Split(new char[] { ',' });
            int      len       = valuesStr.GetLength(0);

            double[] values = new double[len];

            try
            {
                for (int i = 0; i < len; i++)
                {
                    values[i] = SvgNumber.Parse(valuesStr[i]);
                }
            }
            catch
            {
                List <double> valueList = new List <double>();
                foreach (Match m in SvgNumber.DoubleRegex.Matches(str))
                {
                    if (!string.IsNullOrEmpty(m.Value))
                    {
                        valueList.Add(SvgNumber.ParseDouble(m.Value));
                    }
                }

                values = valueList.ToArray();
                len    = values.Length;
            }

            _values = values;

            switch (type.Trim())
            {
            case "translate":
                switch (len)
                {
                case 1:
                    SetTranslate(values[0], 0);
                    break;

                case 2:
                    SetTranslate(values[0], values[1]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in translate transform");
                }
                break;

            case "rotate":
                switch (len)
                {
                case 1:
                    SetRotate(values[0]);
                    break;

                case 3:
                    SetRotate(values[0], values[1], values[2]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in rotate transform");
                }
                break;

            case "scale":
                switch (len)
                {
                case 1:
                    SetScale(values[0], values[0]);
                    break;

                case 2:
                    SetScale(values[0], values[1]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in scale transform");
                }
                break;

            case "skewX":
                if (len != 1)
                {
                    throw new ApplicationException("Wrong number of arguments in skewX transform");
                }
                SetSkewX(values[0]);
                break;

            case "skewY":
                if (len != 1)
                {
                    throw new ApplicationException("Wrong number of arguments in skewY transform");
                }
                SetSkewY(values[0]);
                break;

            case "matrix":
                if (len != 6)
                {
                    throw new ApplicationException("Wrong number of arguments in matrix transform");
                }
                SetMatrix(new SvgMatrix(values[0], values[1], values[2], values[3], values[4], values[5]));
                break;

            default:
                _type = SvgTransformType.Unknown;
                break;
            }
        }