Ensure join of font thread
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / text-abstraction / font-client.h
index e77b53f..ffe3f3b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_PLATFORM_TEXT_ABSTRACTION_FONT_CLIENT_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/text-abstraction/font-list.h>
+#include <dali/devel-api/text-abstraction/glyph-buffer-data.h>
 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/dali-adaptor-common.h>
@@ -64,48 +65,19 @@ public:
   static const PointSize26Dot6 DEFAULT_POINT_SIZE;   ///< The default point size.
   static const float           DEFAULT_ITALIC_ANGLE; ///< The default software italic angle in radians.
 
-  static const bool            DEFAULT_ATLAS_LIMITATION_ENABLED;  ///< The default behavior of whether atlas limitation is enabled in dali.
-  static const uint32_t        DEFAULT_TEXT_ATLAS_WIDTH;          ///< The default width of text-atlas-block.
-  static const uint32_t        DEFAULT_TEXT_ATLAS_HEIGHT;         ///< The default height of text-atlas-block.
-  static const Size            DEFAULT_TEXT_ATLAS_SIZE;           ///< The default size(width, height) of text-atlas-block.
+  static const bool     DEFAULT_ATLAS_LIMITATION_ENABLED; ///< The default behavior of whether atlas limitation is enabled in dali.
+  static const uint32_t DEFAULT_TEXT_ATLAS_WIDTH;         ///< The default width of text-atlas-block.
+  static const uint32_t DEFAULT_TEXT_ATLAS_HEIGHT;        ///< The default height of text-atlas-block.
+  static const Size     DEFAULT_TEXT_ATLAS_SIZE;          ///< The default size(width, height) of text-atlas-block.
 
-  static const uint32_t        MAX_TEXT_ATLAS_WIDTH;             ///< The maximum width of text-atlas-block.
-  static const uint32_t        MAX_TEXT_ATLAS_HEIGHT;            ///< The maximum height of text-atlas-block.
-  static const Size            MAX_TEXT_ATLAS_SIZE;              ///< The maximum height of text-atlas-block.
+  static const uint32_t MAX_TEXT_ATLAS_WIDTH;  ///< The maximum width of text-atlas-block.
+  static const uint32_t MAX_TEXT_ATLAS_HEIGHT; ///< The maximum height of text-atlas-block.
+  static const Size     MAX_TEXT_ATLAS_SIZE;   ///< The maximum height of text-atlas-block.
 
-  static const uint16_t        PADDING_TEXT_ATLAS_BLOCK ;        ///< Padding per edge. How much the block size (width, height) less than the text-atlas-block size (width, height).
-  static const Size            MAX_SIZE_FIT_IN_ATLAS;            ///< The maximum block's size fit into text-atlas-block.
+  static const uint16_t PADDING_TEXT_ATLAS_BLOCK; ///< Padding per edge. How much the block size (width, height) less than the text-atlas-block size (width, height).
+  static const Size     MAX_SIZE_FIT_IN_ATLAS;    ///< The maximum block's size fit into text-atlas-block.
 
-  static const uint32_t        NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE; ///< Factor multiply point-size in toolkit.
-
-
-
-  /**
-   * @brief Struct used to retrieve the glyph's bitmap.
-   */
-  struct DALI_ADAPTOR_API GlyphBufferData
-  {
-    /**
-     * @brief Constructor.
-     *
-     * Initializes struct members to their defaults.
-     */
-    GlyphBufferData();
-
-    /**
-     * @brief Destructor.
-     */
-    ~GlyphBufferData();
-
-    unsigned char* buffer;            ///< The glyph's bitmap buffer data.
-    unsigned int   width;             ///< The width of the bitmap.
-    unsigned int   height;            ///< The height of the bitmap.
-    int            outlineOffsetX;    ///< The additional horizontal offset to be added for the glyph's position for outline.
-    int            outlineOffsetY;    ///< The additional vertical offset to be added for the glyph's position for outline.
-    Pixel::Format  format;            ///< The pixel's format of the bitmap.
-    bool           isColorEmoji : 1;  ///< Whether the glyph is an emoji.
-    bool           isColorBitmap : 1; ///< Whether the glyph is a color bitmap.
-  };
+  static const uint32_t NUMBER_OF_POINTS_PER_ONE_UNIT_OF_POINT_SIZE; ///< Factor multiply point-size in toolkit.
 
   /**
    * @brief Used to load an embedded item into the font client.
@@ -127,6 +99,15 @@ public:
   static FontClient Get();
 
   /**
+   * @brief Create a handle to the new FontClient instance.
+   *
+   * @param[in] horizontalDpi The horizontal resolution in DPI.
+   * @param[in] verticalDpi The vertical resolution in DPI.
+   * @return A handle to the FontClient
+   */
+  static FontClient New(uint32_t horizontalDpi, uint32_t verticalDpi);
+
+  /**
    * @brief Create an uninitialized TextAbstraction handle.
    */
   FontClient();
@@ -153,6 +134,21 @@ public:
    */
   FontClient& operator=(const FontClient& handle);
 
+  /**
+   * @brief This move constructor is required for (smart) pointer semantics.
+   *
+   * @param[in] handle A reference to the moved handle.
+   */
+  FontClient(FontClient&& handle);
+
+  /**
+   * @brief This move assignment operator is required for (smart) pointer semantics.
+   *
+   * @param [in] handle  A reference to the moved handle.
+   * @return A reference to this.
+   */
+  FontClient& operator=(FontClient&& handle);
+
   ////////////////////////////////////////
   // Font management and validation.
   ////////////////////////////////////////
