[NUI] Minimize system settings API calls in Text
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 25 Feb 2025 12:02:20 +0000 (21:02 +0900)
committerBowon Ryu <wonrst22@naver.com>
Wed, 26 Feb 2025 01:42:04 +0000 (10:42 +0900)
Each text component's call to the system API takes a lot of time.
Especially for FontType, initialization of FontConfig occurs natively and consumes most of the time.

This patch updates through static classes only when a specific value is needed.

TODO: manager should handle all events.

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/internal/Common/SystemFontSizeChangedManager.cs
src/Tizen.NUI/src/internal/Common/SystemFontTypeChangedManager.cs [new file with mode: 0644]
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs

index 52db736477a910d90906de7634072e515e59e6fa..59b0564af7b11250111354f282dbf8ced6cd6b40 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -58,10 +58,24 @@ namespace Tizen.NUI
 
         private static void SystemFontSizeChanged(object sender, FontSizeChangedEventArgs args)
         {
+            fontSize = args.Value;
             proxy.Invoke(sender, args);
             Finished?.Invoke(sender, args);
         }
 
+        public static SystemSettingsFontSize FontSize
+        {
+            get
+            {
+                if (fontSize == null)
+                {
+                    fontSize = SystemSettings.FontSize;
+                }
+                return fontSize ?? SystemSettingsFontSize.Normal;
+            }
+        }
+
+        private static SystemSettingsFontSize? fontSize = null;
         private static WeakEvent<EventHandler<FontSizeChangedEventArgs>> proxy = new WeakEvent<EventHandler<FontSizeChangedEventArgs>>();
     }
 }
