Fixed build break
[platform/core/uifw/dali-adaptor.git] / text / dali / internal / text-abstraction / font-client-plugin-impl.cpp
index e6d68c3..de95bd1 100644 (file)
@@ -19,6 +19,7 @@
 #include <dali/internal/text-abstraction/font-client-plugin-impl.h>
 
 // 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>
@@ -38,6 +39,8 @@ const std::string DEFAULT_FONT_FAMILY_NAME( "Tizen" );
 const std::string DEFAULT_FONT_STYLE( "Regular" );
 }
 
+using Dali::Vector;
+
 namespace Dali
 {
 
@@ -55,7 +58,8 @@ FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const Fo
 : fontFamily( fontFamily ),
   fontStyle( fontStyle ),
   index( index )
-{}
+{
+}
 
 FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validatedFontId,
                                                       PointSize26Dot6 pointSize,
@@ -63,21 +67,42 @@ FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validate
 : validatedFontId( validatedFontId ),
   pointSize( pointSize ),
   fontId( fontId )
-{}
+{
+}
+
+FontClient::Plugin::CacheItem::CacheItem( FT_Face ftFace,
+                                          const FontPath& path,
+                                          PointSize26Dot6 pointSize,
+                                          FaceIndex face,
+                                          const FontMetrics& metrics )
+: mFreeTypeFace( ftFace ),
+  mPath( path ),
+  mPointSize( pointSize ),
+  mFaceIndex( face ),
+  mMetrics( metrics ),
+  mFixedWidthPixels( 0.0f ),
+  mFixedHeightPixels( 0.0f ),
+  mIsFixedSizeBitmap( false )
+{
+}
 
 FontClient::Plugin::CacheItem::CacheItem( FT_Face ftFace,
                                           const FontPath& path,
                                           PointSize26Dot6 pointSize,
                                           FaceIndex face,
                                           const FontMetrics& metrics,
-                                          bool isFixedSizeBitmap )
+                                          float fixedWidth,
+                                          float fixedHeight )
 : mFreeTypeFace( ftFace ),
   mPath( path ),
   mPointSize( pointSize ),
   mFaceIndex( face ),
   mMetrics( metrics ),
-  mIsFixedSizeBitmap( isFixedSizeBitmap )
-{}
+  mFixedWidthPixels( fixedWidth ),
+  mFixedHeightPixels( fixedHeight ),
+  mIsFixedSizeBitmap( true )
+{
+}
 
 FontClient::Plugin::Plugin( unsigned int horizontalDpi,
                             unsigned int verticalDpi )
@@ -216,7 +241,7 @@ PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id )
 }
 
 FontId FontClient::Plugin::FindDefaultFont( Character charcode,
-                                            PointSize26Dot6 pointSize )
+                                            PointSize26Dot6 requestedSize )
 {
   // Create the list of default fonts if it has not been created.
   if( mDefaultFonts.empty() )
@@ -246,9 +271,30 @@ FontId FontClient::Plugin::FindDefaultFont( Character charcode,
 
     if( FcCharSetHasChar( charSet, charcode ) )
     {
+      Vector< PointSize26Dot6 > fixedSizes;
+      GetFixedSizes( description.family,
+                     description.style,
+                     fixedSizes );
+
+      const Vector< PointSize26Dot6 >::SizeType count = fixedSizes.Count();
+      if( 0 != count )
+      {
+        // If the font is not scalable, pick the largest size <= requestedSize
+        PointSize26Dot6 size = fixedSizes[0];
+        for( unsigned int i=1; i<count; ++i )
+        {
+          if( fixedSizes[i] <= requestedSize &&
+              fixedSizes[i] > size )
+          {
+            size = fixedSizes[i];
+          }
+        }
+        requestedSize = size;
+      }
+
       return GetFontId( description.family,
                         description.style,
-                        pointSize,
+                        requestedSize,
                         0u );
     }
   }
@@ -430,20 +476,16 @@ bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
         int error = FT_Load_Glyph( ftFace, array[i].index, FT_LOAD_COLOR );
         if ( FT_Err_Ok == error )
         {
-          // TODO passing height for metrics, should store width, height and advance
-
-          float height = mFontCache[ fontId -1 ].mMetrics.height;
-          array[i].width = height;
-          array[i].height = height;
-          array[i].advance = height;
+          array[i].width = mFontCache[ fontId -1 ].mFixedWidthPixels;
+          array[i].height = mFontCache[ fontId -1 ].mFixedHeightPixels;
+          array[i].advance = mFontCache[ fontId -1 ].mFixedWidthPixels;
           array[i].xBearing = 0.0f;
-          array[i].yBearing = 0.0f;
-          return success;
+          array[i].yBearing = mFontCache[ fontId -1 ].mFixedHeightPixels;
         }
         else
         {
           DALI_LOG_ERROR( "FreeType Bitmap Load_Glyph error %d\n", error );
-          return false;
+          success = false;
         }
       }
 
@@ -670,7 +712,7 @@ FontId FontClient::Plugin::CreateFont( const FontPath& path,
       // Ensure this size is available
       for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
       {
-        if ( pointSize == ftFace->available_sizes[ i ].size )
+        if ( static_cast<FT_Pos>(pointSize) == ftFace->available_sizes[ i ].size )
         {
           // Tell Freetype to use this size
           error = FT_Select_Size( ftFace, i );
@@ -680,12 +722,15 @@ FontId FontClient::Plugin::CreateFont( const FontPath& path,
           }
           else
           {
+            float fixedWidth  = static_cast< float >( ftFace->available_sizes[ i ].width );
+            float fixedHeight = static_cast< float >( ftFace->available_sizes[ i ].height );
+
             // Indicate that the font is a fixed sized bitmap
             FontMetrics metrics( 0.0f,
                                  0.0f,
-                                 static_cast< float >( ftFace->available_sizes[ i ].height ) );
+                                 fixedHeight );
 
-            mFontCache.push_back( CacheItem( ftFace, path, pointSize, faceIndex, metrics, FONT_FIXED_SIZE_BITMAP ) );
+            mFontCache.push_back( CacheItem( ftFace, path, pointSize, faceIndex, metrics, fixedWidth, fixedHeight ) );
             id = mFontCache.size();
 
             if( cacheDescription )
@@ -908,7 +953,7 @@ bool FontClient::Plugin::IsScalable( const FontFamily& fontFamily, const FontSty
   return true;
 }
 
-void FontClient::Plugin::GetFixedSizes( const FontPath& path, Dali::Vector< PointSize26Dot6 >& sizes )
+void FontClient::Plugin::GetFixedSizes( const FontPath& path, Vector< PointSize26Dot6 >& sizes )
 {
   // Empty the caller container
   sizes.Clear();
@@ -935,7 +980,7 @@ void FontClient::Plugin::GetFixedSizes( const FontPath& path, Dali::Vector< Poin
 
 void FontClient::Plugin::GetFixedSizes( const FontFamily& fontFamily,
                                         const FontStyle& fontStyle,
-                                        Dali::Vector< PointSize26Dot6 >& sizes )
+                                        Vector< PointSize26Dot6 >& sizes )
 {
   // Create a font pattern.
   FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontFamily,