[NUI] Add FontPreLoad API to FontClient
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 9 May 2023 11:07:39 +0000 (20:07 +0900)
committerBowon Ryu <wonrst22@naver.com>
Fri, 12 May 2023 08:05:34 +0000 (17:05 +0900)
This patch adds a new FontPreLoad API that preloads font faces.
this can prevents delays on main thread during the inital call of FT_New_Face.

using memoryFontPathList involves loading font buffers into memory.
And using FT_New_Memory_Face at runtime, which uses more memory
but can lead to greater performance improvements.

Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
src/Tizen.NUI/src/internal/Interop/Interop.FontClient.cs
src/Tizen.NUI/src/public/Utility/FontClient.cs

index 7479dc1..279ff95 100755 (executable)
@@ -25,6 +25,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FontClient_PreCache")]
             public static extern void PreCache(string[] fallbackFamilyArray, int fallbackFamilySize, string[] extraFamilyArray, int extraFamilySize, string localeFamily, bool useThread);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FontClient_FontPreLoad")]
+            public static extern void FontPreLoad(string[] fontPathArray, int fontPathSize, string[] memoryFontPathArray, int memoryFontPathSize, bool useThread);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_FontClient_DEFAULT_POINT_SIZE_get")]
             public static extern uint DefaultPointSizeGet();
 
index 476c321..2f77e04 100755 (executable)
@@ -66,7 +66,7 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// This is used to pre-cache fonts in order to improve the runtime performance of the application.
+        /// This is used to pre-cache FontConfig in order to improve the runtime performance of the application.
         /// </summary>
         /// <param name="fallbackFamilyList">A list of fallback font families to be pre-cached.</param>
         /// <param name="extraFamilyList">A list of additional font families to be pre-cached.</param>
@@ -85,6 +85,30 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
+        /// <note>
+        /// The fonts in the fontPathList perform FT_New_Face during pre-loading, which can provide some performace benefits.<br />
+        /// The fonts in the memoryFontPathList read the font file and cache the buffer in memory during pre-load.<br />
+        /// This enables the use of FT_New_Memory_Face during runtime and provides a performance boost.<br />
+        /// It requires memory equivalent to the size of each font file.
+        /// </note>
+        /// </summary>
+        /// <param name="fontPathList">A list of font paths to be pre-loaded.</param>
+        /// <param name="memoryFontPathList">A list of memory font paths to be pre-loaded.</param>
+        /// <param name="useThread">if the font client should create thread and perform font pre-loading, false otherwise.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void FontPreLoad(List<string> fontPathList, List<string> memoryFontPathList, bool useThread)
+        {
+            int fontPathSize = fontPathList?.Count ?? 0;
+            int memoryFontPathSize = memoryFontPathList?.Count ?? 0;
+            string[] fontPathArray = fontPathSize > 0 ? fontPathList.ToArray() : null;
+            string[] memoryFontPathArray = memoryFontPathSize > 0 ? memoryFontPathList.ToArray() : null;
+
+            Interop.FontClient.FontPreLoad(fontPathArray, fontPathSize, memoryFontPathArray, memoryFontPathSize, useThread);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// Called when the user changes the system defaults.
         /// </summary>
         /// <since_tizen> 5 </since_tizen>