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); } else { ValueInSpecifiedUnits = float.Parse(value.Substring(0, unit)); switch (value.Substring(unit).ToLowerInvariant()) { case "%": LengthType = SvgLengthType.Percentage; break; case "ems": LengthType = SvgLengthType.ems; break; case "exs": 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)); } } }
internal SvgLength(float value) { LengthType = SvgLengthType.Number; ValueInSpecifiedUnits = value; _context = SvgLengthContext.Null; }