@@ -205,6 +201,11 @@ public:
   void GetDefaultFonts(FontList& defaultFonts);
 
   /**
+   * @brief Initializes and caches default font from the system.
+   */
+  void InitDefaultFontDescription();
+
+  /**
    * @brief Retrieve the active default font from the system.
    *
    * @param[out] fontDescription font structure describing the default font.
@@ -219,21 +220,21 @@ public:
   void GetSystemFonts(FontList& systemFonts);
 
   /**
-   * @brief Retrieves the font description of a given font @p id.
+   * @brief Retrieves the font description of a given font @p fontId.
    *
-   * @param[in] id The font identifier.
+   * @param[in] fontId The font identifier.
    * @param[out] fontDescription The path, family & style (width, weight and slant) describing the font.
    */
-  void GetDescription(FontId id, FontDescription& fontDescription);
+  void GetDescription(FontId fontId, FontDescription& fontDescription);
 
   /**
-   * @brief Retrieves the font point size of a given font @p id.
+   * @brief Retrieves the font point size of a given font @p fontId.
    *
-   * @param[in] id The font identifier.
+   * @param[in] fontId The font identifier.
    *
    * @return The point size in 26.6 fractional points.
    */
-  PointSize26Dot6 GetPointSize(FontId id);
+  PointSize26Dot6 GetPointSize(FontId fontId);
 
   /**
    * @brief Whether the given @p character is supported by the font.
@@ -309,10 +310,11 @@ public:
 
   /**
    * @brief Retrieves a unique font identifier for a given bitmap font.
+   * If the font is not present, it will cache the given font, and give it a new font id.
    *
    * @param[in] bitmapFont A bitmap font.
    *
-   * @return A valid font identifier, or zero if no bitmap font is created.
+   * @return A valid font identifier.
    */
   FontId GetFontId(const BitmapFont& bitmapFont);
 
@@ -386,6 +388,17 @@ public:
   GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
 
   /**
+   * @brief Return the glyph index of a given character code as modified by the variation selector.
+   *
+   * @param[in] fontId The identifier of the font for the required glyph.
+   * @param[in] charcode The UTF-32 character code.
+   * @param[in] variantSelector The UTF-32 character code point of the variation selector.
+   *
+   * @return The glyph index, or zero if the character code is undefined.
+   */
+  GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
+
+  /**
    * @brief Retrieve the metrics for a series of glyphs.
    *
    * @param[in,out] array An array of glyph-info structures with initialized FontId & GlyphIndex values.
@@ -500,7 +513,7 @@ public:
    */
   bool IsAtlasLimitationEnabled() const;
 
-   /**
+  /**
    * @brief retrieve the maximum allowed width and height for text-atlas-block.
    *
    * @note Used default configuration.
@@ -508,7 +521,7 @@ public:
    */
   Size GetMaximumTextAtlasSize() const;
 
-   /**
+  /**
    * @brief retrieve the default width and height for text-atlas-block.
    *
    * @note Used default configuration.
@@ -524,7 +537,7 @@ public:
    */
   Size GetCurrentMaximumBlockSizeFitInAtlas() const;
 
-   /**
+  /**
    * @brief set the achieved size (width and height) for text-atlas-block.
    * If @p currentMaximumBlockSizeFitInAtlas larger than the current maximum text atlas then store, otherwise ignore.
    *
@@ -557,6 +570,40 @@ public: // Not intended for application developers
  */
 DALI_ADAPTOR_API FontClient FontClientPreInitialize();
 
+/**
+ * @brief This is used to pre-cache FontConfig in order to improve the runtime performance of the application.
+ *
+ * @param[in] fallbackFamilyList A list of fallback font families to be pre-cached.
+ * @param[in] extraFamilyList A list of additional font families to be pre-cached.
+ * @param[in] localeFamily A locale font family to be pre-cached.
+ * @param[in] useThread True if the font client should create thread and perform pre-caching, false otherwise.
+ * @param[in] syncCreation True if thread creation guarantees syncronization with the main thread, false async creation.
+ */
+DALI_ADAPTOR_API void FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread, bool syncCreation);
+
+/**
+ * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
+ *
+ * @param[in] fontPathList A list of font paths to be pre-loaded.
+ * @param[in] memoryFontPathList A list of memory font paths to be pre-loaded.
+ * @param[in] useThread True if the font client should create thread and perform font pre-loading, false otherwise.
+ * @param[in] syncCreation True if thread creation guarantees syncronization with the main thread, false async creation.
+ *
+ * @note
+ * The fonts in the fontPathList perform FT_New_Face during pre-loading,
+ * which can provide some performace benefits.
+ *
+ * The fonts in the memoryFontPathList read the font file and cache the buffer in memory during pre-load.
+ * This enables the use of FT_New_Memory_Face during runtime and provides a performance boost.
+ * It requires memory equivalent to the size of each font file.
+ */
+DALI_ADAPTOR_API void FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread, bool syncCreation);
+
+/**
+  * @brief Joins font threads, waiting for their execution to complete.
+  */
+DALI_ADAPTOR_API void FontClientJoinFontThreads();
+
 } // namespace TextAbstraction
 
 } // namespace Dali