\ No newline at end of file
diff --git a/src/Tizen.NUI/src/internal/Common/SystemFontTypeChangedManager.cs b/src/Tizen.NUI/src/internal/Common/SystemFontTypeChangedManager.cs
new file mode 100644 (file)
index 0000000..40e8edd
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2025 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.
+ *
+ */
+
+extern alias TizenSystemSettings;
+using TizenSystemSettings.Tizen.System;
+
+using System;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// A static class which adds user handler to the SystemSettings.FontTypeChanged event.
+    /// This class also adds user handler to the last of the SystemSettings.FontTypeChanged event.
+    /// </summary>
+    internal static class SystemFontTypeChangedManager
+    {
+        static SystemFontTypeChangedManager()
+        {
+            SystemSettings.FontTypeChanged += SystemFontTypeChanged;
+        }
+
+        /// <summary>
+        /// The handler invoked last after all handlers added to the SystemSettings.FontTypeChanged event are invoked.
+        /// </summary>
+        public static event EventHandler<FontTypeChangedEventArgs> Finished;
+
+        /// <summary>
+        /// Adds the given handler to the SystemSettings.FontTypeChanged event.
+        /// </summary>
+        /// <param name="handler">A handler to be added to the event</param>
+        public static void Add(EventHandler<FontTypeChangedEventArgs> handler)
+        {
+            proxy.Add(handler);
+        }
+
+        /// <summary>
+        /// Removes the given handler from the SystemSettings.FontTypeChanged event.
+        /// </summary>
+        /// <param name="handler">A handler to be added to the event</param>
+        public static void Remove(EventHandler<FontTypeChangedEventArgs> handler)
+        {
+            proxy.Remove(handler);
+        }
+
+        private static void SystemFontTypeChanged(object sender, FontTypeChangedEventArgs args)
+        {
+            fontType = args.Value;
+            proxy.Invoke(sender, args);
+            Finished?.Invoke(sender, args);
+        }
+
+        public static string FontType
+        {
+            get
+            {
+                if (string.IsNullOrEmpty(fontType))
+                {
+                    fontType = SystemSettings.FontType;
+                }
+                return fontType;
+            }
+        }
+
+        private static string fontType = string.Empty;
+        private static WeakEvent<EventHandler<FontTypeChangedEventArgs>> proxy = new WeakEvent<EventHandler<FontTypeChangedEventArgs>>();
+    }
+}
\ No newline at end of file
index d190f45c9120b66c9bb13d7917e5f8b1b1ad30c9..35518e7a3df1c8e236f083c25deffde44907d904 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2025 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.
@@ -33,7 +33,6 @@ namespace Tizen.NUI.BaseComponents
     public partial class TextEditor : View
     {
         static private string defaultFontFamily = "TizenSans";
-        private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
         private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
         private string textEditorTextSid = null;
         private string textEditorPlaceHolderTextSid = null;
@@ -258,7 +257,7 @@ namespace Tizen.NUI.BaseComponents
                 {
                     try
                     {
-                        newFontFamily = SystemSettings.FontType;
+                        newFontFamily = SystemFontTypeChangedManager.FontType;
                     }
                     catch (Exception e)
                     {
@@ -2256,7 +2255,7 @@ namespace Tizen.NUI.BaseComponents
 
                     try
                     {
-                        systemSettingsFontSize = SystemSettings.FontSize;
+                        systemSettingsFontSize = SystemFontSizeChangedManager.FontSize;
                     }
                     catch (Exception e)
                     {
@@ -2657,7 +2656,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 try
                 {
-                    systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
+                    SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged);
                     hasSystemFontTypeChanged = true;
                 }
                 catch (Exception e)
@@ -2674,7 +2673,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 try
                 {
-                    systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
+                    SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged);
                     hasSystemFontTypeChanged = false;
                 }
                 catch (Exception e)
index c4a93b1fa1db410c91387a62c8ae565b6af72734..05e51fe27472a03375a36a0cf6acad42a411c7ad 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2025 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.
@@ -32,7 +32,6 @@ namespace Tizen.NUI.BaseComponents
     public partial class TextField : View
     {
         static private string defaultFontFamily = "TizenSans";
-        private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
         private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
         private string textFieldTextSid = null;
         private string textFieldPlaceHolderTextSid = null;
@@ -326,7 +325,7 @@ namespace Tizen.NUI.BaseComponents
                 {
                     try
                     {
-                        newFontFamily = SystemSettings.FontType;
+                        newFontFamily = SystemFontTypeChangedManager.FontType;
                     }
                     catch (Exception e)
                     {
@@ -2375,7 +2374,7 @@ namespace Tizen.NUI.BaseComponents
 
                     try
                     {
-                        systemSettingsFontSize = SystemSettings.FontSize;
+                        systemSettingsFontSize = SystemFontSizeChangedManager.FontSize;
                     }
                     catch (Exception e)
                     {
@@ -2667,7 +2666,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 try
                 {
-                    systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
+                    SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged);
                     hasSystemFontTypeChanged = true;
                 }
                 catch (Exception e)
@@ -2684,7 +2683,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 try
                 {
-                    systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
+                    SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged);
                     hasSystemFontTypeChanged = false;
                 }
                 catch (Exception e)
index ccbb4b68227f2df64851846c668f6265e6779f1d..84dea698e9ae42604eb6b45f19d2ccc180f97f13 100755 (executable)
@@ -81,7 +81,6 @@ namespace Tizen.NUI.BaseComponents
 
         static TextLabel() { }
 
-        private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged();
         private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged();
         static private string defaultFontFamily = "BreezeSans";
         private string textLabelSid = null;
@@ -285,7 +284,7 @@ namespace Tizen.NUI.BaseComponents
                 {
                     try
                     {
-                        newFontFamily = SystemSettings.FontType;
+                        newFontFamily = SystemFontTypeChangedManager.FontType;
                     }
                     catch (Exception e)
                     {
@@ -1537,7 +1536,7 @@ namespace Tizen.NUI.BaseComponents
 
                     try
                     {
-                        systemSettingsFontSize = SystemSettings.FontSize;
+                        systemSettingsFontSize = SystemFontSizeChangedManager.FontSize;
                     }
                     catch (Exception e)
                     {
@@ -1732,7 +1731,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 try
                 {
-                    systemFontTypeChanged.Add(SystemSettingsFontTypeChanged);
+                    SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged);
                     hasSystemFontTypeChanged = true;
                 }
                 catch (Exception e)
@@ -1749,7 +1748,7 @@ namespace Tizen.NUI.BaseComponents
             {
                 try
                 {
-                    systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged);
+                    SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged);
                     hasSystemFontTypeChanged = false;
                 }
                 catch (Exception e)
index b88af1f8487a6c194b9a1983db43aa43e9c07307..bf199be58378377905e27733a2b585c5c2e4cbd5 100644 (file)
@@ -37,7 +37,7 @@ namespace Tizen.NUI
             // TextLabel style.
             theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextLabel", new TextLabelStyle()
             {
-                FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
+                FontFamily = "BreezeSans",
                 PixelSize = 24,
                 TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
                 FontStyle = new PropertyMap().Add("weight", new PropertyValue("regular")),
@@ -52,7 +52,7 @@ namespace Tizen.NUI
             // TextField style.
             theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextField", new TextFieldStyle()
             {
-                FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
+                FontFamily = "BreezeSans",
                 PixelSize = 24,
                 TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
                 PlaceholderTextColor = new Vector4(0.79f, 0.79f, 0.79f, 1),
@@ -89,7 +89,7 @@ namespace Tizen.NUI
             // TextEditor style.
             theme.AddStyleWithoutClone("Tizen.NUI.BaseComponents.TextEditor", new TextEditorStyle()
             {
-                FontFamily = Tizen.NUI.FontFamily.UseSystemSetting,
+                FontFamily = "BreezeSans",
                 PixelSize = 24,
                 TextColor = new Color(0.04f, 0.05f, 0.13f, 1),
                 PlaceholderTextColor = new Color(0.79f, 0.79f, 0.79f, 1),