From 3ddcfc7cca479a816b1a6117d5f4cb4b66f727a9 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Tue, 25 Feb 2025 21:02:20 +0900 Subject: [PATCH] [NUI] Minimize system settings API calls in Text 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 --- .../Common/SystemFontSizeChangedManager.cs | 16 +++- .../Common/SystemFontTypeChangedManager.cs | 81 +++++++++++++++++++ .../src/public/BaseComponents/TextEditor.cs | 11 ++- .../src/public/BaseComponents/TextField.cs | 11 ++- .../src/public/BaseComponents/TextLabel.cs | 11 ++- .../src/public/Theme/DefaultThemeCommon.cs | 6 +- 6 files changed, 114 insertions(+), 22 deletions(-) create mode 100644 src/Tizen.NUI/src/internal/Common/SystemFontTypeChangedManager.cs diff --git a/src/Tizen.NUI/src/internal/Common/SystemFontSizeChangedManager.cs b/src/Tizen.NUI/src/internal/Common/SystemFontSizeChangedManager.cs index 52db736477a..59b0564af7b 100644 --- a/src/Tizen.NUI/src/internal/Common/SystemFontSizeChangedManager.cs +++ b/src/Tizen.NUI/src/internal/Common/SystemFontSizeChangedManager.cs @@ -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 @@ public static void Remove(EventHandler handler) 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> proxy = new WeakEvent>(); } } \ 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 index 00000000000..40e8eddf159 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Common/SystemFontTypeChangedManager.cs @@ -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 +{ + /// + /// 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. + /// + internal static class SystemFontTypeChangedManager + { + static SystemFontTypeChangedManager() + { + SystemSettings.FontTypeChanged += SystemFontTypeChanged; + } + + /// + /// The handler invoked last after all handlers added to the SystemSettings.FontTypeChanged event are invoked. + /// + public static event EventHandler Finished; + + /// + /// Adds the given handler to the SystemSettings.FontTypeChanged event. + /// + /// A handler to be added to the event + public static void Add(EventHandler handler) + { + proxy.Add(handler); + } + + /// + /// Removes the given handler from the SystemSettings.FontTypeChanged event. + /// + /// A handler to be added to the event + public static void Remove(EventHandler 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> proxy = new WeakEvent>(); + } +} \ No newline at end of file diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs index 286d78b5e00..05042937c71 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs @@ -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. @@ -34,7 +34,6 @@ public partial class TextEditor : View { static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextEditor"; 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; @@ -486,7 +485,7 @@ private string InternalFontFamily { try { - newFontFamily = SystemSettings.FontType; + newFontFamily = SystemFontTypeChangedManager.FontType; } catch (Exception e) { @@ -3424,7 +3423,7 @@ private float InternalFontSizeScale try { - systemSettingsFontSize = SystemSettings.FontSize; + systemSettingsFontSize = SystemFontSizeChangedManager.FontSize; } catch (Exception e) { @@ -3978,7 +3977,7 @@ private void AddSystemSettingsFontTypeChanged() { try { - systemFontTypeChanged.Add(SystemSettingsFontTypeChanged); + SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged); hasSystemFontTypeChanged = true; } catch (Exception e) @@ -3995,7 +3994,7 @@ private void RemoveSystemSettingsFontTypeChanged() { try { - systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged); + SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged); hasSystemFontTypeChanged = false; } catch (Exception e) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs index f701b5fdbcd..77085849761 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextField.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextField.cs @@ -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 @@ public partial class TextField : View { static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextField"; 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; @@ -636,7 +635,7 @@ private string InternalFontFamily { try { - newFontFamily = SystemSettings.FontType; + newFontFamily = SystemFontTypeChangedManager.FontType; } catch (Exception e) { @@ -3602,7 +3601,7 @@ private float InternalFontSizeScale try { - systemSettingsFontSize = SystemSettings.FontSize; + systemSettingsFontSize = SystemFontSizeChangedManager.FontSize; } catch (Exception e) { @@ -3975,7 +3974,7 @@ private void AddSystemSettingsFontTypeChanged() { try { - systemFontTypeChanged.Add(SystemSettingsFontTypeChanged); + SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged); hasSystemFontTypeChanged = true; } catch (Exception e) @@ -3992,7 +3991,7 @@ private void RemoveSystemSettingsFontTypeChanged() { try { - systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged); + SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged); hasSystemFontTypeChanged = false; } catch (Exception e) diff --git a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs index d1e033ecd49..4b47a50417e 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs @@ -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. @@ -228,7 +228,6 @@ static TextLabel() // Do nothing. Just call for load static values. } - private static SystemFontTypeChanged systemFontTypeChanged = new SystemFontTypeChanged(); private static SystemLocaleLanguageChanged systemLocaleLanguageChanged = new SystemLocaleLanguageChanged(); static private string defaultStyleName = "Tizen.NUI.BaseComponents.TextLabel"; static private string defaultFontFamily = "BreezeSans"; @@ -555,7 +554,7 @@ private string InternalFontFamily { try { - newFontFamily = SystemSettings.FontType; + newFontFamily = SystemFontTypeChangedManager.FontType; } catch (Exception e) { @@ -2560,7 +2559,7 @@ private float InternalFontSizeScale try { - systemSettingsFontSize = SystemSettings.FontSize; + systemSettingsFontSize = SystemFontSizeChangedManager.FontSize; } catch (Exception e) { @@ -2908,7 +2907,7 @@ private void AddSystemSettingsFontTypeChanged() { try { - systemFontTypeChanged.Add(SystemSettingsFontTypeChanged); + SystemFontTypeChangedManager.Add(SystemSettingsFontTypeChanged); hasSystemFontTypeChanged = true; } catch (Exception e) @@ -2925,7 +2924,7 @@ private void RemoveSystemSettingsFontTypeChanged() { try { - systemFontTypeChanged.Remove(SystemSettingsFontTypeChanged); + SystemFontTypeChangedManager.Remove(SystemSettingsFontTypeChanged); hasSystemFontTypeChanged = false; } catch (Exception e) diff --git a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs index a86785cc9aa..1966578be55 100644 --- a/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs +++ b/src/Tizen.NUI/src/public/Theme/DefaultThemeCommon.cs @@ -37,7 +37,7 @@ public Theme Create() // 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", "regular"), @@ -52,7 +52,7 @@ public Theme Create() // 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 @@ public Theme Create() // 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),