API method added to retrieve the ellipsis glyph. 89/39289/4
authorVictor Cebollada <v.cebollada@samsung.com>
Tue, 12 May 2015 13:22:39 +0000 (14:22 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Tue, 12 May 2015 16:19:26 +0000 (17:19 +0100)
Change-Id: If3e21dca98af940f17242cb50481e70a6108c58c
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
text/dali/internal/text-abstraction/font-client-impl.cpp
text/dali/internal/text-abstraction/font-client-impl.h
text/dali/internal/text-abstraction/font-client-plugin-impl.cpp
text/dali/internal/text-abstraction/font-client-plugin-impl.h
text/dali/public-api/text-abstraction/font-client.cpp
text/dali/public-api/text-abstraction/font-client.h

index 0b4b6e7..9b5d5d2 100644 (file)
@@ -207,6 +207,13 @@ BufferImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
   return mPlugin->CreateBitmap( fontId, glyphIndex );
 }
 
+const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 pointSize )
+{
+  CreatePlugin();
+
+  return mPlugin->GetEllipsisGlyph( pointSize );
+}
+
 void FontClient::CreatePlugin()
 {
   if( !mPlugin )
index c465ead..18145c8 100644 (file)
@@ -142,7 +142,7 @@ public:
   GlyphIndex GetGlyphIndex( FontId fontId, Character charcode );
 
   /**
-   * @copydoc Dali::FontClient::CreateMetrics()
+   * @copydoc Dali::FontClient::GetGlyphMetrics()
    */
   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
 
@@ -151,6 +151,11 @@ public:
    */
   BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
 
+  /**
+   * @copydoc Dali::FontClient::GetEllipsisGlyph()
+   */
+  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
+
 private:
 
   /**
index 6e5198c..d44abc9 100644 (file)
@@ -21,7 +21,6 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/common/vector-wrapper.h>
-#include <dali/public-api/text-abstraction/glyph-info.h>
 #include <dali/integration-api/debug.h>
 
 // EXTERNAL INCLUDES
@@ -37,6 +36,8 @@ const float FROM_266 = 1.0f / 64.0f;
 const std::string FONT_FORMAT( "TrueType" );
 const std::string DEFAULT_FONT_FAMILY_NAME( "Tizen" );
 const std::string DEFAULT_FONT_STYLE( "Regular" );
+
+const uint32_t ELLIPSIS_CHARACTER = 0x2026;
 }
 
 using Dali::Vector;
@@ -114,7 +115,8 @@ FontClient::Plugin::Plugin( unsigned int horizontalDpi,
   mFontCache(),
   mValidatedFontCache(),
   mFontDescriptionCache( 1u ),
-  mFontIdCache()
+  mFontIdCache(),
+  mEllipsisCache()
 {
   int error = FT_Init_FreeType( &mFreeTypeLibrary );
   if( FT_Err_Ok != error )
@@ -605,6 +607,43 @@ BufferImage FontClient::Plugin::CreateBitmap( FontId fontId,
   return bitmap;
 }
 
+const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 pointSize )
+{
+  // First look into the cache if there is an ellipsis glyph for the requested point size.
+  for( Vector<EllipsisItem>::ConstIterator it = mEllipsisCache.Begin(),
+         endIt = mEllipsisCache.End();
+       it != endIt;
+       ++it )
+  {
+    const EllipsisItem& item = *it;
+
+    if( fabsf( item.size - pointSize ) < Math::MACHINE_EPSILON_1000 )
+    {
+      // Use the glyph in the cache.
+      return item.glyph;
+    }
+  }
+
+  // No glyph has been found. Create one.
+  mEllipsisCache.PushBack( EllipsisItem() );
+  EllipsisItem& item = *( mEllipsisCache.End() - 1u );
+
+  item.size = pointSize;
+
+  // Find a font for the ellipsis glyph.
+  item.glyph.fontId = FindDefaultFont( ELLIPSIS_CHARACTER,
+                                       pointSize,
+                                       false );
+
+  // Set the character index to access the glyph inside the font.
+  item.glyph.index = FT_Get_Char_Index( mFontCache[item.glyph.fontId-1].mFreeTypeFace,
+                                        ELLIPSIS_CHARACTER );
+
+  GetGlyphMetrics( &item.glyph, 1u, true );
+
+  return item.glyph;
+}
+
 void FontClient::Plugin::InitSystemFonts()
 {
   FcFontSet* fontSet = GetFcFontSet();
index 426a59e..538cb97 100644 (file)
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/public-api/text-abstraction/font-metrics.h>
+#include <dali/public-api/text-abstraction/glyph-info.h>
 #include <dali/internal/text-abstraction/font-client-impl.h>
 
 // EXTERNAL INCLUDES
@@ -107,6 +108,12 @@ struct FontClient::Plugin
     bool mIsFixedSizeBitmap;     ///< Whether the font has fixed size bitmaps.
   };
 
+  struct EllipsisItem
+  {
+    PointSize26Dot6 size;
+    GlyphInfo glyph;
+  };
+
   /**
    * Constructor.
    *
@@ -209,7 +216,7 @@ 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 );
 
@@ -218,6 +225,11 @@ struct FontClient::Plugin
    */
   BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
 
+  /**
+   * @copydoc Dali::FontClient::GetEllipsisGlyph()
+   */
+  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
+
 private:
 
   /**
@@ -351,6 +363,8 @@ private:
   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<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.
 };
 
 } // namespace Internal
index 80a202f..bc15200 100644 (file)
@@ -110,46 +110,51 @@ FontId FontClient::GetFontId( const FontFamily& fontFamily,
                                              faceIndex );
 }
 
-void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
+bool FontClient::IsScalable( const FontPath& path )
 {
-  GetImplementation(*this).GetFontMetrics( fontId, metrics );
+  return GetImplementation(*this).IsScalable( path );;
 }
 
-GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
+bool FontClient::IsScalable( const FontFamily& fontFamily, const FontStyle& style )
 {
-  return GetImplementation(*this).GetGlyphIndex( fontId, charcode );
+  return GetImplementation(*this).IsScalable( fontFamily, style );
 }
 
-bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal )
+void FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
 {
-  return GetImplementation(*this).GetGlyphMetrics( array, size, horizontal );
+  GetImplementation(*this).GetFixedSizes( path, sizes );
 }
 
-BufferImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
+void FontClient::GetFixedSizes( const FontFamily& fontFamily,
+                                const FontStyle& style,
+                                Dali::Vector< PointSize26Dot6 >& sizes )
 {
-  return GetImplementation(*this).CreateBitmap( fontId, glyphIndex );
+  GetImplementation(*this).GetFixedSizes( fontFamily, style, sizes );
 }
 
-bool FontClient::IsScalable( const FontPath& path )
+void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
 {
-  return GetImplementation(*this).IsScalable( path );;
+  GetImplementation(*this).GetFontMetrics( fontId, metrics );
 }
 
-bool FontClient::IsScalable( const FontFamily& fontFamily, const FontStyle& style )
+GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
 {
-  return GetImplementation(*this).IsScalable( fontFamily, style );
+  return GetImplementation(*this).GetGlyphIndex( fontId, charcode );
 }
 
-void FontClient::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6>& sizes )
+bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal )
 {
-  GetImplementation(*this).GetFixedSizes( path, sizes );
+  return GetImplementation(*this).GetGlyphMetrics( array, size, horizontal );
 }
 
-void FontClient::GetFixedSizes( const FontFamily& fontFamily,
-                                const FontStyle& style,
-                                Dali::Vector< PointSize26Dot6 >& sizes )
+BufferImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
 {
-  GetImplementation(*this).GetFixedSizes( fontFamily, style, sizes );
+  return GetImplementation(*this).CreateBitmap( fontId, glyphIndex );
+}
+
+const GlyphInfo& FontClient::GetEllipsisGlyph( PointSize26Dot6 pointSize )
+{
+  return GetImplementation(*this).GetEllipsisGlyph( pointSize );
 }
 
 FontClient::FontClient( Internal::FontClient* internal )
index 5215d18..06213fa 100644 (file)
@@ -277,6 +277,15 @@ public:
    */
   BufferImage CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
 
+  /**
+   * @brief Retrieves the ellipsis glyph for a requested point size.
+   *
+   * @param[in] pointSize The requested point size.
+   *
+   * @return The ellipsis glyph.
+   */
+  const GlyphInfo& GetEllipsisGlyph( PointSize26Dot6 pointSize );
+
 public: // Not intended for application developers
   /**
    * @brief This constructor is used by FontClient::Get().