[NUI] Apply Sp and Dp type converter for text point size.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / XamlBinding / PointSizeTypeConverter.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Linq;
20 using System.Reflection;
21 using System.Globalization;
22
23 using Tizen.NUI;
24 using Tizen.NUI.Xaml;
25 using System.ComponentModel;
26
27 namespace Tizen.NUI.Binding
28 {
29     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
30     [EditorBrowsable(EditorBrowsableState.Never)]
31     [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.PointSizeTypeConverter")]
32     public class PointSizeTypeConverter : TypeConverter
33     {
34         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public override object ConvertFromInvariantString(string value)
37         {
38             if(!string.IsNullOrEmpty(value))
39             {
40                 return (int)GraphicsTypeManager.Instance.Point.ConvertScriptToPoint(value.Trim());
41             }
42
43             throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(int)}");
44         }
45
46         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public override string ConvertToString(object value)
49         {
50             if (value != null)
51             {
52                 int integer = (int)value;
53                 return integer.ToString();
54             }
55             return "";
56         }
57     }
58 }