From 08dd1f5b67464ad482a4045365cb53a4681f50e9 Mon Sep 17 00:00:00 2001 From: Paul Wisbey Date: Mon, 9 Mar 2015 19:05:24 +0000 Subject: [PATCH] Fix GlyphMetrics for fixed-size fonts Change-Id: Ib9a1c81ae44a9061ca3a85bdddc601349c246022 --- .../text-abstraction/font-client-plugin-impl.cpp | 53 +++++++++++++++------- .../text-abstraction/font-client-plugin-impl.h | 25 ++++++---- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp index da98bdc..6cdf4e6 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp @@ -58,7 +58,8 @@ FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const Fo : fontFamily( fontFamily ), fontStyle( fontStyle ), index( index ) -{} +{ +} FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validatedFontId, PointSize26Dot6 pointSize, @@ -66,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 ) @@ -454,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; } } @@ -704,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 ) diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.h b/text/dali/internal/text-abstraction/font-client-plugin-impl.h index e9da118..5885b19 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.h +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.h @@ -87,15 +87,24 @@ struct FontClient::Plugin const FontPath& path, PointSize26Dot6 pointSize, FaceIndex face, + const FontMetrics& metrics ); + + CacheItem( FT_Face ftFace, + const FontPath& path, + PointSize26Dot6 pointSize, + FaceIndex face, const FontMetrics& metrics, - bool isFixedSizeBitmap = false ); - - FT_Face mFreeTypeFace; ///< The FreeType face. - FontPath mPath; ///< The path to the font file name. - PointSize26Dot6 mPointSize; ///< The font point size. - FaceIndex mFaceIndex; ///< The face index. - FontMetrics mMetrics; ///< The font metrics. - bool mIsFixedSizeBitmap; ///< Font is fixed size bitmap. + float fixedWidth, + float fixedHeight ); + + FT_Face mFreeTypeFace; ///< The FreeType face. + FontPath mPath; ///< The path to the font file name. + PointSize26Dot6 mPointSize; ///< The font point size. + FaceIndex mFaceIndex; ///< The face index. + FontMetrics mMetrics; ///< The font metrics. + FT_Short mFixedWidthPixels; ///< The height in pixels (fixed size bitmaps only) + FT_Short mFixedHeightPixels; ///< The height in pixels (fixed size bitmaps only) + bool mIsFixedSizeBitmap; ///< Whether the font has fixed size bitmaps. }; /** -- 2.7.4