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 mEllipsisCache.Clear();
277 mSystemFonts.clear();
278 mDefaultFonts.clear();
279 mDefaultFontDescriptionCached = false;
280 mDefaultFontCharacterSets.Clear();
281 mDefaultFontDescription = FontDescription();
284 void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
285 unsigned int verticalDpi )
287 mDpiHorizontal = horizontalDpi;
288 mDpiVertical = verticalDpi;
291 void FontClient::Plugin::ResetSystemDefaults()
293 mDefaultFontDescriptionCached = false;
296 void FontClient::Plugin::SetFontList( const FontDescription& fontDescription, FontList& fontList, CharacterSetList& characterSetList )
298 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::SetFontList\n" );
299 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
300 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
301 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
302 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
306 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
308 FcResult result = FcResultMatch;
310 // Match the pattern.
311 FcFontSet* fontSet = FcFontSort( NULL /* use default configure */,
313 false /* don't trim */,
317 if( NULL != fontSet )
319 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts found : [%d]\n", fontSet->nfont );
320 // Reserve some space to avoid reallocations.
321 fontList.reserve( fontSet->nfont );
323 for( int i = 0u; i < fontSet->nfont; ++i )
325 FcPattern* fontPattern = fontSet->fonts[i];
329 // Skip fonts with no path
330 if( GetFcString( fontPattern, FC_FILE, path ) )
332 FcCharSet* characterSet = NULL;
333 FcPatternGetCharSet( fontPattern, FC_CHARSET, 0u, &characterSet );
335 characterSetList.PushBack( characterSet );
336 fontList.push_back( FontDescription() );
337 FontDescription& newFontDescription = fontList.back();
339 newFontDescription.path = path;
344 GetFcString( fontPattern, FC_FAMILY, newFontDescription.family );
345 GetFcInt( fontPattern, FC_WIDTH, width );
346 GetFcInt( fontPattern, FC_WEIGHT, weight );
347 GetFcInt( fontPattern, FC_SLANT, slant );
348 newFontDescription.width = IntToWidthType( width );
349 newFontDescription.weight = IntToWeightType( weight );
350 newFontDescription.slant = IntToSlantType( slant );
352 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", newFontDescription.family.c_str() );
353 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", newFontDescription.path.c_str() );
354 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[newFontDescription.width] );
355 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[newFontDescription.weight] );
356 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[newFontDescription.slant] );
360 FcFontSetDestroy( fontSet );
364 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " No fonts found.\n" );
367 FcPatternDestroy( fontFamilyPattern );
368 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::SetFontList\n" );
371 void FontClient::Plugin::GetDefaultFonts( FontList& defaultFonts )
373 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultFonts\n" );
375 if( mDefaultFonts.empty() )
377 FontDescription fontDescription;
378 fontDescription.family = DEFAULT_FONT_FAMILY_NAME; // todo This could be set to the Platform font
379 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
380 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
381 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
382 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
385 defaultFonts = mDefaultFonts;
387 DALI_LOG_INFO( gLogFilter, Debug::General, " number of default fonts : [%d]\n", mDefaultFonts.size() );
388 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultFonts\n" );
391 void FontClient::Plugin::GetDefaultPlatformFontDescription( FontDescription& fontDescription )
393 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDefaultPlatformFontDescription\n");
395 if( !mDefaultFontDescriptionCached )
397 // Clear any font config stored info in the caches.
398 mDefaultFontCharacterSets.Clear();
399 mCharacterSetCache.Clear();
401 for( std::vector<FallbackCacheItem>::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); it != endIt; ++it )
403 FallbackCacheItem& item = *it;
405 item.characterSets->Clear();
408 for( std::vector<FontFaceCacheItem>::iterator it = mFontCache.begin(), endIt = mFontCache.end(); it != endIt; ++it )
410 FontFaceCacheItem& item = *it;
412 // Set the character set pointer as null. Will be created again the next time IsCharacterSupportedByFont()
413 item.mCharacterSet = NULL;
416 // FcInitBringUptoDate did not seem to reload config file as was still getting old default font.
417 FcInitReinitialize();
419 FcPattern* matchPattern = FcPatternCreate();
423 FcConfigSubstitute( NULL, matchPattern, FcMatchPattern );
424 FcDefaultSubstitute( matchPattern );
426 FcCharSet* characterSet = NULL;
427 MatchFontDescriptionToPattern( matchPattern, mDefaultFontDescription, &characterSet );
428 FcPatternDestroy( matchPattern );
431 // Create again the character sets as they are not valid after FcInitReinitialize()
433 for( FontList::const_iterator it = mDefaultFonts.begin(), endIt = mDefaultFonts.end(); it != endIt; ++it )
435 const FontDescription& description = *it;
437 mDefaultFontCharacterSets.PushBack( CreateCharacterSetFromDescription( description ) );
440 for( FontList::const_iterator it = mFontDescriptionCache.begin(), endIt = mFontDescriptionCache.end(); it != endIt; ++it )
442 const FontDescription& description = *it;
444 mCharacterSetCache.PushBack( CreateCharacterSetFromDescription( description ) );
447 for( std::vector<FallbackCacheItem>::iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end(); it != endIt; ++it )
449 FallbackCacheItem& item = *it;
451 if( NULL != item.fallbackFonts )
453 if( NULL == item.characterSets )
455 item.characterSets = new CharacterSetList;
458 for( FontList::const_iterator flIt = item.fallbackFonts->begin(), flEndIt = item.fallbackFonts->end(); flIt != flEndIt; ++flIt )
460 const FontDescription& description = *flIt;
461 item.characterSets->PushBack( CreateCharacterSetFromDescription( description ) );
466 mDefaultFontDescriptionCached = true;
469 fontDescription.path = mDefaultFontDescription.path;
470 fontDescription.family = mDefaultFontDescription.family;
471 fontDescription.width = mDefaultFontDescription.width;
472 fontDescription.weight = mDefaultFontDescription.weight;
473 fontDescription.slant = mDefaultFontDescription.slant;
475 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
476 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
479 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
480 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDefaultPlatformFontDescription\n");
483 void FontClient::Plugin::GetSystemFonts( FontList& systemFonts )
485 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetSystemFonts\n");
487 if( mSystemFonts.empty() )
492 systemFonts = mSystemFonts;
493 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : [%d]\n", mSystemFonts.size() );
494 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetSystemFonts\n");
497 void FontClient::Plugin::GetDescription( FontId id,
498 FontDescription& fontDescription ) const
500 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetDescription\n");
501 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
503 for( std::vector<FontIdCacheItem>::const_iterator it = mFontIdCache.begin(),
504 endIt = mFontIdCache.end();
508 const FontIdCacheItem& item = *it;
510 if( item.fontId == id )
512 fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId );
514 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
515 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
516 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
517 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
518 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
519 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
524 DALI_LOG_INFO( gLogFilter, Debug::General, " No description found for the font ID %d\n", id );
525 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetDescription\n");
528 PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id )
530 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetPointSize\n");
531 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
532 const FontId index = id - 1u;
535 ( index < mFontCache.size() ) )
537 DALI_LOG_INFO( gLogFilter, Debug::General, " point size : %d\n", ( *( mFontCache.begin() + index ) ).mRequestedPointSize );
538 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
539 return ( *( mFontCache.begin() + index ) ).mRequestedPointSize;
543 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font ID %d\n", id );
546 DALI_LOG_INFO( gLogFilter, Debug::General, " default point size : %d\n", TextAbstraction::FontClient::DEFAULT_POINT_SIZE );
547 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetPointSize\n");
548 return TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
551 bool FontClient::Plugin::IsCharacterSupportedByFont( FontId fontId, Character character )
553 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::IsCharacterSupportedByFont\n");
554 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
555 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
557 if( ( fontId < 1u ) || ( fontId > mFontCache.size() ) )
559 DALI_LOG_INFO( gLogFilter, Debug::General, " Invalid font id. Number of items in the cache: %d\n",mFontCache.size());
560 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
566 bool isSupported = false;
568 FontFaceCacheItem& cacheItem = mFontCache[fontId];
570 if( NULL == cacheItem.mCharacterSet )
572 // Create again the character set.
573 // It can be null if the ResetSystemDefaults() method has been called.
575 FontDescription description;
576 description.path = cacheItem.mPath;
577 description.family = FontFamily( cacheItem.mFreeTypeFace->family_name );
578 description.weight = FontWeight::NONE;
579 description.width = FontWidth::NONE;
580 description.slant = FontSlant::NONE;
582 // Note FreeType doesn't give too much info to build a proper font style.
583 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_ITALIC )
585 description.slant = FontSlant::ITALIC;
587 if( cacheItem.mFreeTypeFace->style_flags & FT_STYLE_FLAG_BOLD )
589 description.weight = FontWeight::BOLD;
592 cacheItem.mCharacterSet = CreateCharacterSetFromDescription( description );
595 isSupported = FcCharSetHasChar( cacheItem.mCharacterSet, character );
597 DALI_LOG_INFO( gLogFilter, Debug::General, " is supported : %s\n", (isSupported ? "true" : "false") );
598 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::IsCharacterSupportedByFont\n");
602 FontId FontClient::Plugin::FindFontForCharacter( const FontList& fontList,
603 const CharacterSetList& characterSetList,
605 PointSize26Dot6 requestedPointSize,
608 DALI_ASSERT_DEBUG( ( fontList.size() == characterSetList.Count() ) && "FontClient::Plugin::FindFontForCharacter. Different number of fonts and character sets." );
610 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFontForCharacter\n" );
611 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", character );
612 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
613 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
616 bool foundColor = false;
618 DALI_LOG_INFO( gLogFilter, Debug::General, " number of fonts : %d\n", fontList.size() );
620 // Traverse the list of fonts.
621 // Check for each font if supports the character.
622 for( unsigned int index = 0u, numberOfFonts = fontList.size(); index < numberOfFonts; ++index )
624 const FontDescription& description = fontList[index];
625 const FcCharSet* const characterSet = characterSetList[index];
627 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", description.family.c_str() );
628 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
629 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
630 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
631 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
633 bool foundInRanges = false;
634 if( NULL != characterSet )
636 foundInRanges = FcCharSetHasChar( characterSet, character );
641 fontId = GetFontId( description,
645 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " font id : %d\n", fontId );
649 if( ( fontId > 0 ) &&
650 ( fontId - 1u < mFontCache.size() ) )
652 const FontFaceCacheItem& item = mFontCache[fontId - 1u];
654 foundColor = item.mHasColorTables;
657 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " foundColor : %s\n", ( foundColor ? "true" : "false" ) );
660 // Keep going unless we prefer a different (color) font.
661 if( !preferColor || foundColor )
668 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
669 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFontForCharacter\n" );
673 FontId FontClient::Plugin::FindDefaultFont( Character charcode,
674 PointSize26Dot6 requestedPointSize,
677 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindDefaultFont\n" );
678 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
679 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
680 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
684 // Create the list of default fonts if it has not been created.
685 if( mDefaultFonts.empty() )
687 FontDescription fontDescription;
688 fontDescription.family = DEFAULT_FONT_FAMILY_NAME;
689 fontDescription.width = IntToWidthType( DEFAULT_FONT_WIDTH );
690 fontDescription.weight = IntToWeightType( DEFAULT_FONT_WEIGHT );
691 fontDescription.slant = IntToSlantType( DEFAULT_FONT_SLANT );
693 SetFontList( fontDescription, mDefaultFonts, mDefaultFontCharacterSets );
695 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of default fonts : %d\n", mDefaultFonts.size() );
698 // Traverse the list of default fonts.
699 // Check for each default font if supports the character.
700 fontId = FindFontForCharacter( mDefaultFonts, mDefaultFontCharacterSets, charcode, requestedPointSize, preferColor );
702 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
703 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindDefaultFont\n" );
708 FontId FontClient::Plugin::FindFallbackFont( Character charcode,
709 const FontDescription& preferredFontDescription,
710 PointSize26Dot6 requestedPointSize,
713 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFont\n" );
714 DALI_LOG_INFO( gLogFilter, Debug::General, " character : %p\n", charcode );
715 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
716 DALI_LOG_INFO( gLogFilter, Debug::General, " preferColor : %s\n", ( preferColor ? "true" : "false" ) );
718 // The font id to be returned.
721 FontDescription fontDescription;
723 // Fill the font description with the preferred font description and complete with the defaults.
724 fontDescription.family = preferredFontDescription.family.empty() ? DEFAULT_FONT_FAMILY_NAME : preferredFontDescription.family;
725 fontDescription.weight = ( ( FontWeight::NONE == preferredFontDescription.weight ) ? IntToWeightType( DEFAULT_FONT_WEIGHT ) : preferredFontDescription.weight );
726 fontDescription.width = ( ( FontWidth::NONE == preferredFontDescription.width ) ? IntToWidthType( DEFAULT_FONT_WIDTH ) : preferredFontDescription.width );
727 fontDescription.slant = ( ( FontSlant::NONE == preferredFontDescription.slant ) ? IntToSlantType( DEFAULT_FONT_SLANT ) : preferredFontDescription.slant );
729 DALI_LOG_INFO( gLogFilter, Debug::General, " preferredFontDescription --> fontDescription\n" );
730 DALI_LOG_INFO( gLogFilter, Debug::General, " [%s] --> [%s]\n", preferredFontDescription.family.c_str(), fontDescription.family.c_str() );
731 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWeight::Name[preferredFontDescription.weight], FontWeight::Name[fontDescription.weight] );
732 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontWidth::Name[preferredFontDescription.width], FontWidth::Name[fontDescription.width] );
733 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " [%s] --> [%s]\n", FontSlant::Name[preferredFontDescription.slant], FontSlant::Name[fontDescription.slant] );
735 // Check first if the font's description has been queried before.
736 FontList* fontList = NULL;
737 CharacterSetList* characterSetList = NULL;
739 if( !FindFallbackFontList( fontDescription, fontList, characterSetList ) )
741 fontList = new FontList;
742 characterSetList = new CharacterSetList;
744 SetFontList( fontDescription, *fontList, *characterSetList );
746 // Add the font-list to the cache.
747 mFallbackCache.push_back( FallbackCacheItem( fontDescription, fontList, characterSetList ) );
750 if( fontList && characterSetList )
752 fontId = FindFontForCharacter( *fontList, *characterSetList, charcode, requestedPointSize, preferColor );
755 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
756 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFont\n");
760 FontId FontClient::Plugin::GetFontId( const FontPath& path,
761 PointSize26Dot6 requestedPointSize,
763 bool cacheDescription )
765 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
766 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
767 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
771 if( NULL != mFreeTypeLibrary )
774 if( FindFont( path, requestedPointSize, faceIndex, foundId ) )
780 id = CreateFont( path, requestedPointSize, faceIndex, cacheDescription );
784 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
785 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
790 FontId FontClient::Plugin::GetFontId( const FontDescription& fontDescription,
791 PointSize26Dot6 requestedPointSize,
792 FaceIndex faceIndex )
794 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetFontId\n" );
795 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
796 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
797 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
798 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
799 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
800 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
802 // This method uses three vectors which caches:
803 // * Pairs of non validated font descriptions and an index to a vector with paths to font file names.
804 // * The path to font file names.
805 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
807 // 1) Checks in the cache if the font's description has been validated before.
808 // If it was it gets an index to the vector with paths to font file names. Otherwise,
809 // retrieves using font config a path to a font file name which matches with the
810 // font's description. The path is stored in the cache.
812 // 2) Checks in the cache if the pair 'font point size, index to the vector with paths to
813 // font file names' exists. If exists, it gets the font id. If it doesn't it calls
814 // the GetFontId() method with the path to the font file name and the point size to
817 // The font id to be returned.
820 // Check first if the font's description have been validated before.
821 FontDescriptionId validatedFontId = 0u;
823 if( !FindValidatedFont( fontDescription,
826 // Use font config to validate the font's description.
827 ValidateFont( fontDescription,
831 // Check if exists a pair 'validatedFontId, requestedPointSize' in the cache.
832 if( !FindFont( validatedFontId, requestedPointSize, fontId ) )
834 // Retrieve the font file name path.
835 const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId );
837 // Retrieve the font id. Do not cache the description as it has been already cached.
838 fontId = GetFontId( description.path,
843 mFontCache[fontId-1u].mCharacterSet = mCharacterSetCache[validatedFontId];
845 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
846 mFontIdCache.push_back( FontIdCacheItem( validatedFontId,
851 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", fontId );
852 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetFontId\n" );
857 void FontClient::Plugin::ValidateFont( const FontDescription& fontDescription,
858 FontDescriptionId& validatedFontId )
860 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::ValidateFont\n" );
861 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
862 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
863 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
864 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
865 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
867 // Create a font pattern.
868 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
870 FontDescription description;
872 FcCharSet* characterSet = NULL;
873 bool matched = MatchFontDescriptionToPattern( fontFamilyPattern, description, &characterSet );
874 FcPatternDestroy( fontFamilyPattern );
876 if( matched && ( NULL != characterSet ) )
878 // Set the index to the vector of paths to font file names.
879 validatedFontId = mFontDescriptionCache.size();
881 DALI_LOG_INFO( gLogFilter, Debug::General, " matched description; family : [%s]\n", description.family.c_str() );
882 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", description.path.c_str() );
883 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[description.width] );
884 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[description.weight] );
885 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[description.slant] );
886 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
888 // Add the path to the cache.
889 mFontDescriptionCache.push_back( description );
890 mCharacterSetCache.PushBack( characterSet );
892 // Cache the index and the matched font's description.
893 FontDescriptionCacheItem item( description,
896 mValidatedFontCache.push_back( item );
898 if( ( fontDescription.family != description.family ) ||
899 ( fontDescription.width != description.width ) ||
900 ( fontDescription.weight != description.weight ) ||
901 ( fontDescription.slant != description.slant ) )
903 // Cache the given font's description if it's different than the matched.
904 FontDescriptionCacheItem item( fontDescription,
907 mValidatedFontCache.push_back( item );
912 DALI_LOG_INFO( gLogFilter, Debug::General, " font validation failed for font [%s]\n", fontDescription.family.c_str() );
915 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::ValidateFont\n" );
918 void FontClient::Plugin::GetFontMetrics( FontId fontId,
919 FontMetrics& metrics )
921 if( ( fontId > 0 ) &&
922 ( fontId - 1u < mFontCache.size() ) )
924 const FontFaceCacheItem& font = mFontCache[fontId-1];
926 metrics = font.mMetrics;
928 // Adjust the metrics if the fixed-size font should be down-scaled
929 if( font.mIsFixedSizeBitmap )
931 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
933 if( desiredFixedSize > 0.f )
935 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
937 metrics.ascender = floorf( metrics.ascender * scaleFactor );
938 metrics.descender = floorf( metrics.descender * scaleFactor );
939 metrics.height = floorf( metrics.height * scaleFactor );
940 metrics.underlinePosition = floorf( metrics.underlinePosition * scaleFactor );
941 metrics.underlineThickness = floorf( metrics.underlineThickness * scaleFactor );
947 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFontMetrics. Invalid font id : %d\n", fontId );
951 GlyphIndex FontClient::Plugin::GetGlyphIndex( FontId fontId,
954 GlyphIndex index = 0u;
956 if( ( fontId > 0u ) &&
957 ( fontId - 1u < mFontCache.size() ) )
959 FT_Face ftFace = mFontCache[fontId-1u].mFreeTypeFace;
961 index = FT_Get_Char_Index( ftFace, charcode );
967 bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
972 if( VECTOR_GLYPH == type )
974 return GetVectorMetrics( array, size, horizontal );
977 return GetBitmapMetrics( array, size, horizontal );
980 bool FontClient::Plugin::GetBitmapMetrics( GlyphInfo* array,
984 bool success( true );
986 for( unsigned int i=0; i<size; ++i )
988 GlyphInfo& glyph = array[i];
990 FontId fontId = glyph.fontId;
993 fontId-1 < mFontCache.size() )
995 const FontFaceCacheItem& font = mFontCache[fontId-1];
997 FT_Face ftFace = font.mFreeTypeFace;
999 #ifdef FREETYPE_BITMAP_SUPPORT
1000 // Check to see if we should be loading a Fixed Size bitmap?
1001 if ( font.mIsFixedSizeBitmap )
1003 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_COLOR );
1004 if ( FT_Err_Ok == error )
1006 glyph.width = font.mFixedWidthPixels;
1007 glyph.height = font.mFixedHeightPixels;
1008 glyph.advance = font.mFixedWidthPixels;
1009 glyph.xBearing = 0.0f;
1010 glyph.yBearing = font.mFixedHeightPixels;
1012 // Adjust the metrics if the fixed-size font should be down-scaled
1013 const float desiredFixedSize = static_cast<float>( font.mRequestedPointSize ) * FROM_266 / POINTS_PER_INCH * mDpiVertical;
1015 if( desiredFixedSize > 0.f )
1017 const float scaleFactor = desiredFixedSize / static_cast<float>( font.mFixedHeightPixels );
1019 glyph.width = floorf( glyph.width * scaleFactor );
1020 glyph.height = floorf( glyph.height * scaleFactor );
1021 glyph.advance = floorf( glyph.advance * scaleFactor );
1022 glyph.xBearing = floorf( glyph.xBearing * scaleFactor );
1023 glyph.yBearing = floorf( glyph.yBearing * scaleFactor );
1025 glyph.scaleFactor = scaleFactor;
1030 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetBitmapMetrics. FreeType Bitmap Load_Glyph error %d\n", error );
1037 int error = FT_Load_Glyph( ftFace, glyph.index, FT_LOAD_NO_AUTOHINT );
1039 if( FT_Err_Ok == error )
1041 glyph.width = static_cast< float >( ftFace->glyph->metrics.width ) * FROM_266;
1042 glyph.height = static_cast< float >( ftFace->glyph->metrics.height ) * FROM_266 ;
1045 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingX ) * FROM_266;
1046 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingY ) * FROM_266;
1050 glyph.xBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingX ) * FROM_266;
1051 glyph.yBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingY ) * FROM_266;
1069 bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array,
1073 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1074 bool success( true );
1076 for( unsigned int i=0; i<size; ++i )
1078 FontId fontId = array[i].fontId;
1081 fontId-1 < mFontCache.size() )
1083 FontFaceCacheItem& font = mFontCache[fontId-1];
1085 if( ! font.mVectorFontId )
1087 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1090 mVectorFontCache->GetGlyphMetrics( font.mVectorFontId, array[i] );
1092 // Vector metrics are in EMs, convert to pixels
1093 const float scale = ( static_cast<float>( font.mRequestedPointSize ) * FROM_266 ) * static_cast<float>( mDpiVertical ) / POINTS_PER_INCH;
1094 array[i].width *= scale;
1095 array[i].height *= scale;
1096 array[i].xBearing *= scale;
1097 array[i].yBearing *= scale;
1098 array[i].advance *= scale;
1112 void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
1114 if( ( fontId > 0 ) &&
1115 ( fontId - 1u < mFontCache.size() ) )
1117 FT_Face ftFace = mFontCache[fontId - 1u].mFreeTypeFace;
1121 #ifdef FREETYPE_BITMAP_SUPPORT
1122 // Check to see if this is fixed size bitmap
1123 if ( mFontCache[fontId - 1u].mIsFixedSizeBitmap )
1125 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1130 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_NO_AUTOHINT );
1132 if( FT_Err_Ok == error )
1135 error = FT_Get_Glyph( ftFace->glyph, &glyph );
1137 // Convert to bitmap if necessary
1138 if ( FT_Err_Ok == error )
1140 if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
1142 // Check whether we should create a bitmap for the outline
1143 if( glyph->format == FT_GLYPH_FORMAT_OUTLINE && outlineWidth > 0 )
1147 error = FT_Stroker_New(mFreeTypeLibrary, &stroker );
1149 if ( FT_Err_Ok == error )
1151 FT_Stroker_Set( stroker, outlineWidth * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 );
1152 error = FT_Glyph_StrokeBorder( &glyph, stroker, 0, 1 );
1154 if ( FT_Err_Ok == error )
1156 FT_Stroker_Done( stroker );
1160 DALI_LOG_ERROR( "FT_Glyph_StrokeBorder Failed with error: %d\n", error );
1165 DALI_LOG_ERROR( "FT_Stroker_New Failed with error: %d\n", error );
1169 error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
1170 if ( FT_Err_Ok == error )
1172 FT_BitmapGlyph bitmapGlyph = reinterpret_cast< FT_BitmapGlyph >( glyph );
1173 ConvertBitmap( data, bitmapGlyph->bitmap );
1177 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Get_Glyph Failed with error: %d\n", error );
1182 ConvertBitmap( data, ftFace->glyph->bitmap );
1185 // Created FT_Glyph object must be released with FT_Done_Glyph
1186 FT_Done_Glyph( glyph );
1191 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::CreateBitmap. FT_Load_Glyph Failed with error: %d\n", error );
1196 PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
1198 TextAbstraction::FontClient::GlyphBufferData data;
1200 CreateBitmap( fontId, glyphIndex, data, outlineWidth );
1202 return PixelData::New( data.buffer,
1203 data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
1207 PixelData::DELETE_ARRAY );
1210 void FontClient::Plugin::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
1215 #ifdef ENABLE_VECTOR_BASED_TEXT_RENDERING
1217 fontId-1 < mFontCache.size() )
1219 FontFaceCacheItem& font = mFontCache[fontId-1];
1221 if( ! font.mVectorFontId )
1223 font.mVectorFontId = mVectorFontCache->GetFontId( font.mPath );
1226 mVectorFontCache->GetVectorBlob( font.mVectorFontId, fontId, glyphIndex, blob, blobLength, nominalWidth, nominalHeight );
1231 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 requestedPointSize )
1233 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::GetEllipsisGlyph\n" );
1234 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize %d.\n", requestedPointSize );
1236 // First look into the cache if there is an ellipsis glyph for the requested point size.
1237 for( Vector<EllipsisItem>::ConstIterator it = mEllipsisCache.Begin(),
1238 endIt = mEllipsisCache.End();
1242 const EllipsisItem& item = *it;
1244 if( fabsf( item.requestedPointSize - requestedPointSize ) < Math::MACHINE_EPSILON_1000 )
1246 // Use the glyph in the cache.
1248 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1249 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1250 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1256 // No glyph has been found. Create one.
1257 mEllipsisCache.PushBack( EllipsisItem() );
1258 EllipsisItem& item = *( mEllipsisCache.End() - 1u );
1260 item.requestedPointSize = requestedPointSize;
1262 // Find a font for the ellipsis glyph.
1263 item.glyph.fontId = FindDefaultFont( ELLIPSIS_CHARACTER,
1267 // Set the character index to access the glyph inside the font.
1268 item.glyph.index = FT_Get_Char_Index( mFontCache[item.glyph.fontId-1].mFreeTypeFace,
1269 ELLIPSIS_CHARACTER );
1271 GetBitmapMetrics( &item.glyph, 1u, true );
1273 DALI_LOG_INFO( gLogFilter, Debug::General, " glyph id %d found in the cache.\n", item.glyph.index );
1274 DALI_LOG_INFO( gLogFilter, Debug::General, " font %d.\n", item.glyph.fontId );
1275 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::GetEllipsisGlyph\n" );
1280 bool FontClient::Plugin::IsColorGlyph( FontId fontId, GlyphIndex glyphIndex )
1282 FT_Error error = -1;
1284 #ifdef FREETYPE_BITMAP_SUPPORT
1285 if( ( fontId > 0 ) &&
1286 ( fontId - 1u < mFontCache.size() ) )
1288 const FontFaceCacheItem& item = mFontCache[fontId - 1u];
1289 FT_Face ftFace = item.mFreeTypeFace;
1291 // Check to see if this is fixed size bitmap
1292 if( item.mHasColorTables )
1294 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
1299 return FT_Err_Ok == error;
1302 bool FontClient::Plugin::AddCustomFontDirectory( const FontPath& path )
1304 // NULL as first parameter means the current configuration is used.
1305 return FcConfigAppFontAddDir( NULL, reinterpret_cast<const FcChar8 *>( path.c_str() ) );
1308 void FontClient::Plugin::InitSystemFonts()
1310 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" );
1312 FcFontSet* fontSet = GetFcFontSet();
1316 DALI_LOG_INFO( gLogFilter, Debug::General, " number of system fonts : %d\n", fontSet->nfont );
1318 // Reserve some space to avoid reallocations.
1319 mSystemFonts.reserve( fontSet->nfont );
1321 for( int i = 0u; i < fontSet->nfont; ++i )
1323 FcPattern* fontPattern = fontSet->fonts[i];
1327 // Skip fonts with no path
1328 if( GetFcString( fontPattern, FC_FILE, path ) )
1330 mSystemFonts.push_back( FontDescription() );
1331 FontDescription& fontDescription = mSystemFonts.back();
1333 fontDescription.path = path;
1338 GetFcString( fontPattern, FC_FAMILY, fontDescription.family );
1339 GetFcInt( fontPattern, FC_WIDTH, width );
1340 GetFcInt( fontPattern, FC_WEIGHT, weight );
1341 GetFcInt( fontPattern, FC_SLANT, slant );
1342 fontDescription.width = IntToWidthType( width );
1343 fontDescription.weight = IntToWeightType( weight );
1344 fontDescription.slant = IntToSlantType( slant );
1346 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " description; family : [%s]\n", fontDescription.family.c_str() );
1347 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1348 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1349 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1350 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1354 FcFontSetDestroy( fontSet );
1356 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::InitSystemFonts\n" );
1359 bool FontClient::Plugin::MatchFontDescriptionToPattern( FcPattern* pattern, Dali::TextAbstraction::FontDescription& fontDescription, FcCharSet** characterSet )
1361 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1363 FcResult result = FcResultMatch;
1364 FcPattern* match = FcFontMatch( NULL /* use default configure */, pattern, &result );
1366 const bool matched = NULL != match;
1367 DALI_LOG_INFO( gLogFilter, Debug::General, " pattern matched : %s\n", ( matched ? "true" : "false" ) );
1374 GetFcString( match, FC_FILE, fontDescription.path );
1375 GetFcString( match, FC_FAMILY, fontDescription.family );
1376 GetFcInt( match, FC_WIDTH, width );
1377 GetFcInt( match, FC_WEIGHT, weight );
1378 GetFcInt( match, FC_SLANT, slant );
1379 fontDescription.width = IntToWidthType( width );
1380 fontDescription.weight = IntToWeightType( weight );
1381 fontDescription.slant = IntToSlantType( slant );
1383 // Cache the character ranges.
1384 FcPatternGetCharSet( match, FC_CHARSET, 0u, characterSet );
1386 // destroyed the matched pattern
1387 FcPatternDestroy( match );
1389 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1390 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1392 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1393 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1396 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::MatchFontDescriptionToPattern\n" );
1400 FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontDescription& fontDescription ) const
1402 // create the cached font family lookup pattern
1403 // a pattern holds a set of names, each name refers to a property of the font
1404 FcPattern* fontFamilyPattern = FcPatternCreate();
1406 if( !fontFamilyPattern )
1411 // add a property to the pattern for the font family
1412 FcPatternAddString( fontFamilyPattern, FC_FAMILY, reinterpret_cast<const FcChar8*>( fontDescription.family.c_str() ) );
1414 // add a property to the pattern for local setting.
1415 const char* locale = setlocale( LC_MESSAGES, NULL );
1418 FcPatternAddString( fontFamilyPattern, FC_LANG, reinterpret_cast<const FcChar8*>( locale ) );
1421 int width = FONT_WIDTH_TYPE_TO_INT[fontDescription.width];
1425 width = DEFAULT_FONT_WIDTH;
1428 int weight = FONT_WEIGHT_TYPE_TO_INT[fontDescription.weight];
1432 weight = DEFAULT_FONT_WEIGHT;
1435 int slant = FONT_SLANT_TYPE_TO_INT[fontDescription.slant];
1439 slant = DEFAULT_FONT_SLANT;
1442 FcPatternAddInteger( fontFamilyPattern, FC_WIDTH, width );
1443 FcPatternAddInteger( fontFamilyPattern, FC_WEIGHT, weight );
1444 FcPatternAddInteger( fontFamilyPattern, FC_SLANT, slant );
1446 // Add a property of the pattern, to say we want to match TrueType fonts
1447 FcPatternAddString( fontFamilyPattern , FC_FONTFORMAT, reinterpret_cast<const FcChar8*>( FONT_FORMAT.c_str() ) );
1449 // modify the config, with the mFontFamilyPatterm
1450 FcConfigSubstitute( NULL /* use default configure */, fontFamilyPattern, FcMatchPattern );
1452 // provide default values for unspecified properties in the font pattern
1453 // e.g. patterns without a specified style or weight are set to Medium
1454 FcDefaultSubstitute( fontFamilyPattern );
1456 return fontFamilyPattern;
1459 _FcFontSet* FontClient::Plugin::GetFcFontSet() const
1461 // create a new pattern.
1462 // a pattern holds a set of names, each name refers to a property of the font
1463 FcPattern* pattern = FcPatternCreate();
1465 // create an object set used to define which properties are to be returned in the patterns from FcFontList.
1466 FcObjectSet* objectSet = FcObjectSetCreate();
1468 // build an object set from a list of property names
1469 FcObjectSetAdd( objectSet, FC_FILE );
1470 FcObjectSetAdd( objectSet, FC_FAMILY );
1471 FcObjectSetAdd( objectSet, FC_WIDTH );
1472 FcObjectSetAdd( objectSet, FC_WEIGHT );
1473 FcObjectSetAdd( objectSet, FC_SLANT );
1475 // get a list of fonts
1476 // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
1477 FcFontSet* fontset = FcFontList( NULL /* the default configuration is checked to be up to date, and used */, pattern, objectSet );
1479 // clear up the object set
1482 FcObjectSetDestroy( objectSet );
1484 // clear up the pattern
1487 FcPatternDestroy( pattern );
1493 bool FontClient::Plugin::GetFcString( const FcPattern* const pattern,
1494 const char* const n,
1495 std::string& string )
1497 FcChar8* file = NULL;
1498 const FcResult retVal = FcPatternGetString( pattern, n, 0u, &file );
1500 if( FcResultMatch == retVal )
1502 // Have to use reinterpret_cast because FcChar8 is unsigned char*, not a const char*.
1503 string.assign( reinterpret_cast<const char*>( file ) );
1511 bool FontClient::Plugin::GetFcInt( const _FcPattern* const pattern, const char* const n, int& intVal )
1513 const FcResult retVal = FcPatternGetInteger( pattern, n, 0u, &intVal );
1515 if( FcResultMatch == retVal )
1523 FontId FontClient::Plugin::CreateFont( const FontPath& path,
1524 PointSize26Dot6 requestedPointSize,
1525 FaceIndex faceIndex,
1526 bool cacheDescription )
1528 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::CreateFont\n" );
1529 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1530 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1534 // Create & cache new font face
1536 int error = FT_New_Face( mFreeTypeLibrary,
1541 if( FT_Err_Ok == error )
1543 // Check if a font is scalable.
1544 const bool isScalable = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_SCALABLE ) );
1545 const bool hasFixedSizedBitmaps = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_FIXED_SIZES ) ) && ( 0 != ftFace->num_fixed_sizes );
1546 const bool hasColorTables = ( 0 != ( ftFace->face_flags & FT_FACE_FLAG_COLOR ) );
1548 DALI_LOG_INFO( gLogFilter, Debug::General, " isScalable : [%s]\n", ( isScalable ? "true" : "false" ) );
1549 DALI_LOG_INFO( gLogFilter, Debug::General, " hasFixedSizedBitmaps : [%s]\n", ( hasFixedSizedBitmaps ? "true" : "false" ) );
1550 DALI_LOG_INFO( gLogFilter, Debug::General, " hasColorTables : [%s]\n", ( hasColorTables ? "true" : "false" ) );
1552 // Check to see if the font contains fixed sizes?
1553 if( !isScalable && hasFixedSizedBitmaps )
1555 PointSize26Dot6 actualPointSize = 0u;
1556 int fixedSizeIndex = 0;
1557 for( ; fixedSizeIndex < ftFace->num_fixed_sizes; ++fixedSizeIndex )
1559 const PointSize26Dot6 fixedSize = ftFace->available_sizes[fixedSizeIndex].size;
1560 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, size : %d\n", fixedSizeIndex, fixedSize );
1562 if( fixedSize >= requestedPointSize )
1564 actualPointSize = fixedSize;
1569 if( 0u == actualPointSize )
1571 // The requested point size is bigger than the bigest fixed size.
1572 fixedSizeIndex = ftFace->num_fixed_sizes - 1;
1573 actualPointSize = ftFace->available_sizes[fixedSizeIndex].size;
1576 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " size index : %d, actual size : %d\n", fixedSizeIndex, actualPointSize );
1578 // Tell Freetype to use this size
1579 error = FT_Select_Size( ftFace, fixedSizeIndex );
1580 if ( FT_Err_Ok != error )
1582 DALI_LOG_INFO( gLogFilter, Debug::General, "FreeType Select_Size error: %d\n", error );
1586 float fixedWidth = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].width );
1587 float fixedHeight = static_cast< float >( ftFace->available_sizes[ fixedSizeIndex ].height );
1589 // Indicate that the font is a fixed sized bitmap
1590 FontMetrics metrics( fixedHeight, // The ascender in pixels.
1592 fixedHeight, // The height in pixels.
1596 mFontCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics, fixedWidth, fixedHeight, hasColorTables ) );
1597 id = mFontCache.size();
1602 error = FT_Set_Char_Size( ftFace,
1608 if( FT_Err_Ok == error )
1611 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
1613 FontMetrics metrics( static_cast< float >( ftMetrics.ascender ) * FROM_266,
1614 static_cast< float >( ftMetrics.descender ) * FROM_266,
1615 static_cast< float >( ftMetrics.height ) * FROM_266,
1616 static_cast< float >( ftFace->underline_position ) * FROM_266,
1617 static_cast< float >( ftFace->underline_thickness ) * FROM_266 );
1619 mFontCache.push_back( FontFaceCacheItem( ftFace, path, requestedPointSize, faceIndex, metrics ) );
1620 id = mFontCache.size();
1624 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType Set_Char_Size error: %d for pointSize %d\n", error, requestedPointSize );
1630 if( cacheDescription )
1632 CacheFontPath( ftFace, id, requestedPointSize, path );
1638 DALI_LOG_INFO( gLogFilter, Debug::General, " FreeType New_Face error: %d for [%s]\n", error, path.c_str() );
1641 DALI_LOG_INFO( gLogFilter, Debug::General, " font id : %d\n", id );
1642 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::CreateFont\n" );
1647 void FontClient::Plugin::ConvertBitmap( TextAbstraction::FontClient::GlyphBufferData& data, FT_Bitmap srcBitmap )
1649 if( srcBitmap.width*srcBitmap.rows > 0 )
1651 switch( srcBitmap.pixel_mode )
1653 case FT_PIXEL_MODE_GRAY:
1655 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width ) )
1657 const unsigned int bufferSize = srcBitmap.width * srcBitmap.rows;
1658 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1659 data.width = srcBitmap.width;
1660 data.height = srcBitmap.rows;
1661 data.format = Pixel::L8;
1662 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1667 #ifdef FREETYPE_BITMAP_SUPPORT
1668 case FT_PIXEL_MODE_BGRA:
1670 if( srcBitmap.pitch == static_cast<int>( srcBitmap.width << 2u ) )
1672 // Set the input dimensions.
1673 const ImageDimensions inputDimensions( srcBitmap.width, srcBitmap.rows );
1675 // Set the output dimensions.
1676 // If the output dimension is not given, the input dimension is set
1677 // and won't be downscaling.
1678 data.width = ( data.width == 0 ) ? srcBitmap.width : data.width;
1679 data.height = ( data.height == 0 ) ? srcBitmap.rows : data.height;
1680 const ImageDimensions desiredDimensions( data.width, data.height );
1682 // Creates the output buffer
1683 const unsigned int bufferSize = data.width * data.height * 4u;
1684 data.buffer = new unsigned char[bufferSize]; // @note The caller is responsible for deallocating the bitmap data using delete[].
1686 if( inputDimensions == desiredDimensions )
1688 // There isn't downscaling.
1689 memcpy( data.buffer, srcBitmap.buffer, bufferSize );
1693 Dali::Internal::Platform::LanczosSample4BPP( srcBitmap.buffer,
1696 desiredDimensions );
1698 data.format = Pixel::BGRA8888;
1705 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::ConvertBitmap. FontClient Unable to create Bitmap of this PixelType\n" );
1712 bool FontClient::Plugin::FindFont( const FontPath& path,
1713 PointSize26Dot6 requestedPointSize,
1714 FaceIndex faceIndex,
1715 FontId& fontId ) const
1717 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1718 DALI_LOG_INFO( gLogFilter, Debug::General, " path : [%s]\n", path.c_str() );
1719 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1720 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fonts in the cache : %d\n", mFontCache.size() );
1723 for( std::vector<FontFaceCacheItem>::const_iterator it = mFontCache.begin(),
1724 endIt = mFontCache.end();
1728 const FontFaceCacheItem& cacheItem = *it;
1730 if( cacheItem.mRequestedPointSize == requestedPointSize &&
1731 cacheItem.mFaceIndex == faceIndex &&
1732 cacheItem.mPath == path )
1736 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1737 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1743 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found\n" );
1744 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1749 bool FontClient::Plugin::FindValidatedFont( const FontDescription& fontDescription,
1750 FontDescriptionId& validatedFontId )
1752 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindValidatedFont\n" );
1753 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1754 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1755 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1756 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1757 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1758 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of validated fonts in the cache : %d\n", mValidatedFontCache.size() );
1760 validatedFontId = 0u;
1762 for( std::vector<FontDescriptionCacheItem>::const_iterator it = mValidatedFontCache.begin(),
1763 endIt = mValidatedFontCache.end();
1767 const FontDescriptionCacheItem& item = *it;
1769 if( !fontDescription.family.empty() &&
1770 ( fontDescription.family == item.fontDescription.family ) &&
1771 ( fontDescription.width == item.fontDescription.width ) &&
1772 ( fontDescription.weight == item.fontDescription.weight ) &&
1773 ( fontDescription.slant == item.fontDescription.slant ) )
1775 validatedFontId = item.index;
1777 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font found, id : %d\n", validatedFontId );
1778 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1783 DALI_LOG_INFO( gLogFilter, Debug::General, " validated font not found\n" );
1784 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindValidatedFont\n" );
1788 bool FontClient::Plugin::FindFallbackFontList( const FontDescription& fontDescription,
1789 FontList*& fontList,
1790 CharacterSetList*& characterSetList )
1792 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFallbackFontList\n" );
1793 DALI_LOG_INFO( gLogFilter, Debug::General, " description; family : [%s]\n", fontDescription.family.c_str() );
1794 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " path : [%s]\n", fontDescription.path.c_str() );
1795 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " width : [%s]\n", FontWidth::Name[fontDescription.width] );
1796 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " weight : [%s]\n", FontWeight::Name[fontDescription.weight] );
1797 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " slant : [%s]\n\n", FontSlant::Name[fontDescription.slant] );
1798 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of fallback font lists in the cache : %d\n", mFallbackCache.size() );
1802 for( std::vector<FallbackCacheItem>::const_iterator it = mFallbackCache.begin(), endIt = mFallbackCache.end();
1806 const FallbackCacheItem& item = *it;
1808 if( !fontDescription.family.empty() &&
1809 ( fontDescription.family == item.fontDescription.family ) &&
1810 ( fontDescription.width == item.fontDescription.width ) &&
1811 ( fontDescription.weight == item.fontDescription.weight ) &&
1812 ( fontDescription.slant == item.fontDescription.slant ) )
1814 fontList = item.fallbackFonts;
1815 characterSetList = item.characterSets;
1817 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list found.\n" );
1818 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1823 DALI_LOG_INFO( gLogFilter, Debug::General, " fallback font list not found.\n" );
1824 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFallbackFontList\n" );
1828 bool FontClient::Plugin::FindFont( FontDescriptionId validatedFontId,
1829 PointSize26Dot6 requestedPointSize,
1832 DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::FindFont\n" );
1833 DALI_LOG_INFO( gLogFilter, Debug::General, " validatedFontId : %d\n", validatedFontId );
1834 DALI_LOG_INFO( gLogFilter, Debug::General, " requestedPointSize : %d\n", requestedPointSize );
1838 for( std::vector<FontIdCacheItem>::const_iterator it = mFontIdCache.begin(),
1839 endIt = mFontIdCache.end();
1843 const FontIdCacheItem& item = *it;
1845 if( ( validatedFontId == item.validatedFontId ) &&
1846 ( requestedPointSize == item.requestedPointSize ) )
1848 fontId = item.fontId;
1850 DALI_LOG_INFO( gLogFilter, Debug::General, " font found, id : %d\n", fontId );
1851 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1856 DALI_LOG_INFO( gLogFilter, Debug::General, " font not found.\n" );
1857 DALI_LOG_INFO( gLogFilter, Debug::General, "<--FontClient::Plugin::FindFont\n" );
1861 bool FontClient::Plugin::IsScalable( const FontPath& path )
1863 bool isScalable = false;
1866 int error = FT_New_Face( mFreeTypeLibrary,
1870 if( FT_Err_Ok != error )
1872 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: %s\n", path.c_str() );
1876 isScalable = ftFace->face_flags & FT_FACE_FLAG_SCALABLE;
1882 bool FontClient::Plugin::IsScalable( const FontDescription& fontDescription )
1884 // Create a font pattern.
1885 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1887 FcResult result = FcResultMatch;
1889 // match the pattern
1890 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
1891 bool isScalable = false;
1895 // Get the path to the font file name.
1897 GetFcString( match, FC_FILE, path );
1898 isScalable = IsScalable( path );
1902 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::IsScalable. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1904 FcPatternDestroy( fontFamilyPattern );
1905 FcPatternDestroy( match );
1909 void FontClient::Plugin::GetFixedSizes( const FontPath& path, Vector< PointSize26Dot6 >& sizes )
1911 // Empty the caller container
1915 int error = FT_New_Face( mFreeTypeLibrary,
1919 if( FT_Err_Ok != error )
1921 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font path : [%s]\n", path.c_str() );
1924 // Fetch the number of fixed sizes available
1925 if ( ftFace->num_fixed_sizes && ftFace->available_sizes )
1927 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
1929 sizes.PushBack( ftFace->available_sizes[ i ].size );
1934 void FontClient::Plugin::GetFixedSizes( const FontDescription& fontDescription,
1935 Vector< PointSize26Dot6 >& sizes )
1937 // Create a font pattern.
1938 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontDescription );
1940 FcResult result = FcResultMatch;
1942 // match the pattern
1943 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
1947 // Get the path to the font file name.
1949 GetFcString( match, FC_FILE, path );
1950 GetFixedSizes( path, sizes );
1954 DALI_LOG_INFO( gLogFilter, Debug::General, "FontClient::Plugin::GetFixedSizes. FreeType Cannot check font: [%s]\n", fontDescription.family.c_str() );
1956 FcPatternDestroy( match );
1957 FcPatternDestroy( fontFamilyPattern );
1960 void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path )
1962 FontDescription description;
1963 description.path = path;
1964 description.family = FontFamily( ftFace->family_name );
1965 description.weight = FontWeight::NONE;
1966 description.width = FontWidth::NONE;
1967 description.slant = FontSlant::NONE;
1969 // Note FreeType doesn't give too much info to build a proper font style.
1970 if( ftFace->style_flags & FT_STYLE_FLAG_ITALIC )
1972 description.slant = FontSlant::ITALIC;
1974 if( ftFace->style_flags & FT_STYLE_FLAG_BOLD )
1976 description.weight = FontWeight::BOLD;
1979 FontDescriptionId validatedFontId = 0u;
1980 if( !FindValidatedFont( description,
1983 // Set the index to the vector of paths to font file names.
1984 validatedFontId = mFontDescriptionCache.size();
1986 FcPattern* pattern = CreateFontFamilyPattern( description );
1988 FcResult result = FcResultMatch;
1989 FcPattern* match = FcFontMatch( NULL, pattern, &result );
1991 FcCharSet* characterSet = NULL;
1992 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
1994 FcPatternDestroy( match );
1995 FcPatternDestroy( pattern );
1997 mFontCache[id-1u].mCharacterSet = characterSet;
1999 // Add the path to the cache.
2000 mFontDescriptionCache.push_back( description );
2001 mCharacterSetCache.PushBack( characterSet );
2003 // Cache the index and the font's description.
2004 FontDescriptionCacheItem item( description,
2007 mValidatedFontCache.push_back( item );
2009 // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
2010 mFontIdCache.push_back( FontIdCacheItem( validatedFontId,
2016 FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) const
2018 FcCharSet* characterSet = NULL;
2020 FcPattern* pattern = CreateFontFamilyPattern( description );
2022 if( NULL != pattern )
2024 FcResult result = FcResultMatch;
2025 FcPattern* match = FcFontMatch( NULL, pattern, &result );
2027 FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
2029 FcPatternDestroy( match );
2030 FcPatternDestroy( pattern );
2033 return characterSet;
2036 } // namespace Internal
2038 } // namespace TextAbstraction