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
// 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;
 
namespace AntdUI.Svg.DataTypes
{
    internal class SvgPreserveAspectRatioConverter
    {
        public static SvgAspectRatio Parse(string value)
        {
            if (value == null) return new SvgAspectRatio();
            bool bDefer = false, bSlice = false;
            var sParts = value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int nAlignIndex = 0;
            if (sParts[0].Equals("defer"))
            {
                bDefer = true;
                nAlignIndex++;
                if (sParts.Length < 2) throw new ArgumentOutOfRangeException("value is not a member of SvgPreserveAspectRatio");
            }
            var eAlign = (SvgPreserveAspectRatio)Enum.Parse(typeof(SvgPreserveAspectRatio), sParts[nAlignIndex]);
            nAlignIndex++;
            if (sParts.Length > nAlignIndex)
            {
                switch (sParts[nAlignIndex])
                {
                    case "meet":
                        break;
                    case "slice":
                        bSlice = true;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("value is not a member of SvgPreserveAspectRatio");
                }
            }
            nAlignIndex++;
            if (sParts.Length > nAlignIndex) throw new ArgumentOutOfRangeException("value is not a member of SvgPreserveAspectRatio");
            return new SvgAspectRatio(eAlign, bSlice, bDefer);
        }
    }
}