[Tizen] Add support for FontClientFontPreLoad API
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-impl.h
old mode 100755 (executable)
new mode 100644 (file)
index def0799..d0f7494
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_IMPL_H
 
 /*
- * Copyright (c) 2019 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.
 // INTERNAL INCLUDES
 #include <dali/devel-api/text-abstraction/font-client.h>
 
-
 struct FT_FaceRec_;
 
 namespace Dali
 {
-
 namespace TextAbstraction
 {
-
 namespace Internal
 {
+using HarfBuzzFontHandle = void*; ///< @note We don't want to make other class include harfbuzz header. So we will keep harfbuzz font data as HarfBuzzFontHandle.
 
 /**
  * Implementation of the FontClient
@@ -42,7 +40,6 @@ namespace Internal
 class FontClient : public BaseObject
 {
 public:
-
   /**
    * Constructor
    */
@@ -53,6 +50,7 @@ public:
    */
   ~FontClient();
 
+public: // API for Dali::TextAbstraction::FontClient used.
   /**
    * @copydoc Dali::TextAbstraction::FontClient::Get()
    */
@@ -66,6 +64,30 @@ public:
   static Dali::TextAbstraction::FontClient PreInitialize();
 
   /**
+   * @brief This is used to pre-cache FontConfig in order to improve the runtime performance of the application.
+   *
+   * @see Dali::TextAbstraction::FontClientPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread);
+   */
+  static void PreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily, bool useThread);
+
+  /**
+   * @brief This is used to creates a global font client and pre-caches the FontConfig.
+   */
+  static void PreCacheRun(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily);
+
+  /**
+   * @brief This is used to pre-load FreeType font face in order to improve the runtime performance of the application.
+   *
+   * @see Dali::TextAbstraction:FontClientFontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread);
+   */
+  static void PreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList, bool useThread);
+
+  /**
+   * @brief This is used to creates a global font client and pre-loads the FreeType font face.
+   */
+  static void PreLoadRun(const FontPathList& fontPathList, const FontPathList& memoryFontPathList);
+
+  /**
    * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
    */
   void ClearCache();
@@ -73,12 +95,12 @@ public:
   /**
    * @copydoc Dali::TextAbstraction::FontClient::SetDpi()
    */
-  void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
+  void SetDpi(unsigned int horizontalDpi, unsigned int verticalDpi);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDpi()
    */
-  void GetDpi( unsigned int& horizontalDpi, unsigned int& verticalDpi );
+  void GetDpi(unsigned int& horizontalDpi, unsigned int& verticalDpi);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFontSize()
@@ -93,144 +115,195 @@ public:
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
    */
-  void GetDefaultFonts( FontList& defaultFonts );
+  void GetDefaultFonts(FontList& defaultFonts);
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::InitDefaultFontDescription()
+   */
+  void InitDefaultFontDescription();
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
    */
-  void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
+  void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
    */
-  void GetSystemFonts( FontList& systemFonts );
+  void GetSystemFonts(FontList& systemFonts);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
    */
-  void GetDescription( FontId id, FontDescription& fontDescription );
+  void GetDescription(FontId fontId, FontDescription& fontDescription);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
    */
-  PointSize26Dot6 GetPointSize( FontId id );
+  PointSize26Dot6 GetPointSize(FontId fontId);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
    */
-  bool IsCharacterSupportedByFont( FontId fontId, Character character );
+  bool IsCharacterSupportedByFont(FontId fontId, Character character);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::FindDefaultFont()
    */
-  FontId FindDefaultFont( Character charcode,
-                          PointSize26Dot6 requestedPointSize,
-                          bool preferColor );
+  FontId FindDefaultFont(Character       charcode,
+                         PointSize26Dot6 requestedPointSize,
+                         bool            preferColor);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::FindFallbackFont()
    */
-  FontId FindFallbackFont( Character charcode,
-                           const FontDescription& preferredFontDescription,
-                           PointSize26Dot6 requestedPointSize,
-                           bool preferColor );
+  FontId FindFallbackFont(Character              charcode,
+                          const FontDescription& preferredFontDescription,
+                          PointSize26Dot6        requestedPointSize,
+                          bool                   preferColor);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
    */
-  FontId GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex );
+  FontId GetFontId(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
    */
-  FontId GetFontId( const FontDescription& fontDescription,
-                    PointSize26Dot6 requestedPointSize,
-                    FaceIndex faceIndex );
+  FontId GetFontId(const FontDescription& fontDescription,
+                   PointSize26Dot6        requestedPointSize,
+                   FaceIndex              faceIndex);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const BitmapFont& bitmapFont )
    */
-  FontId GetFontId( const BitmapFont& bitmapFont );
+  FontId GetFontId(const BitmapFont& bitmapFont);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontPath& path )
    */
-  bool IsScalable( const FontPath& path );
+  bool IsScalable(const FontPath& path);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::IsScalable( const FontDescription& fontDescription )
    */
-  bool IsScalable( const FontDescription& fontDescription );
+  bool IsScalable(const FontDescription& fontDescription);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
    */
-  void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
+  void GetFixedSizes(const FontPath& path, Dali::Vector<PointSize26Dot6>& sizes);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFixedSizes()
    */
-  void GetFixedSizes( const FontDescription& fontDescription,
-                      Dali::Vector< PointSize26Dot6 >& sizes );
+  void GetFixedSizes(const FontDescription&         fontDescription,
+                     Dali::Vector<PointSize26Dot6>& sizes);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::HasItalicStyle()
    */
