From c3609bbca47a9e8851e765ff9603649e0a348a88 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Thu, 5 Jul 2018 10:49:28 +0100 Subject: [PATCH] FontClient - Minor refactoring. * Renames some font caches to match what they store. * Some c++11 updates. Change-Id: Ica93be1abea21d7e39b9635ae4e7f0213f5aa6be Signed-off-by: Victor Cebollada --- dali/devel-api/text-abstraction/font-client.cpp | 2 +- .../text/text-abstraction/font-client-impl.cpp | 2 +- .../text-abstraction/font-client-plugin-impl.cpp | 274 +++++++++------------ .../text-abstraction/font-client-plugin-impl.h | 28 ++- 4 files changed, 136 insertions(+), 170 deletions(-) diff --git a/dali/devel-api/text-abstraction/font-client.cpp b/dali/devel-api/text-abstraction/font-client.cpp index 43519c8..e49410a 100644 --- a/dali/devel-api/text-abstraction/font-client.cpp +++ b/dali/devel-api/text-abstraction/font-client.cpp @@ -30,7 +30,7 @@ namespace TextAbstraction const PointSize26Dot6 FontClient::DEFAULT_POINT_SIZE = 768u; // 12*64 FontClient::GlyphBufferData::GlyphBufferData() -: buffer( NULL ), +: buffer( nullptr ), width( 0u ), height( 0u ), format( Pixel::A8 ) diff --git a/dali/internal/text/text-abstraction/font-client-impl.cpp b/dali/internal/text/text-abstraction/font-client-impl.cpp index 2d47928..6e081af 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-impl.cpp @@ -37,7 +37,7 @@ namespace Internal { FontClient::FontClient() -: mPlugin( NULL ), +: mPlugin( nullptr ), mDpiHorizontal( 0 ), mDpiVertical( 0 ) { 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 14efb7b..fc85a4b 100644 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -138,23 +138,30 @@ FontSlant::Type IntToSlantType( int slant ) return static_cast( ValueToIndex( slant, FONT_SLANT_TYPE_TO_INT, NUM_FONT_SLANT_TYPE - 1u ) ); } - FontClient::Plugin::FallbackCacheItem::FallbackCacheItem( const FontDescription& font, FontList* fallbackFonts, CharacterSetList* characterSets ) -: fontDescription( font ), - fallbackFonts( fallbackFonts ), - characterSets( characterSets ) +FontClient::Plugin::FallbackCacheItem::FallbackCacheItem( FontDescription&& font, FontList* fallbackFonts, CharacterSetList* characterSets ) +: fontDescription{ std::move( font ) }, + fallbackFonts{ fallbackFonts }, + characterSets{ characterSets } { } FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const FontDescription& fontDescription, FontDescriptionId index ) -: fontDescription( fontDescription ), - index( index ) +: fontDescription{ fontDescription }, + index{ index } { } -FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validatedFontId, - PointSize26Dot6 requestedPointSize, - FontId fontId ) +FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( FontDescription&& fontDescription, + FontDescriptionId index ) +: fontDescription{ std::move( fontDescription ) }, + index{ index } +{ +} + +FontClient::Plugin::FontDescriptionSizeCacheItem::FontDescriptionSizeCacheItem( FontDescriptionId validatedFontId, + PointSize26Dot6 requestedPointSize, + FontId fontId ) : validatedFontId( validatedFontId ), requestedPointSize( requestedPointSize ), fontId( fontId ) @@ -171,7 +178,7 @@ FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace, mRequestedPointSize( requestedPointSize ), mFaceIndex( face ), mMetrics( metrics ), - mCharacterSet( NULL ), + mCharacterSet( nullptr ), mFixedWidthPixels( 0.0f ), mFixedHeightPixels( 0.0f ), mVectorFontId( 0 ), @@ -193,7 +200,7 @@ FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace, mRequestedPointSize( requestedPointSize ), mFaceIndex( face ), mMetrics( metrics ), - mCharacterSet( NULL ), + mCharacterSet( nullptr ), mFixedWidthPixels( fixedWidth ), mFixedHeightPixels( fixedHeight ), mVectorFontId( 0 ), @@ -204,18 +211,18 @@ FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace, FontClient::Plugin::Plugin( unsigned int horizontalDpi, unsigned int verticalDpi ) -: mFreeTypeLibrary( NULL ), +: mFreeTypeLibrary( nullptr ), mDpiHorizontal( horizontalDpi ), mDpiVertical( verticalDpi ), mDefaultFontDescription(), mSystemFonts(), mDefaultFonts(), - mFontCache(), + mFontFaceCache(), mValidatedFontCache(), mFontDescriptionCache( 1u ), mCharacterSetCache(), - mFontIdCache(), - mVectorFontCache( NULL ), + mFontDescriptionSizeCache(), + mVectorFontCache( nullptr ), mEllipsisCache(), mDefaultFontDescriptionCached( false ) { @@ -234,18 +241,14 @@ FontClient::Plugin::Plugin( unsigned int horizontalDpi, FontClient::Plugin::~Plugin() { - for( std::vector::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); - it != endIt; - ++it ) + for( auto& item : mFallbackCache ) { - FallbackCacheItem& item = *it; - if( item.fallbackFonts ) { delete item.fallbackFonts; delete item.characterSets; - item.fallbackFonts = NULL; - item.characterSets = NULL; + item.fallbackFonts = nullptr; + item.characterSets = nullptr; } } @@ -283,13 +286,13 @@ void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, Fo FcResult result = FcResultMatch; // Match the pattern. - FcFontSet* fontSet = FcFontSort( NULL /* use default configure */, + FcFontSet* fontSet = FcFontSort( nullptr /* use default configure */, fontFamilyPattern, false /* don't trim */, - NULL, + nullptr, &result ); - if( NULL != fontSet ) + if( nullptr != fontSet ) { DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts found : [%d]\n", fontSet->nfont ); // Reserve some space to avoid reallocations. @@ -304,14 +307,14 @@ void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, Fo // Skip fonts with no path if( GetFcString( fontPattern, FC_FILE, path ) ) { - FcCharSet* characterSet = NULL; + FcCharSet* characterSet = nullptr; FcPatternGetCharSet( fontPattern, FC_CHARSET, 0u, &characterSet ); characterSetList.PushBack( characterSet ); fontList.push_back( FontDescription() ); FontDescription& newFontDescription = fontList.back(); - newFontDescription.path = path; + newFontDescription.path = std::move( path ); int width = 0; int weight = 0; @@ -373,19 +376,15 @@ void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fon mDefaultFontCharacterSets.Clear(); mCharacterSetCache.Clear(); - for( std::vector::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); it != endIt; ++it ) + for( auto& item : mFallbackCache ) { - FallbackCacheItem& item = *it; - item.characterSets->Clear(); } - for( std::vector::iterator it = mFontCache.begin(), endIt = mFontCache.end(); it != endIt; ++it ) + for( auto& item : mFontFaceCache ) { - FontFaceCacheItem& item = *it; - // Set the character set pointer as null. Will be created again the next time IsCharacterSupportedByFont() - item.mCharacterSet = NULL; + item.mCharacterSet = nullptr; } // FcInitBringUptoDate did not seem to reload config file as was still getting old default font. @@ -395,44 +394,37 @@ void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fon if( matchPattern ) { - FcConfigSubstitute( NULL, matchPattern, FcMatchPattern ); + FcConfigSubstitute( nullptr, matchPattern, FcMatchPattern ); FcDefaultSubstitute( matchPattern ); - FcCharSet* characterSet = NULL; + FcCharSet* characterSet = nullptr; MatchFontDescriptionToPattern( matchPattern, mDefaultFontDescription, &characterSet ); FcPatternDestroy( matchPattern ); } // Create again the character sets as they are not valid after FcInitReinitialize() - for( FontList::const_iterator it = mDefaultFonts.begin(), endIt = mDefaultFonts.end(); it != endIt; ++it ) + for( const auto& description : mDefaultFonts ) { - const FontDescription& description = *it; - mDefaultFontCharacterSets.PushBack( CreateCharacterSetFromDescription( description ) ); } - for( FontList::const_iterator it = mFontDescriptionCache.begin(), endIt = mFontDescriptionCache.end(); it != endIt; ++it ) + for( const auto& description : mFontDescriptionCache ) { - const FontDescription& description = *it; - mCharacterSetCache.PushBack( CreateCharacterSetFromDescription( description ) ); } - for( std::vector::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); it != endIt; ++it ) + for( auto& item : mFallbackCache ) { - FallbackCacheItem& item = *it; - - if( NULL != item.fallbackFonts ) + if( nullptr != item.fallbackFonts ) { - if( NULL == item.characterSets ) + if( nullptr == item.characterSets ) { item.characterSets = new CharacterSetList; } - for( FontList::const_iterator flIt = item.fallbackFonts->begin(), flEndIt = item.fallbackFonts->end(); flIt != flEndIt; ++flIt ) + for( const auto& description : *( item.fallbackFonts ) ) { - const FontDescription& description = *flIt; item.characterSets->PushBack( CreateCharacterSetFromDescription( description ) ); } } @@ -475,13 +467,8 @@ void FontClient::Plugin::GetDescription( FontId id, DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDescription\n"); DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id ); - for( std::vector::const_iterator it = mFontIdCache.begin(), - endIt = mFontIdCache.end(); - it != endIt; - ++it ) + for( const auto& item : mFontDescriptionSizeCache ) { - const FontIdCacheItem& item = *it; - if( item.fontId == id ) { fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId ); @@ -507,11 +494,11 @@ PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id ) const FontId index = id - 1u; if( ( id > 0u ) && - ( index < mFontCache.size() ) ) + ( index < mFontFaceCache.size() ) ) { - DALI_LOG_INFO( gLogFilter, Debug::General, " point size : %d\n", ( *( mFontCache.begin() + index ) ).mRequestedPointSize ); + DALI_LOG_INFO( gLogFilter, Debug::General, " point size : %d\n", ( *( mFontFaceCache.begin() + index ) ).mRequestedPointSize ); DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n"); - return ( *( mFontCache.begin() + index ) ).mRequestedPointSize; + return ( *( mFontFaceCache.begin() + index ) ).mRequestedPointSize; } else { @@ -529,9 +516,9 @@ bool FontClient::Plugin::IsCharacterSupportedByFont( FontId fontId, Character ch DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId ); DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character ); - if( ( fontId < 1u ) || ( fontId > mFontCache.size() ) ) + if( ( fontId < 1u ) || ( fontId > mFontFaceCache.size() ) ) { - DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font id. Number of items in the cache: %d\n",mFontCache.size()); + DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font id. Number of items in the cache: %d\n",mFontFaceCache.size()); DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n"); return false; } @@ -540,16 +527,16 @@ bool FontClient::Plugin::IsCharacterSupportedByFont( FontId fontId, Character ch bool isSupported = false; - FontFaceCacheItem& cacheItem = mFontCache[fontId]; + FontFaceCacheItem& cacheItem = mFontFaceCache[fontId]; - if( NULL == cacheItem.mCharacterSet ) + if( nullptr == cacheItem.mCharacterSet ) { // Create again the character set. // It can be null if the ResetSystemDefaults() method has been called. FontDescription description; description.path = cacheItem.mPath; - description.family = FontFamily( cacheItem.mFreeTypeFace->family_name ); + description.family = std::move( FontFamily( cacheItem.mFreeTypeFace->family_name ) ); description.weight = FontWeight::NONE; description.width = FontWidth::NONE; description.slant = FontSlant::NONE; @@ -606,7 +593,7 @@ FontId FontClient::Plugin::FindFontForCharacter( const FontList& fontList, DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] ); bool foundInRanges = false; - if( NULL != characterSet ) + if( nullptr != characterSet ) { foundInRanges = FcCharSetHasChar( characterSet, character ); } @@ -622,9 +609,9 @@ FontId FontClient::Plugin::FindFontForCharacter( const FontList& fontList, if( preferColor ) { if( ( fontId > 0 ) && - ( fontId - 1u < mFontCache.size() ) ) + ( fontId - 1u < mFontFaceCache.size() ) ) { - const FontFaceCacheItem& item = mFontCache[fontId - 1u]; + const FontFaceCacheItem& item = mFontFaceCache[fontId - 1u]; foundColor = item.mHasColorTables; } @@ -708,8 +695,8 @@ FontId FontClient::Plugin::FindFallbackFont( Character charcode, DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant] ); // Check first if the font's description has been queried before. - FontList* fontList = NULL; - CharacterSetList* characterSetList = NULL; + FontList* fontList = nullptr; + CharacterSetList* characterSetList = nullptr; if( !FindFallbackFontList( fontDescription, fontList, characterSetList ) ) { @@ -719,7 +706,7 @@ FontId FontClient::Plugin::FindFallbackFont( Character charcode, SetFontList( fontDescription, *fontList, *characterSetList ); // Add the font-list to the cache. - mFallbackCache.push_back( FallbackCacheItem( fontDescription, fontList, characterSetList ) ); + mFallbackCache.push_back( std::move( FallbackCacheItem( std::move( fontDescription ), fontList, characterSetList ) ) ); } if( fontList && characterSetList ) @@ -743,7 +730,7 @@ FontId FontClient::Plugin::GetFontId( const FontPath& path, FontId id( 0 ); - if( NULL != mFreeTypeLibrary ) + if( nullptr != mFreeTypeLibrary ) { FontId foundId(0); if( FindFont( path, requestedPointSize, faceIndex, foundId ) ) @@ -815,12 +802,12 @@ FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription, faceIndex, false ); - mFontCache[fontId-1u].mCharacterSet = mCharacterSetCache[validatedFontId]; + mFontFaceCache[fontId-1u].mCharacterSet = mCharacterSetCache[validatedFontId]; // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries. - mFontIdCache.push_back( FontIdCacheItem( validatedFontId, - requestedPointSize, - fontId ) ); + mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId, + requestedPointSize, + fontId ) ); } DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId ); @@ -844,11 +831,11 @@ void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription, FontDescription description; - FcCharSet* characterSet = NULL; + FcCharSet* characterSet = nullptr; bool matched = MatchFontDescriptionToPattern( fontFamilyPattern, description, &characterSet ); FcPatternDestroy( fontFamilyPattern ); - if( matched && ( NULL != characterSet ) ) + if( matched && ( nullptr != characterSet ) ) { // Set the index to the vector of paths to font file names. validatedFontId = mFontDescriptionCache.size(); @@ -868,7 +855,7 @@ void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription, FontDescriptionCacheItem item( description, validatedFontId ); - mValidatedFontCache.push_back( item ); + mValidatedFontCache.push_back( std::move( item ) ); if( ( fontDescription.family != description.family ) || ( fontDescription.width != description.width ) || @@ -879,7 +866,7 @@ void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription, FontDescriptionCacheItem item( fontDescription, validatedFontId ); - mValidatedFontCache.push_back( item ); + mValidatedFontCache.push_back( std::move( item ) ); } } else @@ -894,9 +881,9 @@ void FontClient::Plugin::GetFontMetrics( FontId fontId, FontMetrics& metrics ) { if( ( fontId > 0 ) && - ( fontId - 1u < mFontCache.size() ) ) + ( fontId - 1u < mFontFaceCache.size() ) ) { - const FontFaceCacheItem& font = mFontCache[fontId-1]; + const FontFaceCacheItem& font = mFontFaceCache[fontId-1]; metrics = font.mMetrics; @@ -929,9 +916,9 @@ GlyphIndex FontClient::Plugin::GetGlyphIndex( FontId fontId, GlyphIndex index = 0u; if( ( fontId > 0u ) && - ( fontId - 1u < mFontCache.size() ) ) + ( fontId - 1u < mFontFaceCache.size() ) ) { - FT_Face ftFace = mFontCache[fontId-1u].mFreeTypeFace; + FT_Face ftFace = mFontFaceCache[fontId-1u].mFreeTypeFace; index = FT_Get_Char_Index( ftFace, charcode ); } @@ -965,9 +952,9 @@ bool FontClient::Plugin::GetBitmapMetrics( GlyphInfo* array, FontId fontId = glyph.fontId; if( fontId > 0 && - fontId-1 < mFontCache.size() ) + fontId-1 < mFontFaceCache.size() ) { - const FontFaceCacheItem& font = mFontCache[fontId-1]; + const FontFaceCacheItem& font = mFontFaceCache[fontId-1]; FT_Face ftFace = font.mFreeTypeFace; @@ -1053,9 +1040,9 @@ bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array, FontId fontId = array[i].fontId; if( fontId > 0 && - fontId-1 < mFontCache.size() ) + fontId-1 < mFontFaceCache.size() ) { - FontFaceCacheItem& font = mFontCache[fontId-1]; + FontFaceCacheItem& font = mFontFaceCache[fontId-1]; if( ! font.mVectorFontId ) { @@ -1087,15 +1074,15 @@ bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array, void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth ) { if( ( fontId > 0 ) && - ( fontId - 1u < mFontCache.size() ) ) + ( fontId - 1u < mFontFaceCache.size() ) ) { - FT_Face ftFace = mFontCache[fontId - 1u].mFreeTypeFace; + FT_Face ftFace = mFontFaceCache[fontId - 1u].mFreeTypeFace; FT_Error error; #ifdef FREETYPE_BITMAP_SUPPORT // Check to see if this is fixed size bitmap - if ( mFontCache[fontId - 1u].mIsFixedSizeBitmap ) + if ( mFontFaceCache[fontId - 1u].mIsFixedSizeBitmap ) { error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR ); } @@ -1184,14 +1171,14 @@ PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex void FontClient::Plugin::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight ) { - blob = NULL; + blob = nullptr; blobLength = 0; #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING if( fontId > 0 && - fontId-1 < mFontCache.size() ) + fontId-1 < mFontFaceCache.size() ) { - FontFaceCacheItem& font = mFontCache[fontId-1]; + FontFaceCacheItem& font = mFontFaceCache[fontId-1]; if( ! font.mVectorFontId ) { @@ -1209,13 +1196,8 @@ const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 requested DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize %d.\n", requestedPointSize ); // First look into the cache if there is an ellipsis glyph for the requested point size. - for( Vector::ConstIterator it = mEllipsisCache.Begin(), - endIt = mEllipsisCache.End(); - it != endIt; - ++it ) + for( const auto& item : mEllipsisCache ) { - const EllipsisItem& item = *it; - if( fabsf( item.requestedPointSize - requestedPointSize ) < Math::MACHINE_EPSILON_1000 ) { // Use the glyph in the cache. @@ -1240,7 +1222,7 @@ const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 requested false ); // Set the character index to access the glyph inside the font. - item.glyph.index = FT_Get_Char_Index( mFontCache[item.glyph.fontId-1].mFreeTypeFace, + item.glyph.index = FT_Get_Char_Index( mFontFaceCache[item.glyph.fontId-1].mFreeTypeFace, ELLIPSIS_CHARACTER ); GetBitmapMetrics( &item.glyph, 1u, true ); @@ -1258,9 +1240,9 @@ bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex ) #ifdef FREETYPE_BITMAP_SUPPORT if( ( fontId > 0 ) && - ( fontId - 1u < mFontCache.size() ) ) + ( fontId - 1u < mFontFaceCache.size() ) ) { - const FontFaceCacheItem& item = mFontCache[fontId - 1u]; + const FontFaceCacheItem& item = mFontFaceCache[fontId - 1u]; FT_Face ftFace = item.mFreeTypeFace; // Check to see if this is fixed size bitmap @@ -1299,7 +1281,7 @@ void FontClient::Plugin::InitSystemFonts() mSystemFonts.push_back( FontDescription() ); FontDescription& fontDescription = mSystemFonts.back(); - fontDescription.path = path; + fontDescription.path = std::move( path ); int width = 0; int weight = 0; @@ -1330,9 +1312,9 @@ bool FontClient::Plugin::MatchFontDescriptionToPattern( FcPattern* pattern, Dali DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::MatchFontDescriptionToPattern\n" ); FcResult result = FcResultMatch; - FcPattern* match = FcFontMatch( NULL /* use default configure */, pattern, &result ); + FcPattern* match = FcFontMatch( nullptr /* use default configure */, pattern, &result ); - const bool matched = NULL != match; + const bool matched = nullptr != match; DALI_LOG_INFO( gLogFilter, Debug::General, " pattern matched : %s\n", ( matched ? "true" : "false" ) ); if( matched ) @@ -1374,7 +1356,7 @@ FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& f if( !fontFamilyPattern ) { - return NULL; + return nullptr; } // add a property to the pattern for the font family @@ -1409,7 +1391,7 @@ FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& f FcPatternAddString( fontFamilyPattern , FC_FONTFORMAT, reinterpret_cast( FONT_FORMAT.c_str() ) ); // modify the config, with the mFontFamilyPatterm - FcConfigSubstitute( NULL /* use default configure */, fontFamilyPattern, FcMatchPattern ); + FcConfigSubstitute( nullptr /* use default configure */, fontFamilyPattern, FcMatchPattern ); // provide default values for unspecified properties in the font pattern // e.g. patterns without a specified style or weight are set to Medium @@ -1458,7 +1440,7 @@ bool FontClient::Plugin::GetFcString( const FcPattern* const pattern, const char* const n, std::string& string ) { - FcChar8* file = NULL; + FcChar8* file = nullptr; const FcResult retVal = FcPatternGetString( pattern, n, 0u, &file ); if( FcResultMatch == retVal ) @@ -1557,8 +1539,8 @@ FontId FontClient::Plugin::CreateFont( const FontPath& path, 0.0f, 0.0f ); - mFontCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics, fixedWidth, fixedHeight, hasColorTables ) ); - id = mFontCache.size(); + mFontFaceCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics, fixedWidth, fixedHeight, hasColorTables ) ); + id = mFontFaceCache.size(); } } else @@ -1580,8 +1562,8 @@ FontId FontClient::Plugin::CreateFont( const FontPath& path, static_cast< float >( ftFace->underline_position ) * FROM_266, static_cast< float >( ftFace->underline_thickness ) * FROM_266 ); - mFontCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics ) ); - id = mFontCache.size(); + mFontFaceCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics ) ); + id = mFontFaceCache.size(); } else { @@ -1681,21 +1663,16 @@ bool FontClient::Plugin::FindFont( const FontPath& path, DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" ); DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() ); DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize ); - DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fonts in the cache : %d\n", mFontCache.size() ); + DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fonts in the cache : %d\n", mFontFaceCache.size() ); fontId = 0u; - for( std::vector::const_iterator it = mFontCache.begin(), - endIt = mFontCache.end(); - it != endIt; - ++it, ++fontId ) + for( const auto& cacheItem : mFontFaceCache ) { - const FontFaceCacheItem& cacheItem = *it; - + ++fontId; if( cacheItem.mRequestedPointSize == requestedPointSize && cacheItem.mFaceIndex == faceIndex && cacheItem.mPath == path ) { - ++fontId; DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId ); DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" ); @@ -1707,6 +1684,7 @@ bool FontClient::Plugin::FindFont( const FontPath& path, DALI_LOG_INFO( gLogFilter, Debug::General, " font not found\n" ); DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" ); + fontId = 0u; return false; } @@ -1723,13 +1701,8 @@ bool FontClient::Plugin::FindValidatedFont( const FontDescription& fontDescripti validatedFontId = 0u; - for( std::vector::const_iterator it = mValidatedFontCache.begin(), - endIt = mValidatedFontCache.end(); - it != endIt; - ++it ) + for( const auto& item : mValidatedFontCache ) { - const FontDescriptionCacheItem& item = *it; - if( !fontDescription.family.empty() && ( fontDescription.family == item.fontDescription.family ) && ( fontDescription.width == item.fontDescription.width ) && @@ -1761,14 +1734,10 @@ bool FontClient::Plugin::FindFallbackFontList( const FontDescription& fontDescri DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] ); DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fallback font lists in the cache : %d\n", mFallbackCache.size() ); - fontList = NULL; + fontList = nullptr; - for( std::vector::const_iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); - it != endIt; - ++it ) + for( const auto& item : mFallbackCache ) { - const FallbackCacheItem& item = *it; - if( !fontDescription.family.empty() && ( fontDescription.family == item.fontDescription.family ) && ( fontDescription.width == item.fontDescription.width ) && @@ -1799,13 +1768,8 @@ bool FontClient::Plugin::FindFont( FontDescriptionId validatedFontId, fontId = 0u; - for( std::vector::const_iterator it = mFontIdCache.begin(), - endIt = mFontIdCache.end(); - it != endIt; - ++it ) + for( const auto& item : mFontDescriptionSizeCache ) { - const FontIdCacheItem& item = *it; - if( ( validatedFontId == item.validatedFontId ) && ( requestedPointSize == item.requestedPointSize ) ) { @@ -1851,7 +1815,7 @@ bool FontClient::Plugin::IsScalable( const FontDescription& fontDescription ) FcResult result = FcResultMatch; // match the pattern - FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result ); + FcPattern* match = FcFontMatch( nullptr /* use default configure */, fontFamilyPattern, &result ); bool isScalable = false; if( match ) @@ -1904,7 +1868,7 @@ void FontClient::Plugin::GetFixedSizes( const FontDescription& fontDescription, FcResult result = FcResultMatch; // match the pattern - FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result ); + FcPattern* match = FcFontMatch( nullptr /* use default configure */, fontFamilyPattern, &result ); if( match ) { @@ -1925,7 +1889,7 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do { FontDescription description; description.path = path; - description.family = FontFamily( ftFace->family_name ); + description.family = std::move( FontFamily( ftFace->family_name ) ); description.weight = FontWeight::NONE; description.width = FontWidth::NONE; description.slant = FontSlant::NONE; @@ -1950,43 +1914,42 @@ void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Do FcPattern* pattern = CreateFontFamilyPattern( description ); FcResult result = FcResultMatch; - FcPattern* match = FcFontMatch( NULL, pattern, &result ); + FcPattern* match = FcFontMatch( nullptr, pattern, &result ); - FcCharSet* characterSet = NULL; + FcCharSet* characterSet = nullptr; FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet ); FcPatternDestroy( pattern ); mMatchedFcPatternCache.PushBack( match ); - mFontCache[id-1u].mCharacterSet = characterSet; + + mFontFaceCache[id-1u].mCharacterSet = characterSet; // Add the path to the cache. mFontDescriptionCache.push_back( description ); mCharacterSetCache.PushBack( characterSet ); // Cache the index and the font's description. - FontDescriptionCacheItem item( description, - validatedFontId ); - - mValidatedFontCache.push_back( item ); + mValidatedFontCache.push_back( std::move( FontDescriptionCacheItem( std::move( description ), + validatedFontId) ) ); // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries. - mFontIdCache.push_back( FontIdCacheItem( validatedFontId, - requestedPointSize, - id ) ); + mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId, + requestedPointSize, + id ) ); } } FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) { - FcCharSet* characterSet = NULL; + FcCharSet* characterSet = nullptr; FcPattern* pattern = CreateFontFamilyPattern( description ); - if( NULL != pattern ) + if( nullptr != pattern ) { FcResult result = FcResultMatch; - FcPattern* match = FcFontMatch( NULL, pattern, &result ); + FcPattern* match = FcFontMatch( nullptr, pattern, &result ); FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet ); mMatchedFcPatternCache.PushBack( match ); @@ -1999,7 +1962,8 @@ FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDesc void FontClient::Plugin::DestroyMatchedPatterns() { - for (auto & object : mMatchedFcPatternCache) { + for (auto & object : mMatchedFcPatternCache) + { FcPatternDestroy(reinterpret_cast(object)); } mMatchedFcPatternCache.Clear(); diff --git a/dali/internal/text/text-abstraction/font-client-plugin-impl.h b/dali/internal/text/text-abstraction/font-client-plugin-impl.h index 3ada20c..4de27b7 100644 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.h +++ b/dali/internal/text/text-abstraction/font-client-plugin-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_TEXT_ABSTRACTION_FONT_CLIENT_PLUGIN_IMPL_H /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ struct FontClient::Plugin */ struct FallbackCacheItem { - FallbackCacheItem( const FontDescription& fontDescription, FontList* fallbackFonts, CharacterSetList* characterSets ); + FallbackCacheItem( FontDescription&& fontDescription, FontList* fallbackFonts, CharacterSetList* characterSets ); FontDescription fontDescription; ///< The font description. FontList* fallbackFonts; ///< The list of fallback fonts for the given font-description. @@ -80,6 +80,8 @@ struct FontClient::Plugin { FontDescriptionCacheItem( const FontDescription& fontDescription, FontDescriptionId index ); + FontDescriptionCacheItem( FontDescription&& fontDescription, + FontDescriptionId index ); FontDescription fontDescription; ///< The font description. FontDescriptionId index; ///< Index to the vector of font descriptions. @@ -88,11 +90,11 @@ struct FontClient::Plugin /** * @brief Caches the font id of the pair font point size and the index to the vector of font descriptions of validated fonts. */ - struct FontIdCacheItem + struct FontDescriptionSizeCacheItem { - FontIdCacheItem( FontDescriptionId validatedFontId, - PointSize26Dot6 requestedPointSize, - FontId fontId ); + FontDescriptionSizeCacheItem( FontDescriptionId validatedFontId, + PointSize26Dot6 requestedPointSize, + FontId fontId ); FontDescriptionId validatedFontId; ///< Index to the vector with font descriptions. PointSize26Dot6 requestedPointSize; ///< The font point size. @@ -429,8 +431,8 @@ private: * @brief Finds a fallback font list from the cache for a given font-description * * @param[in] fontDescription The font to validate. - * @param[out] A valid pointer to a font list, or NULL if not found. - * @param[out] characterSetList A valid pointer to a character set list, or NULL if not found. + * @param[out] A valid pointer to a font list, or @e nullptr if not found. + * @param[out] characterSetList A valid pointer to a character set list, or @e nullptr if not found. */ bool FindFallbackFontList( const FontDescription& fontDescription, FontList*& fontList, @@ -515,11 +517,11 @@ private: std::vector mFallbackCache; ///< Cached fallback font lists. - std::vector mFontCache; ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'. - std::vector mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given font. - FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font. - CharacterSetList mCharacterSetCache; ///< Caches character set lists for the validated font. - std::vector mFontIdCache; ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts. + std::vector mFontFaceCache; ///< Caches the FreeType face and font metrics of the triplet 'path to the font file name, font point size and face index'. + std::vector mValidatedFontCache; ///< Caches indices to the vector of font descriptions for a given font. + FontList mFontDescriptionCache; ///< Caches font descriptions for the validated font. + CharacterSetList mCharacterSetCache; ///< Caches character set lists for the validated font. + std::vector mFontDescriptionSizeCache; ///< Caches font identifiers for the pairs of font point size and the index to the vector with font descriptions of the validated fonts. VectorFontCache* mVectorFontCache; ///< Separate cache for vector data blobs etc. Vector mEllipsisCache; ///< Caches ellipsis glyphs for a particular point size. -- 2.7.4