2 * Copyright (c) 2017 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( const FontDescription& font, FontList* fallbackFonts, CharacterSetList* characterSets )
145 : fontDescription( font ),
146 fallbackFonts( fallbackFonts ),
147 characterSets( characterSets )
151 FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const FontDescription& fontDescription,
152 FontDescriptionId index )
153 : fontDescription( fontDescription ),
158 FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validatedFontId,
159 PointSize26Dot6 requestedPointSize,
161 : validatedFontId( validatedFontId ),
162 requestedPointSize( requestedPointSize ),
167 FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace,
168 const FontPath& path,
169 PointSize26Dot6 requestedPointSize,
171 const FontMetrics& metrics )
172 : mFreeTypeFace( ftFace ),
174 mRequestedPointSize( requestedPointSize ),
177 mCharacterSet( NULL ),
178 mFixedWidthPixels( 0.0f ),
179 mFixedHeightPixels( 0.0f ),
181 mIsFixedSizeBitmap( false ),
182 mHasColorTables( false )
186 FontClient::Plugin::FontFaceCacheItem::FontFaceCacheItem( FT_Face ftFace,
187 const FontPath& path,
188 PointSize26Dot6 requestedPointSize,
190 const FontMetrics& metrics,
193 bool hasColorTables )
194 : mFreeTypeFace( ftFace ),
196 mRequestedPointSize( requestedPointSize ),
199 mCharacterSet( NULL ),
200 mFixedWidthPixels( fixedWidth ),
201 mFixedHeightPixels( fixedHeight ),
203 mIsFixedSizeBitmap( true ),
204 mHasColorTables( hasColorTables )
208 FontClient::Plugin::Plugin( unsigned int horizontalDpi,
209 unsigned int verticalDpi )
210 : mFreeTypeLibrary( NULL ),
211 mDpiHorizontal( horizontalDpi ),
212 mDpiVertical( verticalDpi ),
213 mDefaultFontDescription(),
217 mValidatedFontCache(),
218 mFontDescriptionCache( 1u ),
219 mCharacterSetCache(),
221 mVectorFontCache( NULL ),
223 mDefaultFontDescriptionCached( false )
225 mCharacterSetCache.Resize( 1u );
227 int error = FT_Init_FreeType( &mFreeTypeLibrary );
228 if( FT_Err_Ok != error )
230 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Init error: %d\n", error );
233 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
234 mVectorFontCache = new VectorFontCache( mFreeTypeLibrary );
239 FontClient::Plugin::~Plugin()
241 for( std::vector<FallbackCacheItem>::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end();
245 FallbackCacheItem& item = *it;
247 if( item.fallbackFonts )
249 delete item.fallbackFonts;
250 delete item.characterSets;
251 item.fallbackFonts = NULL;
252 item.characterSets = NULL;
256 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
257 delete mVectorFontCache;
260 FT_Done_FreeType( mFreeTypeLibrary );
263 void FontClient::Plugin::ClearCache()
266 mValidatedFontCache.clear();
267 mFontDescriptionCache.clear();
268 mFontDescriptionCache.resize( 1u );
270 mCharacterSetCache.Clear();
271 mCharacterSetCache.Resize( 1u );
273 mFontIdCache.clear();
274 mFallbackCache.clear();
276 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
279 mVectorFontCache.clear();
280 mVectorFontCache = NULL;
284 mEllipsisCache.Clear();
285 mSystemFonts.clear();
286 mDefaultFonts.clear();
287 mDefaultFontDescriptionCached = false;
288 mDefaultFontCharacterSets.Clear();
289 mDefaultFontDescription = FontDescription();
292 void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
293 unsigned int verticalDpi )
295 mDpiHorizontal = horizontalDpi;
296 mDpiVertical = verticalDpi;
299 void FontClient::Plugin::ResetSystemDefaults()
301 mDefaultFontDescriptionCached = false;
304 void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList )
306 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::SetFontList\n" );
307 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
308 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
309 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
310 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
314 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
316 FcResult result = FcResultMatch;
318 // Match the pattern.
319 FcFontSet* fontSet = FcFontSort( NULL /* use default configure */,
321 false /* don't trim */,
325 if( NULL != fontSet )
327 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts found : [%d]\n", fontSet->nfont );
328 // Reserve some space to avoid reallocations.
329 fontList.reserve( fontSet->nfont );
331 for( int i = 0u; i < fontSet->nfont; ++i )
333 FcPattern* fontPattern = fontSet->fonts[i];
337 // Skip fonts with no path
338 if( GetFcString( fontPattern, FC_FILE, path ) )
340 FcCharSet* characterSet = NULL;
341 FcPatternGetCharSet( fontPattern, FC_CHARSET, 0u, &characterSet );
343 characterSetList.PushBack( characterSet );
344 fontList.push_back( FontDescription() );
345 FontDescription& newFontDescription = fontList.back();
347 newFontDescription.path = path;
352 GetFcString( fontPattern, FC_FAMILY, newFontDescription.family );
353 GetFcInt( fontPattern, FC_WIDTH, width );
354 GetFcInt( fontPattern, FC_WEIGHT, weight );
355 GetFcInt( fontPattern, FC_SLANT, slant );
356 newFontDescription.width = IntToWidthType( width );
357 newFontDescription.weight = IntToWeightType( weight );
358 newFontDescription.slant = IntToSlantType( slant );
360 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", newFontDescription.family.c_str() );
361 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", newFontDescription.path.c_str() );
362 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[newFontDescription.width] );
363 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[newFontDescription.weight] );
364 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[newFontDescription.slant] );
368 FcFontSetDestroy( fontSet );
372 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " No fonts found.\n" );
375 FcPatternDestroy( fontFamilyPattern );
376 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::SetFontList\n" );
379 void FontClient::Plugin::GetDefaultFonts( FontList& defaultFonts )
381 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultFonts\n" );
383 if( mDefaultFonts.empty() )
385 FontDescription fontDescription;
386 fontDescription.family = DEFAULT_FONT_FAMILY_NAME; // todo This could be set to the Platform font
387 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
388 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
389 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
390 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
393 defaultFonts = mDefaultFonts;
395 DALI_LOG_INFO( gLogFilter, Debug::General, " number of default fonts : [%d]\n", mDefaultFonts.size() );
396 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultFonts\n" );
399 void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
401 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultPlatformFontDescription\n");
403 if( !mDefaultFontDescriptionCached )
405 // Clear any font config stored info in the caches.
406 mDefaultFontCharacterSets.Clear();
407 mCharacterSetCache.Clear();
409 for( std::vector<FallbackCacheItem>::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); it != endIt; ++it )
411 FallbackCacheItem& item = *it;
413 item.characterSets->Clear();
416 for( std::vector<FontFaceCacheItem>::iterator it = mFontCache.begin(), endIt = mFontCache.end(); it != endIt; ++it )
418 FontFaceCacheItem& item = *it;
420 // Set the character set pointer as null. Will be created again the next time IsCharacterSupportedByFont()
421 item.mCharacterSet = NULL;
424 // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
425 FcInitReinitialize();
427 FcPattern* matchPattern = FcPatternCreate();
431 FcConfigSubstitute( NULL, matchPattern, FcMatchPattern );
432 FcDefaultSubstitute( matchPattern );
434 FcCharSet* characterSet = NULL;
435 MatchFontDescriptionToPattern( matchPattern, mDefaultFontDescription, &characterSet );
436 FcPatternDestroy( matchPattern );
439 // Create again the character sets as they are not valid after FcInitReinitialize()
441 for( FontList::const_iterator it = mDefaultFonts.begin(), endIt = mDefaultFonts.end(); it != endIt; ++it )
443 const FontDescription& description = *it;
445 mDefaultFontCharacterSets.PushBack( CreateCharacterSetFromDescription( description ) );
448 for( FontList::const_iterator it = mFontDescriptionCache.begin(), endIt = mFontDescriptionCache.end(); it != endIt; ++it )
450 const FontDescription& description = *it;
452 mCharacterSetCache.PushBack( CreateCharacterSetFromDescription( description ) );
455 for( std::vector<FallbackCacheItem>::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); it != endIt; ++it )
457 FallbackCacheItem& item = *it;
459 if( NULL != item.fallbackFonts )
461 if( NULL == item.characterSets )
463 item.characterSets = new CharacterSetList;
466 for( FontList::const_iterator flIt = item.fallbackFonts->begin(), flEndIt = item.fallbackFonts->end(); flIt != flEndIt; ++flIt )
468 const FontDescription& description = *flIt;
469 item.characterSets->PushBack( CreateCharacterSetFromDescription( description ) );
474 mDefaultFontDescriptionCached = true;
477 fontDescription.path = mDefaultFontDescription.path;
478 fontDescription.family = mDefaultFontDescription.family;
479 fontDescription.width = mDefaultFontDescription.width;
480 fontDescription.weight = mDefaultFontDescription.weight;
481 fontDescription.slant = mDefaultFontDescription.slant;
483 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
484 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
485 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
486 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
487 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
488 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultPlatformFontDescription\n");
491 void FontClient::Plugin::GetSystemFonts( FontList& systemFonts )
493 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetSystemFonts\n");
495 if( mSystemFonts.empty() )
500 systemFonts = mSystemFonts;
501 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : [%d]\n", mSystemFonts.size() );
502 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetSystemFonts\n");
505 void FontClient::Plugin::GetDescription( FontId id,
506 FontDescription& fontDescription ) const
508 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDescription\n");
509 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
511 for( std::vector<FontIdCacheItem>::const_iterator it = mFontIdCache.begin(),
512 endIt = mFontIdCache.end();
516 const FontIdCacheItem& item = *it;
518 if( item.fontId == id )
520 fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId );
522 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
523 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
524 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
525 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
526 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
527 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
532 DALI_LOG_INFO( gLogFilter, Debug::General, " No description found for the font ID %d\n", id );
533 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
536 PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id )
538 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetPointSize\n");
539 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
540 const FontId index = id - 1u;
543 ( index < mFontCache.size() ) )
545 DALI_LOG_INFO( gLogFilter, Debug::General, " point size : %d\n", ( *( mFontCache.begin() + index ) ).mRequestedPointSize );
546 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
547 return ( *( mFontCache.begin() + index ) ).mRequestedPointSize;
551 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font ID %d\n", id );
554 DALI_LOG_INFO( gLogFilter, Debug::General, " default point size : %d\n", TextAbstraction::FontClient::DEFAULT_POINT_SIZE );
555 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
556 return TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
559 bool FontClient::Plugin::IsCharacterSupportedByFont( FontId fontId, Character character )
561 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::IsCharacterSupportedByFont\n");
562 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
563 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
565 if( ( fontId < 1u ) || ( fontId > mFontCache.size() ) )
567 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font id. Number of items in the cache: %d\n",mFontCache.size());
568 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
574 bool isSupported = false;
576 FontFaceCacheItem& cacheItem = mFontCache[fontId];
578 if( NULL == cacheItem.mCharacterSet )
580 // Create again the character set.
581 // It can be null if the ResetSystemDefaults() method has been called.
583 FontDescription description;
584 description.path = cacheItem.mPath;
585 description.family = FontFamily( cacheItem.mFreeTypeFace->family_name );
586 description.weight = FontWeight::NONE;
587 description.width = FontWidth::NONE;
588 description.slant = FontSlant::NONE;
590 // Note FreeType doesn't give too much info to build a proper font style.
591 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC )
593 description.slant = FontSlant::ITALIC;
595 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_BOLD )
597 description.weight = FontWeight::BOLD;
600 cacheItem.mCharacterSet = CreateCharacterSetFromDescription( description );
603 isSupported = FcCharSetHasChar( cacheItem.mCharacterSet, character );
605 DALI_LOG_INFO( gLogFilter, Debug::General, " is supported : %s\n", (isSupported ? "true" : "false") );
606 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
610 FontId FontClient::Plugin::FindFontForCharacter( const FontList& fontList,
611 const CharacterSetList& characterSetList,
613 PointSize26Dot6 requestedPointSize,
616 DALI_ASSERT_DEBUG( ( fontList.size() == characterSetList.Count() ) && "FontClient::Plugin::FindFontForCharacter. Different number of fonts and character sets." );
618 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFontForCharacter\n" );
619 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
620 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
621 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
624 bool foundColor = false;
626 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts : %d\n", fontList.size() );
628 // Traverse the list of fonts.
629 // Check for each font if supports the character.
630 for( unsigned int index = 0u, numberOfFonts = fontList.size(); index < numberOfFonts; ++index )
632 const FontDescription& description = fontList[index];
633 const FcCharSet* const characterSet = characterSetList[index];
635 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", description.family.c_str() );
636 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
637 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
638 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
639 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
641 bool foundInRanges = false;
642 if( NULL != characterSet )
644 foundInRanges = FcCharSetHasChar( characterSet, character );
649 fontId = GetFontId( description,
653 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " font id : %d\n", fontId );
657 if( ( fontId > 0 ) &&
658 ( fontId - 1u < mFontCache.size() ) )
660 const FontFaceCacheItem& item = mFontCache[fontId - 1u];
662 foundColor = item.mHasColorTables;
665 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " foundColor : %s\n", ( foundColor ? "true" : "false" ) );
668 // Keep going unless we prefer a different (color) font.
669 if( !preferColor || foundColor )
676 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
677 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFontForCharacter\n" );
681 FontId FontClient::Plugin::FindDefaultFont( Character charcode,
682 PointSize26Dot6 requestedPointSize,
685 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindDefaultFont\n" );
686 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
687 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
688 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
692 // Create the list of default fonts if it has not been created.
693 if( mDefaultFonts.empty() )
695 FontDescription fontDescription;
696 fontDescription.family = DEFAULT_FONT_FAMILY_NAME;
697 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
698 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
699 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
701 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
703 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of default fonts : %d\n", mDefaultFonts.size() );
706 // Traverse the list of default fonts.
707 // Check for each default font if supports the character.
708 fontId = FindFontForCharacter( mDefaultFonts, mDefaultFontCharacterSets, charcode, requestedPointSize, preferColor );
710 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
711 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindDefaultFont\n" );
716 FontId FontClient::Plugin::FindFallbackFont( Character charcode,
717 const FontDescription& preferredFontDescription,
718 PointSize26Dot6 requestedPointSize,
721 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFont\n" );
722 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
723 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
724 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
726 // The font id to be returned.
729 FontDescription fontDescription;
731 // Fill the font description with the preferred font description and complete with the defaults.
732 fontDescription.family = preferredFontDescription.family.empty() ? DEFAULT_FONT_FAMILY_NAME : preferredFontDescription.family;
733 fontDescription.weight = ( ( FontWeight::NONE == preferredFontDescription.weight ) ? IntToWeightType( DEFAULT_FONT_WEIGHT ) : preferredFontDescription.weight );
734 fontDescription.width = ( ( FontWidth::NONE == preferredFontDescription.width ) ? IntToWidthType( DEFAULT_FONT_WIDTH ) : preferredFontDescription.width );
735 fontDescription.slant = ( ( FontSlant::NONE == preferredFontDescription.slant ) ? IntToSlantType( DEFAULT_FONT_SLANT ) : preferredFontDescription.slant );
737 DALI_LOG_INFO( gLogFilter, Debug::General, " preferredFontDescription --> fontDescription\n" );
738 DALI_LOG_INFO( gLogFilter, Debug::General, " [%s] --> [%s]\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str() );
739 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWeight::Name[preferredFontDescription.weight], FontWeight::Name[fontDescription.weight] );
740 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width] );
741 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant] );
743 // Check first if the font's description has been queried before.
744 FontList* fontList = NULL;
745 CharacterSetList* characterSetList = NULL;
747 if( !FindFallbackFontList( fontDescription, fontList, characterSetList ) )
749 fontList = new FontList;
750 characterSetList = new CharacterSetList;
752 SetFontList( fontDescription, *fontList, *characterSetList );
754 // Add the font-list to the cache.
755 mFallbackCache.push_back( FallbackCacheItem( fontDescription, fontList, characterSetList ) );
758 if( fontList && characterSetList )
760 fontId = FindFontForCharacter( *fontList, *characterSetList, charcode, requestedPointSize, preferColor );
763 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
764 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFont\n");
768 FontId FontClient::Plugin::GetFontId( const FontPath& path,
769 PointSize26Dot6 requestedPointSize,
771 bool cacheDescription )
773 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
774 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
775 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
779 if( NULL != mFreeTypeLibrary )
782 if( FindFont( path, requestedPointSize, faceIndex, foundId ) )
788 id = CreateFont( path, requestedPointSize, faceIndex, cacheDescription );
792 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
793 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
798 FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription,
799 PointSize26Dot6 requestedPointSize,
800 FaceIndex faceIndex )
802 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
803 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
804 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
806 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
807 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
808 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
810 // This method uses three vectors which caches:
811 // * Pairs of non validated font descriptions and an index to a vector with paths to font file names.
812 // * The path to font file names.
813 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
815 // 1) Checks in the cache if the font's description has been validated before.
816 // If it was it gets an index to the vector with paths to font file names. Otherwise,
817 // retrieves using font config a path to a font file name which matches with the
818 // font's description. The path is stored in the cache.
820 // 2) Checks in the cache if the pair 'font point size, index to the vector with paths to
821 // font file names' exists. If exists, it gets the font id. If it doesn't it calls
822 // the GetFontId() method with the path to the font file name and the point size to
825 // The font id to be returned.
828 // Check first if the font's description have been validated before.
829 FontDescriptionId validatedFontId = 0u;
831 if( !FindValidatedFont( fontDescription,
834 // Use font config to validate the font's description.
835 ValidateFont( fontDescription,
839 // Check if exists a pair 'validatedFontId, requestedPointSize' in the cache.
840 if( !FindFont( validatedFontId, requestedPointSize, fontId ) )
842 // Retrieve the font file name path.
843 const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId );
845 // Retrieve the font id. Do not cache the description as it has been already cached.
846 fontId = GetFontId( description.path,
851 mFontCache[fontId-1u].mCharacterSet = mCharacterSetCache[validatedFontId];
853 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
854 mFontIdCache.push_back( FontIdCacheItem( validatedFontId,
859 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
860 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
865 void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription,
866 FontDescriptionId& validatedFontId )
868 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::ValidateFont\n" );
869 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
870 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
871 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
872 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
873 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
875 // Create a font pattern.
876 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
878 FontDescription description;
880 FcCharSet* characterSet = NULL;
881 bool matched = MatchFontDescriptionToPattern( fontFamilyPattern, description, &characterSet );
882 FcPatternDestroy( fontFamilyPattern );
884 if( matched && ( NULL != characterSet ) )
886 // Set the index to the vector of paths to font file names.
887 validatedFontId = mFontDescriptionCache.size();
889 DALI_LOG_INFO( gLogFilter, Debug::General, " matched description; family : [%s]\n", description.family.c_str() );
890 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
891 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
892 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
893 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
894 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
896 // Add the path to the cache.
897 mFontDescriptionCache.push_back( description );
898 mCharacterSetCache.PushBack( characterSet );
900 // Cache the index and the matched font's description.
901 FontDescriptionCacheItem item( description,
904 mValidatedFontCache.push_back( item );
906 if( ( fontDescription.family != description.family ) ||
907 ( fontDescription.width != description.width ) ||
908 ( fontDescription.weight != description.weight ) ||
909 ( fontDescription.slant != description.slant ) )
911 // Cache the given font's description if it's different than the matched.
912 FontDescriptionCacheItem item( fontDescription,
915 mValidatedFontCache.push_back( item );
920 DALI_LOG_INFO( gLogFilter, Debug::General, " font validation failed for font [%s]\n", fontDescription.family.c_str() );
923 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::ValidateFont\n" );
926 void FontClient::Plugin::GetFontMetrics( FontId fontId,
927 FontMetrics& metrics )
929 if( ( fontId > 0 ) &&
930 ( fontId - 1u < mFontCache.size() ) )
932 const FontFaceCacheItem& font = mFontCache[fontId-1];
934 metrics = font.mMetrics;
936 // Adjust the metrics if the fixed-size font should be down-scaled
937 if( font.mIsFixedSizeBitmap )
939 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
941 if( desiredFixedSize > 0.f )
943 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
945 metrics.ascender = floorf( metrics.ascender * scaleFactor );
946 metrics.descender = floorf( metrics.descender * scaleFactor );
947 metrics.height = floorf( metrics.height * scaleFactor );
948 metrics.underlinePosition = floorf( metrics.underlinePosition * scaleFactor );
949 metrics.underlineThickness = floorf( metrics.underlineThickness * scaleFactor );
955 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFontMetrics. Invalid font id : %d\n", fontId );
959 GlyphIndex FontClient::Plugin::GetGlyphIndex( FontId fontId,
962 GlyphIndex index = 0u;
964 if( ( fontId > 0u ) &&
965 ( fontId - 1u < mFontCache.size() ) )
967 FT_Face ftFace = mFontCache[fontId-1u].mFreeTypeFace;
969 index = FT_Get_Char_Index( ftFace, charcode );
975 bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
980 if( VECTOR_GLYPH == type )
982 return GetVectorMetrics( array, size, horizontal );
985 return GetBitmapMetrics( array, size, horizontal );
988 bool FontClient::Plugin::GetBitmapMetrics( GlyphInfo* array,
992 bool success( true );
994 for( unsigned int i=0; i<size; ++i )
996 GlyphInfo& glyph = array[i];
998 FontId fontId = glyph.fontId;
1001 fontId-1 < mFontCache.size() )
1003 const FontFaceCacheItem& font = mFontCache[fontId-1];
1005 FT_Face ftFace = font.mFreeTypeFace;
1007 #ifdef FREETYPE_BITMAP_SUPPORT
1008 // Check to see if we should be loading a Fixed Size bitmap?
1009 if ( font.mIsFixedSizeBitmap )
1011 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_COLOR );
1012 if ( FT_Err_Ok == error )
1014 glyph.width = font.mFixedWidthPixels;
1015 glyph.height = font.mFixedHeightPixels;
1016 glyph.advance = font.mFixedWidthPixels;
1017 glyph.xBearing = 0.0f;
1018 glyph.yBearing = font.mFixedHeightPixels;
1020 // Adjust the metrics if the fixed-size font should be down-scaled
1021 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
1023 if( desiredFixedSize > 0.f )
1025 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
1027 glyph.width = floorf( glyph.width * scaleFactor );
1028 glyph.height = floorf( glyph.height * scaleFactor );
1029 glyph.advance = floorf( glyph.advance * scaleFactor );
1030 glyph.xBearing = floorf( glyph.xBearing * scaleFactor );
1031 glyph.yBearing = floorf( glyph.yBearing * scaleFactor );
1033 glyph.scaleFactor = scaleFactor;
1038 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetBitmapMetrics. FreeType Bitmap Load_Glyph error %d\n", error );
1045 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_DEFAULT );
1047 if( FT_Err_Ok == error )
1049 glyph.width = static_cast< float >( ftFace->glyph->metrics.width ) * FROM_266;
1050 glyph.height = static_cast< float >( ftFace->glyph->metrics.height ) * FROM_266 ;
1053 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingX ) * FROM_266;
1054 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingY ) * FROM_266;
1058 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingX ) * FROM_266;
1059 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingY ) * FROM_266;
1077 bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array,
1081 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1082 bool success( true );
1084 for( unsigned int i=0; i<size; ++i )
1086 FontId fontId = array[i].fontId;
1089 fontId-1 < mFontCache.size() )
1091 FontFaceCacheItem& font = mFontCache[fontId-1];
1093 if( ! font.mVectorFontId )
1095 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1098 mVectorFontCache->GetGlyphMetrics( font.mVectorFontId, array[i] );
1100 // Vector metrics are in EMs, convert to pixels
1101 const float scale = ( static_cast<float>( font.mRequestedPointSize ) * FROM_266 ) * static_cast<float>( mDpiVertical ) / POINTS_PER_INCH;
1102 array[i].width *= scale;
1103 array[i].height *= scale;
1104 array[i].xBearing *= scale;
1105 array[i].yBearing *= scale;
1106 array[i].advance *= scale;
1120 void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
1122 if( ( fontId > 0 ) &&
1123 ( fontId - 1u < mFontCache.size() ) )
1125 FT_Face ftFace = mFontCache[fontId - 1u].mFreeTypeFace;
1129 #ifdef FREETYPE_BITMAP_SUPPORT
1130 // Check to see if this is fixed size bitmap
1131 if ( mFontCache[fontId - 1u].mIsFixedSizeBitmap )
1133 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1138 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_DEFAULT );
1140 if( FT_Err_Ok == error )
1143 error = FT_Get_Glyph( ftFace->glyph, &glyph );
1145 // Convert to bitmap if necessary
1146 if ( FT_Err_Ok == error )
1148 if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
1150 // Check whether we should create a bitmap for the outline
1151 if( glyph->format == FT_GLYPH_FORMAT_OUTLINE && outlineWidth > 0 )
1155 error = FT_Stroker_New(mFreeTypeLibrary, &stroker );
1157 if ( FT_Err_Ok == error )
1159 FT_Stroker_Set( stroker, outlineWidth * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 );
1160 error = FT_Glyph_StrokeBorder( &glyph, stroker, 0, 1 );
1162 if ( FT_Err_Ok == error )
1164 FT_Stroker_Done( stroker );
1168 DALI_LOG_ERROR( "FT_Glyph_StrokeBorder Failed with error: %d\n", error );
1173 DALI_LOG_ERROR( "FT_Stroker_New Failed with error: %d\n", error );
1177 error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
1178 if ( FT_Err_Ok == error )
1180 FT_BitmapGlyph bitmapGlyph = reinterpret_cast< FT_BitmapGlyph >( glyph );
1181 ConvertBitmap( data, bitmapGlyph->bitmap );
1185 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Get_Glyph Failed with error: %d\n", error );
1190 ConvertBitmap( data, ftFace->glyph->bitmap );
1193 // Created FT_Glyph object must be released with FT_Done_Glyph
1194 FT_Done_Glyph( glyph );
1199 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Load_Glyph Failed with error: %d\n", error );
1204 PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
1206 TextAbstraction::FontClient::GlyphBufferData data;
1208 CreateBitmap( fontId, glyphIndex, data, outlineWidth );
1210 return PixelData::New( data.buffer,
1211 data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
1215 PixelData::DELETE_ARRAY );
1218 void FontClient::Plugin::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
1223 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1225 fontId-1 < mFontCache.size() )
1227 FontFaceCacheItem& font = mFontCache[fontId-1];
1229 if( ! font.mVectorFontId )
1231 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1234 mVectorFontCache->GetVectorBlob( font.mVectorFontId, fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
1239 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
1241 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetEllipsisGlyph\n" );
1242 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize %d.\n", requestedPointSize );
1244 // First look into the cache if there is an ellipsis glyph for the requested point size.
1245 for( Vector<EllipsisItem>::ConstIterator it = mEllipsisCache.Begin(),
1246 endIt = mEllipsisCache.End();
1250 const EllipsisItem& item = *it;
1252 if( fabsf( item.requestedPointSize - requestedPointSize ) < Math::MACHINE_EPSILON_1000 )
1254 // Use the glyph in the cache.
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" );
1264 // No glyph has been found. Create one.
1265 mEllipsisCache.PushBack( EllipsisItem() );
1266 EllipsisItem& item = *( mEllipsisCache.End() - 1u );
1268 item.requestedPointSize = requestedPointSize;
1270 // Find a font for the ellipsis glyph.
1271 item.glyph.fontId = FindDefaultFont( ELLIPSIS_CHARACTER,
1275 // Set the character index to access the glyph inside the font.
1276 item.glyph.index = FT_Get_Char_Index( mFontCache[item.glyph.fontId-1].mFreeTypeFace,
1277 ELLIPSIS_CHARACTER );
1279 GetBitmapMetrics( &item.glyph, 1u, true );
1281 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1282 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1283 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1288 bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
1290 FT_Error error = -1;
1292 #ifdef FREETYPE_BITMAP_SUPPORT
1293 if( ( fontId > 0 ) &&
1294 ( fontId - 1u < mFontCache.size() ) )
1296 const FontFaceCacheItem& item = mFontCache[fontId - 1u];
1297 FT_Face ftFace = item.mFreeTypeFace;
1299 // Check to see if this is fixed size bitmap
1300 if( item.mHasColorTables )
1302 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1307 return FT_Err_Ok == error;
1310 bool FontClient::Plugin::AddCustomFontDirectory( const FontPath& path )
1312 // NULL as first parameter means the current configuration is used.
1313 return FcConfigAppFontAddDir( NULL, reinterpret_cast<const FcChar8 *>( path.c_str() ) );
1316 void FontClient::Plugin::InitSystemFonts()
1318 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" );
1320 FcFontSet* fontSet = GetFcFontSet();
1324 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : %d\n", fontSet->nfont );
1326 // Reserve some space to avoid reallocations.
1327 mSystemFonts.reserve( fontSet->nfont );
1329 for( int i = 0u; i < fontSet->nfont; ++i )
1331 FcPattern* fontPattern = fontSet->fonts[i];
1335 // Skip fonts with no path
1336 if( GetFcString( fontPattern, FC_FILE, path ) )
1338 mSystemFonts.push_back( FontDescription() );
1339 FontDescription& fontDescription = mSystemFonts.back();
1341 fontDescription.path = path;
1346 GetFcString( fontPattern, FC_FAMILY, fontDescription.family );
1347 GetFcInt( fontPattern, FC_WIDTH, width );
1348 GetFcInt( fontPattern, FC_WEIGHT, weight );
1349 GetFcInt( fontPattern, FC_SLANT, slant );
1350 fontDescription.width = IntToWidthType( width );
1351 fontDescription.weight = IntToWeightType( weight );
1352 fontDescription.slant = IntToSlantType( slant );
1354 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", fontDescription.family.c_str() );
1355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1356 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1357 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1358 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1362 FcFontSetDestroy( fontSet );
1364 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::InitSystemFonts\n" );
1367 bool FontClient::Plugin::MatchFontDescriptionToPattern( FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet )
1369 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1371 FcResult result = FcResultMatch;
1372 FcPattern* match = FcFontMatch( NULL /* use default configure */, pattern, &result );
1374 const bool matched = NULL != match;
1375 DALI_LOG_INFO( gLogFilter, Debug::General, " pattern matched : %s\n", ( matched ? "true" : "false" ) );
1382 GetFcString( match, FC_FILE, fontDescription.path );
1383 GetFcString( match, FC_FAMILY, fontDescription.family );
1384 GetFcInt( match, FC_WIDTH, width );
1385 GetFcInt( match, FC_WEIGHT, weight );
1386 GetFcInt( match, FC_SLANT, slant );
1387 fontDescription.width = IntToWidthType( width );
1388 fontDescription.weight = IntToWeightType( weight );
1389 fontDescription.slant = IntToSlantType( slant );
1391 // Cache the character ranges.
1392 FcPatternGetCharSet( match, FC_CHARSET, 0u, characterSet );
1394 // destroyed the matched pattern
1395 FcPatternDestroy( match );
1397 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1400 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1401 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1404 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1408 FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& fontDescription ) const
1410 // create the cached font family lookup pattern
1411 // a pattern holds a set of names, each name refers to a property of the font
1412 FcPattern* fontFamilyPattern = FcPatternCreate();
1414 if( !fontFamilyPattern )
1419 // add a property to the pattern for the font family
1420 FcPatternAddString( fontFamilyPattern, FC_FAMILY, reinterpret_cast<const FcChar8*>( fontDescription.family.c_str() ) );
1422 // add a property to the pattern for local setting.
1423 const char* locale = setlocale( LC_MESSAGES, NULL );
1426 FcPatternAddString( fontFamilyPattern, FC_LANG, reinterpret_cast<const FcChar8*>( locale ) );
1429 int width = FONT_WIDTH_TYPE_TO_INT[fontDescription.width];
1433 width = DEFAULT_FONT_WIDTH;
1436 int weight = FONT_WEIGHT_TYPE_TO_INT[fontDescription.weight];
1440 weight = DEFAULT_FONT_WEIGHT;
1443 int slant = FONT_SLANT_TYPE_TO_INT[fontDescription.slant];
1447 slant = DEFAULT_FONT_SLANT;
1450 FcPatternAddInteger( fontFamilyPattern, FC_WIDTH, width );
1451 FcPatternAddInteger( fontFamilyPattern, FC_WEIGHT, weight );
1452 FcPatternAddInteger( fontFamilyPattern, FC_SLANT, slant );
1454 // Add a property of the pattern, to say we want to match TrueType fonts
1455 FcPatternAddString( fontFamilyPattern , FC_FONTFORMAT, reinterpret_cast<const FcChar8*>( FONT_FORMAT.c_str() ) );
1457 // modify the config, with the mFontFamilyPatterm
1458 FcConfigSubstitute( NULL /* use default configure */, fontFamilyPattern, FcMatchPattern );
1460 // provide default values for unspecified properties in the font pattern
1461 // e.g. patterns without a specified style or weight are set to Medium
1462 FcDefaultSubstitute( fontFamilyPattern );
1464 return fontFamilyPattern;
1467 _FcFontSet* FontClient::Plugin::GetFcFontSet() const
1469 // create a new pattern.
1470 // a pattern holds a set of names, each name refers to a property of the font
1471 FcPattern* pattern = FcPatternCreate();
1473 // create an object set used to define which properties are to be returned in the patterns from FcFontList.
1474 FcObjectSet* objectSet = FcObjectSetCreate();
1476 // build an object set from a list of property names
1477 FcObjectSetAdd( objectSet, FC_FILE );
1478 FcObjectSetAdd( objectSet, FC_FAMILY );
1479 FcObjectSetAdd( objectSet, FC_WIDTH );
1480 FcObjectSetAdd( objectSet, FC_WEIGHT );
1481 FcObjectSetAdd( objectSet, FC_SLANT );
1483 // get a list of fonts
1484 // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
1485 FcFontSet* fontset = FcFontList( NULL /* the default configuration is checked to be up to date, and used */, pattern, objectSet );
1487 // clear up the object set
1490 FcObjectSetDestroy( objectSet );
1492 // clear up the pattern
1495 FcPatternDestroy( pattern );
1501 bool FontClient::Plugin::GetFcString( const FcPattern* const pattern,
1502 const char* const n,
1503 std::string& string )
1505 FcChar8* file = NULL;
1506 const FcResult retVal = FcPatternGetString( pattern, n, 0u, &file );
1508 if( FcResultMatch == retVal )
1510 // Have to use reinterpret_cast because FcChar8 is unsigned char*, not a const char*.
1511 string.assign( reinterpret_cast<const char*>( file ) );
1519 bool FontClient::Plugin::GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal )
1521 const FcResult retVal = FcPatternGetInteger( pattern, n, 0u, &intVal );
1523 if( FcResultMatch == retVal )
1531 FontId FontClient::Plugin::CreateFont( const FontPath& path,
1532 PointSize26Dot6 requestedPointSize,
1533 FaceIndex faceIndex,
1534 bool cacheDescription )
1536 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::CreateFont\n" );
1537 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1538 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1542 // Create & cache new font face
1544 int error = FT_New_Face( mFreeTypeLibrary,
1549 if( FT_Err_Ok == error )
1551 // Check if a font is scalable.
1552 const bool isScalable = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_SCALABLE ) );
1553 const bool hasFixedSizedBitmaps = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES ) ) && ( 0 != ftFace->num_fixed_sizes );
1554 const bool hasColorTables = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_COLOR ) );
1556 DALI_LOG_INFO( gLogFilter, Debug::General, " isScalable : [%s]\n", ( isScalable ? "true" : "false" ) );
1557 DALI_LOG_INFO( gLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", ( hasFixedSizedBitmaps ? "true" : "false" ) );
1558 DALI_LOG_INFO( gLogFilter, Debug::General, " hasColorTables : [%s]\n", ( hasColorTables ? "true" : "false" ) );
1560 // Check to see if the font contains fixed sizes?
1561 if( !isScalable && hasFixedSizedBitmaps )
1563 PointSize26Dot6 actualPointSize = 0u;
1564 int fixedSizeIndex = 0;
1565 for( ; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex )
1567 const PointSize26Dot6 fixedSize = ftFace->available_sizes[fixedSizeIndex].size;
1568 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize );
1570 if( fixedSize >= requestedPointSize )
1572 actualPointSize = fixedSize;
1577 if( 0u == actualPointSize )
1579 // The requested point size is bigger than the bigest fixed size.
1580 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1581 actualPointSize = ftFace->available_sizes[fixedSizeIndex].size;
1584 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize );
1586 // Tell Freetype to use this size
1587 error = FT_Select_Size( ftFace, fixedSizeIndex );
1588 if ( FT_Err_Ok != error )
1590 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error );
1594 float fixedWidth = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].width );
1595 float fixedHeight = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].height );
1597 // Indicate that the font is a fixed sized bitmap
1598 FontMetrics metrics( fixedHeight, // The ascender in pixels.
1600 fixedHeight, // The height in pixels.
1604 mFontCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics, fixedWidth, fixedHeight, hasColorTables ) );
1605 id = mFontCache.size();
1610 error = FT_Set_Char_Size( ftFace,
1616 if( FT_Err_Ok == error )
1619 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1621 FontMetrics metrics( static_cast< float >( ftMetrics.ascender ) * FROM_266,
1622 static_cast< float >( ftMetrics.descender ) * FROM_266,
1623 static_cast< float >( ftMetrics.height ) * FROM_266,
1624 static_cast< float >( ftFace->underline_position ) * FROM_266,
1625 static_cast< float >( ftFace->underline_thickness ) * FROM_266 );
1627 mFontCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics ) );
1628 id = mFontCache.size();
1632 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize );
1638 if( cacheDescription )
1640 CacheFontPath( ftFace, id, requestedPointSize, path );
1646 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str() );
1649 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
1650 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::CreateFont\n" );
1655 void FontClient::Plugin::ConvertBitmap( TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap )
1657 if( srcBitmap.width*srcBitmap.rows > 0 )
1659 switch( srcBitmap.pixel_mode )
1661 case FT_PIXEL_MODE_GRAY:
1663 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width ) )
1665 const unsigned int bufferSize = srcBitmap.width * srcBitmap.rows;
1666 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1667 data.width = srcBitmap.width;
1668 data.height = srcBitmap.rows;
1669 data.format = Pixel::L8;
1670 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1675 #ifdef FREETYPE_BITMAP_SUPPORT
1676 case FT_PIXEL_MODE_BGRA:
1678 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width << 2u ) )
1680 // Set the input dimensions.
1681 const ImageDimensions inputDimensions( srcBitmap.width, srcBitmap.rows );
1683 // Set the output dimensions.
1684 // If the output dimension is not given, the input dimension is set
1685 // and won't be downscaling.
1686 data.width = ( data.width == 0 ) ? srcBitmap.width : data.width;
1687 data.height = ( data.height == 0 ) ? srcBitmap.rows : data.height;
1688 const ImageDimensions desiredDimensions( data.width, data.height );
1690 // Creates the output buffer
1691 const unsigned int bufferSize = data.width * data.height * 4u;
1692 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1694 if( inputDimensions == desiredDimensions )
1696 // There isn't downscaling.
1697 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1701 Dali::Internal::Platform::LanczosSample4BPP( srcBitmap.buffer,
1704 desiredDimensions );
1706 data.format = Pixel::BGRA8888;
1713 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::ConvertBitmap. FontClient Unable to create Bitmap of this PixelType\n" );
1720 bool FontClient::Plugin::FindFont( const FontPath& path,
1721 PointSize26Dot6 requestedPointSize,
1722 FaceIndex faceIndex,
1723 FontId& fontId ) const
1725 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1726 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1727 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1728 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fonts in the cache : %d\n", mFontCache.size() );
1731 for( std::vector<FontFaceCacheItem>::const_iterator it = mFontCache.begin(),
1732 endIt = mFontCache.end();
1736 const FontFaceCacheItem& cacheItem = *it;
1738 if( cacheItem.mRequestedPointSize == requestedPointSize &&
1739 cacheItem.mFaceIndex == faceIndex &&
1740 cacheItem.mPath == path )
1744 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1745 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1751 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found\n" );
1752 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1757 bool FontClient::Plugin::FindValidatedFont( const FontDescription& fontDescription,
1758 FontDescriptionId& validatedFontId )
1760 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindValidatedFont\n" );
1761 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1762 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1763 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1764 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1765 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1766 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of validated fonts in the cache : %d\n", mValidatedFontCache.size() );
1768 validatedFontId = 0u;
1770 for( std::vector<FontDescriptionCacheItem>::const_iterator it = mValidatedFontCache.begin(),
1771 endIt = mValidatedFontCache.end();
1775 const FontDescriptionCacheItem& item = *it;
1777 if( !fontDescription.family.empty() &&
1778 ( fontDescription.family == item.fontDescription.family ) &&
1779 ( fontDescription.width == item.fontDescription.width ) &&
1780 ( fontDescription.weight == item.fontDescription.weight ) &&
1781 ( fontDescription.slant == item.fontDescription.slant ) )
1783 validatedFontId = item.index;
1785 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font found, id : %d\n", validatedFontId );
1786 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1791 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font not found\n" );
1792 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1796 bool FontClient::Plugin::FindFallbackFontList( const FontDescription& fontDescription,
1797 FontList*& fontList,
1798 CharacterSetList*& characterSetList )
1800 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFontList\n" );
1801 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1802 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1803 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1804 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1806 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fallback font lists in the cache : %d\n", mFallbackCache.size() );
1810 for( std::vector<FallbackCacheItem>::const_iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end();
1814 const FallbackCacheItem& item = *it;
1816 if( !fontDescription.family.empty() &&
1817 ( fontDescription.family == item.fontDescription.family ) &&
1818 ( fontDescription.width == item.fontDescription.width ) &&
1819 ( fontDescription.weight == item.fontDescription.weight ) &&
1820 ( fontDescription.slant == item.fontDescription.slant ) )
1822 fontList = item.fallbackFonts;
1823 characterSetList = item.characterSets;
1825 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list found.\n" );
1826 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1831 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list not found.\n" );
1832 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1836 bool FontClient::Plugin::FindFont( FontDescriptionId validatedFontId,
1837 PointSize26Dot6 requestedPointSize,
1840 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1841 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
1842 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1846 for( std::vector<FontIdCacheItem>::const_iterator it = mFontIdCache.begin(),
1847 endIt = mFontIdCache.end();
1851 const FontIdCacheItem& item = *it;
1853 if( ( validatedFontId == item.validatedFontId ) &&
1854 ( requestedPointSize == item.requestedPointSize ) )
1856 fontId = item.fontId;
1858 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1859 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1864 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found.\n" );
1865 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1869 bool FontClient::Plugin::IsScalable( const FontPath& path )
1871 bool isScalable = false;
1874 int error = FT_New_Face( mFreeTypeLibrary,
1878 if( FT_Err_Ok != error )
1880 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str() );
1884 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1890 bool FontClient::Plugin::IsScalable( const FontDescription& fontDescription )
1892 // Create a font pattern.
1893 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1895 FcResult result = FcResultMatch;
1897 // match the pattern
1898 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
1899 bool isScalable = false;
1903 // Get the path to the font file name.
1905 GetFcString( match, FC_FILE, path );
1906 isScalable = IsScalable( path );
1910 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1912 FcPatternDestroy( fontFamilyPattern );
1913 FcPatternDestroy( match );
1917 void FontClient::Plugin::GetFixedSizes( const FontPath& path, Vector< PointSize26Dot6 >& sizes )
1919 // Empty the caller container
1923 int error = FT_New_Face( mFreeTypeLibrary,
1927 if( FT_Err_Ok != error )
1929 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str() );
1932 // Fetch the number of fixed sizes available
1933 if ( ftFace->num_fixed_sizes && ftFace->available_sizes )
1935 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
1937 sizes.PushBack( ftFace->available_sizes[ i ].size );
1942 void FontClient::Plugin::GetFixedSizes( const FontDescription& fontDescription,
1943 Vector< PointSize26Dot6 >& sizes )
1945 // Create a font pattern.
1946 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1948 FcResult result = FcResultMatch;
1950 // match the pattern
1951 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
1955 // Get the path to the font file name.
1957 GetFcString( match, FC_FILE, path );
1958 GetFixedSizes( path, sizes );
1962 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1964 FcPatternDestroy( match );
1965 FcPatternDestroy( fontFamilyPattern );
1968 void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path )
1970 FontDescription description;
1971 description.path = path;
1972 description.family = FontFamily( ftFace->family_name );
1973 description.weight = FontWeight::NONE;
1974 description.width = FontWidth::NONE;
1975 description.slant = FontSlant::NONE;
1977 // Note FreeType doesn't give too much info to build a proper font style.
1978 if( ftFace->style_flags & FT_STYLE_FLAG_ITALIC )
1980 description.slant = FontSlant::ITALIC;
1982 if( ftFace->style_flags & FT_STYLE_FLAG_BOLD )
1984 description.weight = FontWeight::BOLD;
1987 FontDescriptionId validatedFontId = 0u;
1988 if( !FindValidatedFont( description,
1991 // Set the index to the vector of paths to font file names.
1992 validatedFontId = mFontDescriptionCache.size();
1994 FcPattern* pattern = CreateFontFamilyPattern( description );
1996 FcResult result = FcResultMatch;
1997 FcPattern* match = FcFontMatch( NULL, pattern, &result );
1999 FcCharSet* characterSet = NULL;
2000 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
2002 FcPatternDestroy( match );
2003 FcPatternDestroy( pattern );
2005 mFontCache[id-1u].mCharacterSet = characterSet;
2007 // Add the path to the cache.
2008 mFontDescriptionCache.push_back( description );
2009 mCharacterSetCache.PushBack( characterSet );
2011 // Cache the index and the font's description.
2012 FontDescriptionCacheItem item( description,
2015 mValidatedFontCache.push_back( item );
2017 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
2018 mFontIdCache.push_back( FontIdCacheItem( validatedFontId,
2024 FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) const
2026 FcCharSet* characterSet = NULL;
2028 FcPattern* pattern = CreateFontFamilyPattern( description );
2030 if( NULL != pattern )
2032 FcResult result = FcResultMatch;
2033 FcPattern* match = FcFontMatch( NULL, pattern, &result );
2035 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
2037 FcPatternDestroy( match );
2038 FcPatternDestroy( pattern );
2041 return characterSet;
2044 } // namespace Internal
2046 } // namespace TextAbstraction