Merge "[AT-SPI] Add API for blocking automatic Bridge initialization" into devel...
[platform/core/uifw/dali-adaptor.git] / dali / internal / text / text-abstraction / font-client-plugin-impl.h
index da207d5..fb3569a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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/adaptor-framework/pixel-buffer.h>
+#include <dali/devel-api/text-abstraction/bitmap-font.h>
 #include <dali/devel-api/text-abstraction/font-metrics.h>
 #include <dali/devel-api/text-abstraction/glyph-info.h>
 #include <dali/internal/text/text-abstraction/font-client-impl.h>
 
 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
-#include <dali/internal/text/glyphy/vector-font-cache.h>
+#include <third-party/glyphy/vector-font-cache.h>
 #else
 class VectorFontCache;
 #endif
@@ -44,17 +46,23 @@ struct _FcPattern;
 
 namespace Dali
 {
-
 namespace TextAbstraction
 {
-
 namespace Internal
 {
-
 /**
- *@brief Type used for indices addressing the vector with front descriptions of validated fonts.
+ * @brief Type used for indices addressing the vector with front descriptions of validated fonts.
  */
 typedef uint32_t FontDescriptionId;
+
+/**
+ * @brief Type used for indices addressing the vector with pixel buffers.
+ */
+typedef uint32_t PixelBufferId;
+
+/**
+ * @brief Vector of character sets.
+ */
 typedef Vector<_FcCharSet*> CharacterSetList;
 
 /**
@@ -62,16 +70,22 @@ typedef Vector<_FcCharSet*> CharacterSetList;
  */
 struct FontClient::Plugin
 {
+  struct FontIdCacheItem
+  {
+    FontDescription::Type type; ///< The type of font.
+    FontId                id;   ///< Index to the cache of fonts for the specified type.
+  };
+
   /**
    * @brief Caches an list of fallback fonts for a given font-description
    */
   struct FallbackCacheItem
   {
-    FallbackCacheItem( FontDescription&& fontDescription, FontList* fallbackFonts, CharacterSetList* characterSets );
+    FallbackCacheItem(FontDescription&& fontDescription, FontList* fallbackFonts, CharacterSetList* characterSets);
 
-    FontDescription fontDescription; ///< The font description.
-    FontList* fallbackFonts;         ///< The list of fallback fonts for the given font-description.
-    CharacterSetList* characterSets; ///< The list of character sets for the given font-description.
+    FontDescription   fontDescription; ///< The font description.
+    FontList*         fallbackFonts;   ///< The list of fallback fonts for the given font-description.
+    CharacterSetList* characterSets;   ///< The list of character sets for the given font-description.
   };
 
   /**
@@ -79,13 +93,13 @@ struct FontClient::Plugin
    */
   struct FontDescriptionCacheItem
   {
-    FontDescriptionCacheItem( const FontDescription& fontDescription,
-                              FontDescriptionId index );
-    FontDescriptionCacheItem( FontDescription&& fontDescription,
-                              FontDescriptionId index );
+    FontDescriptionCacheItem(const FontDescription& fontDescription,
+                             FontDescriptionId      index);
+    FontDescriptionCacheItem(FontDescription&& fontDescription,
+                             FontDescriptionId index);
 
-    FontDescription fontDescription; ///< The font description.
-    FontDescriptionId index;         ///< Index to the vector of font descriptions.
+    FontDescription   fontDescription; ///< The font description.
+    FontDescriptionId index;           ///< Index to the vector of font descriptions.
   };
 
   /**
@@ -93,9 +107,9 @@ struct FontClient::Plugin
    */
   struct FontDescriptionSizeCacheItem
   {
-    FontDescriptionSizeCacheItem( FontDescriptionId validatedFontId,
-                                  PointSize26Dot6 requestedPointSize,
-                                  FontId fontId );
+    FontDescriptionSizeCacheItem(FontDescriptionId validatedFontId,
+                                 PointSize26Dot6   requestedPointSize,
+                                 FontId            fontId);
 
     FontDescriptionId validatedFontId;    ///< Index to the vector with font descriptions.
     PointSize26Dot6   requestedPointSize; ///< The font point size.
@@ -107,38 +121,70 @@ struct FontClient::Plugin
    */
   struct FontFaceCacheItem
   {
-    FontFaceCacheItem( FT_Face ftFace,
-                       const FontPath& path,
-                       PointSize26Dot6 requestedPointSize,
-                       FaceIndex face,
-                       const FontMetrics& metrics );
-
-    FontFaceCacheItem( FT_Face ftFace,
-                       const FontPath& path,
-                       PointSize26Dot6 requestedPointSize,
-                       FaceIndex face,
-                       const FontMetrics& metrics,
-                       float fixedWidth,
-                       float fixedHeight,
-                       bool hasColorTables );
-
-    FT_Face mFreeTypeFace;               ///< The FreeType face.
-    FontPath mPath;                      ///< The path to the font file name.
-    PointSize26Dot6 mRequestedPointSize; ///< The font point size.
-    FaceIndex mFaceIndex;                ///< The face index.
-    FontMetrics mMetrics;                ///< The font metrics.
-    _FcCharSet* mCharacterSet;           ///< Pointer with the range of characters.
-    FT_Short mFixedWidthPixels;          ///< The height in pixels (fixed size bitmaps only)
-    FT_Short mFixedHeightPixels;         ///< The height in pixels (fixed size bitmaps only)
-    unsigned int mVectorFontId;          ///< The ID of the equivalent vector-based font
-    bool mIsFixedSizeBitmap : 1;         ///< Whether the font has fixed size bitmaps.
-    bool mHasColorTables    : 1;         ///< Whether the font has color tables.
+    FontFaceCacheItem(FT_Face            ftFace,
+                      const FontPath&    path,
+                      PointSize26Dot6    requestedPointSize,
+                      FaceIndex          face,
+                      const FontMetrics& metrics);
+
+    FontFaceCacheItem(FT_Face            ftFace,
+                      const FontPath&    path,
+                      PointSize26Dot6    requestedPointSize,
+                      FaceIndex          face,
+                      const FontMetrics& metrics,
+                      int                fixedSizeIndex,
+                      float              fixedWidth,
+                      float              fixedHeight,
+                      bool               hasColorTables);
+
+    FT_Face         mFreeTypeFace;          ///< The FreeType face.
+    FontPath        mPath;                  ///< The path to the font file name.
+    PointSize26Dot6 mRequestedPointSize;    ///< The font point size.
+    FaceIndex       mFaceIndex;             ///< The face index.
+    FontMetrics     mMetrics;               ///< The font metrics.
+    _FcCharSet*     mCharacterSet;          ///< Pointer with the range of characters.
+    int             mFixedSizeIndex;        ///< Index to the fixed size table for the requested size.
+    float           mFixedWidthPixels;      ///< The height in pixels (fixed size bitmaps only)
+    float           mFixedHeightPixels;     ///< The height in pixels (fixed size bitmaps only)
+    unsigned int    mVectorFontId;          ///< The ID of the equivalent vector-based font
+    FontId          mFontId;                ///< Index to the vector with the cache of font's ids.
+    bool            mIsFixedSizeBitmap : 1; ///< Whether the font has fixed size bitmaps.
+    bool            mHasColorTables : 1;    ///< Whether the font has color tables.
   };
 
   struct EllipsisItem
   {
     PointSize26Dot6 requestedPointSize;
-    GlyphInfo glyph;
+    GlyphInfo       glyph;
+  };
+
+  /**
+   * @brief Caches pixel buffers.
+   */
+  struct PixelBufferCacheItem
+  {
+    Devel::PixelBuffer pixelBuffer; ///< The pixel buffer loaded from the url.
+    std::string        url;         ///< The url.
+  };
+
+  /**
+   * @brief Caches embedded items.
+   */
+  struct EmbeddedItem
+  {
+    PixelBufferId pixelBufferId; ///< Index to the vector of pixel buffers
+    unsigned int  width;         ///< The desired width.
+    unsigned int  height;        ///< The desired height.
+  };
+
+  /**
+   * @brief Stores a bitmap font and its pixel buffers per glyph.
+   */
+  struct BitmapFontCacheItem
+  {
+    BitmapFont                      font;         ///< The bitmap font.
+    std::vector<Devel::PixelBuffer> pixelBuffers; ///< The pixel buffers of the glyphs.
+    FontId                          id;           ///< Index to the vector with the cache of font's ids.
   };
 
   /**
@@ -150,7 +196,7 @@ struct FontClient::Plugin
    * @param[in] horizontalDpi The horizontal dpi.
    * @param[in] verticalDpi The vertical dpi.
    */
-  Plugin( unsigned int horizontalDpi, unsigned int verticalDpi );
+  Plugin(unsigned int horizontalDpi, unsigned int verticalDpi);
 
   /**
    * Default destructor.
@@ -160,9 +206,14 @@ struct FontClient::Plugin
   ~Plugin();
 
   /**
+   * @copydoc Dali::TextAbstraction::FontClient::ClearCache()
+   */
+  void ClearCache();
+
+  /**
    * @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::ResetSystemDefaults()
@@ -172,37 +223,37 @@ struct FontClient::Plugin
   /**
    * @copydoc Dali::TextAbstraction::FontClient::SetDefaultFont()
    */
-  void SetDefaultFont( const FontDescription& preferredFontDescription );
+  void SetDefaultFont(const FontDescription& preferredFontDescription);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultPlatformFontDescription()
    */
-  void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
+  void GetDefaultPlatformFontDescription(FontDescription& fontDescription);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDefaultFonts()
    */
-  void GetDefaultFonts( FontList& defaultFonts );
+  void GetDefaultFonts(FontList& defaultFonts);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetSystemFonts()
    */
-  void GetSystemFonts( FontList& systemFonts );
+  void GetSystemFonts(FontList& systemFonts);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetDescription()
    */
-  void GetDescription( FontId id, FontDescription& fontDescription ) const;
+  void GetDescription(FontId id, FontDescription& fontDescription) const;
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetPointSize()
    */
-  PointSize26Dot6 GetPointSize( FontId id );
+  PointSize26Dot6 GetPointSize(FontId id);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::IsCharacterSupportedByFont()
    */
-  bool IsCharacterSupportedByFont( FontId fontId, Character character );
+  bool IsCharacterSupportedByFont(FontId fontId, Character character);
 
   /**
    * @brief Finds within the @p fontList a font which support the @p carcode.
@@ -215,123 +266,182 @@ struct FontClient::Plugin
    *
    * @return A valid font identifier, or zero if no font is found.
    */
-  FontId FindFontForCharacter( const FontList& fontList,
-                               const CharacterSetList& characterSetList,
-                               Character charcode,
-                               PointSize26Dot6 requestedPointSize,
-                               bool preferColor );
+  FontId FindFontForCharacter(const FontList&         fontList,
+                              const CharacterSetList& characterSetList,
+                              Character               charcode,
+                              PointSize26Dot6         requestedPointSize,
+                              bool                    preferColor);
 
   /**
    * @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);
 
   /**
    * @see Dali::TextAbstraction::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex )
    *
    * @param[in] cacheDescription Whether to cache the font description.
    */
-  FontId GetFontId( const FontPath& path,
-                    PointSize26Dot6 requestedPointSize,
-                    FaceIndex faceIndex,
-                    bool cacheDescription );
+  FontId GetFontId(const FontPath& path,
+                   PointSize26Dot6 requestedPointSize,
+                   FaceIndex       faceIndex,
+                   bool            cacheDescription);
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::GetFontId( const FontDescription& preferredFontDescription, 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);
 
   /**
    * @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()
    */
-  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;
 
   /**
    * @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 );
+  GlyphIndex GetGlyphIndex(FontId fontId, Character charcode);
 
   /**
    * @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);
 
   /**
    * Helper for GetGlyphMetrics when using bitmaps
    */
-  bool GetBitmapMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
+  bool GetBitmapMetrics(GlyphInfo* array, uint32_t size, bool horizontal);
 
   /**
    * Helper for GetGlyphMetrics when using vectors
    */
-  bool GetVectorMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
+  bool GetVectorMetrics(GlyphInfo* array, uint32_t size, bool horizontal);
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
+   * @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 softwareItalic, bool softwareBold, 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);
+
+  /**
+   * @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::Internal::FontClient::GetFreetypeFace()
    */
-  FT_FaceRec_* GetFreetypeFace( FontId fontId );
+  FT_FaceRec_* GetFreetypeFace(FontId fontId);
 
-private:
+  /**
+   * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFontType()
+   */
+  FontDescription::Type GetFontType(FontId fontId);
 
   /**
+   * @copydoc Dali::TextAbstraction::FontClient::AddCustomFontDirectory()
+   */
+  bool AddCustomFontDirectory(const FontPath& path);
+
+private:
+  /**
    * @brief Caches the fonts present in the platform.
    *
    * Calls GetFcFontSet() to retrieve the fonts.
@@ -340,31 +450,38 @@ private:
 
   /**
    * @brief Gets the FontDescription which matches the given pattern.
+   *
+   * @note The reference counter of the @p characterSet has been increased. Call FcCharSetDestroy to decrease it.
+   *
    * @param[in] pattern pattern to match against.
    * @param[out] fontDescription the resultant fontDescription that matched.
    * @param[out] characterSet The character set for that pattern.
    * @return true if match found.
    */
-  bool MatchFontDescriptionToPattern( _FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, _FcCharSet** characterSet );
+  bool MatchFontDescriptionToPattern(_FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, _FcCharSet** characterSet);
 
   /**
    * @brief Creates a font family pattern used to match fonts.
    *
+   * @note Need to call FcPatternDestroy to free the resources.
+   *
    * @param[in] fontDescription The font to cache.
    *
    * @return The pattern.
    */
-  _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription ) const;
+  _FcPattern* CreateFontFamilyPattern(const FontDescription& fontDescription) const;
 
   /**
-   * Retrieves the fonts present in the platform.
+   * @brief Retrieves the fonts present in the platform.
+   *
+   * @note Need to call FcFontSetDestroy to free the allocated resources.
    *
    * @return A font fonfig data structure with the platform's fonts.
    */
   _FcFontSet* GetFcFontSet() const;
 
   /**
-   * Retrieves a font config object's value from a pattern.
+   * @brief Retrieves a font config object's value from a pattern.
    *
    * @param[in] pattern The font config pattern.
    * @param[in] n The object.
@@ -372,10 +489,10 @@ private:
    *
    * @return @e true if the operation is successful.
    */
-  bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
+  bool GetFcString(const _FcPattern* const pattern, const char* const n, std::string& string);
 
   /**
-   * Retrieves a font config object's value from a pattern.
+   * @brief Retrieves a font config object's value from a pattern.
    *
    * @param[in] pattern The font config pattern.
    * @param[in] n The object.
@@ -383,7 +500,7 @@ private:
    *
    * @return @e true if the operation is successful.
    */
-  bool GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal );
+  bool GetFcInt(const _FcPattern* const pattern, const char* const n, int& intVal);
 
   /**
    * @brief Creates a font.
@@ -395,18 +512,29 @@ private:
    *
    * @return The font identifier.
    */
-  FontId CreateFont( const FontPath& path,
-                     PointSize26Dot6 requestedPointSize,
-                     FaceIndex faceIndex,
-                     bool cacheDescription );
+  FontId CreateFont(const FontPath& path,
+                    PointSize26Dot6 requestedPointSize,
+                    FaceIndex       faceIndex,
+                    bool            cacheDescription);
+
+  /**
+   * @brief Copy the color bitmap given in @p srcBuffer to @p data.
+   *
+   * @param[out] data The bitmap data.
+   * @param[in] srcWidth The width of the bitmap.
+   * @param[in] srcHeight The height of the bitmap.
+   * @param[in] srcBuffer The buffer of the bitmap.
+   */
+  void ConvertBitmap(TextAbstraction::FontClient::GlyphBufferData& data, unsigned int srcWidth, unsigned int srcHeight, const unsigned char* const srcBuffer);
 
   /**
    * @brief Copy the FreeType bitmap to the given buffer.
    *
    * @param[out] data The bitmap data.
    * @param[in] srcBitmap The FreeType bitmap.
+   * @param[in] isShearRequired Whether the bitmap needs a shear transform (for software italics).
    */
-  void ConvertBitmap( TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap );
+  void ConvertBitmap(TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap, bool isShearRequired);
 
   /**
    * @brief Finds in the cache if there is a triplet with the path to the font file name, the font point size and the face index.
@@ -419,7 +547,7 @@ private:
    *
    * @return @e true if there triplet is found.
    */
-  bool FindFont( const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex, FontId& fontId ) const;
+  bool FindFont(const FontPath& path, PointSize26Dot6 requestedPointSize, FaceIndex faceIndex, FontId& fontId) const;
 
   /**
    * @brief Finds in the cache a cluster 'font family, font width, font weight, font slant'
@@ -430,8 +558,8 @@ private:
    *
    * @return @e true if the pair is found.
    */
-  bool FindValidatedFont( const FontDescription& fontDescription,
-                          FontDescriptionId& validatedFontId );
+  bool FindValidatedFont(const FontDescription& fontDescription,
+                         FontDescriptionId&     validatedFontId);
 
   /**
    * @brief Finds a fallback font list from the cache for a given font-description
@@ -440,9 +568,9 @@ private:
    * @param[out] A valid pointer to a font list, or @e nullptr if not found.
    * @param[out] characterSetList A valid pointer to a character set list, or @e nullptr if not found.
    */
-  bool FindFallbackFontList( const FontDescription& fontDescription,
-                             FontList*& fontList,
-                             CharacterSetList*& characterSetList );
+  bool FindFallbackFontList(const FontDescription& fontDescription,
+                            FontList*&             fontList,
+                            CharacterSetList*&     characterSetList);
 
   /**
    * @brief Finds in the cache a pair 'validated font identifier and font point size'.
@@ -454,9 +582,19 @@ private:
    *
    * @return @e true if the pair is found.
    */
-  bool FindFont( FontDescriptionId validatedFontId,
-                 PointSize26Dot6 requestedPointSize,
-                 FontId& fontId );
+  bool FindFont(FontDescriptionId validatedFontId,
+                PointSize26Dot6   requestedPointSize,
+                FontId&           fontId);
+
+  /**
+   * @brief Finds in the cache a bitmap font with the @p bitmapFont family name.
+   *
+   * @param[in] bitmapFont The font's family name.
+   * @param[out] fontId The id of the font.
+   *
+   * @return Whether the font has been found.
+   */
+  bool FindBitmapFont(const FontFamily& bitmapFont, FontId& fontId) const;
 
   /**
    * @brief Validate a font description.
@@ -464,17 +602,19 @@ private:
    * @param[in] fontDescription The font to validate.
    * @param[out] validatedFontId Result of validation
    */
-  void ValidateFont( const FontDescription& fontDescription,
-                     FontDescriptionId& validatedFontId );
+  void ValidateFont(const FontDescription& fontDescription,
+                    FontDescriptionId&     validatedFontId);
 
   /**
-   * Helper for GetDefaultFonts etc.
+   * @brief Helper for GetDefaultFonts etc.
+   *
+   * @note CharacterSetList is a vector of FcCharSet that are reference counted. It's needed to call FcCharSetDestroy to decrease the reference counter.
    *
    * @param[in] fontDescription A font description.
    * @param[out] fontList A list of the fonts which are a close match for fontDescription.
-   * @param[out] characterSetList A list of the character sets which are a close match for fontDescription.
+   * @param[out] characterSetList A list of character sets which are a close match for fontDescription.
    */
-  void SetFontList( const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList );
+  void SetFontList(const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList);
 
   /**
    * Caches a font path.
@@ -484,32 +624,38 @@ private:
    * @param[in] requestedPointSize The font point size.
    * @param[in] path Path to the font file name.
    */
-  void CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize,  const FontPath& path );
+  void CacheFontPath(FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path);
 
   /**
    * @brief Creates a character set from a given font's @p description.
    *
+   * @note Need to call FcCharSetDestroy to free the resources.
+   *
    * @param[in] description The font's description.
    *
    * @return A character set.
    */
-  _FcCharSet* CreateCharacterSetFromDescription( const FontDescription& description );
+  _FcCharSet* CreateCharacterSetFromDescription(const FontDescription& description);
 
   /**
-   * @brief Destroy all matched Patterns.
+   * @brief Free the resources allocated in the fallback cache.
    *
+   * @param[in] fallbackCache The fallback cache.
    */
-  void DestroyMatchedPatterns();
+  void ClearFallbackCache(std::vector<FallbackCacheItem>& fallbackCache);
 
-private:
+  /**
+   * @brief Free the resources allocated by the FcCharSet objects.
+   */
+  void ClearCharacterSetFromFontFaceCache();
 
+private:
   // Declared private and left undefined to avoid copies.
-  Plugin( const Plugin& );
+  Plugin(const Plugin&);
   // Declared private and left undefined to avoid copies.
-  Plugin& operator=( const Plugin& );
+  Plugin& operator=(const Plugin&);
 
 private:
-
   FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
 
   unsigned int mDpiHorizontal; ///< Horizontal dpi.
@@ -517,23 +663,30 @@ private:
 
   FontDescription mDefaultFontDescription; ///< The cached default font from the system
 
-  FontList mSystemFonts;       ///< Cached system fonts.
-  FontList mDefaultFonts;      ///< Cached default fonts.
+  FontList         mSystemFonts;  ///< Cached system fonts.
+  FontList         mDefaultFonts; ///< Cached default fonts.
   CharacterSetList mDefaultFontCharacterSets;
 
   std::vector<FallbackCacheItem> mFallbackCache; ///< Cached fallback font lists.
 
+  Vector<FontIdCacheItem>                   mFontIdCache;
   std::vector<FontFaceCacheItem>            mFontFaceCache;            ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'.
   std::vector<FontDescriptionCacheItem>     mValidatedFontCache;       ///< Caches indices to the vector of font descriptions for a given font.
   FontList                                  mFontDescriptionCache;     ///< Caches font descriptions for the validated font.
   CharacterSetList                          mCharacterSetCache;        ///< Caches character set lists for the validated font.
   std::vector<FontDescriptionSizeCacheItem> mFontDescriptionSizeCache; ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts.
 
-  VectorFontCache* mVectorFontCache;            ///< Separate cache for vector data blobs etc.
-  Vector<EllipsisItem> mEllipsisCache;          ///< Caches ellipsis glyphs for a particular point size.
-  Vector<_FcPattern*>  mMatchedFcPatternCache;  ///< Contain matched FcPattern pointer.
+  VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc.
+
+  Vector<EllipsisItem>              mEllipsisCache;     ///< Caches ellipsis glyphs for a particular point size.
+  std::vector<PixelBufferCacheItem> mPixelBufferCache;  ///< Caches the pixel buffer of a url.
+  Vector<EmbeddedItem>              mEmbeddedItemCache; ///< Cache embedded items.
+  std::vector<BitmapFontCacheItem>  mBitmapFontCache;   ///< Stores bitmap fonts.
 
   bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not
+
+  bool mIsAtlasLimitationEnabled : 1; ///< Whether the validation on maximum atlas block size, then reduce block size to fit into it is enabled or not.
+  Vector2 mCurrentMaximumBlockSizeFitInAtlas; ///< The current maximum size (width, height) of text-atlas-block.
 };
 
 } // namespace Internal