Exemple #1
0
        internal SvgLength(string value, SvgLengthContext context)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentNullException(nameof(value));
            }
            _context = context ?? throw new ArgumentNullException(nameof(context));
            value    = value.Trim();
            var unit = value.IndexOfAny(new[] { '%', 'e', 'p', 'c', 'm', 'i' });

            if (unit < 0)
            {
                LengthType            = SvgLengthType.Number;
                ValueInSpecifiedUnits = float.Parse(value, CultureInfo.InvariantCulture);
            }
            else
            {
                ValueInSpecifiedUnits = float.Parse(value.Substring(0, unit), CultureInfo.InvariantCulture);
                switch (value.Substring(unit).ToLowerInvariant())
                {
                case "%":
                    LengthType = SvgLengthType.Percentage;
                    break;

                case "em":
                    LengthType = SvgLengthType.ems;
                    break;

                case "ex":
                    LengthType = SvgLengthType.exs;
                    break;

                case "px":
                    LengthType = SvgLengthType.px;
                    break;

                case "cm":
                    LengthType = SvgLengthType.cm;
                    break;

                case "mm":
                    LengthType = SvgLengthType.mm;
                    break;

                case "in":
                    LengthType = SvgLengthType.@in;
                    break;

                case "pt":
                    LengthType = SvgLengthType.pt;
                    break;

                case "pc":
                    LengthType = SvgLengthType.pc;
                    break;

                default:
                    throw new ArgumentException($"Invalid unit specified on length '{value}'", nameof(value));
                }
            }
        }
Exemple #2
0
 internal SvgLength(float value)
 {
     LengthType            = SvgLengthType.Number;
     ValueInSpecifiedUnits = value;
     _context = SvgLengthContext.Null;
 }