Cache the GetDefaultPlatformFontDescription results
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-plugin-impl.h
index 426a59e..bcfaec1 100644 (file)
@@ -19,7 +19,8 @@
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/text-abstraction/font-metrics.h>
+#include <dali/devel-api/text-abstraction/font-metrics.h>
+#include <dali/devel-api/text-abstraction/glyph-info.h>
 #include <dali/internal/text-abstraction/font-client-impl.h>
 
 // EXTERNAL INCLUDES
@@ -41,7 +42,7 @@ namespace Internal
 {
 
 /**
- *@brief Type used for indices addressing the vector with front descriptions of validated pairs 'font family name, font style'.
+ *@brief Type used for indices addressing the vector with front descriptions of validated fonts.
  */
 typedef uint32_t FontDescriptionId;
 
@@ -51,17 +52,26 @@ typedef uint32_t FontDescriptionId;
 struct FontClient::Plugin
 {
   /**
-   * @brief Caches an index to the vector of font descriptions for a given 'font family name, font style'.
+   * @brief Caches an list of fallback fonts for a given font-description
+   */
+  struct FallbackCacheItem
+  {
+    FallbackCacheItem( const FontDescription& fontDescription, FontList* fallbackFonts );
+
+    FontDescription fontDescription; ///< The font description.
+    FontList* fallbackFonts;         ///< The list of fallback fonts for the given font-description.
+  };
+
+  /**
+   * @brief Caches an index to the vector of font descriptions for a given font.
    */
   struct FontDescriptionCacheItem
   {
-    FontDescriptionCacheItem( const FontFamily& fontFamily,
-                              const FontStyle& fontStyle,
+    FontDescriptionCacheItem( const FontDescription& fontDescription,
                               FontDescriptionId index );
 
-    FontFamily        fontFamily; ///< The font family name.
-    FontStyle         fontStyle;  ///< The font style.
-    FontDescriptionId index;      ///< Index to the vector of font descriptions.
+    FontDescription fontDescription; ///< The font description.
+    FontDescriptionId index;         ///< Index to the vector of font descriptions.
   };
 
   /**
@@ -107,6 +117,12 @@ struct FontClient::Plugin
     bool mIsFixedSizeBitmap;     ///< Whether the font has fixed size bitmaps.
   };
 
+  struct EllipsisItem
+  {
+    PointSize26Dot6 size;
+    GlyphInfo glyph;
+  };
+
   /**
    * Constructor.
    *
@@ -131,10 +147,19 @@ struct FontClient::Plugin
   void SetDpi( unsigned int horizontalDpi, unsigned int verticalDpi );
 
   /**
-   * @copydoc Dali::FontClient::SetDefaultFontFamily()
+   * @copydoc Dali::FontClient::ResetSystemDefaults()
+   */
+  void ResetSystemDefaults();
+
+  /**
+   * @copydoc Dali::FontClient::SetDefaultFont()
    */
-  void SetDefaultFontFamily( const FontFamily& fontFamilyName,
-                             const FontStyle& fontStyle );
+  void SetDefaultFont( const FontDescription& fontDescription );
+
+  /**
+   * @copydoc Dali::FontClient::GetDefaultPlatformFontDescription()
+   */
+  void GetDefaultPlatformFontDescription( FontDescription& fontDescription );
 
   /**
    * @copydoc Dali::FontClient::GetDefaultFonts()
@@ -157,11 +182,24 @@ struct FontClient::Plugin
   PointSize26Dot6 GetPointSize( FontId id );
 
   /**
+   * @copydoc Dali::FontClient::FindFontForCharacter()
+   */
+  FontId FindFontForCharacter( const FontList& fontList,
+                               Character charcode,
+                               PointSize26Dot6 requestedSize,
+                               bool preferColor );
+
+  /**
    * @copydoc Dali::FontClient::FindDefaultFont()
    */
   FontId FindDefaultFont( Character charcode, PointSize26Dot6 pointSize, bool preferColor );
 
   /**
+   * @copydoc Dali::FontClient::FindFallbackFont()
+   */
+  FontId FindFallbackFont( FontId preferredFont, Character charcode, PointSize26Dot6 requestedSize, bool preferColor );
+
+  /**
    * @see Dali::FontClient::GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex )
    *
    * @param[in] cacheDescription Whether to cache the font description.
@@ -169,39 +207,37 @@ struct FontClient::Plugin
   FontId GetFontId( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, bool cacheDescription = true );
 
   /**
-   * @copydoc Dali::FontClient::GetFontId(const FontFamily& fontFamily, const FontStyle& fontStyle, PointSize26Dot6 pointSize, FaceIndex faceIndex )
+   * @copydoc Dali::FontClient::GetFontId( const FontDescription& fontDescription, PointSize26Dot6 pointSize, FaceIndex faceIndex )
    */
-  FontId GetFontId( const FontFamily& fontFamily,
-                    const FontStyle& fontStyle,
+  FontId GetFontId( const FontDescription& fontDescription,
                     PointSize26Dot6 pointSize,
                     FaceIndex faceIndex );
 
   /**
-   * @copydoc Dali::FontClient::IsScalable(const FontPath& path )
+   * @copydoc Dali::FontClient::IsScalable( const FontPath& path )
    */
   bool IsScalable( const FontPath& path );
 
   /**
-   * @copydoc Dali::FontClient::IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle )
+   * @copydoc Dali::FontClient::IsScalable( const FontDescription& fontDescription )
    */
-  bool IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle );
+  bool IsScalable( const FontDescription& fontDescription );
 
   /**
-   * @copydoc Dali::FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
+   * @copydoc Dali::FontClient::GetFixedSizes()
    */
   void GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes );
 
   /**
-   * @copydoc Dali::FontClient::GetFixedSizes( const FontFamily& fontFamily, const FontStyle& fontStyle, Dali::Vector< PointSize26Dot6>& sizes )
+   * @copydoc Dali::FontClient::GetFixedSizes()
    */
-  void GetFixedSizes( const FontFamily& fontFamily,
-                      const FontStyle& fontStyle,
+  void GetFixedSizes( const FontDescription& fontDescription,
                       Dali::Vector< PointSize26Dot6 >& sizes );
 
   /**
    * @copydoc Dali::FontClient::GetFontMetrics()
    */
-  void GetFontMetrics( FontId fontId, FontMetrics& metrics );
+  void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize );
 
   /**
    * @copydoc Dali::FontClient::GetGlyphIndex()
@@ -209,15 +245,20 @@ struct FontClient::Plugin
   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
 
   /**
-   * @copydoc Dali::FontClient::CreateMetrics()
+   * @copydoc Dali::FontClient::GetGlyphMetrics()
    */
-  bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
+  bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal, int maxFixedSize );
 
   /**
    * @copydoc Dali::FontClient::CreateBitmap()
    */
   BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
 
+  /**
+   * @copydoc Dali::FontClient::GetEllipsisGlyph()
+   */
+  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
+
 private:
 
   /**
@@ -228,15 +269,21 @@ private:
   void InitSystemFonts();
 
   /**
+   * Gets the FontDescription which matches the given pattern
+   * @param[in] pattern pattern to match against
+   * @param[out] fontDescription the resultant fontDescription that matched
+   * @return true if match found
+   */
+  bool MatchFontDescriptionToPattern( _FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription );
+
+  /**
    * @brief Creates a font family pattern used to match fonts.
    *
-   * @param[in] fontFamily The font family name.
-   * @param[in] fontStyle The font style.
+   * @param[in] fontDescription The font to cache.
    *
    * @return The pattern.
    */
-  _FcPattern* CreateFontFamilyPattern( const FontFamily& fontFamily,
-                                       const FontStyle& fontStyle );
+  _FcPattern* CreateFontFamilyPattern( const FontDescription& fontDescription );
 
   /**
    * Retrieves the fonts present in the platform.
@@ -257,6 +304,17 @@ private:
   bool GetFcString( const _FcPattern* const pattern, const char* const n, std::string& string );
 
   /**
+   * Retrieves a font config object's value from a pattern.
+   *
+   * @param[in] pattern The font config pattern.
+   * @param[in] n The object.
+   * @param[out] intVal The object's value.
+   *
+   * @return @e true if the operation is successful.
+   */
+  bool GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal );
+
+  /**
    * @brief Creates a font.
    *
    * @param[in] path The path to the font file name.
@@ -301,20 +359,27 @@ private:
   bool FindFont( const FontPath& path, PointSize26Dot6 pointSize, FaceIndex faceIndex, FontId& fontId ) const;
 
   /**
-   * @brief Finds in the cahce a pair 'font family, font style'.
-   * If there is one, it writes the index to the vector with font descriptions in the param @p  validatedFontId.
+   * @brief Finds in the cache a cluster 'font family, font width, font weight, font slant'
+   * If there is one, it writes the index to the vector with font descriptions in the param @p validatedFontId.
    *
-   * @param[in] fontFamily The font family name.
-   * @param[in] fontStyle The font style.
+   * @param[in] fontDescription The font to validate.
    * @param[out] validatedFontId The index to the vector with font descriptions.
    *
    * @return @e true if the pair is found.
    */
