From 1ff9108626c8c2c5e7e2f1f2795af698372cf134 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Mon, 15 Apr 2019 15:36:55 +0100 Subject: [PATCH] FontClient - Do not resize cache vectors to size one. * The font id 0 is invalid. Some caches were adding an extra item in the position 0 to use the same index to access the cached value. * Do not add this extra item and use the index-1 instead. Change-Id: I0972fdba8cbee8a65750bf2092615e03313e9102 Signed-off-by: Victor Cebollada --- .../text-abstraction/font-client-plugin-impl.cpp | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp index a53fd1b..319f35e 100755 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp @@ -241,7 +241,7 @@ FontClient::Plugin::Plugin( unsigned int horizontalDpi, mFontIdCache(), mFontFaceCache(), mValidatedFontCache(), - mFontDescriptionCache( 1u ), + mFontDescriptionCache(), mCharacterSetCache(), mFontDescriptionSizeCache(), mVectorFontCache( nullptr ), @@ -249,8 +249,6 @@ FontClient::Plugin::Plugin( unsigned int horizontalDpi, mEmbeddedItemCache(), mDefaultFontDescriptionCached( false ) { - mCharacterSetCache.Resize( 1u ); - int error = FT_Init_FreeType( &mFreeTypeLibrary ); if( FT_Err_Ok != error ) { @@ -298,11 +296,9 @@ void FontClient::Plugin::ClearCache() mValidatedFontCache.clear(); mFontDescriptionCache.clear(); - mFontDescriptionCache.resize( 1u ); DestroyCharacterSets( mCharacterSetCache ); mCharacterSetCache.Clear(); - mCharacterSetCache.Resize( 1u ); mFontDescriptionSizeCache.clear(); @@ -549,7 +545,7 @@ void FontClient::Plugin::GetDescription( FontId id, { if( item.fontId == fontIdCacheItem.id ) { - fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId ); + fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId - 1u ); DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() ); DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() ); @@ -944,7 +940,7 @@ FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription, if( !FindFont( validatedFontId, requestedPointSize, fontFaceId ) ) { // Retrieve the font file name path. - const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId ); + const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId - 1u ); // Retrieve the font id. Do not cache the description as it has been already cached. fontId = GetFontId( description.path, @@ -953,7 +949,7 @@ FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription, false ); fontFaceId = mFontIdCache[fontId-1u].id; - mFontFaceCache[fontFaceId].mCharacterSet = FcCharSetCopy( mCharacterSetCache[validatedFontId] ); + mFontFaceCache[fontFaceId].mCharacterSet = FcCharSetCopy( mCharacterSetCache[validatedFontId - 1u] ); // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries. mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId, @@ -1042,6 +1038,10 @@ void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription, if( matched && ( nullptr != characterSet ) ) { + // Add the path to the cache. + description.type = FontDescription::FACE_FONT; + mFontDescriptionCache.push_back( description ); + // Set the index to the vector of paths to font file names. validatedFontId = mFontDescriptionCache.size(); @@ -1052,10 +1052,6 @@ void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription, DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] ); DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId ); - // Add the path to the cache. - description.type = FontDescription::FACE_FONT; - mFontDescriptionCache.push_back( description ); - // The reference counter of the character set has already been increased in MatchFontDescriptionToPattern. mCharacterSetCache.PushBack( characterSet ); @@ -2606,9 +2602,6 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do if( !FindValidatedFont( description, validatedFontId ) ) { - // Set the index to the vector of paths to font file names. - validatedFontId = mFontDescriptionCache.size(); - FcPattern* pattern = CreateFontFamilyPattern( description ); // Creates a new pattern that needs to be destroyed by calling FcPatternDestroy. FcResult result = FcResultMatch; @@ -2628,6 +2621,9 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do description.type = FontDescription::FACE_FONT; mFontDescriptionCache.push_back( description ); + // Set the index to the vector of paths to font file names. + validatedFontId = mFontDescriptionCache.size(); + // Increase the reference counter and add the character set to the cache. mCharacterSetCache.PushBack( FcCharSetCopy( characterSet ) ); -- 2.7.4