using System.Globalization;
using System.ComponentModel;
using Tizen.NUI.Text;
+using Tizen.NUI.Binding;
namespace Tizen.NUI.BaseComponents
{
/// The size of font in points.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
public float PointSize
{
get
/// The font's size of the new input text in points.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
public float InputPointSize
{
get
/// The size of font in points.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
public float PointSize
{
get
/// The font's size of the new input text in points.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
public float InputPointSize
{
get
using System.Globalization;
using System.ComponentModel;
using Tizen.NUI.Text;
+using Tizen.NUI.Binding;
namespace Tizen.NUI.BaseComponents
{
/// The size of font in points.<br />
/// </summary>
/// <since_tizen> 3 </since_tizen>
+ [Binding.TypeConverter(typeof(PointSizeTypeConverter))]
public float PointSize
{
get
-using System.ComponentModel;
+/*
+ * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System.ComponentModel;
namespace Tizen.NUI
{
{
return GraphicsTypeManager.Instance.Point.ConvertPointToDp(pt);
}
+
+ /// <summary>
+ /// Converter float font sp size to point size.
+ /// </summary>
+ /// <param name="sp">The float sp unit value to be converted point unit.</param>
+ /// <returns>The float point unit value.</returns>
+ /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static float SpToPt(this float sp)
+ {
+ return GraphicsTypeManager.Instance.Point.ConvertSpToPoint(sp);
+ }
+
+ /// <summary>
+ /// Converter float font point size to sp size.
+ /// </summary>
+ /// <param name="pt">The float point unit value to be converted sp unit.</param>
+ /// <returns>The float dp unit value.</returns>
+ /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static float PtToSp(this float pt)
+ {
+ return GraphicsTypeManager.Instance.Point.ConvertPointToSp(pt);
+ }
}
}
}
/// <summary>
+ /// Converts script to pixel.
+ /// </summary>
+ /// <returns>Pixel value that is converted from input string</returns>
+ /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public float ConvertScriptToPoint(string scriptValue)
+ {
+ float convertedValue = 0;
+ if (scriptValue != null)
+ {
+ if (scriptValue.EndsWith("sp"))
+ {
+ convertedValue = ConvertSpToPoint(float.Parse(scriptValue.Substring(0, scriptValue.LastIndexOf("sp")), CultureInfo.InvariantCulture));
+ }
+ else if (scriptValue.EndsWith("dp"))
+ {
+ convertedValue = ConvertDpToPoint(float.Parse(scriptValue.Substring(0, scriptValue.LastIndexOf("dp")), CultureInfo.InvariantCulture));
+ }
+ else if (scriptValue.EndsWith("pt"))
+ {
+ convertedValue = float.Parse(scriptValue.Substring(0, scriptValue.LastIndexOf("px")), CultureInfo.InvariantCulture);
+ }
+ else
+ {
+ if (!float.TryParse(scriptValue, NumberStyles.Any, CultureInfo.InvariantCulture, out convertedValue))
+ {
+ NUILog.Error("Cannot convert the script {scriptValue}\n");
+ convertedValue = 0;
+ }
+ }
+ }
+ return convertedValue;
+ }
+
+ /// <summary>
/// Converts point type to pixel.
/// </summary>
/// <returns>Pixel value that is converted by the the display matric</returns>
}
/// <summary>
- /// Converts point type to pixel.
+ /// Converts dp type to point type.
/// </summary>
- /// <returns>Pixel value that is converted by the the display matric</returns>
+ /// <returns>Point value that is converted from dp.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public float ConvertDpToPoint(float value)
}
/// <summary>
- /// Converts pixel to point type.
+ /// Converts point type to dp type.
/// </summary>
- /// <returns>An converted value from pixel</returns>
+ /// <returns>Dp value that is converted from point.</returns>
/// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
[EditorBrowsable(EditorBrowsableState.Never)]
public float ConvertPointToDp(float value)
{
return value * ((float)GraphicsTypeManager.Instance.BaselineDpi / (float)pointDpi);
}
+
+ /// <summary>
+ /// Converts sp type to point type.
+ /// </summary>
+ /// <returns>Point value that is converted from dp.</returns>
+ /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public float ConvertSpToPoint(float value)
+ {
+ float scale = GraphicsTypeManager.Instance.ScalingFactor;
+ if (scale <= 0) scale = 1;
+ return value * ((float)pointDpi / (float)GraphicsTypeManager.Instance.BaselineDpi) * scale;
+ }
+
+ /// <summary>
+ /// Converts point type to sp type.
+ /// </summary>
+ /// <returns>Sp value that is converted from point.</returns>
+ /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public float ConvertPointToSp(float value)
+ {
+ float scale = GraphicsTypeManager.Instance.ScalingFactor;
+ if (scale <= 0) scale = 1;
+ return value * ((float)GraphicsTypeManager.Instance.BaselineDpi / (float)pointDpi) / scale;
+ }
}
}
--- /dev/null
+/*
+ * Copyright(c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.Linq;
+using System.Reflection;
+using System.Globalization;
+
+using Tizen.NUI;
+using Tizen.NUI.Xaml;
+using System.ComponentModel;
+
+namespace Tizen.NUI.Binding
+{
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [ProvideCompiledAttribute("Tizen.NUI.Xaml.Core.XamlC.PointSizeTypeConverter")]
+ public class PointSizeTypeConverter : TypeConverter
+ {
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override object ConvertFromInvariantString(string value)
+ {
+ if(!string.IsNullOrEmpty(value))
+ {
+ return (int)GraphicsTypeManager.Instance.Point.ConvertScriptToPoint(value.Trim());
+ }
+
+ throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(int)}");
+ }
+
+ /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override string ConvertToString(object value)
+ {
+ if (value != null)
+ {
+ int integer = (int)value;
+ return integer.ToString();
+ }
+ return "";
+ }
+ }
+}