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/text-abstraction/font-client-plugin-impl.h>
22 #include <dali/devel-api/text-abstraction/font-list.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/platform-abstraction.h>
27 #include <dali/internal/text/text-abstraction/font-client-helper.h>
28 #include <dali/internal/imaging/common/image-operations.h>
29 #include <dali/internal/adaptor/common/adaptor-impl.h>
32 #include <fontconfig/fontconfig.h>
37 #if defined(DEBUG_ENABLED)
38 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_FONT_CLIENT");
42 * Conversion from Fractional26.6 to float
44 const float FROM_266 = 1.0f / 64.0f;
45 const float POINTS_PER_INCH = 72.f;
47 const std::string FONT_FORMAT( "TrueType" );
48 const std::string DEFAULT_FONT_FAMILY_NAME( "Tizen" );
49 const int DEFAULT_FONT_WIDTH = 100; // normal
50 const int DEFAULT_FONT_WEIGHT = 80; // normal
51 const int DEFAULT_FONT_SLANT = 0; // normal
53 const uint32_t ELLIPSIS_CHARACTER = 0x2026;
55 // http://www.freedesktop.org/software/fontconfig/fontconfig-user.html
57 // NONE -1 --> DEFAULT_FONT_WIDTH (NORMAL) will be used.
67 const int FONT_WIDTH_TYPE_TO_INT[] = { -1, 50, 63, 75, 87, 100, 113, 125, 150, 200 };
68 const unsigned int NUM_FONT_WIDTH_TYPE = sizeof( FONT_WIDTH_TYPE_TO_INT ) / sizeof( int );
70 // NONE -1 --> DEFAULT_FONT_WEIGHT (NORMAL) will be used.
72 // ULTRA_LIGHT, EXTRA_LIGHT 40
74 // DEMI_LIGHT, SEMI_LIGHT 55
78 // DEMI_BOLD, SEMI_BOLD 180
80 // ULTRA_BOLD, EXTRA_BOLD 205
81 // BLACK, HEAVY, EXTRA_BLACK 210
82 const int FONT_WEIGHT_TYPE_TO_INT[] = { -1, 0, 40, 50, 55, 75, 80, 100, 180, 200, 205, 210 };
83 const unsigned int NUM_FONT_WEIGHT_TYPE = sizeof( FONT_WEIGHT_TYPE_TO_INT ) / sizeof( int );
85 // NONE -1 --> DEFAULT_FONT_SLANT (NORMAL) will be used.
89 const int FONT_SLANT_TYPE_TO_INT[] = { -1, 0, 100, 110 };
90 const unsigned int NUM_FONT_SLANT_TYPE = sizeof( FONT_SLANT_TYPE_TO_INT ) / sizeof( int );
99 namespace TextAbstraction
106 * @brief Returns the FontWidth's enum index for the given width value.
108 * @param[in] width The width value.
110 * @return The FontWidth's enum index.
112 FontWidth::Type IntToWidthType( int width )
114 return static_cast<FontWidth::Type>( ValueToIndex( width, FONT_WIDTH_TYPE_TO_INT, NUM_FONT_WIDTH_TYPE - 1u ) );
118 * @brief Returns the FontWeight's enum index for the given weight value.
120 * @param[in] weight The weight value.
122 * @return The FontWeight's enum index.
124 FontWeight::Type IntToWeightType( int weight )
126 return static_cast<FontWeight::Type>( ValueToIndex( weight, FONT_WEIGHT_TYPE_TO_INT, NUM_FONT_WEIGHT_TYPE - 1u ) );
130 * @brief Returns the FontSlant's enum index for the given slant value.
132 * @param[in] slant The slant value.
134 * @return The FontSlant's enum index.
136 FontSlant::Type IntToSlantType( int slant )
138 return static_cast<FontSlant::Type>( ValueToIndex( slant, FONT_SLANT_TYPE_TO_INT, NUM_FONT_SLANT_TYPE - 1u ) );
141 FontClient::Plugin::FallbackCacheItem::FallbackCacheItem( FontDescription&& font, FontList* fallbackFonts, CharacterSetList* characterSets )
142 : fontDescription{ std::move( font ) },
143 fallbackFonts{ fallbackFonts },
144 characterSets{ characterSets }
148 FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const FontDescription& fontDescription,
149 FontDescriptionId index )
150 : fontDescription{ fontDescription },
155 FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( FontDescription&& fontDescription,
156 FontDescriptionId index )
157 : fontDescription{ std::move( fontDescription ) },
162 FontClient::Plugin::FontDescriptionSizeCacheItem::FontDescriptionSizeCacheItem( FontDescriptionId validatedFontId,
163 PointSize26Dot6 requestedPointSize,
165 : validatedFontId( validatedFontId ),
166 requestedPointSize( requestedPointSize ),
171 FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace,
172 const FontPath& path,
173 PointSize26Dot6 requestedPointSize,
175 const FontMetrics& metrics )
176 : mFreeTypeFace( ftFace ),
178 mRequestedPointSize( requestedPointSize ),
181 mCharacterSet( nullptr ),
182 mFixedWidthPixels( 0.0f ),
183 mFixedHeightPixels( 0.0f ),
185 mIsFixedSizeBitmap( false ),
186 mHasColorTables( false )
190 FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace,
191 const FontPath& path,
192 PointSize26Dot6 requestedPointSize,
194 const FontMetrics& metrics,
197 bool hasColorTables )
198 : mFreeTypeFace( ftFace ),
200 mRequestedPointSize( requestedPointSize ),
203 mCharacterSet( nullptr ),
204 mFixedWidthPixels( fixedWidth ),
205 mFixedHeightPixels( fixedHeight ),
207 mIsFixedSizeBitmap( true ),
208 mHasColorTables( hasColorTables )
212 FontClient::Plugin::Plugin( unsigned int horizontalDpi,
213 unsigned int verticalDpi )
214 : mFreeTypeLibrary( nullptr ),
215 mDpiHorizontal( horizontalDpi ),
216 mDpiVertical( verticalDpi ),
217 mDefaultFontDescription(),
221 mValidatedFontCache(),
222 mFontDescriptionCache( 1u ),
223 mCharacterSetCache(),
224 mFontDescriptionSizeCache(),
225 mVectorFontCache( nullptr ),
227 mDefaultFontDescriptionCached( false )
229 mCharacterSetCache.Resize( 1u );
231 int error = FT_Init_FreeType( &mFreeTypeLibrary );
232 if( FT_Err_Ok != error )
234 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Init error: %d\n", error );
237 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
238 mVectorFontCache = new VectorFontCache( mFreeTypeLibrary );
242 FontClient::Plugin::~Plugin()
244 for( auto& item : mFallbackCache )
246 if( item.fallbackFonts )
248 delete item.fallbackFonts;
249 delete item.characterSets;
250 item.fallbackFonts = nullptr;
251 item.characterSets = nullptr;
255 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
256 delete mVectorFontCache;
258 DestroyMatchedPatterns();
259 FT_Done_FreeType( mFreeTypeLibrary );
262 void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
263 unsigned int verticalDpi )
265 mDpiHorizontal = horizontalDpi;
266 mDpiVertical = verticalDpi;
269 void FontClient::Plugin::ResetSystemDefaults()
271 mDefaultFontDescriptionCached = false;
274 void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList )
276 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::SetFontList\n" );
277 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
278 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
279 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
280 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
284 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
286 FcResult result = FcResultMatch;
288 // Match the pattern.
289 FcFontSet* fontSet = FcFontSort( nullptr /* use default configure */,
291 false /* don't trim */,
295 if( nullptr != fontSet )
297 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts found : [%d]\n", fontSet->nfont );
298 // Reserve some space to avoid reallocations.
299 fontList.reserve( fontSet->nfont );
301 for( int i = 0u; i < fontSet->nfont; ++i )
303 FcPattern* fontPattern = fontSet->fonts[i];
307 // Skip fonts with no path
308 if( GetFcString( fontPattern, FC_FILE, path ) )
310 FcCharSet* characterSet = nullptr;
311 FcPatternGetCharSet( fontPattern, FC_CHARSET, 0u, &characterSet );
313 characterSetList.PushBack( characterSet );
314 fontList.push_back( FontDescription() );
315 FontDescription& newFontDescription = fontList.back();
317 newFontDescription.path = std::move( path );
322 GetFcString( fontPattern, FC_FAMILY, newFontDescription.family );
323 GetFcInt( fontPattern, FC_WIDTH, width );
324 GetFcInt( fontPattern, FC_WEIGHT, weight );
325 GetFcInt( fontPattern, FC_SLANT, slant );
326 newFontDescription.width = IntToWidthType( width );
327 newFontDescription.weight = IntToWeightType( weight );
328 newFontDescription.slant = IntToSlantType( slant );
330 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", newFontDescription.family.c_str() );
331 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", newFontDescription.path.c_str() );
332 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[newFontDescription.width] );
333 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[newFontDescription.weight] );
334 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[newFontDescription.slant] );
338 FcFontSetDestroy( fontSet );
342 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " No fonts found.\n" );
345 FcPatternDestroy( fontFamilyPattern );
346 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::SetFontList\n" );
349 void FontClient::Plugin::GetDefaultFonts( FontList& defaultFonts )
351 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultFonts\n" );
353 if( mDefaultFonts.empty() )
355 FontDescription fontDescription;
356 fontDescription.family = DEFAULT_FONT_FAMILY_NAME; // todo This could be set to the Platform font
357 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
358 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
359 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
360 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
363 defaultFonts = mDefaultFonts;
365 DALI_LOG_INFO( gLogFilter, Debug::General, " number of default fonts : [%d]\n", mDefaultFonts.size() );
366 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultFonts\n" );
369 void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
371 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultPlatformFontDescription\n");
373 if( !mDefaultFontDescriptionCached )
375 // Clear any font config stored info in the caches.
376 mDefaultFontCharacterSets.Clear();
377 mCharacterSetCache.Clear();
379 for( auto& item : mFallbackCache )
381 item.characterSets->Clear();
384 for( auto& item : mFontFaceCache )
386 // Set the character set pointer as null. Will be created again the next time IsCharacterSupportedByFont()
387 item.mCharacterSet = nullptr;
390 // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
391 FcInitReinitialize();
393 FcPattern* matchPattern = FcPatternCreate();
397 FcConfigSubstitute( nullptr, matchPattern, FcMatchPattern );
398 FcDefaultSubstitute( matchPattern );
400 FcCharSet* characterSet = nullptr;
401 MatchFontDescriptionToPattern( matchPattern, mDefaultFontDescription, &characterSet );
402 FcPatternDestroy( matchPattern );
405 // Create again the character sets as they are not valid after FcInitReinitialize()
407 for( const auto& description : mDefaultFonts )
409 mDefaultFontCharacterSets.PushBack( CreateCharacterSetFromDescription( description ) );
412 for( const auto& description : mFontDescriptionCache )
414 mCharacterSetCache.PushBack( CreateCharacterSetFromDescription( description ) );
417 for( auto& item : mFallbackCache )
419 if( nullptr != item.fallbackFonts )
421 if( nullptr == item.characterSets )
423 item.characterSets = new CharacterSetList;
426 for( const auto& description : *( item.fallbackFonts ) )
428 item.characterSets->PushBack( CreateCharacterSetFromDescription( description ) );
433 mDefaultFontDescriptionCached = true;
436 fontDescription.path = mDefaultFontDescription.path;
437 fontDescription.family = mDefaultFontDescription.family;
438 fontDescription.width = mDefaultFontDescription.width;
439 fontDescription.weight = mDefaultFontDescription.weight;
440 fontDescription.slant = mDefaultFontDescription.slant;
442 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
445 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
447 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultPlatformFontDescription\n");
450 void FontClient::Plugin::GetSystemFonts( FontList& systemFonts )
452 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetSystemFonts\n");
454 if( mSystemFonts.empty() )
459 systemFonts = mSystemFonts;
460 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : [%d]\n", mSystemFonts.size() );
461 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetSystemFonts\n");
464 void FontClient::Plugin::GetDescription( FontId id,
465 FontDescription& fontDescription ) const
467 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDescription\n");
468 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
470 for( const auto& item : mFontDescriptionSizeCache )
472 if( item.fontId == id )
474 fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId );
476 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
479 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
480 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
481 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
486 DALI_LOG_INFO( gLogFilter, Debug::General, " No description found for the font ID %d\n", id );
487 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
490 PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id )
492 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetPointSize\n");
493 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
494 const FontId index = id - 1u;
497 ( index < mFontFaceCache.size() ) )
499 DALI_LOG_INFO( gLogFilter, Debug::General, " point size : %d\n", ( *( mFontFaceCache.begin() + index ) ).mRequestedPointSize );
500 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
501 return ( *( mFontFaceCache.begin() + index ) ).mRequestedPointSize;
505 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font ID %d\n", id );
508 DALI_LOG_INFO( gLogFilter, Debug::General, " default point size : %d\n", TextAbstraction::FontClient::DEFAULT_POINT_SIZE );
509 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
510 return TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
513 bool FontClient::Plugin::IsCharacterSupportedByFont( FontId fontId, Character character )
515 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::IsCharacterSupportedByFont\n");
516 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
517 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
519 if( ( fontId < 1u ) || ( fontId > mFontFaceCache.size() ) )
521 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font id. Number of items in the cache: %d\n",mFontFaceCache.size());
522 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
528 bool isSupported = false;
530 FontFaceCacheItem& cacheItem = mFontFaceCache[fontId];
532 if( nullptr == cacheItem.mCharacterSet )
534 // Create again the character set.
535 // It can be null if the ResetSystemDefaults() method has been called.
537 FontDescription description;
538 description.path = cacheItem.mPath;
539 description.family = std::move( FontFamily( cacheItem.mFreeTypeFace->family_name ) );
540 description.weight = FontWeight::NONE;
541 description.width = FontWidth::NONE;
542 description.slant = FontSlant::NONE;
544 // Note FreeType doesn't give too much info to build a proper font style.
545 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC )
547 description.slant = FontSlant::ITALIC;
549 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_BOLD )
551 description.weight = FontWeight::BOLD;
554 cacheItem.mCharacterSet = CreateCharacterSetFromDescription( description );
557 isSupported = FcCharSetHasChar( cacheItem.mCharacterSet, character );
559 DALI_LOG_INFO( gLogFilter, Debug::General, " is supported : %s\n", (isSupported ? "true" : "false") );
560 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
564 FontId FontClient::Plugin::FindFontForCharacter( const FontList& fontList,
565 const CharacterSetList& characterSetList,
567 PointSize26Dot6 requestedPointSize,
570 DALI_ASSERT_DEBUG( ( fontList.size() == characterSetList.Count() ) && "FontClient::Plugin::FindFontForCharacter. Different number of fonts and character sets." );
572 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFontForCharacter\n" );
573 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
574 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
575 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
578 bool foundColor = false;
580 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts : %d\n", fontList.size() );
582 // Traverse the list of fonts.
583 // Check for each font if supports the character.
584 for( unsigned int index = 0u, numberOfFonts = fontList.size(); index < numberOfFonts; ++index )
586 const FontDescription& description = fontList[index];
587 const FcCharSet* const characterSet = characterSetList[index];
589 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", description.family.c_str() );
590 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
591 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
592 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
593 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
595 bool foundInRanges = false;
596 if( nullptr != characterSet )
598 foundInRanges = FcCharSetHasChar( characterSet, character );
603 fontId = GetFontId( description,
607 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " font id : %d\n", fontId );
611 if( ( fontId > 0 ) &&
612 ( fontId - 1u < mFontFaceCache.size() ) )
614 const FontFaceCacheItem& item = mFontFaceCache[fontId - 1u];
616 foundColor = item.mHasColorTables;
619 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " foundColor : %s\n", ( foundColor ? "true" : "false" ) );
622 // Keep going unless we prefer a different (color) font.
623 if( !preferColor || foundColor )
630 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
631 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFontForCharacter\n" );
635 FontId FontClient::Plugin::FindDefaultFont( Character charcode,
636 PointSize26Dot6 requestedPointSize,
639 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindDefaultFont\n" );
640 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
641 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
642 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
646 // Create the list of default fonts if it has not been created.
647 if( mDefaultFonts.empty() )
649 FontDescription fontDescription;
650 fontDescription.family = DEFAULT_FONT_FAMILY_NAME;
651 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
652 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
653 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
655 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
657 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of default fonts : %d\n", mDefaultFonts.size() );
660 // Traverse the list of default fonts.
661 // Check for each default font if supports the character.
662 fontId = FindFontForCharacter( mDefaultFonts, mDefaultFontCharacterSets, charcode, requestedPointSize, preferColor );
664 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
665 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindDefaultFont\n" );
670 FontId FontClient::Plugin::FindFallbackFont( Character charcode,
671 const FontDescription& preferredFontDescription,
672 PointSize26Dot6 requestedPointSize,
675 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFont\n" );
676 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
677 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
678 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
680 // The font id to be returned.
683 FontDescription fontDescription;
685 // Fill the font description with the preferred font description and complete with the defaults.
686 fontDescription.family = preferredFontDescription.family.empty() ? DEFAULT_FONT_FAMILY_NAME : preferredFontDescription.family;
687 fontDescription.weight = ( ( FontWeight::NONE == preferredFontDescription.weight ) ? IntToWeightType( DEFAULT_FONT_WEIGHT ) : preferredFontDescription.weight );
688 fontDescription.width = ( ( FontWidth::NONE == preferredFontDescription.width ) ? IntToWidthType( DEFAULT_FONT_WIDTH ) : preferredFontDescription.width );
689 fontDescription.slant = ( ( FontSlant::NONE == preferredFontDescription.slant ) ? IntToSlantType( DEFAULT_FONT_SLANT ) : preferredFontDescription.slant );
691 DALI_LOG_INFO( gLogFilter, Debug::General, " preferredFontDescription --> fontDescription\n" );
692 DALI_LOG_INFO( gLogFilter, Debug::General, " [%s] --> [%s]\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str() );
693 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWeight::Name[preferredFontDescription.weight], FontWeight::Name[fontDescription.weight] );
694 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width] );
695 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant] );
697 // Check first if the font's description has been queried before.
698 FontList* fontList = nullptr;
699 CharacterSetList* characterSetList = nullptr;
701 if( !FindFallbackFontList( fontDescription, fontList, characterSetList ) )
703 fontList = new FontList;
704 characterSetList = new CharacterSetList;
706 SetFontList( fontDescription, *fontList, *characterSetList );
708 // Add the font-list to the cache.
709 mFallbackCache.push_back( std::move( FallbackCacheItem( std::move( fontDescription ), fontList, characterSetList ) ) );
712 if( fontList && characterSetList )
714 fontId = FindFontForCharacter( *fontList, *characterSetList, charcode, requestedPointSize, preferColor );
717 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
718 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFont\n");
722 FontId FontClient::Plugin::GetFontId( const FontPath& path,
723 PointSize26Dot6 requestedPointSize,
725 bool cacheDescription )
727 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
728 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
729 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
733 if( nullptr != mFreeTypeLibrary )
736 if( FindFont( path, requestedPointSize, faceIndex, foundId ) )
742 id = CreateFont( path, requestedPointSize, faceIndex, cacheDescription );
746 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
747 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
752 FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription,
753 PointSize26Dot6 requestedPointSize,
754 FaceIndex faceIndex )
756 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
757 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
758 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
759 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
760 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
761 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
762 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
764 // This method uses three vectors which caches:
765 // * Pairs of non validated font descriptions and an index to a vector with paths to font file names.
766 // * The path to font file names.
767 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
769 // 1) Checks in the cache if the font's description has been validated before.
770 // If it was it gets an index to the vector with paths to font file names. Otherwise,
771 // retrieves using font config a path to a font file name which matches with the
772 // font's description. The path is stored in the cache.
774 // 2) Checks in the cache if the pair 'font point size, index to the vector with paths to
775 // font file names' exists. If exists, it gets the font id. If it doesn't it calls
776 // the GetFontId() method with the path to the font file name and the point size to
779 // The font id to be returned.
782 // Check first if the font's description have been validated before.
783 FontDescriptionId validatedFontId = 0u;
785 if( !FindValidatedFont( fontDescription,
788 // Use font config to validate the font's description.
789 ValidateFont( fontDescription,
793 // Check if exists a pair 'validatedFontId, requestedPointSize' in the cache.
794 if( !FindFont( validatedFontId, requestedPointSize, fontId ) )
796 // Retrieve the font file name path.
797 const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId );
799 // Retrieve the font id. Do not cache the description as it has been already cached.
800 fontId = GetFontId( description.path,
805 mFontFaceCache[fontId-1u].mCharacterSet = mCharacterSetCache[validatedFontId];
807 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
808 mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId,
813 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
814 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
819 void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription,
820 FontDescriptionId& validatedFontId )
822 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::ValidateFont\n" );
823 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
824 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
825 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
826 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
827 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
829 // Create a font pattern.
830 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
832 FontDescription description;
834 FcCharSet* characterSet = nullptr;
835 bool matched = MatchFontDescriptionToPattern( fontFamilyPattern, description, &characterSet );
836 FcPatternDestroy( fontFamilyPattern );
838 if( matched && ( nullptr != characterSet ) )
840 // Set the index to the vector of paths to font file names.
841 validatedFontId = mFontDescriptionCache.size();
843 DALI_LOG_INFO( gLogFilter, Debug::General, " matched description; family : [%s]\n", description.family.c_str() );
844 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
845 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
846 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
847 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
848 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
850 // Add the path to the cache.
851 mFontDescriptionCache.push_back( description );
852 mCharacterSetCache.PushBack( characterSet );
854 // Cache the index and the matched font's description.
855 FontDescriptionCacheItem item( description,
858 mValidatedFontCache.push_back( std::move( item ) );
860 if( ( fontDescription.family != description.family ) ||
861 ( fontDescription.width != description.width ) ||
862 ( fontDescription.weight != description.weight ) ||
863 ( fontDescription.slant != description.slant ) )
865 // Cache the given font's description if it's different than the matched.
866 FontDescriptionCacheItem item( fontDescription,
869 mValidatedFontCache.push_back( std::move( item ) );
874 DALI_LOG_INFO( gLogFilter, Debug::General, " font validation failed for font [%s]\n", fontDescription.family.c_str() );
877 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::ValidateFont\n" );
880 void FontClient::Plugin::GetFontMetrics( FontId fontId,
881 FontMetrics& metrics )
883 if( ( fontId > 0 ) &&
884 ( fontId - 1u < mFontFaceCache.size() ) )
886 const FontFaceCacheItem& font = mFontFaceCache[fontId-1];
888 metrics = font.mMetrics;
890 // Adjust the metrics if the fixed-size font should be down-scaled
891 if( font.mIsFixedSizeBitmap )
893 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
895 if( desiredFixedSize > 0.f )
897 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
899 metrics.ascender = floorf( metrics.ascender * scaleFactor );
900 metrics.descender = floorf( metrics.descender * scaleFactor );
901 metrics.height = floorf( metrics.height * scaleFactor );
902 metrics.underlinePosition = floorf( metrics.underlinePosition * scaleFactor );
903 metrics.underlineThickness = floorf( metrics.underlineThickness * scaleFactor );
909 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFontMetrics. Invalid font id : %d\n", fontId );
913 GlyphIndex FontClient::Plugin::GetGlyphIndex( FontId fontId,
916 GlyphIndex index = 0u;
918 if( ( fontId > 0u ) &&
919 ( fontId - 1u < mFontFaceCache.size() ) )
921 FT_Face ftFace = mFontFaceCache[fontId-1u].mFreeTypeFace;
923 index = FT_Get_Char_Index( ftFace, charcode );
929 bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
934 if( VECTOR_GLYPH == type )
936 return GetVectorMetrics( array, size, horizontal );
939 return GetBitmapMetrics( array, size, horizontal );
942 bool FontClient::Plugin::GetBitmapMetrics( GlyphInfo* array,
946 bool success( true );
948 for( unsigned int i=0; i<size; ++i )
950 GlyphInfo& glyph = array[i];
952 FontId fontId = glyph.fontId;
955 fontId-1 < mFontFaceCache.size() )
957 const FontFaceCacheItem& font = mFontFaceCache[fontId-1];
959 FT_Face ftFace = font.mFreeTypeFace;
961 #ifdef FREETYPE_BITMAP_SUPPORT
962 // Check to see if we should be loading a Fixed Size bitmap?
963 if ( font.mIsFixedSizeBitmap )
965 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_COLOR );
966 if ( FT_Err_Ok == error )
968 glyph.width = font.mFixedWidthPixels;
969 glyph.height = font.mFixedHeightPixels;
970 glyph.advance = font.mFixedWidthPixels;
971 glyph.xBearing = 0.0f;
972 glyph.yBearing = font.mFixedHeightPixels;
974 // Adjust the metrics if the fixed-size font should be down-scaled
975 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
977 if( desiredFixedSize > 0.f )
979 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
981 glyph.width = floorf( glyph.width * scaleFactor );
982 glyph.height = floorf( glyph.height * scaleFactor );
983 glyph.advance = floorf( glyph.advance * scaleFactor );
984 glyph.xBearing = floorf( glyph.xBearing * scaleFactor );
985 glyph.yBearing = floorf( glyph.yBearing * scaleFactor );
987 glyph.scaleFactor = scaleFactor;
992 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetBitmapMetrics. FreeType Bitmap Load_Glyph error %d\n", error );
999 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_NO_AUTOHINT );
1001 if( FT_Err_Ok == error )
1003 glyph.width = static_cast< float >( ftFace->glyph->metrics.width ) * FROM_266;
1004 glyph.height = static_cast< float >( ftFace->glyph->metrics.height ) * FROM_266 ;
1007 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingX ) * FROM_266;
1008 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingY ) * FROM_266;
1012 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingX ) * FROM_266;
1013 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingY ) * FROM_266;
1031 bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array,
1035 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1036 bool success( true );
1038 for( unsigned int i=0; i<size; ++i )
1040 FontId fontId = array[i].fontId;
1043 fontId-1 < mFontFaceCache.size() )
1045 FontFaceCacheItem& font = mFontFaceCache[fontId-1];
1047 if( ! font.mVectorFontId )
1049 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1052 mVectorFontCache->GetGlyphMetrics( font.mVectorFontId, array[i] );
1054 // Vector metrics are in EMs, convert to pixels
1055 const float scale = ( static_cast<float>( font.mRequestedPointSize ) * FROM_266 ) * static_cast<float>( mDpiVertical ) / POINTS_PER_INCH;
1056 array[i].width *= scale;
1057 array[i].height *= scale;
1058 array[i].xBearing *= scale;
1059 array[i].yBearing *= scale;
1060 array[i].advance *= scale;
1074 void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
1076 if( ( fontId > 0 ) &&
1077 ( fontId - 1u < mFontFaceCache.size() ) )
1079 FT_Face ftFace = mFontFaceCache[fontId - 1u].mFreeTypeFace;
1083 #ifdef FREETYPE_BITMAP_SUPPORT
1084 // Check to see if this is fixed size bitmap
1085 if ( mFontFaceCache[fontId - 1u].mIsFixedSizeBitmap )
1087 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1092 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_NO_AUTOHINT );
1094 if( FT_Err_Ok == error )
1097 error = FT_Get_Glyph( ftFace->glyph, &glyph );
1099 // Convert to bitmap if necessary
1100 if ( FT_Err_Ok == error )
1102 if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
1104 // Check whether we should create a bitmap for the outline
1105 if( glyph->format == FT_GLYPH_FORMAT_OUTLINE && outlineWidth > 0 )
1109 error = FT_Stroker_New(mFreeTypeLibrary, &stroker );
1111 if ( FT_Err_Ok == error )
1113 FT_Stroker_Set( stroker, outlineWidth * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 );
1114 error = FT_Glyph_StrokeBorder( &glyph, stroker, 0, 1 );
1116 if ( FT_Err_Ok == error )
1118 FT_Stroker_Done( stroker );
1122 DALI_LOG_ERROR( "FT_Glyph_StrokeBorder Failed with error: %d\n", error );
1127 DALI_LOG_ERROR( "FT_Stroker_New Failed with error: %d\n", error );
1131 error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
1132 if ( FT_Err_Ok == error )
1134 FT_BitmapGlyph bitmapGlyph = reinterpret_cast< FT_BitmapGlyph >( glyph );
1135 ConvertBitmap( data, bitmapGlyph->bitmap );
1139 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Get_Glyph Failed with error: %d\n", error );
1144 ConvertBitmap( data, ftFace->glyph->bitmap );
1147 // Created FT_Glyph object must be released with FT_Done_Glyph
1148 FT_Done_Glyph( glyph );
1153 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Load_Glyph Failed with error: %d\n", error );
1158 PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
1160 TextAbstraction::FontClient::GlyphBufferData data;
1162 CreateBitmap( fontId, glyphIndex, data, outlineWidth );
1164 return PixelData::New( data.buffer,
1165 data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
1169 PixelData::DELETE_ARRAY );
1172 void FontClient::Plugin::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
1177 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1179 fontId-1 < mFontFaceCache.size() )
1181 FontFaceCacheItem& font = mFontFaceCache[fontId-1];
1183 if( ! font.mVectorFontId )
1185 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1188 mVectorFontCache->GetVectorBlob( font.mVectorFontId, fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
1193 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
1195 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetEllipsisGlyph\n" );
1196 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize %d.\n", requestedPointSize );
1198 // First look into the cache if there is an ellipsis glyph for the requested point size.
1199 for( const auto& item : mEllipsisCache )
1201 if( fabsf( item.requestedPointSize - requestedPointSize ) < Math::MACHINE_EPSILON_1000 )
1203 // Use the glyph in the cache.
1205 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1206 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1207 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1213 // No glyph has been found. Create one.
1214 mEllipsisCache.PushBack( EllipsisItem() );
1215 EllipsisItem& item = *( mEllipsisCache.End() - 1u );
1217 item.requestedPointSize = requestedPointSize;
1219 // Find a font for the ellipsis glyph.
1220 item.glyph.fontId = FindDefaultFont( ELLIPSIS_CHARACTER,
1224 // Set the character index to access the glyph inside the font.
1225 item.glyph.index = FT_Get_Char_Index( mFontFaceCache[item.glyph.fontId-1].mFreeTypeFace,
1226 ELLIPSIS_CHARACTER );
1228 GetBitmapMetrics( &item.glyph, 1u, true );
1230 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1231 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1232 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1237 bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
1239 FT_Error error = -1;
1241 #ifdef FREETYPE_BITMAP_SUPPORT
1242 if( ( fontId > 0 ) &&
1243 ( fontId - 1u < mFontFaceCache.size() ) )
1245 const FontFaceCacheItem& item = mFontFaceCache[fontId - 1u];
1246 FT_Face ftFace = item.mFreeTypeFace;
1248 // Check to see if this is fixed size bitmap
1249 if( item.mHasColorTables )
1251 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1256 return FT_Err_Ok == error;
1259 FT_FaceRec_* FontClient::Plugin::GetFreetypeFace( FontId fontId )
1261 FT_Face fontFace = nullptr;
1263 if( ( fontId > 0u ) &&
1264 ( fontId - 1u < mFontFaceCache.size() ) )
1266 fontFace = mFontFaceCache[fontId - 1u].mFreeTypeFace;
1272 void FontClient::Plugin::InitSystemFonts()
1274 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" );
1276 FcFontSet* fontSet = GetFcFontSet();
1280 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : %d\n", fontSet->nfont );
1282 // Reserve some space to avoid reallocations.
1283 mSystemFonts.reserve( fontSet->nfont );
1285 for( int i = 0u; i < fontSet->nfont; ++i )
1287 FcPattern* fontPattern = fontSet->fonts[i];
1291 // Skip fonts with no path
1292 if( GetFcString( fontPattern, FC_FILE, path ) )
1294 mSystemFonts.push_back( FontDescription() );
1295 FontDescription& fontDescription = mSystemFonts.back();
1297 fontDescription.path = std::move( path );
1302 GetFcString( fontPattern, FC_FAMILY, fontDescription.family );
1303 GetFcInt( fontPattern, FC_WIDTH, width );
1304 GetFcInt( fontPattern, FC_WEIGHT, weight );
1305 GetFcInt( fontPattern, FC_SLANT, slant );
1306 fontDescription.width = IntToWidthType( width );
1307 fontDescription.weight = IntToWeightType( weight );
1308 fontDescription.slant = IntToSlantType( slant );
1310 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", fontDescription.family.c_str() );
1311 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1312 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1313 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1314 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1318 FcFontSetDestroy( fontSet );
1320 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::InitSystemFonts\n" );
1323 bool FontClient::Plugin::MatchFontDescriptionToPattern( FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet )
1325 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1327 FcResult result = FcResultMatch;
1328 FcPattern* match = FcFontMatch( nullptr /* use default configure */, pattern, &result );
1330 const bool matched = nullptr != match;
1331 DALI_LOG_INFO( gLogFilter, Debug::General, " pattern matched : %s\n", ( matched ? "true" : "false" ) );
1338 GetFcString( match, FC_FILE, fontDescription.path );
1339 GetFcString( match, FC_FAMILY, fontDescription.family );
1340 GetFcInt( match, FC_WIDTH, width );
1341 GetFcInt( match, FC_WEIGHT, weight );
1342 GetFcInt( match, FC_SLANT, slant );
1343 fontDescription.width = IntToWidthType( width );
1344 fontDescription.weight = IntToWeightType( weight );
1345 fontDescription.slant = IntToSlantType( slant );
1347 // Cache the character ranges.
1348 FcPatternGetCharSet( match, FC_CHARSET, 0u, characterSet );
1350 // destroyed the matched pattern
1351 FcPatternDestroy( match );
1353 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1354 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1356 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1357 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1360 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1364 FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& fontDescription ) const
1366 // create the cached font family lookup pattern
1367 // a pattern holds a set of names, each name refers to a property of the font
1368 FcPattern* fontFamilyPattern = FcPatternCreate();
1370 if( !fontFamilyPattern )
1375 // add a property to the pattern for the font family
1376 FcPatternAddString( fontFamilyPattern, FC_FAMILY, reinterpret_cast<const FcChar8*>( fontDescription.family.c_str() ) );
1378 int width = FONT_WIDTH_TYPE_TO_INT[fontDescription.width];
1382 width = DEFAULT_FONT_WIDTH;
1385 int weight = FONT_WEIGHT_TYPE_TO_INT[fontDescription.weight];
1389 weight = DEFAULT_FONT_WEIGHT;
1392 int slant = FONT_SLANT_TYPE_TO_INT[fontDescription.slant];
1396 slant = DEFAULT_FONT_SLANT;
1399 FcPatternAddInteger( fontFamilyPattern, FC_WIDTH, width );
1400 FcPatternAddInteger( fontFamilyPattern, FC_WEIGHT, weight );
1401 FcPatternAddInteger( fontFamilyPattern, FC_SLANT, slant );
1403 // Add a property of the pattern, to say we want to match TrueType fonts
1404 FcPatternAddString( fontFamilyPattern , FC_FONTFORMAT, reinterpret_cast<const FcChar8*>( FONT_FORMAT.c_str() ) );
1406 // modify the config, with the mFontFamilyPatterm
1407 FcConfigSubstitute( nullptr /* use default configure */, fontFamilyPattern, FcMatchPattern );
1409 // provide default values for unspecified properties in the font pattern
1410 // e.g. patterns without a specified style or weight are set to Medium
1411 FcDefaultSubstitute( fontFamilyPattern );
1413 return fontFamilyPattern;
1416 _FcFontSet* FontClient::Plugin::GetFcFontSet() const
1418 // create a new pattern.
1419 // a pattern holds a set of names, each name refers to a property of the font
1420 FcPattern* pattern = FcPatternCreate();
1422 FcFontSet* fontset = NULL;
1424 // create an object set used to define which properties are to be returned in the patterns from FcFontList.
1425 FcObjectSet* objectSet = FcObjectSetCreate();
1429 // build an object set from a list of property names
1430 FcObjectSetAdd( objectSet, FC_FILE );
1431 FcObjectSetAdd( objectSet, FC_FAMILY );
1432 FcObjectSetAdd( objectSet, FC_WIDTH );
1433 FcObjectSetAdd( objectSet, FC_WEIGHT );
1434 FcObjectSetAdd( objectSet, FC_SLANT );
1436 // get a list of fonts
1437 // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
1438 fontset = FcFontList( NULL /* the default configuration is checked to be up to date, and used */, pattern, objectSet );
1440 // clear up the object set
1441 FcObjectSetDestroy( objectSet );
1443 // clear up the pattern
1446 FcPatternDestroy( pattern );
1452 bool FontClient::Plugin::GetFcString( const FcPattern* const pattern,
1453 const char* const n,
1454 std::string& string )
1456 FcChar8* file = nullptr;
1457 const FcResult retVal = FcPatternGetString( pattern, n, 0u, &file );
1459 if( FcResultMatch == retVal )
1461 // Have to use reinterpret_cast because FcChar8 is unsigned char*, not a const char*.
1462 string.assign( reinterpret_cast<const char*>( file ) );
1470 bool FontClient::Plugin::GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal )
1472 const FcResult retVal = FcPatternGetInteger( pattern, n, 0u, &intVal );
1474 if( FcResultMatch == retVal )
1482 FontId FontClient::Plugin::CreateFont( const FontPath& path,
1483 PointSize26Dot6 requestedPointSize,
1484 FaceIndex faceIndex,
1485 bool cacheDescription )
1487 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::CreateFont\n" );
1488 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1489 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1493 // Create & cache new font face
1495 int error = FT_New_Face( mFreeTypeLibrary,
1500 if( FT_Err_Ok == error )
1502 // Check if a font is scalable.
1503 const bool isScalable = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_SCALABLE ) );
1504 const bool hasFixedSizedBitmaps = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES ) ) && ( 0 != ftFace->num_fixed_sizes );
1505 const bool hasColorTables = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_COLOR ) );
1507 DALI_LOG_INFO( gLogFilter, Debug::General, " isScalable : [%s]\n", ( isScalable ? "true" : "false" ) );
1508 DALI_LOG_INFO( gLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", ( hasFixedSizedBitmaps ? "true" : "false" ) );
1509 DALI_LOG_INFO( gLogFilter, Debug::General, " hasColorTables : [%s]\n", ( hasColorTables ? "true" : "false" ) );
1511 // Check to see if the font contains fixed sizes?
1512 if( !isScalable && hasFixedSizedBitmaps )
1514 PointSize26Dot6 actualPointSize = 0u;
1515 int fixedSizeIndex = 0;
1516 for( ; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex )
1518 const PointSize26Dot6 fixedSize = ftFace->available_sizes[fixedSizeIndex].size;
1519 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize );
1521 if( fixedSize >= requestedPointSize )
1523 actualPointSize = fixedSize;
1528 if( 0u == actualPointSize )
1530 // The requested point size is bigger than the bigest fixed size.
1531 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1532 actualPointSize = ftFace->available_sizes[fixedSizeIndex].size;
1535 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize );
1537 // Tell Freetype to use this size
1538 error = FT_Select_Size( ftFace, fixedSizeIndex );
1539 if ( FT_Err_Ok != error )
1541 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error );
1545 float fixedWidth = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].width );
1546 float fixedHeight = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].height );
1548 // Indicate that the font is a fixed sized bitmap
1549 FontMetrics metrics( fixedHeight, // The ascender in pixels.
1551 fixedHeight, // The height in pixels.
1555 mFontFaceCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics, fixedWidth, fixedHeight, hasColorTables ) );
1556 id = mFontFaceCache.size();
1561 error = FT_Set_Char_Size( ftFace,
1567 if( FT_Err_Ok == error )
1570 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1572 FontMetrics metrics( static_cast< float >( ftMetrics.ascender ) * FROM_266,
1573 static_cast< float >( ftMetrics.descender ) * FROM_266,
1574 static_cast< float >( ftMetrics.height ) * FROM_266,
1575 static_cast< float >( ftFace->underline_position ) * FROM_266,
1576 static_cast< float >( ftFace->underline_thickness ) * FROM_266 );
1578 mFontFaceCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics ) );
1579 id = mFontFaceCache.size();
1583 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize );
1589 if( cacheDescription )
1591 CacheFontPath( ftFace, id, requestedPointSize, path );
1597 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str() );
1600 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
1601 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::CreateFont\n" );
1606 void FontClient::Plugin::ConvertBitmap( TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap )
1608 if( srcBitmap.width*srcBitmap.rows > 0 )
1610 switch( srcBitmap.pixel_mode )
1612 case FT_PIXEL_MODE_GRAY:
1614 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width ) )
1616 const unsigned int bufferSize = srcBitmap.width * srcBitmap.rows;
1617 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1618 data.width = srcBitmap.width;
1619 data.height = srcBitmap.rows;
1620 data.format = Pixel::L8;
1621 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1626 #ifdef FREETYPE_BITMAP_SUPPORT
1627 case FT_PIXEL_MODE_BGRA:
1629 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width << 2u ) )
1631 // Set the input dimensions.
1632 const ImageDimensions inputDimensions( srcBitmap.width, srcBitmap.rows );
1634 // Set the output dimensions.
1635 // If the output dimension is not given, the input dimension is set
1636 // and won't be downscaling.
1637 data.width = ( data.width == 0 ) ? srcBitmap.width : data.width;
1638 data.height = ( data.height == 0 ) ? srcBitmap.rows : data.height;
1639 const ImageDimensions desiredDimensions( data.width, data.height );
1641 // Creates the output buffer
1642 const unsigned int bufferSize = data.width * data.height * 4u;
1643 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1645 if( inputDimensions == desiredDimensions )
1647 // There isn't downscaling.
1648 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1652 Dali::Internal::Platform::LanczosSample4BPP( srcBitmap.buffer,
1655 desiredDimensions );
1657 data.format = Pixel::BGRA8888;
1664 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::ConvertBitmap. FontClient Unable to create Bitmap of this PixelType\n" );
1671 bool FontClient::Plugin::FindFont( const FontPath& path,
1672 PointSize26Dot6 requestedPointSize,
1673 FaceIndex faceIndex,
1674 FontId& fontId ) const
1676 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1677 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1678 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1679 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fonts in the cache : %d\n", mFontFaceCache.size() );
1682 for( const auto& cacheItem : mFontFaceCache )
1685 if( cacheItem.mRequestedPointSize == requestedPointSize &&
1686 cacheItem.mFaceIndex == faceIndex &&
1687 cacheItem.mPath == path )
1690 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1691 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1697 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found\n" );
1698 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1704 bool FontClient::Plugin::FindValidatedFont( const FontDescription& fontDescription,
1705 FontDescriptionId& validatedFontId )
1707 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindValidatedFont\n" );
1708 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1709 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1710 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1711 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1712 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1713 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of validated fonts in the cache : %d\n", mValidatedFontCache.size() );
1715 validatedFontId = 0u;
1717 for( const auto& item : mValidatedFontCache )
1719 if( !fontDescription.family.empty() &&
1720 ( fontDescription.family == item.fontDescription.family ) &&
1721 ( fontDescription.width == item.fontDescription.width ) &&
1722 ( fontDescription.weight == item.fontDescription.weight ) &&
1723 ( fontDescription.slant == item.fontDescription.slant ) )
1725 validatedFontId = item.index;
1727 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font found, id : %d\n", validatedFontId );
1728 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1733 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font not found\n" );
1734 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1738 bool FontClient::Plugin::FindFallbackFontList( const FontDescription& fontDescription,
1739 FontList*& fontList,
1740 CharacterSetList*& characterSetList )
1742 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFontList\n" );
1743 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1744 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1745 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1746 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1747 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1748 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fallback font lists in the cache : %d\n", mFallbackCache.size() );
1752 for( const auto& item : mFallbackCache )
1754 if( !fontDescription.family.empty() &&
1755 ( fontDescription.family == item.fontDescription.family ) &&
1756 ( fontDescription.width == item.fontDescription.width ) &&
1757 ( fontDescription.weight == item.fontDescription.weight ) &&
1758 ( fontDescription.slant == item.fontDescription.slant ) )
1760 fontList = item.fallbackFonts;
1761 characterSetList = item.characterSets;
1763 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list found.\n" );
1764 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1769 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list not found.\n" );
1770 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1774 bool FontClient::Plugin::FindFont( FontDescriptionId validatedFontId,
1775 PointSize26Dot6 requestedPointSize,
1778 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1779 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
1780 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1784 for( const auto& item : mFontDescriptionSizeCache )
1786 if( ( validatedFontId == item.validatedFontId ) &&
1787 ( requestedPointSize == item.requestedPointSize ) )
1789 fontId = item.fontId;
1791 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1792 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1797 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found.\n" );
1798 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1802 bool FontClient::Plugin::IsScalable( const FontPath& path )
1804 bool isScalable = false;
1807 int error = FT_New_Face( mFreeTypeLibrary,
1811 if( FT_Err_Ok != error )
1813 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str() );
1817 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1823 bool FontClient::Plugin::IsScalable( const FontDescription& fontDescription )
1825 // Create a font pattern.
1826 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1828 FcResult result = FcResultMatch;
1830 // match the pattern
1831 FcPattern* match = FcFontMatch( nullptr /* use default configure */, fontFamilyPattern, &result );
1832 bool isScalable = false;
1836 // Get the path to the font file name.
1838 GetFcString( match, FC_FILE, path );
1839 isScalable = IsScalable( path );
1843 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1845 FcPatternDestroy( fontFamilyPattern );
1846 FcPatternDestroy( match );
1850 void FontClient::Plugin::GetFixedSizes( const FontPath& path, Vector< PointSize26Dot6 >& sizes )
1852 // Empty the caller container
1856 int error = FT_New_Face( mFreeTypeLibrary,
1860 if( FT_Err_Ok != error )
1862 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str() );
1865 // Fetch the number of fixed sizes available
1866 if ( ftFace->num_fixed_sizes && ftFace->available_sizes )
1868 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
1870 sizes.PushBack( ftFace->available_sizes[ i ].size );
1875 void FontClient::Plugin::GetFixedSizes( const FontDescription& fontDescription,
1876 Vector< PointSize26Dot6 >& sizes )
1878 // Create a font pattern.
1879 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1881 FcResult result = FcResultMatch;
1883 // match the pattern
1884 FcPattern* match = FcFontMatch( nullptr /* use default configure */, fontFamilyPattern, &result );
1888 // Get the path to the font file name.
1890 GetFcString( match, FC_FILE, path );
1891 GetFixedSizes( path, sizes );
1895 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1897 FcPatternDestroy( match );
1898 FcPatternDestroy( fontFamilyPattern );
1901 void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path )
1903 FontDescription description;
1904 description.path = path;
1905 description.family = std::move( FontFamily( ftFace->family_name ) );
1906 description.weight = FontWeight::NONE;
1907 description.width = FontWidth::NONE;
1908 description.slant = FontSlant::NONE;
1910 // Note FreeType doesn't give too much info to build a proper font style.
1911 if( ftFace->style_flags & FT_STYLE_FLAG_ITALIC )
1913 description.slant = FontSlant::ITALIC;
1915 if( ftFace->style_flags & FT_STYLE_FLAG_BOLD )
1917 description.weight = FontWeight::BOLD;
1920 FontDescriptionId validatedFontId = 0u;
1921 if( !FindValidatedFont( description,
1924 // Set the index to the vector of paths to font file names.
1925 validatedFontId = mFontDescriptionCache.size();
1927 FcPattern* pattern = CreateFontFamilyPattern( description );
1929 FcResult result = FcResultMatch;
1930 FcPattern* match = FcFontMatch( nullptr, pattern, &result );
1932 FcCharSet* characterSet = nullptr;
1933 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
1935 FcPatternDestroy( pattern );
1937 mMatchedFcPatternCache.PushBack( match );
1939 mFontFaceCache[id-1u].mCharacterSet = characterSet;
1941 // Add the path to the cache.
1942 mFontDescriptionCache.push_back( description );
1943 mCharacterSetCache.PushBack( characterSet );
1945 // Cache the index and the font's description.
1946 mValidatedFontCache.push_back( std::move( FontDescriptionCacheItem( std::move( description ),
1947 validatedFontId) ) );
1949 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
1950 mFontDescriptionSizeCache.push_back( FontDescriptionSizeCacheItem( validatedFontId,
1956 FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description )
1958 FcCharSet* characterSet = nullptr;
1960 FcPattern* pattern = CreateFontFamilyPattern( description );
1962 if( nullptr != pattern )
1964 FcResult result = FcResultMatch;
1965 FcPattern* match = FcFontMatch( nullptr, pattern, &result );
1967 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
1968 mMatchedFcPatternCache.PushBack( match );
1970 FcPatternDestroy( pattern );
1973 return characterSet;
1976 void FontClient::Plugin::DestroyMatchedPatterns()
1978 for (auto & object : mMatchedFcPatternCache)
1980 FcPatternDestroy(reinterpret_cast<FcPattern*>(object));
1982 mMatchedFcPatternCache.Clear();
1985 } // namespace Internal
1987 } // namespace TextAbstraction