GetImplementation(*this).GetFixedSizes( fontFamily, style, sizes );
}
-void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
+void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize )
{
- GetImplementation(*this).GetFontMetrics( fontId, metrics );
+ GetImplementation(*this).GetFontMetrics( fontId, metrics, maxFixedSize );
}
GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
return GetImplementation(*this).GetGlyphIndex( fontId, charcode );
}
-bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal )
+bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal, int maxFixedSize )
{
- return GetImplementation(*this).GetGlyphMetrics( array, size, horizontal );
+ return GetImplementation(*this).GetGlyphMetrics( array, size, horizontal, maxFixedSize );
}
BufferImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
*
* @param[in] fontId The ID of the font for the required glyph.
* @param[out] metrics The font metrics.
+ * @param[in] maxFixedSize The metrics for fixed-size fonts will be down-scaled, when exceeding this maximum value in pixels.
*/
- void GetFontMetrics( FontId fontId, FontMetrics& metrics );
+ void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize = 0 );
/**
* @brief Retrieve the glyph index for a UTF-32 character code.
* On return, the glyph's size value will be initialized. The bearing value will be updated by adding the font's glyph bearing to the one set by the shaping tool.
* @param[in] size The size of the array.
* @param[in] horizontal True for horizontal layouts (set to false for vertical layouting).
+ * @param[in] maxFixedSize The metrics for fixed-size fonts will be down-scaled, when exceeding this maximum value in pixels.
* @return True if all of the requested metrics were found.
*/
- bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal = true );
+ bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal = true, int maxFixedSize = 0 );
/**
* @brief Render a bitmap representation of a glyph.
height( 0 ),
xBearing( 0 ),
yBearing( 0 ),
- advance( 0 )
+ advance( 0 ),
+ scaleFactor( 0 )
{
}
height( 0 ),
xBearing( 0 ),
yBearing( 0 ),
- advance( 0 )
+ advance( 0 ),
+ scaleFactor( 0 )
{
}
*/
GlyphInfo( FontId font, GlyphIndex i );
- FontId fontId; ///< Identifies the font containing the glyph
- GlyphIndex index; ///< Uniquely identifies a glyph for a given FontId
- float width; ///< The width of the glyph
- float height; ///< The height of the glyph
- float xBearing; ///< The distance from the cursor position to the leftmost border of the glyph
- float yBearing; ///< The distance from the baseline to the topmost border of the glyph
- float advance; ///< The distance to move the cursor for this glyph
+ FontId fontId; ///< Identifies the font containing the glyph
+ GlyphIndex index; ///< Uniquely identifies a glyph for a given FontId
+ float width; ///< The width of the glyph
+ float height; ///< The height of the glyph
+ float xBearing; ///< The distance from the cursor position to the leftmost border of the glyph
+ float yBearing; ///< The distance from the baseline to the topmost border of the glyph
+ float advance; ///< The distance to move the cursor for this glyph
+ float scaleFactor; ///< The scaling applied (fixed-size fonts only)
};
} // Dali
faceIndex );
}
-void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics )
+void FontClient::GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize )
{
CreatePlugin();
- return mPlugin->GetFontMetrics( fontId, metrics );
+ return mPlugin->GetFontMetrics( fontId, metrics, maxFixedSize );
}
GlyphIndex FontClient::GetGlyphIndex( FontId fontId, Character charcode )
return mPlugin->GetGlyphIndex( fontId, charcode );
}
-bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal )
+bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, bool horizontal, int maxFixedSize )
{
CreatePlugin();
- return mPlugin->GetGlyphMetrics( array, size, horizontal );
+ return mPlugin->GetGlyphMetrics( array, size, horizontal, maxFixedSize );
}
BufferImage FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
/**
* @copydoc Dali::FontClient::GetFontMetrics()
*/
- void GetFontMetrics( FontId fontId, FontMetrics& metrics );
+ void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize );
/**
* @copydoc Dali::FontClient::GetGlyphIndex()
/**
* @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()
FcPatternDestroy( fontFamilyPattern );
}
-
-
void FontClient::Plugin::GetFontMetrics( FontId fontId,
- FontMetrics& metrics )
+ FontMetrics& metrics,
+ int maxFixedSize )
{
if( fontId > 0 &&
fontId-1 < mFontCache.size() )
{
- metrics = mFontCache[fontId-1].mMetrics;
+ const CacheItem& font = mFontCache[fontId-1];
+
+ metrics = font.mMetrics;
+
+ // Adjust the metrics if the fixed-size font should be down-scaled
+ if( font.mIsFixedSizeBitmap &&
+ ( maxFixedSize > 0 ) &&
+ ( font.mFixedHeightPixels > maxFixedSize ) )
+ {
+ float scaleFactor = static_cast<float>(maxFixedSize) / static_cast<float>(font.mFixedHeightPixels);
+
+ metrics.ascender *= scaleFactor;
+ metrics.descender *= scaleFactor;
+ metrics.height *= scaleFactor;
+ metrics.underlinePosition *= scaleFactor;
+ metrics.underlineThickness *= scaleFactor;
+ }
}
else
{
bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
uint32_t size,
- bool horizontal )
+ bool horizontal,
+ int maxFixedSize )
{
bool success( true );
if( fontId > 0 &&
fontId-1 < mFontCache.size() )
{
- FT_Face ftFace = mFontCache[fontId-1].mFreeTypeFace;
+ const CacheItem& font = mFontCache[fontId-1];
+
+ FT_Face ftFace = font.mFreeTypeFace;
#ifdef FREETYPE_BITMAP_SUPPORT
// Check to see if we should be loading a Fixed Size bitmap?
- if ( mFontCache[fontId-1].mIsFixedSizeBitmap )
+ if ( font.mIsFixedSizeBitmap )
{
int error = FT_Load_Glyph( ftFace, array[i].index, FT_LOAD_COLOR );
if ( FT_Err_Ok == error )
{
- array[i].width = mFontCache[ fontId -1 ].mFixedWidthPixels;
- array[i].height = mFontCache[ fontId -1 ].mFixedHeightPixels;
- array[i].advance = mFontCache[ fontId -1 ].mFixedWidthPixels;
+ array[i].width = font.mFixedWidthPixels;
+ array[i].height = font.mFixedHeightPixels;
+ array[i].advance = font.mFixedWidthPixels;
array[i].xBearing = 0.0f;
- array[i].yBearing = mFontCache[ fontId -1 ].mFixedHeightPixels;
+ array[i].yBearing = font.mFixedHeightPixels;
+
+ // Adjust the metrics if the fixed-size font should be down-scaled
+ if( ( maxFixedSize > 0 ) &&
+ ( font.mFixedHeightPixels > maxFixedSize ) )
+ {
+ float scaleFactor = static_cast<float>(maxFixedSize) / static_cast<float>(font.mFixedHeightPixels);
+
+ array[i].width *= scaleFactor;
+ array[i].height *= scaleFactor;
+ array[i].advance *= scaleFactor;
+ array[i].xBearing *= scaleFactor;
+ array[i].yBearing *= scaleFactor;
+
+ array[i].scaleFactor = scaleFactor;
+ }
}
else
{
item.glyph.index = FT_Get_Char_Index( mFontCache[item.glyph.fontId-1].mFreeTypeFace,
ELLIPSIS_CHARACTER );
- GetGlyphMetrics( &item.glyph, 1u, true );
+ GetGlyphMetrics( &item.glyph, 1u, true, 0 );
return item.glyph;
}
float fixedHeight = static_cast< float >( ftFace->available_sizes[ i ].height );
// Indicate that the font is a fixed sized bitmap
- FontMetrics metrics( fixedHeight,
+ FontMetrics metrics( fixedHeight, // The ascender in pixels.
0.0f,
- fixedHeight,
+ fixedHeight, // The height in pixels.
0.0f,
0.0f );
/**
* @copydoc Dali::FontClient::GetFontMetrics()
*/
- void GetFontMetrics( FontId fontId, FontMetrics& metrics );
+ void GetFontMetrics( FontId fontId, FontMetrics& metrics, int maxFixedSize );
/**
* @copydoc Dali::FontClient::GetGlyphIndex()
/**
* @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()