From: Victor Cebollada Date: Mon, 15 Apr 2019 14:36:55 +0000 (+0100) Subject: FontClient - Do not resize cache vectors to size one. X-Git-Tag: dali_1.4.16~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F203536%2F1;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git 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 --- 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 ) );