-  bool FindValidatedFont( const FontFamily& fontFamily,
-                          const FontStyle& fontStyle,
+  bool FindValidatedFont( const FontDescription& fontDescription,
                           FontDescriptionId& validatedFontId );
 
   /**
+   * @brief Finds a fallback font list from the cache for a given font-description
+   *
+   * @param[in] fontDescription The font to validate.
+   * @param[out] A valid pointer to a font list, or NULL if not found.
+   */
+  bool FindFallbackFontList( const FontDescription& fontDescription,
+                             FontList*& fontList );
+
+  /**
    * @brief Finds in the cache a pair 'validated font id and font point size'.
    * If there is one it writes the font id in the param @p fontId.
    *
@@ -329,28 +394,42 @@ private:
                  FontId& fontId );
 
   /**
-   * @brief Validate a font family and style
+   * @brief Validate a font description.
    *
-   * @param[in] fontFamily Font Family to validate
-   * @param[in] fontStyle Font Style to validate
+   * @param[in] fontDescription The font to validate.
    * @param[out] validatedFontId Result of validation
    */
-  void ValidateFont( const FontFamily& fontFamily,
-                     const FontStyle& fontStyle,
+  void ValidateFont( const FontDescription& fontDescription,
                      FontDescriptionId& validatedFontId );
 
+  /**
+   * Helper for GetDefaultFonts etc.
+   *
+   * @param[in] fontDescription A font description.
+   * @param[out] fontList A list of the fonts which are a close match for fontDescription.
+   */
+  void SetFontList( const FontDescription& fontDescription, FontList& fontList );
+
   FT_Library mFreeTypeLibrary; ///< A handle to a FreeType library instance.
 
   unsigned int mDpiHorizontal; ///< Horizontal dpi.
   unsigned int mDpiVertical;   ///< Vertical dpi.
 
+  FontDescription mDefaultFontDescription; ///< The cached default font from the system
+
   FontList mSystemFonts;       ///< Cached system fonts.
   FontList mDefaultFonts;      ///< Cached default fonts.
 
+  std::vector<FallbackCacheItem> mFallbackCache; ///< Cached fallback font lists.
+
   std::vector<CacheItem>                mFontCache;            ///< 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 family name, font style'.
-  FontList                              mFontDescriptionCache; ///< Caches font descriptions for the validated font family name and font style pairs.
+  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.
   std::vector<FontIdCacheItem>          mFontIdCache;          ///< Caches font ids for the pairs of font point size and the index to the vector with font descriptions of the validated fonts.
+
+  Vector<EllipsisItem> mEllipsisCache;      ///< Caches ellipsis glyphs for a particular point size.
+
+  bool mDefaultFontDescriptionCached : 1; ///< Whether the default font is cached or not
 };
 
 } // namespace Internal