#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>
const std::string DEFAULT_FONT_STYLE( "Regular" );
}
+using Dali::Vector;
+
namespace Dali
{
: fontFamily( fontFamily ),
fontStyle( fontStyle ),
index( index )
-{}
+{
+}
FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validatedFontId,
PointSize26Dot6 pointSize,
: 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 )
}
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() )
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 );
}
}
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;
}
}
// 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 );
}
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 )
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();
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,