From fb8ab87d972ff22c38ef0210be3c63c3b49bb35c Mon Sep 17 00:00:00 2001 From: SangHyeon Jade Lee Date: Mon, 27 Sep 2021 13:59:05 +0900 Subject: [PATCH] [NUI] Apply dp converting in xaml float, int, extents, rectangles (#3590) * [NUI] Apply dp converting in xaml float, int, extents, rectangles * [NUI] refactoring converters. * [NUI] use Convert.To intead of implicit type converting * [NUI] fix wrong extent array sequence Co-authored-by: hosangKim --- .../src/internal/Xaml/CreateValuesVisitor.cs | 32 ++++++---------------- .../src/internal/Xaml/TypeConversionExtensions.cs | 32 ++++++++++++++++------ .../internal/XamlBinding/ExtentsTypeConverter.cs | 8 +++--- .../internal/XamlBinding/RectangleTypeConverter.cs | 9 ++++-- 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs index ed6bf55..d9f70ae 100755 --- a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs +++ b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs @@ -448,21 +448,15 @@ namespace Tizen.NUI.Xaml } if (nodeType == typeof(Int16)) { - short retval; - if (short.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToInt16(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(Int32)) { - int retval; - if (int.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToInt32(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(Int64)) { - long retval; - if (long.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToInt64(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(Byte)) { @@ -472,33 +466,23 @@ namespace Tizen.NUI.Xaml } if (nodeType == typeof(UInt16)) { - ushort retval; - if (ushort.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToUInt16(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(UInt32)) { - uint retval; - if (uint.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToUInt32(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(UInt64)) { - ulong retval; - if (ulong.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToUInt64(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(Single)) { - float retval; - if (float.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring); } if (nodeType == typeof(Double)) { - double retval; - if (double.TryParse(valuestring, NumberStyles.Number, CultureInfo.InvariantCulture, out retval)) - return retval; + return Convert.ToDouble(GraphicsTypeManager.Instance.ConvertScriptToPixel(valuestring)); } if (nodeType == typeof(Boolean)) { diff --git a/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs b/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs index b0e25a5..2372031 100755 --- a/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs +++ b/src/Tizen.NUI/src/internal/Xaml/TypeConversionExtensions.cs @@ -196,23 +196,39 @@ namespace Tizen.NUI.Xaml if (toType == typeof(SByte)) return SByte.Parse(str, CultureInfo.InvariantCulture); if (toType == typeof(Int16)) - return Int16.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToInt16(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(Int32)) - return Int32.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToInt32(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(Int64)) - return Int64.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToInt64(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(Byte)) return Byte.Parse(str, CultureInfo.InvariantCulture); if (toType == typeof(UInt16)) - return UInt16.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToUInt16(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(UInt32)) - return UInt32.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToUInt32(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(UInt64)) - return UInt64.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToUInt64(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(Single)) - return Single.Parse(str, CultureInfo.InvariantCulture); + { + return GraphicsTypeManager.Instance.ConvertScriptToPixel(str); + } if (toType == typeof(Double)) - return Double.Parse(str, CultureInfo.InvariantCulture); + { + return Convert.ToDouble(GraphicsTypeManager.Instance.ConvertScriptToPixel(str)); + } if (toType == typeof(Boolean)) return Boolean.Parse(str); if (toType == typeof(TimeSpan)) diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ExtentsTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/ExtentsTypeConverter.cs index 85fb48b..97673c9 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/ExtentsTypeConverter.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/ExtentsTypeConverter.cs @@ -32,10 +32,10 @@ namespace Tizen.NUI.Binding string[] parts = value.Split(','); if (parts.Length == 4) { - return new Extents(ushort.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), - ushort.Parse(parts[1].Trim(), CultureInfo.InvariantCulture), - ushort.Parse(parts[2].Trim(), CultureInfo.InvariantCulture), - ushort.Parse(parts[3].Trim(), CultureInfo.InvariantCulture)); + return new Extents((ushort)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[0].Trim()), + (ushort)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[1].Trim()), + (ushort)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[2].Trim()), + (ushort)GraphicsTypeManager.Instance.ConvertScriptToPixel(parts[3].Trim())); } else if (parts.Length == 1) { diff --git a/src/Tizen.NUI/src/internal/XamlBinding/RectangleTypeConverter.cs b/src/Tizen.NUI/src/internal/XamlBinding/RectangleTypeConverter.cs index 51f665c..8162506 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/RectangleTypeConverter.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/RectangleTypeConverter.cs @@ -37,9 +37,14 @@ namespace Tizen.NUI.Binding { double x, y, w, h; string[] xywh = value.Split(','); - if (xywh.Length == 4 && double.TryParse(xywh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) && double.TryParse(xywh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y) && - double.TryParse(xywh[2], NumberStyles.Number, CultureInfo.InvariantCulture, out w) && double.TryParse(xywh[3], NumberStyles.Number, CultureInfo.InvariantCulture, out h)) + if (xywh.Length == 4) + { + x = GraphicsTypeManager.Instance.ConvertScriptToPixel(xywh[0]); + y = GraphicsTypeManager.Instance.ConvertScriptToPixel(xywh[1]); + w = GraphicsTypeManager.Instance.ConvertScriptToPixel(xywh[2]); + h = GraphicsTypeManager.Instance.ConvertScriptToPixel(xywh[3]); return new Rectangle((int)x, (int)y, (int)w, (int)h); + } } throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Rectangle))); -- 2.7.4