tangxu
2024-10-24 3024f6d3d1618d8e90082f5aec0cc1bb6fabeea6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// THIS FILE IS PART OF SVG PROJECT
// THE SVG PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MS-PL License.
// COPYRIGHT (C) svg-net. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/svg-net/SVG
 
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace AntdUI.Svg
{
    /// <summary>
    /// Represents a list of <see cref="SvgUnit"/>.
    /// </summary>
    public class SvgUnitCollection : List<SvgUnit>
    {
        public override string ToString()
        {
            // The correct separator should be a single white space.
            // More see:
            // http://www.w3.org/TR/SVG/coords.html
            // "Superfluous white space and separators such as commas can be eliminated
            // (e.g., 'M 100 100 L 200 200' contains unnecessary spaces and could be expressed more compactly as 'M100 100L200 200')."
            // http://www.w3.org/TR/SVGTiny12/paths.html#PathDataGeneralInformation
            // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#Notes
            return string.Join(" ", this.Select(u => u.ToString()).ToArray());
        }
 
        public static bool IsNullOrEmpty(SvgUnitCollection collection)
        {
            return collection == null || collection.Count < 1 ||
                (collection.Count == 1 && (collection[0] == SvgUnit.Empty || collection[0] == SvgUnit.None));
        }
    }
 
    internal class SvgUnitCollectionConverter
    {
        public static SvgUnitCollection Parse(string value)
        {
            if (string.Compare((value).Trim(), "none", StringComparison.InvariantCultureIgnoreCase) == 0) return null;
            string[] points = (value).Trim().Split(new char[] { ',', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            var units = new SvgUnitCollection();
            foreach (string point in points)
            {
                var newUnit = SvgUnitConverter.Parse(point.Trim());
                if (!newUnit.IsNone) units.Add(newUnit);
            }
            return units;
        }
    }
}