2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/text-abstraction/font-client-plugin-impl.h>
22 #include <dali/devel-api/text-abstraction/font-list.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/platform-abstraction.h>
28 #include <dali/internal/text-abstraction/font-client-helper.h>
29 #include <platform-abstractions/portable/image-operations.h>
30 #include <adaptor-impl.h>
33 #include <fontconfig/fontconfig.h>
38 #if defined(DEBUG_ENABLED)
39 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_FONT_CLIENT");
43 * Conversion from Fractional26.6 to float
45 const float FROM_266 = 1.0f / 64.0f;
46 const float POINTS_PER_INCH = 72.f;
48 const std::string FONT_FORMAT( "TrueType" );
49 const std::string DEFAULT_FONT_FAMILY_NAME( "Tizen" );
50 const int DEFAULT_FONT_WIDTH = 100; // normal
51 const int DEFAULT_FONT_WEIGHT = 80; // normal
52 const int DEFAULT_FONT_SLANT = 0; // normal
54 const uint32_t ELLIPSIS_CHARACTER = 0x2026;
56 // http://www.freedesktop.org/software/fontconfig/fontconfig-user.html
58 // NONE -1 --> DEFAULT_FONT_WIDTH (NORMAL) will be used.
68 const int FONT_WIDTH_TYPE_TO_INT[] = { -1, 50, 63, 75, 87, 100, 113, 125, 150, 200 };
69 const unsigned int NUM_FONT_WIDTH_TYPE = sizeof( FONT_WIDTH_TYPE_TO_INT ) / sizeof( int );
71 // NONE -1 --> DEFAULT_FONT_WEIGHT (NORMAL) will be used.
73 // ULTRA_LIGHT, EXTRA_LIGHT 40
75 // DEMI_LIGHT, SEMI_LIGHT 55
79 // DEMI_BOLD, SEMI_BOLD 180
81 // ULTRA_BOLD, EXTRA_BOLD 205
82 // BLACK, HEAVY, EXTRA_BLACK 210
83 const int FONT_WEIGHT_TYPE_TO_INT[] = { -1, 0, 40, 50, 55, 75, 80, 100, 180, 200, 205, 210 };
84 const unsigned int NUM_FONT_WEIGHT_TYPE = sizeof( FONT_WEIGHT_TYPE_TO_INT ) / sizeof( int );
86 // NONE -1 --> DEFAULT_FONT_SLANT (NORMAL) will be used.
90 const int FONT_SLANT_TYPE_TO_INT[] = { -1, 0, 100, 110 };
91 const unsigned int NUM_FONT_SLANT_TYPE = sizeof( FONT_SLANT_TYPE_TO_INT ) / sizeof( int );
102 namespace TextAbstraction
109 * @brief Returns the FontWidth's enum index for the given width value.
111 * @param[in] width The width value.
113 * @return The FontWidth's enum index.
115 FontWidth::Type IntToWidthType( int width )
117 return static_cast<FontWidth::Type>( ValueToIndex( width, FONT_WIDTH_TYPE_TO_INT, NUM_FONT_WIDTH_TYPE - 1u ) );
121 * @brief Returns the FontWeight's enum index for the given weight value.
123 * @param[in] weight The weight value.
125 * @return The FontWeight's enum index.
127 FontWeight::Type IntToWeightType( int weight )
129 return static_cast<FontWeight::Type>( ValueToIndex( weight, FONT_WEIGHT_TYPE_TO_INT, NUM_FONT_WEIGHT_TYPE - 1u ) );
133 * @brief Returns the FontSlant's enum index for the given slant value.
135 * @param[in] slant The slant value.
137 * @return The FontSlant's enum index.
139 FontSlant::Type IntToSlantType( int slant )
141 return static_cast<FontSlant::Type>( ValueToIndex( slant, FONT_SLANT_TYPE_TO_INT, NUM_FONT_SLANT_TYPE - 1u ) );
144 FontClient::Plugin::FallbackCacheItem::FallbackCacheItem( FontDescription&& font, FontList* fallbackFonts, CharacterSetList* characterSets )
145 : fontDescription{ std::move( font ) },
146 fallbackFonts{ fallbackFonts },
147 characterSets{ characterSets }
151 FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const FontDescription& fontDescription,
152 FontDescriptionId index )
153 : fontDescription{ fontDescription },
158 FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( FontDescription&& fontDescription,
159 FontDescriptionId index )
160 : fontDescription{ std::move( fontDescription ) },
165 FontClient::Plugin::FontDescriptionSizeCacheItem::FontDescriptionSizeCacheItem( FontDescriptionId validatedFontId,
166 PointSize26Dot6 requestedPointSize,
168 : validatedFontId( validatedFontId ),
169 requestedPointSize( requestedPointSize ),
174 FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace,
175 const FontPath& path,
176 PointSize26Dot6 requestedPointSize,
178 const FontMetrics& metrics )
179 : mFreeTypeFace( ftFace ),
181 mRequestedPointSize( requestedPointSize ),
184 mCharacterSet( nullptr ),
185 mFixedWidthPixels( 0.0f ),
186 mFixedHeightPixels( 0.0f ),
188 mIsFixedSizeBitmap( false ),
189 mHasColorTables( false )
193 FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace,
194 const FontPath& path,
195 PointSize26Dot6 requestedPointSize,
197 const FontMetrics& metrics,
200 bool hasColorTables )
201 : mFreeTypeFace( ftFace ),
203 mRequestedPointSize( requestedPointSize ),
206 mCharacterSet( nullptr ),
207 mFixedWidthPixels( fixedWidth ),
208 mFixedHeightPixels( fixedHeight ),
210 mIsFixedSizeBitmap( true ),
211 mHasColorTables( hasColorTables )
215 FontClient::Plugin::Plugin( unsigned int horizontalDpi,
216 unsigned int verticalDpi )
217 : mFreeTypeLibrary( nullptr ),
218 mDpiHorizontal( horizontalDpi ),
219 mDpiVertical( verticalDpi ),
220 mDefaultFontDescription(),
224 mValidatedFontCache(),
225 mFontDescriptionCache( 1u ),
226 mCharacterSetCache(),
227 mFontDescriptionSizeCache(),
228 mVectorFontCache( nullptr ),
230 mDefaultFontDescriptionCached( false )
232 mCharacterSetCache.Resize( 1u );
234 int error = FT_Init_FreeType( &mFreeTypeLibrary );
235 if( FT_Err_Ok != error )
237 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Init error: %d\n", error );
240 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
241 mVectorFontCache = new VectorFontCache( mFreeTypeLibrary );
246 FontClient::Plugin::~Plugin()
248 for( auto& item : mFallbackCache )
250 if( item.fallbackFonts )
252 delete item.fallbackFonts;
253 delete item.characterSets;
254 item.fallbackFonts = nullptr;
255 item.characterSets = nullptr;
259 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
260 delete mVectorFontCache;
262 DestroyMatchedPatterns();
263 FT_Done_FreeType( mFreeTypeLibrary );
266 void FontClient::Plugin::ClearCache()
268 mFontFaceCache.clear();
269 mValidatedFontCache.clear();
270 mFontDescriptionCache.clear();
271 mFontDescriptionCache.resize( 1u );
273 mCharacterSetCache.Clear();
274 mCharacterSetCache.Resize( 1u );
276 mFontDescriptionSizeCache.clear();
277 mFallbackCache.clear();
279 mEllipsisCache.Clear();
280 mSystemFonts.clear();
281 mDefaultFonts.clear();
282 mDefaultFontDescriptionCached = false;
283 mDefaultFontCharacterSets.Clear();
284 mDefaultFontDescription = FontDescription();
285 DestroyMatchedPatterns();
288 void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
289 unsigned int verticalDpi )
291 mDpiHorizontal = horizontalDpi;
292 mDpiVertical = verticalDpi;
295 void FontClient::Plugin::ResetSystemDefaults()
297 mDefaultFontDescriptionCached = false;
300 void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList )
302 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::SetFontList\n" );
303 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
304 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
305 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
306 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
310 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
312 FcResult result = FcResultMatch;
314 // Match the pattern.
315 FcFontSet* fontSet = FcFontSort( nullptr /* use default configure */,
317 false /* don't trim */,
321 if( nullptr != fontSet )
323 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts found : [%d]\n", fontSet->nfont );
324 // Reserve some space to avoid reallocations.
325 fontList.reserve( fontSet->nfont );
327 for( int i = 0u; i < fontSet->nfont; ++i )
329 FcPattern* fontPattern = fontSet->fonts[i];
333 // Skip fonts with no path
334 if( GetFcString( fontPattern, FC_FILE, path ) )
336 FcCharSet* characterSet = nullptr;
337 FcPatternGetCharSet( fontPattern, FC_CHARSET, 0u, &characterSet );
339 characterSetList.PushBack( characterSet );
340 fontList.push_back( FontDescription() );
341 FontDescription& newFontDescription = fontList.back();
343 newFontDescription.path = std::move( path );
348 GetFcString( fontPattern, FC_FAMILY, newFontDescription.family );
349 GetFcInt( fontPattern, FC_WIDTH, width );
350 GetFcInt( fontPattern, FC_WEIGHT, weight );
351 GetFcInt( fontPattern, FC_SLANT, slant );
352 newFontDescription.width = IntToWidthType( width );
353 newFontDescription.weight = IntToWeightType( weight );
354 newFontDescription.slant = IntToSlantType( slant );
356 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", newFontDescription.family.c_str() );
357 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", newFontDescription.path.c_str() );
358 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[newFontDescription.width] );
359 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[newFontDescription.weight] );
360 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[newFontDescription.slant] );
364 FcFontSetDestroy( fontSet );
368 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " No fonts found.\n" );
371 FcPatternDestroy( fontFamilyPattern );
372 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::SetFontList\n" );
375 void FontClient::Plugin::GetDefaultFonts( FontList& defaultFonts )
377 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultFonts\n" );
379 if( mDefaultFonts.empty() )
381 FontDescription fontDescription;
382 fontDescription.family = DEFAULT_FONT_FAMILY_NAME; // todo This could be set to the Platform font
383 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
384 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
385 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
386 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
389 defaultFonts = mDefaultFonts;
391 DALI_LOG_INFO( gLogFilter, Debug::General, " number of default fonts : [%d]\n", mDefaultFonts.size() );
392 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultFonts\n" );
395 void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
397 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultPlatformFontDescription\n");
399 if( !mDefaultFontDescriptionCached )
401 // Clear any font config stored info in the caches.
402 mDefaultFontCharacterSets.Clear();
403 mCharacterSetCache.Clear();
405 for( auto& item : mFallbackCache )
407 item.characterSets->Clear();
410 for( auto& item : mFontFaceCache )
412 // Set the character set pointer as null. Will be created again the next time IsCharacterSupportedByFont()
413 item.mCharacterSet = nullptr;
416 // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
417 FcInitReinitialize();
419 FcPattern* matchPattern = FcPatternCreate();
423 FcConfigSubstitute( nullptr, matchPattern, FcMatchPattern );
424 FcDefaultSubstitute( matchPattern );
426 FcCharSet* characterSet = nullptr;
427 MatchFontDescriptionToPattern( matchPattern, mDefaultFontDescription, &characterSet );
428 FcPatternDestroy( matchPattern );
431 // Create again the character sets as they are not valid after FcInitReinitialize()
433 for( const auto& description : mDefaultFonts )
435 mDefaultFontCharacterSets.PushBack( CreateCharacterSetFromDescription( description ) );
438 for( const auto& description : mFontDescriptionCache )
440 mCharacterSetCache.PushBack( CreateCharacterSetFromDescription( description ) );
443 for( auto& item : mFallbackCache )
445 if( nullptr != item.fallbackFonts )
447 if( nullptr == item.characterSets )
449 item.characterSets = new CharacterSetList;
452 for( const auto& description : *( item.fallbackFonts ) )
454 item.characterSets->PushBack( CreateCharacterSetFromDescription( description ) );
459 mDefaultFontDescriptionCached = true;
462 fontDescription.path = mDefaultFontDescription.path;
463 fontDescription.family = mDefaultFontDescription.family;
464 fontDescription.width = mDefaultFontDescription.width;
465 fontDescription.weight = mDefaultFontDescription.weight;
466 fontDescription.slant = mDefaultFontDescription.slant;
468 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
471 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
472 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
473 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultPlatformFontDescription\n");
476 void FontClient::Plugin::GetSystemFonts( FontList& systemFonts )
478 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetSystemFonts\n");
480 if( mSystemFonts.empty() )
485 systemFonts = mSystemFonts;
486 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : [%d]\n", mSystemFonts.size() );
487 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetSystemFonts\n");
490 void FontClient::Plugin::GetDescription( FontId id,
491 FontDescription& fontDescription ) const
493 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDescription\n");
494 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
496 for( const auto& item : mFontDescriptionSizeCache )
498 if( item.fontId == id )
500 fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId );
502 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
503 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
504 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
505 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
506 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
507 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
512 DALI_LOG_INFO( gLogFilter, Debug::General, " No description found for the font ID %d\n", id );
513 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
516 PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id )
518 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetPointSize\n");
519 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
520 const FontId index = id - 1u;
523 ( index < mFontFaceCache.size() ) )
525 DALI_LOG_INFO( gLogFilter, Debug::General, " point size : %d\n", ( *( mFontFaceCache.begin() + index ) ).mRequestedPointSize );
526 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
527 return ( *( mFontFaceCache.begin() + index ) ).mRequestedPointSize;
531 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font ID %d\n", id );
534 DALI_LOG_INFO( gLogFilter, Debug::General, " default point size : %d\n", TextAbstraction::FontClient::DEFAULT_POINT_SIZE );
535 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
536 return TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
539 bool FontClient::Plugin::IsCharacterSupportedByFont( FontId fontId, Character character )
541 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::IsCharacterSupportedByFont\n");
542 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
543 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
545 if( ( fontId < 1u ) || ( fontId > mFontFaceCache.size() ) )
547 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font id. Number of items in the cache: %d\n",mFontFaceCache.size());
548 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
554 bool isSupported = false;
556 FontFaceCacheItem& cacheItem = mFontFaceCache[fontId];
558 if( nullptr == cacheItem.mCharacterSet )
560 // Create again the character set.
561 // It can be null if the ResetSystemDefaults() method has been called.
563 FontDescription description;
564 description.path = cacheItem.mPath;
565 description.family = std::move( FontFamily( cacheItem.mFreeTypeFace->family_name ) );
566 description.weight = FontWeight::NONE;
567 description.width = FontWidth::NONE;
568 description.slant = FontSlant::NONE;
570 // Note FreeType doesn't give too much info to build a proper font style.
571 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC )
573 description.slant = FontSlant::ITALIC;
575 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_BOLD )
577 description.weight = FontWeight::BOLD;
580 cacheItem.mCharacterSet = CreateCharacterSetFromDescription( description );
583 isSupported = FcCharSetHasChar( cacheItem.mCharacterSet, character );
585 DALI_LOG_INFO( gLogFilter, Debug::General, " is supported : %s\n", (isSupported ? "true" : "false") );
586 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
590 FontId FontClient::Plugin::FindFontForCharacter( const FontList& fontList,
591 const CharacterSetList& characterSetList,
593 PointSize26Dot6 requestedPointSize,
596 DALI_ASSERT_DEBUG( ( fontList.size() == characterSetList.Count() ) && "FontClient::Plugin::FindFontForCharacter. Different number of fonts and character sets." );
598 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFontForCharacter\n" );
599 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
600 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
601 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
604 bool foundColor = false;
606 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts : %d\n", fontList.size() );
608 // Traverse the list of fonts.
609 // Check for each font if supports the character.
610 for( unsigned int index = 0u, numberOfFonts = fontList.size(); index < numberOfFonts; ++index )
612 const FontDescription& description = fontList[index];
613 const FcCharSet* const characterSet = characterSetList[index];
615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", description.family.c_str() );
616 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
617 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
618 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
619 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
621 bool foundInRanges = false;
622 if( nullptr != characterSet )
624 foundInRanges = FcCharSetHasChar( characterSet, character );
629 fontId = GetFontId( description,
633 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " font id : %d\n", fontId );
637 if( ( fontId > 0 ) &&
638 ( fontId - 1u < mFontFaceCache.size() ) )
640 const FontFaceCacheItem& item = mFontFaceCache[fontId - 1u];
642 foundColor = item.mHasColorTables;
645 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " foundColor : %s\n", ( foundColor ? "true" : "false" ) );
648 // Keep going unless we prefer a different (color) font.
649 if( !preferColor || foundColor )
656 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
657 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFontForCharacter\n" );
661 FontId FontClient::Plugin::FindDefaultFont( Character charcode,
662 PointSize26Dot6 requestedPointSize,
665 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindDefaultFont\n" );
666 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
667 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
668 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
672 // Create the list of default fonts if it has not been created.
673 if( mDefaultFonts.empty() )
675 FontDescription fontDescription;
676 fontDescription.family = DEFAULT_FONT_FAMILY_NAME;
677 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
678 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
679 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
681 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
683 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of default fonts : %d\n", mDefaultFonts.size() );
686 // Traverse the list of default fonts.
687 // Check for each default font if supports the character.
688 fontId = FindFontForCharacter( mDefaultFonts, mDefaultFontCharacterSets, charcode, requestedPointSize, preferColor );
690 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
691 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindDefaultFont\n" );
696 FontId FontClient::Plugin::FindFallbackFont( Character charcode,
697 const FontDescription& preferredFontDescription,
698 PointSize26Dot6 requestedPointSize,
701 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFont\n" );
702 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
703 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
704 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
706 // The font id to be returned.
709 FontDescription fontDescription;
711 // Fill the font description with the preferred font description and complete with the defaults.
712 fontDescription.family = preferredFontDescription.family.empty() ? DEFAULT_FONT_FAMILY_NAME : preferredFontDescription.family;
713 fontDescription.weight = ( ( FontWeight::NONE == preferredFontDescription.weight ) ? IntToWeightType( DEFAULT_FONT_WEIGHT ) : preferredFontDescription.weight );
714 fontDescription.width = ( ( FontWidth::NONE == preferredFontDescription.width ) ? IntToWidthType( DEFAULT_FONT_WIDTH ) : preferredFontDescription.width );
715 fontDescription.slant = ( ( FontSlant::NONE == preferredFontDescription.slant ) ? IntToSlantType( DEFAULT_FONT_SLANT ) : preferredFontDescription.slant );
717 DALI_LOG_INFO( gLogFilter, Debug::General, " preferredFontDescription --> fontDescription\n" );
718 DALI_LOG_INFO( gLogFilter, Debug::General, " [%s] --> [%s]\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str() );
719 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWeight::Name[preferredFontDescription.weight], FontWeight::Name[fontDescription.weight] );
720 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width] );
721 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant] );
723 // Check first if the font's description has been queried before.
724 FontList* fontList = nullptr;
725 CharacterSetList* characterSetList = nullptr;
727 if( !FindFallbackFontList( fontDescription, fontList, characterSetList ) )
729 fontList = new FontList;
730 characterSetList = new CharacterSetList;
732 SetFontList( fontDescription, *fontList, *characterSetList );
734 // Add the font-list to the cache.
735 mFallbackCache.push_back( std::move( FallbackCacheItem( std::move( fontDescription ), fontList, characterSetList ) ) );
738 if( fontList && characterSetList )
740 fontId = FindFontForCharacter( *fontList, *characterSetList, charcode, requestedPointSize, preferColor );
743 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
744 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFont\n");
748 FontId FontClient::Plugin::GetFontId( const FontPath& path,
749 PointSize26Dot6 requestedPointSize,
751 bool cacheDescription )
753 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
754 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
755 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
759 if( nullptr != mFreeTypeLibrary )
762 if( FindFont( path, requestedPointSize, faceIndex, foundId ) )
768 id = CreateFont( path, requestedPointSize, faceIndex, cacheDescription );
772 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
773 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
778 FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription,
779 PointSize26Dot6 requestedPointSize,
780 FaceIndex faceIndex )
782 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
783 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
784 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
785 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
786 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
787 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
788 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
790 // This method uses three vectors which caches:
791 // * Pairs of non validated font descriptions and an index to a vector with paths to font file names.
792 // * The path to font file names.
793 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
795 // 1) Checks in the cache if the font's description has been validated before.
796 // If it was it gets an index to the vector with paths to font file names. Otherwise,
797 // retrieves using font config a path to a font file name which matches with the
798 // font's description. The path is stored in the cache.
800 // 2) Checks in the cache if the pair 'font point size, index to the vector with paths to
801 // font file names' exists. If exists, it gets the font id. If it doesn't it calls
802 // the GetFontId() method with the path to the font file name and the point size to
805 // The font id to be returned.
808 // Check first if the font's description have been validated before.
809 FontDescriptionId validatedFontId = 0u;
811 if( !FindValidatedFont( fontDescription,
814 // Use font config to validate the font's description.
815 ValidateFont( fontDescription,
819 // Check if exists a pair 'validatedFontId, requestedPointSize' in the cache.
820 if( !FindFont( validatedFontId, requestedPointSize, fontId ) )
822 // Retrieve the font file name path.
823 const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId );
825 // Retrieve the font id. Do not cache the description as it has been already cached.
826 fontId = GetFontId( description.path,
831 mFontFaceCache[fontId-1u].mCharacterSet = mCharacterSetCache[validatedFontId];
833 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
834 mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId,
839 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
840 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
845 void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription,
846 FontDescriptionId& validatedFontId )
848 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::ValidateFont\n" );
849 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
850 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
851 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
852 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
853 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
855 // Create a font pattern.
856 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
858 FontDescription description;
860 FcCharSet* characterSet = nullptr;
861 bool matched = MatchFontDescriptionToPattern( fontFamilyPattern, description, &characterSet );
862 FcPatternDestroy( fontFamilyPattern );
864 if( matched && ( nullptr != characterSet ) )
866 // Set the index to the vector of paths to font file names.
867 validatedFontId = mFontDescriptionCache.size();
869 DALI_LOG_INFO( gLogFilter, Debug::General, " matched description; family : [%s]\n", description.family.c_str() );
870 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
871 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
872 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
873 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
874 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
876 // Add the path to the cache.
877 mFontDescriptionCache.push_back( description );
878 mCharacterSetCache.PushBack( characterSet );
880 // Cache the index and the matched font's description.
881 FontDescriptionCacheItem item( description,
884 mValidatedFontCache.push_back( std::move( item ) );
886 if( ( fontDescription.family != description.family ) ||
887 ( fontDescription.width != description.width ) ||
888 ( fontDescription.weight != description.weight ) ||
889 ( fontDescription.slant != description.slant ) )
891 // Cache the given font's description if it's different than the matched.
892 FontDescriptionCacheItem item( fontDescription,
895 mValidatedFontCache.push_back( std::move( item ) );
900 DALI_LOG_INFO( gLogFilter, Debug::General, " font validation failed for font [%s]\n", fontDescription.family.c_str() );
903 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::ValidateFont\n" );
906 void FontClient::Plugin::GetFontMetrics( FontId fontId,
907 FontMetrics& metrics )
909 if( ( fontId > 0 ) &&
910 ( fontId - 1u < mFontFaceCache.size() ) )
912 const FontFaceCacheItem& font = mFontFaceCache[fontId-1];
914 metrics = font.mMetrics;
916 // Adjust the metrics if the fixed-size font should be down-scaled
917 if( font.mIsFixedSizeBitmap )
919 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
921 if( desiredFixedSize > 0.f )
923 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
925 metrics.ascender = floorf( metrics.ascender * scaleFactor );
926 metrics.descender = floorf( metrics.descender * scaleFactor );
927 metrics.height = floorf( metrics.height * scaleFactor );
928 metrics.underlinePosition = floorf( metrics.underlinePosition * scaleFactor );
929 metrics.underlineThickness = floorf( metrics.underlineThickness * scaleFactor );
935 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFontMetrics. Invalid font id : %d\n", fontId );
939 GlyphIndex FontClient::Plugin::GetGlyphIndex( FontId fontId,
942 GlyphIndex index = 0u;
944 if( ( fontId > 0u ) &&
945 ( fontId - 1u < mFontFaceCache.size() ) )
947 FT_Face ftFace = mFontFaceCache[fontId-1u].mFreeTypeFace;
949 index = FT_Get_Char_Index( ftFace, charcode );
955 bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
960 if( VECTOR_GLYPH == type )
962 return GetVectorMetrics( array, size, horizontal );
965 return GetBitmapMetrics( array, size, horizontal );
968 bool FontClient::Plugin::GetBitmapMetrics( GlyphInfo* array,
972 bool success( true );
974 for( unsigned int i=0; i<size; ++i )
976 GlyphInfo& glyph = array[i];
978 FontId fontId = glyph.fontId;
981 fontId-1 < mFontFaceCache.size() )
983 const FontFaceCacheItem& font = mFontFaceCache[fontId-1];
985 FT_Face ftFace = font.mFreeTypeFace;
987 #ifdef FREETYPE_BITMAP_SUPPORT
988 // Check to see if we should be loading a Fixed Size bitmap?
989 if ( font.mIsFixedSizeBitmap )
991 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_COLOR );
992 if ( FT_Err_Ok == error )
994 glyph.width = font.mFixedWidthPixels;
995 glyph.height = font.mFixedHeightPixels;
996 glyph.advance = font.mFixedWidthPixels;
997 glyph.xBearing = 0.0f;
998 glyph.yBearing = font.mFixedHeightPixels;
1000 // Adjust the metrics if the fixed-size font should be down-scaled
1001 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
1003 if( desiredFixedSize > 0.f )
1005 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
1007 glyph.width = floorf( glyph.width * scaleFactor );
1008 glyph.height = floorf( glyph.height * scaleFactor );
1009 glyph.advance = floorf( glyph.advance * scaleFactor );
1010 glyph.xBearing = floorf( glyph.xBearing * scaleFactor );
1011 glyph.yBearing = floorf( glyph.yBearing * scaleFactor );
1013 glyph.scaleFactor = scaleFactor;
1018 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetBitmapMetrics. FreeType Bitmap Load_Glyph error %d\n", error );
1025 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_NO_AUTOHINT );
1027 if( FT_Err_Ok == error )
1029 glyph.width = static_cast< float >( ftFace->glyph->metrics.width ) * FROM_266;
1030 glyph.height = static_cast< float >( ftFace->glyph->metrics.height ) * FROM_266 ;
1033 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingX ) * FROM_266;
1034 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingY ) * FROM_266;
1038 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingX ) * FROM_266;
1039 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingY ) * FROM_266;
1057 bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array,
1061 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1062 bool success( true );
1064 for( unsigned int i=0; i<size; ++i )
1066 FontId fontId = array[i].fontId;
1069 fontId-1 < mFontFaceCache.size() )
1071 FontFaceCacheItem& font = mFontFaceCache[fontId-1];
1073 if( ! font.mVectorFontId )
1075 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1078 mVectorFontCache->GetGlyphMetrics( font.mVectorFontId, array[i] );
1080 // Vector metrics are in EMs, convert to pixels
1081 const float scale = ( static_cast<float>( font.mRequestedPointSize ) * FROM_266 ) * static_cast<float>( mDpiVertical ) / POINTS_PER_INCH;
1082 array[i].width *= scale;
1083 array[i].height *= scale;
1084 array[i].xBearing *= scale;
1085 array[i].yBearing *= scale;
1086 array[i].advance *= scale;
1100 void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
1102 if( ( fontId > 0 ) &&
1103 ( fontId - 1u < mFontFaceCache.size() ) )
1105 FT_Face ftFace = mFontFaceCache[fontId - 1u].mFreeTypeFace;
1109 #ifdef FREETYPE_BITMAP_SUPPORT
1110 // Check to see if this is fixed size bitmap
1111 if ( mFontFaceCache[fontId - 1u].mIsFixedSizeBitmap )
1113 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1118 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_NO_AUTOHINT );
1120 if( FT_Err_Ok == error )
1123 error = FT_Get_Glyph( ftFace->glyph, &glyph );
1125 // Convert to bitmap if necessary
1126 if ( FT_Err_Ok == error )
1128 if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
1130 // Check whether we should create a bitmap for the outline
1131 if( glyph->format == FT_GLYPH_FORMAT_OUTLINE && outlineWidth > 0 )
1135 error = FT_Stroker_New(mFreeTypeLibrary, &stroker );
1137 if ( FT_Err_Ok == error )
1139 FT_Stroker_Set( stroker, outlineWidth * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 );
1140 error = FT_Glyph_StrokeBorder( &glyph, stroker, 0, 1 );
1142 if ( FT_Err_Ok == error )
1144 FT_Stroker_Done( stroker );
1148 DALI_LOG_ERROR( "FT_Glyph_StrokeBorder Failed with error: %d\n", error );
1153 DALI_LOG_ERROR( "FT_Stroker_New Failed with error: %d\n", error );
1157 error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
1158 if ( FT_Err_Ok == error )
1160 FT_BitmapGlyph bitmapGlyph = reinterpret_cast< FT_BitmapGlyph >( glyph );
1161 ConvertBitmap( data, bitmapGlyph->bitmap );
1165 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Get_Glyph Failed with error: %d\n", error );
1170 ConvertBitmap( data, ftFace->glyph->bitmap );
1173 // Created FT_Glyph object must be released with FT_Done_Glyph
1174 FT_Done_Glyph( glyph );
1179 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Load_Glyph Failed with error: %d\n", error );
1184 PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
1186 TextAbstraction::FontClient::GlyphBufferData data;
1188 CreateBitmap( fontId, glyphIndex, data, outlineWidth );
1190 return PixelData::New( data.buffer,
1191 data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
1195 PixelData::DELETE_ARRAY );
1198 void FontClient::Plugin::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
1203 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1205 fontId-1 < mFontFaceCache.size() )
1207 FontFaceCacheItem& font = mFontFaceCache[fontId-1];
1209 if( ! font.mVectorFontId )
1211 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1214 mVectorFontCache->GetVectorBlob( font.mVectorFontId, fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
1219 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
1221 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetEllipsisGlyph\n" );
1222 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize %d.\n", requestedPointSize );
1224 // First look into the cache if there is an ellipsis glyph for the requested point size.
1225 for( const auto& item : mEllipsisCache )
1227 if( fabsf( item.requestedPointSize - requestedPointSize ) < Math::MACHINE_EPSILON_1000 )
1229 // Use the glyph in the cache.
1231 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1232 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1233 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1239 // No glyph has been found. Create one.
1240 mEllipsisCache.PushBack( EllipsisItem() );
1241 EllipsisItem& item = *( mEllipsisCache.End() - 1u );
1243 item.requestedPointSize = requestedPointSize;
1245 // Find a font for the ellipsis glyph.
1246 item.glyph.fontId = FindDefaultFont( ELLIPSIS_CHARACTER,
1250 // Set the character index to access the glyph inside the font.
1251 item.glyph.index = FT_Get_Char_Index( mFontFaceCache[item.glyph.fontId-1].mFreeTypeFace,
1252 ELLIPSIS_CHARACTER );
1254 GetBitmapMetrics( &item.glyph, 1u, true );
1256 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1257 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1258 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1263 bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
1265 FT_Error error = -1;
1267 #ifdef FREETYPE_BITMAP_SUPPORT
1268 if( ( fontId > 0 ) &&
1269 ( fontId - 1u < mFontFaceCache.size() ) )
1271 const FontFaceCacheItem& item = mFontFaceCache[fontId - 1u];
1272 FT_Face ftFace = item.mFreeTypeFace;
1274 // Check to see if this is fixed size bitmap
1275 if( item.mHasColorTables )
1277 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1282 return FT_Err_Ok == error;
1285 bool FontClient::Plugin::AddCustomFontDirectory( const FontPath& path )
1287 // nullptr as first parameter means the current configuration is used.
1288 return FcConfigAppFontAddDir( nullptr, reinterpret_cast<const FcChar8 *>( path.c_str() ) );
1291 FT_FaceRec_* FontClient::Plugin::GetFreetypeFace( FontId fontId )
1293 FT_Face fontFace = nullptr;
1295 if( ( fontId > 0u ) &&
1296 ( fontId - 1u < mFontFaceCache.size() ) )
1298 fontFace = mFontFaceCache[fontId - 1u].mFreeTypeFace;
1304 void FontClient::Plugin::InitSystemFonts()
1306 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" );
1308 FcFontSet* fontSet = GetFcFontSet();
1312 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : %d\n", fontSet->nfont );
1314 // Reserve some space to avoid reallocations.
1315 mSystemFonts.reserve( fontSet->nfont );
1317 for( int i = 0u; i < fontSet->nfont; ++i )
1319 FcPattern* fontPattern = fontSet->fonts[i];
1323 // Skip fonts with no path
1324 if( GetFcString( fontPattern, FC_FILE, path ) )
1326 mSystemFonts.push_back( FontDescription() );
1327 FontDescription& fontDescription = mSystemFonts.back();
1329 fontDescription.path = std::move( path );
1334 GetFcString( fontPattern, FC_FAMILY, fontDescription.family );
1335 GetFcInt( fontPattern, FC_WIDTH, width );
1336 GetFcInt( fontPattern, FC_WEIGHT, weight );
1337 GetFcInt( fontPattern, FC_SLANT, slant );
1338 fontDescription.width = IntToWidthType( width );
1339 fontDescription.weight = IntToWeightType( weight );
1340 fontDescription.slant = IntToSlantType( slant );
1342 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", fontDescription.family.c_str() );
1343 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1344 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1345 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1346 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1350 FcFontSetDestroy( fontSet );
1352 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::InitSystemFonts\n" );
1355 bool FontClient::Plugin::MatchFontDescriptionToPattern( FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet )
1357 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1359 FcResult result = FcResultMatch;
1360 FcPattern* match = FcFontMatch( nullptr /* use default configure */, pattern, &result );
1362 const bool matched = nullptr != match;
1363 DALI_LOG_INFO( gLogFilter, Debug::General, " pattern matched : %s\n", ( matched ? "true" : "false" ) );
1370 GetFcString( match, FC_FILE, fontDescription.path );
1371 GetFcString( match, FC_FAMILY, fontDescription.family );
1372 GetFcInt( match, FC_WIDTH, width );
1373 GetFcInt( match, FC_WEIGHT, weight );
1374 GetFcInt( match, FC_SLANT, slant );
1375 fontDescription.width = IntToWidthType( width );
1376 fontDescription.weight = IntToWeightType( weight );
1377 fontDescription.slant = IntToSlantType( slant );
1379 // Cache the character ranges.
1380 FcPatternGetCharSet( match, FC_CHARSET, 0u, characterSet );
1382 // destroyed the matched pattern
1383 FcPatternDestroy( match );
1385 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1386 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1389 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1392 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1396 FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& fontDescription ) const
1398 // create the cached font family lookup pattern
1399 // a pattern holds a set of names, each name refers to a property of the font
1400 FcPattern* fontFamilyPattern = FcPatternCreate();
1402 if( !fontFamilyPattern )
1407 // add a property to the pattern for the font family
1408 FcPatternAddString( fontFamilyPattern, FC_FAMILY, reinterpret_cast<const FcChar8*>( fontDescription.family.c_str() ) );
1410 // add a property to the pattern for local setting.
1411 const char* locale = setlocale( LC_MESSAGES, nullptr );
1412 if( locale != nullptr)
1414 FcPatternAddString( fontFamilyPattern, FC_LANG, reinterpret_cast<const FcChar8*>( locale ) );
1417 int width = FONT_WIDTH_TYPE_TO_INT[fontDescription.width];
1421 width = DEFAULT_FONT_WIDTH;
1424 int weight = FONT_WEIGHT_TYPE_TO_INT[fontDescription.weight];
1428 weight = DEFAULT_FONT_WEIGHT;
1431 int slant = FONT_SLANT_TYPE_TO_INT[fontDescription.slant];
1435 slant = DEFAULT_FONT_SLANT;
1438 FcPatternAddInteger( fontFamilyPattern, FC_WIDTH, width );
1439 FcPatternAddInteger( fontFamilyPattern, FC_WEIGHT, weight );
1440 FcPatternAddInteger( fontFamilyPattern, FC_SLANT, slant );
1442 // Add a property of the pattern, to say we want to match TrueType fonts
1443 FcPatternAddString( fontFamilyPattern , FC_FONTFORMAT, reinterpret_cast<const FcChar8*>( FONT_FORMAT.c_str() ) );
1445 // modify the config, with the mFontFamilyPatterm
1446 FcConfigSubstitute( nullptr /* use default configure */, fontFamilyPattern, FcMatchPattern );
1448 // provide default values for unspecified properties in the font pattern
1449 // e.g. patterns without a specified style or weight are set to Medium
1450 FcDefaultSubstitute( fontFamilyPattern );
1452 return fontFamilyPattern;
1455 _FcFontSet* FontClient::Plugin::GetFcFontSet() const
1457 // create a new pattern.
1458 // a pattern holds a set of names, each name refers to a property of the font
1459 FcPattern* pattern = FcPatternCreate();
1461 // create an object set used to define which properties are to be returned in the patterns from FcFontList.
1462 FcObjectSet* objectSet = FcObjectSetCreate();
1464 // build an object set from a list of property names
1465 FcObjectSetAdd( objectSet, FC_FILE );
1466 FcObjectSetAdd( objectSet, FC_FAMILY );
1467 FcObjectSetAdd( objectSet, FC_WIDTH );
1468 FcObjectSetAdd( objectSet, FC_WEIGHT );
1469 FcObjectSetAdd( objectSet, FC_SLANT );
1471 // get a list of fonts
1472 // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
1473 FcFontSet* fontset = FcFontList( nullptr /* the default configuration is checked to be up to date, and used */, pattern, objectSet );
1475 // clear up the object set
1478 FcObjectSetDestroy( objectSet );
1480 // clear up the pattern
1483 FcPatternDestroy( pattern );
1489 bool FontClient::Plugin::GetFcString( const FcPattern* const pattern,
1490 const char* const n,
1491 std::string& string )
1493 FcChar8* file = nullptr;
1494 const FcResult retVal = FcPatternGetString( pattern, n, 0u, &file );
1496 if( FcResultMatch == retVal )
1498 // Have to use reinterpret_cast because FcChar8 is unsigned char*, not a const char*.
1499 string.assign( reinterpret_cast<const char*>( file ) );
1507 bool FontClient::Plugin::GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal )
1509 const FcResult retVal = FcPatternGetInteger( pattern, n, 0u, &intVal );
1511 if( FcResultMatch == retVal )
1519 FontId FontClient::Plugin::CreateFont( const FontPath& path,
1520 PointSize26Dot6 requestedPointSize,
1521 FaceIndex faceIndex,
1522 bool cacheDescription )
1524 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::CreateFont\n" );
1525 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1526 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1530 // Create & cache new font face
1532 int error = FT_New_Face( mFreeTypeLibrary,
1537 if( FT_Err_Ok == error )
1539 // Check if a font is scalable.
1540 const bool isScalable = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_SCALABLE ) );
1541 const bool hasFixedSizedBitmaps = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES ) ) && ( 0 != ftFace->num_fixed_sizes );
1542 const bool hasColorTables = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_COLOR ) );
1544 DALI_LOG_INFO( gLogFilter, Debug::General, " isScalable : [%s]\n", ( isScalable ? "true" : "false" ) );
1545 DALI_LOG_INFO( gLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", ( hasFixedSizedBitmaps ? "true" : "false" ) );
1546 DALI_LOG_INFO( gLogFilter, Debug::General, " hasColorTables : [%s]\n", ( hasColorTables ? "true" : "false" ) );
1548 // Check to see if the font contains fixed sizes?
1549 if( !isScalable && hasFixedSizedBitmaps )
1551 PointSize26Dot6 actualPointSize = 0u;
1552 int fixedSizeIndex = 0;
1553 for( ; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex )
1555 const PointSize26Dot6 fixedSize = ftFace->available_sizes[fixedSizeIndex].size;
1556 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize );
1558 if( fixedSize >= requestedPointSize )
1560 actualPointSize = fixedSize;
1565 if( 0u == actualPointSize )
1567 // The requested point size is bigger than the bigest fixed size.
1568 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1569 actualPointSize = ftFace->available_sizes[fixedSizeIndex].size;
1572 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize );
1574 // Tell Freetype to use this size
1575 error = FT_Select_Size( ftFace, fixedSizeIndex );
1576 if ( FT_Err_Ok != error )
1578 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error );
1582 float fixedWidth = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].width );
1583 float fixedHeight = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].height );
1585 // Indicate that the font is a fixed sized bitmap
1586 FontMetrics metrics( fixedHeight, // The ascender in pixels.
1588 fixedHeight, // The height in pixels.
1592 mFontFaceCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics, fixedWidth, fixedHeight, hasColorTables ) );
1593 id = mFontFaceCache.size();
1598 error = FT_Set_Char_Size( ftFace,
1604 if( FT_Err_Ok == error )
1607 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1609 FontMetrics metrics( static_cast< float >( ftMetrics.ascender ) * FROM_266,
1610 static_cast< float >( ftMetrics.descender ) * FROM_266,
1611 static_cast< float >( ftMetrics.height ) * FROM_266,
1612 static_cast< float >( ftFace->underline_position ) * FROM_266,
1613 static_cast< float >( ftFace->underline_thickness ) * FROM_266 );
1615 mFontFaceCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics ) );
1616 id = mFontFaceCache.size();
1620 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize );
1626 if( cacheDescription )
1628 CacheFontPath( ftFace, id, requestedPointSize, path );
1634 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str() );
1637 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
1638 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::CreateFont\n" );
1643 void FontClient::Plugin::ConvertBitmap( TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap )
1645 if( srcBitmap.width*srcBitmap.rows > 0 )
1647 switch( srcBitmap.pixel_mode )
1649 case FT_PIXEL_MODE_GRAY:
1651 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width ) )
1653 const unsigned int bufferSize = srcBitmap.width * srcBitmap.rows;
1654 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1655 data.width = srcBitmap.width;
1656 data.height = srcBitmap.rows;
1657 data.format = Pixel::L8;
1658 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1663 #ifdef FREETYPE_BITMAP_SUPPORT
1664 case FT_PIXEL_MODE_BGRA:
1666 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width << 2u ) )
1668 // Set the input dimensions.
1669 const ImageDimensions inputDimensions( srcBitmap.width, srcBitmap.rows );
1671 // Set the output dimensions.
1672 // If the output dimension is not given, the input dimension is set
1673 // and won't be downscaling.
1674 data.width = ( data.width == 0 ) ? srcBitmap.width : data.width;
1675 data.height = ( data.height == 0 ) ? srcBitmap.rows : data.height;
1676 const ImageDimensions desiredDimensions( data.width, data.height );
1678 // Creates the output buffer
1679 const unsigned int bufferSize = data.width * data.height * 4u;
1680 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1682 if( inputDimensions == desiredDimensions )
1684 // There isn't downscaling.
1685 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1689 Dali::Internal::Platform::LanczosSample4BPP( srcBitmap.buffer,
1692 desiredDimensions );
1694 data.format = Pixel::BGRA8888;
1701 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::ConvertBitmap. FontClient Unable to create Bitmap of this PixelType\n" );
1708 bool FontClient::Plugin::FindFont( const FontPath& path,
1709 PointSize26Dot6 requestedPointSize,
1710 FaceIndex faceIndex,
1711 FontId& fontId ) const
1713 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1714 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1715 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1716 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fonts in the cache : %d\n", mFontFaceCache.size() );
1719 for( const auto& cacheItem : mFontFaceCache )
1722 if( cacheItem.mRequestedPointSize == requestedPointSize &&
1723 cacheItem.mFaceIndex == faceIndex &&
1724 cacheItem.mPath == path )
1726 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1727 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1733 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found\n" );
1734 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1740 bool FontClient::Plugin::FindValidatedFont( const FontDescription& fontDescription,
1741 FontDescriptionId& validatedFontId )
1743 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindValidatedFont\n" );
1744 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1745 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1746 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1747 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1748 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1749 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of validated fonts in the cache : %d\n", mValidatedFontCache.size() );
1751 validatedFontId = 0u;
1753 for( const auto& item : mValidatedFontCache )
1755 if( !fontDescription.family.empty() &&
1756 ( fontDescription.family == item.fontDescription.family ) &&
1757 ( fontDescription.width == item.fontDescription.width ) &&
1758 ( fontDescription.weight == item.fontDescription.weight ) &&
1759 ( fontDescription.slant == item.fontDescription.slant ) )
1761 validatedFontId = item.index;
1763 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font found, id : %d\n", validatedFontId );
1764 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1769 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font not found\n" );
1770 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1774 bool FontClient::Plugin::FindFallbackFontList( const FontDescription& fontDescription,
1775 FontList*& fontList,
1776 CharacterSetList*& characterSetList )
1778 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFontList\n" );
1779 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1780 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1781 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1782 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1783 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1784 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fallback font lists in the cache : %d\n", mFallbackCache.size() );
1788 for( const auto& item : mFallbackCache )
1790 if( !fontDescription.family.empty() &&
1791 ( fontDescription.family == item.fontDescription.family ) &&
1792 ( fontDescription.width == item.fontDescription.width ) &&
1793 ( fontDescription.weight == item.fontDescription.weight ) &&
1794 ( fontDescription.slant == item.fontDescription.slant ) )
1796 fontList = item.fallbackFonts;
1797 characterSetList = item.characterSets;
1799 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list found.\n" );
1800 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1805 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list not found.\n" );
1806 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1810 bool FontClient::Plugin::FindFont( FontDescriptionId validatedFontId,
1811 PointSize26Dot6 requestedPointSize,
1814 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1815 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
1816 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1820 for( const auto& item : mFontDescriptionSizeCache )
1822 if( ( validatedFontId == item.validatedFontId ) &&
1823 ( requestedPointSize == item.requestedPointSize ) )
1825 fontId = item.fontId;
1827 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1828 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1833 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found.\n" );
1834 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1838 bool FontClient::Plugin::IsScalable( const FontPath& path )
1840 bool isScalable = false;
1843 int error = FT_New_Face( mFreeTypeLibrary,
1847 if( FT_Err_Ok != error )
1849 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str() );
1853 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1859 bool FontClient::Plugin::IsScalable( const FontDescription& fontDescription )
1861 // Create a font pattern.
1862 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1864 FcResult result = FcResultMatch;
1866 // match the pattern
1867 FcPattern* match = FcFontMatch( nullptr /* use default configure */, fontFamilyPattern, &result );
1868 bool isScalable = false;
1872 // Get the path to the font file name.
1874 GetFcString( match, FC_FILE, path );
1875 isScalable = IsScalable( path );
1879 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1881 FcPatternDestroy( fontFamilyPattern );
1882 FcPatternDestroy( match );
1886 void FontClient::Plugin::GetFixedSizes( const FontPath& path, Vector< PointSize26Dot6 >& sizes )
1888 // Empty the caller container
1892 int error = FT_New_Face( mFreeTypeLibrary,
1896 if( FT_Err_Ok != error )
1898 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str() );
1901 // Fetch the number of fixed sizes available
1902 if ( ftFace->num_fixed_sizes && ftFace->available_sizes )
1904 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
1906 sizes.PushBack( ftFace->available_sizes[ i ].size );
1911 void FontClient::Plugin::GetFixedSizes( const FontDescription& fontDescription,
1912 Vector< PointSize26Dot6 >& sizes )
1914 // Create a font pattern.
1915 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1917 FcResult result = FcResultMatch;
1919 // match the pattern
1920 FcPattern* match = FcFontMatch( nullptr /* use default configure */, fontFamilyPattern, &result );
1924 // Get the path to the font file name.
1926 GetFcString( match, FC_FILE, path );
1927 GetFixedSizes( path, sizes );
1931 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1933 FcPatternDestroy( match );
1934 FcPatternDestroy( fontFamilyPattern );
1937 void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path )
1939 FontDescription description;
1940 description.path = path;
1941 description.family = std::move( FontFamily( ftFace->family_name ) );
1942 description.weight = FontWeight::NONE;
1943 description.width = FontWidth::NONE;
1944 description.slant = FontSlant::NONE;
1946 // Note FreeType doesn't give too much info to build a proper font style.
1947 if( ftFace->style_flags & FT_STYLE_FLAG_ITALIC )
1949 description.slant = FontSlant::ITALIC;
1951 if( ftFace->style_flags & FT_STYLE_FLAG_BOLD )
1953 description.weight = FontWeight::BOLD;
1956 FontDescriptionId validatedFontId = 0u;
1957 if( !FindValidatedFont( description,
1960 // Set the index to the vector of paths to font file names.
1961 validatedFontId = mFontDescriptionCache.size();
1963 FcPattern* pattern = CreateFontFamilyPattern( description );
1965 FcResult result = FcResultMatch;
1966 FcPattern* match = FcFontMatch( nullptr, pattern, &result );
1968 FcCharSet* characterSet = nullptr;
1969 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
1971 FcPatternDestroy( pattern );
1973 mMatchedFcPatternCache.PushBack( match );
1975 mFontFaceCache[id-1u].mCharacterSet = characterSet;
1977 // Add the path to the cache.
1978 mFontDescriptionCache.push_back( description );
1979 mCharacterSetCache.PushBack( characterSet );
1981 // Cache the index and the font's description.
1982 mValidatedFontCache.push_back( std::move( FontDescriptionCacheItem( std::move( description ),
1983 validatedFontId) ) );
1985 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
1986 mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId,
1992 FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description )
1994 FcCharSet* characterSet = nullptr;
1996 FcPattern* pattern = CreateFontFamilyPattern( description );
1998 if( nullptr != pattern )
2000 FcResult result = FcResultMatch;
2001 FcPattern* match = FcFontMatch( nullptr, pattern, &result );
2003 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
2005 mMatchedFcPatternCache.PushBack( match );
2007 FcPatternDestroy( pattern );
2010 return characterSet;
2013 void FontClient::Plugin::DestroyMatchedPatterns()
2015 for (auto & object : mMatchedFcPatternCache)
2017 FcPatternDestroy(reinterpret_cast<FcPattern*>(object));
2019 mMatchedFcPatternCache.Clear();
2022 } // namespace Internal
2024 } // namespace TextAbstraction