2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Globalization;
24 /// Default PointTypeConverter class to convert point types.
26 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public sealed class PointTypeConverter : GraphicsTypeConverter
30 private volatile static PointTypeConverter ptTypeConverter;
31 private const ushort pointDpi = 72;
34 /// An unique Singleton Instance of PointTypeConverter.
36 /// <value>Singleton instance of PointTypeConverter</value>
37 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public static PointTypeConverter Instance
43 if (ptTypeConverter == null)
45 ptTypeConverter = new PointTypeConverter();
48 return ptTypeConverter;
53 /// Converts script to pixel.
55 /// <returns>Pixel value that is converted from input string</returns>
56 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public override float ConvertScriptToPixel(string scriptValue)
60 float convertedValue = 0;
61 if (scriptValue != null)
63 if (scriptValue.EndsWith("pt"))
65 convertedValue = ConvertToPixel(float.Parse(scriptValue.Substring(0, scriptValue.LastIndexOf("pt")), CultureInfo.InvariantCulture));
67 else if (scriptValue.EndsWith("px"))
69 convertedValue = float.Parse(scriptValue.Substring(0, scriptValue.LastIndexOf("px")), CultureInfo.InvariantCulture);
73 if (!float.TryParse(scriptValue, NumberStyles.Any, CultureInfo.InvariantCulture, out convertedValue))
75 NUILog.Error("Cannot convert the script {scriptValue}\n");
80 return convertedValue;
84 /// Converts point type to pixel.
86 /// <returns>Pixel value that is converted by the the display matric</returns>
87 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public override float ConvertToPixel(float value)
91 return value * (GraphicsTypeManager.Instance.ScaledDpi / (float)pointDpi);
95 /// Converts pixel to point type.
97 /// <returns>An converted value from pixel</returns>
98 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public override float ConvertFromPixel(float value)
102 return value * ((float)pointDpi / (float)GraphicsTypeManager.Instance.ScaledDpi);
106 /// Converts point type to pixel.
108 /// <returns>Pixel value that is converted by the the display matric</returns>
109 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
110 [EditorBrowsable(EditorBrowsableState.Never)]
111 public float ConvertDpToPoint(float value)
113 return value * ((float)pointDpi / (float)GraphicsTypeManager.Instance.BaselineDpi);
117 /// Converts pixel to point type.
119 /// <returns>An converted value from pixel</returns>
120 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public float ConvertPointToDp(float value)
124 return value * ((float)GraphicsTypeManager.Instance.BaselineDpi / (float)pointDpi);