-  bool HasItalicStyle( FontId fontId ) const;
+  bool HasItalicStyle(FontId fontId) const;
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFontMetrics()
    */
-  void GetFontMetrics( FontId fontId, FontMetrics& metrics );
+  void GetFontMetrics(FontId fontId, FontMetrics& metrics);
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
+   */
+  GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphIndex()
    */
-  GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
+  GlyphIndex GetGlyphIndex(FontId fontId, Character charcode, Character variantSelector);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetGlyphMetrics()
    */
-  bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
+  bool GetGlyphMetrics(GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
    */
-  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
+  void CreateBitmap(FontId fontId, GlyphIndex glyphIndex, bool isItalicRequired, bool isBoldRequired, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
    */
-  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
+  PixelData CreateBitmap(FontId fontId, GlyphIndex glyphIndex, int outlineWidth);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
    */
-  void CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight );
+  void CreateVectorBlob(FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetEllipsisGlyph()
    */
-  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 requestedPointSize );
+  const GlyphInfo& GetEllipsisGlyph(PointSize26Dot6 requestedPointSize);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::IsColorGlyph()
    */
-  bool IsColorGlyph( FontId fontId, GlyphIndex glyphIndex );
+  bool IsColorGlyph(FontId fontId, GlyphIndex glyphIndex);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateEmbeddedItem()
    */
-  GlyphIndex CreateEmbeddedItem( const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat );
+  GlyphIndex CreateEmbeddedItem(const TextAbstraction::FontClient::EmbeddedItemDescription& description, Pixel::Format& pixelFormat);
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::EnableAtlasLimitation(bool enabled)
+   */
+  void EnableAtlasLimitation(bool enabled);
 
   /**
+   * @copydoc Dali::TextAbstraction::FontClient::IsAtlasLimitationEnabled()
+   */
+  bool IsAtlasLimitationEnabled() const;
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::GetMaximumTextAtlasSize()
+   */
+  Size GetMaximumTextAtlasSize() const;
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::GetDefaultTextAtlasSize()
+   */
+  Size GetDefaultTextAtlasSize() const;
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::GetCurrentMaximumBlockSizeFitInAtlas()
+   */
+  Size GetCurrentMaximumBlockSizeFitInAtlas() const;
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas)
+   */
+  bool SetCurrentMaximumBlockSizeFitInAtlas(const Size& currentMaximumBlockSizeFitInAtlas);
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::GetNumberOfPointsPerOneUnitOfPointSize()
+   */
+  uint32_t GetNumberOfPointsPerOneUnitOfPointSize() const;
+
+  /**
+   * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
+   */
+  bool AddCustomFontDirectory(const FontPath& path);
+
+public: // API for Dali::TextAbstraction::Internal::FontClient used.
+  /**
    * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
    *
    * @param[in] fontId The font id.
    *
    * @return The pointer to the FreeType Font Face.
    */
-  FT_FaceRec_* GetFreetypeFace( FontId fontId );
+  FT_FaceRec_* GetFreetypeFace(FontId fontId);
 
   /**
    * @brief Retrieves the type of font.
@@ -239,28 +312,48 @@ public:
    *
    * @return FACE_FONT if the font has been loaded by FreeType, BITMAP_FONT if it's a font that has been loaded from images or INVALID if it's a non valid font.
    */
-  FontDescription::Type GetFontType( FontId fontId );
+  FontDescription::Type GetFontType(FontId fontId);
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
+   * @brief Get the harfbuzz font data of font.
+   *
+   * @param fontId The font id.
+   * @return The harfbuzz font data, or nullptr if failed.
    */
-  bool AddCustomFontDirectory( const FontPath& path );
+  HarfBuzzFontHandle GetHarfBuzzFont(FontId fontId);
 
-private:
+  /**
+   * @brief This is used to pre-cache fonts 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.
+   */
+  void FontPreCache(const FontFamilyList& fallbackFamilyList, const FontFamilyList& extraFamilyList, const FontFamily& localeFamily);
 
   /**
+   * @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.
+   */
+  void FontPreLoad(const FontPathList& fontPathList, const FontPathList& memoryFontPathList);
+
+
+private:
+  /**
    * Helper for lazy initialization.
    */
   void CreatePlugin();
 
   // Undefined copy constructor.
-  FontClient( const FontClient& );
+  FontClient(const FontClient&);
 
   // Undefined assignment constructor.
-  FontClient& operator=( const FontClient& );
+  FontClient& operator=(const FontClient&);
 
 private:
-
   struct Plugin;
   Plugin* mPlugin;
 
@@ -268,7 +361,7 @@ private:
   unsigned int mDpiHorizontal;
   unsigned int mDpiVertical;
 
-  static Dali::TextAbstraction::FontClient gPreInitializedFontClient;
+  static Dali::TextAbstraction::FontClient gPreCreatedFontClient;
 
 }; // class FontClient
 
@@ -276,14 +369,14 @@ private:
 
 inline static Internal::FontClient& GetImplementation(FontClient& fontClient)
 {
-  DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
+  DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
   BaseObject& handle = fontClient.GetBaseObject();
   return static_cast<Internal::FontClient&>(handle);
 }
 
 inline static const Internal::FontClient& GetImplementation(const FontClient& fontClient)
 {
-  DALI_ASSERT_ALWAYS( fontClient && "fontClient handle is empty" );
+  DALI_ASSERT_ALWAYS(fontClient && "fontClient handle is empty");
   const BaseObject& handle = fontClient.GetBaseObject();
   return static_cast<const Internal::FontClient&>(handle);
 }