2 * Copyright (c) 2015 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/public-api/common/dali-vector.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/integration-api/debug.h>
27 #include <fontconfig/fontconfig.h>
30 * Conversion from Fractional26.6 to float
34 const float FROM_266 = 1.0f / 64.0f;
36 const std::string FONT_FORMAT( "TrueType" );
37 const std::string DEFAULT_FONT_FAMILY_NAME( "Tizen" );
38 const std::string DEFAULT_FONT_STYLE( "Regular" );
40 const uint32_t ELLIPSIS_CHARACTER = 0x2026;
48 namespace TextAbstraction
54 const bool FONT_FIXED_SIZE_BITMAP( true );
56 FontClient::Plugin::FontDescriptionCacheItem::FontDescriptionCacheItem( const FontFamily& fontFamily,
57 const FontStyle& fontStyle,
58 FontDescriptionId index )
59 : fontFamily( fontFamily ),
60 fontStyle( fontStyle ),
65 FontClient::Plugin::FontIdCacheItem::FontIdCacheItem( FontDescriptionId validatedFontId,
66 PointSize26Dot6 pointSize,
68 : validatedFontId( validatedFontId ),
69 pointSize( pointSize ),
74 FontClient::Plugin::CacheItem::CacheItem( FT_Face ftFace,
76 PointSize26Dot6 pointSize,
78 const FontMetrics& metrics )
79 : mFreeTypeFace( ftFace ),
81 mPointSize( pointSize ),
84 mFixedWidthPixels( 0.0f ),
85 mFixedHeightPixels( 0.0f ),
86 mIsFixedSizeBitmap( false )
90 FontClient::Plugin::CacheItem::CacheItem( FT_Face ftFace,
92 PointSize26Dot6 pointSize,
94 const FontMetrics& metrics,
97 : mFreeTypeFace( ftFace ),
99 mPointSize( pointSize ),
102 mFixedWidthPixels( fixedWidth ),
103 mFixedHeightPixels( fixedHeight ),
104 mIsFixedSizeBitmap( true )
108 FontClient::Plugin::Plugin( unsigned int horizontalDpi,
109 unsigned int verticalDpi )
110 : mFreeTypeLibrary( NULL ),
111 mDpiHorizontal( horizontalDpi ),
112 mDpiVertical( verticalDpi ),
116 mValidatedFontCache(),
117 mFontDescriptionCache( 1u ),
121 int error = FT_Init_FreeType( &mFreeTypeLibrary );
122 if( FT_Err_Ok != error )
124 DALI_LOG_ERROR( "FreeType Init error: %d\n", error );
128 FontClient::Plugin::~Plugin()
130 FT_Done_FreeType( mFreeTypeLibrary );
133 void FontClient::Plugin::SetDpi( unsigned int horizontalDpi,
134 unsigned int verticalDpi )
136 mDpiHorizontal = horizontalDpi;
137 mDpiVertical = verticalDpi;
140 void FontClient::Plugin::SetDefaultFontFamily( const FontFamily& fontFamilyName,
141 const FontStyle& fontStyle )
143 mDefaultFonts.clear();
145 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontFamilyName,
148 FcResult result = FcResultMatch;
150 // Match the pattern.
151 FcFontSet* fontSet = FcFontSort( NULL /* use default configure */,
153 false /* don't trim */,
157 if( NULL != fontSet )
159 // Reserve some space to avoid reallocations.
160 mDefaultFonts.reserve( fontSet->nfont );
162 for( int i = 0u; i < fontSet->nfont; ++i )
164 FcPattern* fontPattern = fontSet->fonts[i];
168 // Skip fonts with no path
169 if( GetFcString( fontPattern, FC_FILE, path ) )
171 mDefaultFonts.push_back( FontDescription() );
172 FontDescription& fontDescription = mDefaultFonts.back();
174 fontDescription.path = path;
176 GetFcString( fontPattern, FC_FAMILY, fontDescription.family );
177 GetFcString( fontPattern, FC_STYLE, fontDescription.style );
181 FcFontSetDestroy( fontSet );
184 FcPatternDestroy( fontFamilyPattern );
187 void FontClient::Plugin::GetDefaultFonts( FontList& defaultFonts )
189 if( mDefaultFonts.empty() )
191 SetDefaultFontFamily( DEFAULT_FONT_FAMILY_NAME,
192 DEFAULT_FONT_STYLE );
195 defaultFonts = mDefaultFonts;
198 void FontClient::Plugin::GetSystemFonts( FontList& systemFonts )
200 if( mSystemFonts.empty() )
205 systemFonts = mSystemFonts;
208 void FontClient::Plugin::GetDescription( FontId id,
209 FontDescription& fontDescription ) const
211 for( std::vector<FontIdCacheItem>::const_iterator it = mFontIdCache.begin(),
212 endIt = mFontIdCache.end();
216 const FontIdCacheItem& item = *it;
218 if( item.fontId == id )
220 fontDescription = *( mFontDescriptionCache.begin() + item.validatedFontId );
225 DALI_LOG_ERROR( "FontClient::Plugin::GetDescription. No description found for the font ID %d\n", id );
228 PointSize26Dot6 FontClient::Plugin::GetPointSize( FontId id )
230 const FontId index = id - 1u;
233 index < mFontCache.size() )
235 return ( *( mFontCache.begin() + index ) ).mPointSize;
239 DALI_LOG_ERROR( "FontClient::Plugin::GetPointSize. Invalid font ID %d\n", id );
242 return TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
245 FontId FontClient::Plugin::FindDefaultFont( Character charcode,
246 PointSize26Dot6 requestedSize,
250 bool foundColor(false);
252 // Create the list of default fonts if it has not been created.
253 if( mDefaultFonts.empty() )
255 SetDefaultFontFamily( DEFAULT_FONT_FAMILY_NAME,
256 DEFAULT_FONT_STYLE );
259 // Traverse the list of default fonts.
260 // Check for each default font if supports the character.
262 for( FontList::const_iterator it = mDefaultFonts.begin(), endIt = mDefaultFonts.end();
266 const FontDescription& description = *it;
268 FcPattern* pattern = CreateFontFamilyPattern( description.family,
271 FcResult result = FcResultMatch;
272 FcPattern* match = FcFontMatch( NULL /* use default configure */, pattern, &result );
274 FcCharSet* charSet = NULL;
275 FcPatternGetCharSet( match, FC_CHARSET, 0u, &charSet );
277 if( FcCharSetHasChar( charSet, charcode ) )
279 Vector< PointSize26Dot6 > fixedSizes;
280 GetFixedSizes( description.family,
284 const Vector< PointSize26Dot6 >::SizeType count = fixedSizes.Count();
287 // If the font is not scalable, pick the largest size <= requestedSize
288 PointSize26Dot6 size = fixedSizes[0];
289 for( unsigned int i=1; i<count; ++i )
291 if( fixedSizes[i] <= requestedSize &&
292 fixedSizes[i] > size )
294 size = fixedSizes[i];
297 requestedSize = size;
300 fontId = GetFontId( description.family,
307 BufferImage bitmap = CreateBitmap( fontId, GetGlyphIndex(fontId,charcode) );
309 Pixel::BGRA8888 == bitmap.GetPixelFormat() )
315 // Keep going unless we prefer a different (color) font
316 if( !preferColor || foundColor )
318 FcPatternDestroy( match );
319 FcPatternDestroy( pattern );
324 FcPatternDestroy( match );
325 FcPatternDestroy( pattern );
330 FontId FontClient::Plugin::GetFontId( const FontPath& path,
331 PointSize26Dot6 pointSize,
333 bool cacheDescription )
337 if( NULL != mFreeTypeLibrary )
340 if( FindFont( path, pointSize, faceIndex, foundId ) )
346 id = CreateFont( path, pointSize, faceIndex, cacheDescription );
353 FontId FontClient::Plugin::GetFontId( const FontFamily& fontFamily,
354 const FontStyle& fontStyle,
355 PointSize26Dot6 pointSize,
356 FaceIndex faceIndex )
358 // This method uses three vectors which caches:
359 // * Pairs of non validated 'fontFamily, fontStyle' and an index to a vector with paths to font file names.
360 // * The path to font file names.
361 // * The font ids of pairs 'font point size, index to the vector with paths to font file names'.
363 // 1) Checks in the cache if the pair 'fontFamily, fontStyle' has been validated before.
364 // If it was it gets an index to the vector with paths to font file names. Otherwise,
365 // retrieves using font config a path to a font file name which matches with the pair
366 // 'fontFamily, fontStyle'. The path is stored in the chache.
368 // 2) Checks in the cache if the pair 'font point size, index to the vector with paths to
369 // fon file names' exists. If exists, it gets the font id. If it doesn't it calls
370 // the GetFontId() method with the path to the font file name and the point size to
373 // The font id to be returned.
376 // Check first if the pair font family and style have been validated before.
377 FontDescriptionId validatedFontId = 0u;
379 if( !FindValidatedFont( fontFamily,
383 // Use font config to validate the font family name and font style.
384 ValidateFont( fontFamily, fontStyle, validatedFontId );
387 // Check if exists a pair 'validatedFontId, pointSize' in the cache.
388 if( !FindFont( validatedFontId, pointSize, fontId ) )
390 // Retrieve the font file name path.
391 const FontDescription& description = *( mFontDescriptionCache.begin() + validatedFontId );
393 // Retrieve the font id. Do not cache the description as it has been already cached.
394 fontId = GetFontId( description.path,
399 // Cache the pair 'validatedFontId, pointSize' to improve the following queries.
400 mFontIdCache.push_back( FontIdCacheItem( validatedFontId,
408 void FontClient::Plugin::ValidateFont( const FontFamily& fontFamily,
409 const FontStyle& fontStyle,
410 FontDescriptionId& validatedFontId )
412 // Create a font pattern.
413 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontFamily,
416 FcResult result = FcResultMatch;
419 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
423 // Get the path to the font file name.
424 FontDescription description;
425 GetFcString( match, FC_FILE, description.path );
426 GetFcString( match, FC_FAMILY, description.family );
427 GetFcString( match, FC_STYLE, description.style );
429 // Set the index to the vector of paths to font file names.
430 validatedFontId = mFontDescriptionCache.size();
432 // Add the path to the cache.
433 mFontDescriptionCache.push_back( description );
435 // Cache the index and the pair font family name, font style.
436 FontDescriptionCacheItem item( fontFamily, fontStyle, validatedFontId );
437 mValidatedFontCache.push_back( item );
439 // destroyed the matched pattern
440 FcPatternDestroy( match );
444 DALI_LOG_ERROR( "FontClient::Plugin::ValidateFont failed for font %s %s\n", fontFamily.c_str(), fontStyle.c_str() );
447 // destroy the pattern
448 FcPatternDestroy( fontFamilyPattern );
453 void FontClient::Plugin::GetFontMetrics( FontId fontId,
454 FontMetrics& metrics )
457 fontId-1 < mFontCache.size() )
459 metrics = mFontCache[fontId-1].mMetrics;
463 DALI_LOG_ERROR( "Invalid font ID %d\n", fontId );
467 GlyphIndex FontClient::Plugin::GetGlyphIndex( FontId fontId,
470 GlyphIndex index( 0 );
473 fontId-1 < mFontCache.size() )
475 FT_Face ftFace = mFontCache[fontId-1].mFreeTypeFace;
477 index = FT_Get_Char_Index( ftFace, charcode );
483 bool FontClient::Plugin::GetGlyphMetrics( GlyphInfo* array,
487 bool success( true );
489 for( unsigned int i=0; i<size; ++i )
491 FontId fontId = array[i].fontId;
494 fontId-1 < mFontCache.size() )
496 FT_Face ftFace = mFontCache[fontId-1].mFreeTypeFace;
498 #ifdef FREETYPE_BITMAP_SUPPORT
499 // Check to see if we should be loading a Fixed Size bitmap?
500 if ( mFontCache[fontId-1].mIsFixedSizeBitmap )
502 int error = FT_Load_Glyph( ftFace, array[i].index, FT_LOAD_COLOR );
503 if ( FT_Err_Ok == error )
505 array[i].width = mFontCache[ fontId -1 ].mFixedWidthPixels;
506 array[i].height = mFontCache[ fontId -1 ].mFixedHeightPixels;
507 array[i].advance = mFontCache[ fontId -1 ].mFixedWidthPixels;
508 array[i].xBearing = 0.0f;
509 array[i].yBearing = mFontCache[ fontId -1 ].mFixedHeightPixels;
513 DALI_LOG_ERROR( "FreeType Bitmap Load_Glyph error %d\n", error );
520 int error = FT_Load_Glyph( ftFace, array[i].index, FT_LOAD_DEFAULT );
522 if( FT_Err_Ok == error )
524 array[i].width = static_cast< float >( ftFace->glyph->metrics.width ) * FROM_266;
525 array[i].height = static_cast< float >( ftFace->glyph->metrics.height ) * FROM_266 ;
528 array[i].xBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingX ) * FROM_266;
529 array[i].yBearing += static_cast< float >( ftFace->glyph->metrics.horiBearingY ) * FROM_266;
533 array[i].xBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingX ) * FROM_266;
534 array[i].yBearing += static_cast< float >( ftFace->glyph->metrics.vertBearingY ) * FROM_266;
552 BufferImage FontClient::Plugin::CreateBitmap( FontId fontId,
553 GlyphIndex glyphIndex )
558 fontId-1 < mFontCache.size() )
560 FT_Face ftFace = mFontCache[fontId-1].mFreeTypeFace;
564 #ifdef FREETYPE_BITMAP_SUPPORT
565 // Check to see if this is fixed size bitmap
566 if ( mFontCache[fontId-1].mIsFixedSizeBitmap )
568 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_COLOR );
573 error = FT_Load_Glyph( ftFace, glyphIndex, FT_LOAD_DEFAULT );
575 if( FT_Err_Ok == error )
578 error = FT_Get_Glyph( ftFace->glyph, &glyph );
580 // Convert to bitmap if necessary
581 if ( FT_Err_Ok == error )
583 if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
585 error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
586 if ( FT_Err_Ok == error )
588 FT_BitmapGlyph bitmapGlyph = (FT_BitmapGlyph)glyph;
589 ConvertBitmap( bitmap, bitmapGlyph->bitmap );
593 DALI_LOG_ERROR( "FT_Get_Glyph Failed with error: %d\n", error );
598 ConvertBitmap( bitmap, ftFace->glyph->bitmap );
601 // Created FT_Glyph object must be released with FT_Done_Glyph
602 FT_Done_Glyph( glyph );
607 DALI_LOG_ERROR( "FT_Load_Glyph Failed with error: %d\n", error );
614 const GlyphInfo& FontClient::Plugin::GetEllipsisGlyph( PointSize26Dot6 pointSize )
616 // First look into the cache if there is an ellipsis glyph for the requested point size.
617 for( Vector<EllipsisItem>::ConstIterator it = mEllipsisCache.Begin(),
618 endIt = mEllipsisCache.End();
622 const EllipsisItem& item = *it;
624 if( fabsf( item.size - pointSize ) < Math::MACHINE_EPSILON_1000 )
626 // Use the glyph in the cache.
631 // No glyph has been found. Create one.
632 mEllipsisCache.PushBack( EllipsisItem() );
633 EllipsisItem& item = *( mEllipsisCache.End() - 1u );
635 item.size = pointSize;
637 // Find a font for the ellipsis glyph.
638 item.glyph.fontId = FindDefaultFont( ELLIPSIS_CHARACTER,
642 // Set the character index to access the glyph inside the font.
643 item.glyph.index = FT_Get_Char_Index( mFontCache[item.glyph.fontId-1].mFreeTypeFace,
644 ELLIPSIS_CHARACTER );
646 GetGlyphMetrics( &item.glyph, 1u, true );
651 void FontClient::Plugin::InitSystemFonts()
653 FcFontSet* fontSet = GetFcFontSet();
657 // Reserve some space to avoid reallocations.
658 mSystemFonts.reserve( fontSet->nfont );
660 for( int i = 0u; i < fontSet->nfont; ++i )
662 FcPattern* fontPattern = fontSet->fonts[i];
666 // Skip fonts with no path
667 if( GetFcString( fontPattern, FC_FILE, path ) )
669 mSystemFonts.push_back( FontDescription() );
670 FontDescription& fontDescription = mSystemFonts.back();
672 fontDescription.path = path;
674 GetFcString( fontPattern, FC_FAMILY, fontDescription.family );
675 GetFcString( fontPattern, FC_STYLE, fontDescription.style );
679 FcFontSetDestroy( fontSet );
683 FcPattern* FontClient::Plugin::CreateFontFamilyPattern( const FontFamily& fontFamily,
684 const FontStyle& fontStyle )
686 // create the cached font family lookup pattern
687 // a pattern holds a set of names, each name refers to a property of the font
688 FcPattern* fontFamilyPattern = FcPatternCreate();
690 // add a property to the pattern for the font family
691 FcPatternAddString( fontFamilyPattern, FC_FAMILY, reinterpret_cast<const FcChar8*>( fontFamily.c_str() ) );
693 // add a property to the pattern for the font family
694 FcPatternAddString( fontFamilyPattern, FC_STYLE, reinterpret_cast<const FcChar8*>( fontStyle.c_str() ) );
696 // Add a property of the pattern, to say we want to match TrueType fonts
697 FcPatternAddString( fontFamilyPattern , FC_FONTFORMAT, reinterpret_cast<const FcChar8*>( FONT_FORMAT.c_str() ) );
699 // modify the config, with the mFontFamilyPatterm
700 FcConfigSubstitute( NULL /* use default configure */, fontFamilyPattern, FcMatchPattern );
702 // provide default values for unspecified properties in the font pattern
703 // e.g. patterns without a specified style or weight are set to Medium
704 FcDefaultSubstitute( fontFamilyPattern );
706 return fontFamilyPattern;
709 _FcFontSet* FontClient::Plugin::GetFcFontSet() const
711 // create a new pattern.
712 // a pattern holds a set of names, each name refers to a property of the font
713 FcPattern* pattern = FcPatternCreate();
715 // create an object set used to define which properties are to be returned in the patterns from FcFontList.
716 FcObjectSet* objectSet = FcObjectSetCreate();
718 // build an object set from a list of property names
719 FcObjectSetAdd( objectSet, FC_FILE );
720 FcObjectSetAdd( objectSet, FC_FAMILY );
721 FcObjectSetAdd( objectSet, FC_STYLE );
723 // get a list of fonts
724 // creates patterns from those fonts containing only the objects in objectSet and returns the set of unique such patterns
725 FcFontSet* fontset = FcFontList( NULL /* the default configuration is checked to be up to date, and used */, pattern, objectSet );
727 // clear up the object set
730 FcObjectSetDestroy( objectSet );
732 // clear up the pattern
735 FcPatternDestroy( pattern );
741 bool FontClient::Plugin::GetFcString( const FcPattern* const pattern,
743 std::string& string )
745 FcChar8* file = NULL;
746 const FcResult retVal = FcPatternGetString( pattern, n, 0u, &file );
748 if( FcResultMatch == retVal )
750 // Have to use reinterpret_cast because FcChar8 is unsigned char*, not a const char*.
751 string.assign( reinterpret_cast<const char*>( file ) );
759 FontId FontClient::Plugin::CreateFont( const FontPath& path,
760 PointSize26Dot6 pointSize,
762 bool cacheDescription )
766 // Create & cache new font face
768 int error = FT_New_Face( mFreeTypeLibrary,
773 if( FT_Err_Ok == error )
775 // Check to see if the font contains fixed sizes?
776 if ( ftFace->num_fixed_sizes && ftFace->available_sizes )
778 // Ensure this size is available
779 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
781 if ( static_cast<FT_Pos>(pointSize) == ftFace->available_sizes[ i ].size )
783 // Tell Freetype to use this size
784 error = FT_Select_Size( ftFace, i );
785 if ( FT_Err_Ok != error )
787 DALI_LOG_ERROR( "FreeType Select_Size error: %d\n", error );
791 float fixedWidth = static_cast< float >( ftFace->available_sizes[ i ].width );
792 float fixedHeight = static_cast< float >( ftFace->available_sizes[ i ].height );
794 // Indicate that the font is a fixed sized bitmap
795 FontMetrics metrics( fixedHeight,
801 mFontCache.push_back( CacheItem( ftFace, path, pointSize, faceIndex, metrics, fixedWidth, fixedHeight ) );
802 id = mFontCache.size();
804 if( cacheDescription )
806 FontDescription description;
807 description.path = path;
808 description.family = FontFamily( ftFace->family_name );
809 description.style = FontStyle( ftFace->style_name );
811 mFontDescriptionCache.push_back( description );
818 // Can't find this size
819 std::stringstream sizes;
820 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
826 sizes << ftFace->available_sizes[ i ].size;
828 DALI_LOG_ERROR( "FreeType Font: %s, does not contain Bitmaps of size: %d. Available sizes are: %s\n",
829 path.c_str(), pointSize, sizes.str().c_str() );
833 error = FT_Set_Char_Size( ftFace,
839 if( FT_Err_Ok == error )
842 FT_Size_Metrics& ftMetrics = ftFace->size->metrics;
844 FontMetrics metrics( static_cast< float >( ftMetrics.ascender ) * FROM_266,
845 static_cast< float >( ftMetrics.descender ) * FROM_266,
846 static_cast< float >( ftMetrics.height ) * FROM_266,
847 static_cast< float >( ftFace->underline_position ) * FROM_266,
848 static_cast< float >( ftFace->underline_thickness ) * FROM_266 );
850 mFontCache.push_back( CacheItem( ftFace, path, pointSize, faceIndex, metrics ) );
851 id = mFontCache.size();
853 if( cacheDescription )
855 FontDescription description;
856 description.path = path;
857 description.family = FontFamily( ftFace->family_name );
858 description.style = FontStyle( ftFace->style_name );
860 mFontDescriptionCache.push_back( description );
865 DALI_LOG_ERROR( "FreeType Set_Char_Size error: %d for pointSize %d\n", error, pointSize );
871 DALI_LOG_ERROR( "FreeType New_Face error: %d for %s\n", error, path.c_str() );
877 void FontClient::Plugin::ConvertBitmap( BufferImage& destBitmap,
878 FT_Bitmap srcBitmap )
880 if( srcBitmap.width*srcBitmap.rows > 0 )
882 switch( srcBitmap.pixel_mode )
884 case FT_PIXEL_MODE_GRAY:
886 if( srcBitmap.pitch == static_cast< int >( srcBitmap.width ) )
888 destBitmap = BufferImage::New( srcBitmap.width, srcBitmap.rows, Pixel::L8 );
890 PixelBuffer* destBuffer = destBitmap.GetBuffer();
893 memcpy( destBuffer, srcBitmap.buffer, srcBitmap.width*srcBitmap.rows );
897 DALI_LOG_ERROR( "GetBuffer returns null\n" );
903 #ifdef FREETYPE_BITMAP_SUPPORT
904 case FT_PIXEL_MODE_BGRA:
906 if ( srcBitmap.pitch == static_cast< int >( srcBitmap.width << 2 ) )
908 destBitmap = BufferImage::New( srcBitmap.width, srcBitmap.rows, Pixel::BGRA8888 );
910 PixelBuffer* destBuffer = destBitmap.GetBuffer();
913 memcpy( destBuffer, srcBitmap.buffer, srcBitmap.width*srcBitmap.rows*4 );
917 DALI_LOG_ERROR( "GetBuffer returns null\n" );
925 DALI_LOG_ERROR( "FontClient Unable to create Bitmap of this PixelType\n" );
932 bool FontClient::Plugin::FindFont( const FontPath& path,
933 PointSize26Dot6 pointSize,
935 FontId& fontId ) const
938 for( std::vector<CacheItem>::const_iterator it = mFontCache.begin(),
939 endIt = mFontCache.end();
943 const CacheItem& cacheItem = *it;
945 if( cacheItem.mPointSize == pointSize &&
946 cacheItem.mFaceIndex == faceIndex &&
947 cacheItem.mPath == path )
957 bool FontClient::Plugin::FindValidatedFont( const FontFamily& fontFamily,
958 const FontStyle& fontStyle,
959 FontDescriptionId& validatedFontId )
961 validatedFontId = 0u;
963 for( std::vector<FontDescriptionCacheItem>::const_iterator it = mValidatedFontCache.begin(),
964 endIt = mValidatedFontCache.end();
968 const FontDescriptionCacheItem& item = *it;
970 if( ( fontFamily == item.fontFamily ) &&
971 ( fontStyle == item.fontStyle ) )
973 validatedFontId = item.index;
982 bool FontClient::Plugin::FindFont( FontDescriptionId validatedFontId,
983 PointSize26Dot6 pointSize,
988 for( std::vector<FontIdCacheItem>::const_iterator it = mFontIdCache.begin(),
989 endIt = mFontIdCache.end();
993 const FontIdCacheItem& item = *it;
995 if( ( validatedFontId == item.validatedFontId ) &&
996 ( pointSize == item.pointSize ) )
998 fontId = item.fontId;
1006 bool FontClient::Plugin::IsScalable( const FontPath& path )
1009 int error = FT_New_Face( mFreeTypeLibrary,
1013 if( FT_Err_Ok != error )
1015 DALI_LOG_ERROR( "FreeType Cannot check font: %s\n", path.c_str() );
1017 return ( ftFace->num_fixed_sizes == 0 );
1020 bool FontClient::Plugin::IsScalable( const FontFamily& fontFamily, const FontStyle& fontStyle )
1022 // Create a font pattern.
1023 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontFamily,
1026 FcResult result = FcResultMatch;
1028 // match the pattern
1029 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
1030 bool isScalable = true;
1034 // Get the path to the font file name.
1036 GetFcString( match, FC_FILE, path );
1037 isScalable = IsScalable( path );
1041 DALI_LOG_ERROR( "FreeType Cannot check font: %s %s\n", fontFamily.c_str(), fontStyle.c_str() );
1043 FcPatternDestroy( fontFamilyPattern );
1044 FcPatternDestroy( match );
1048 void FontClient::Plugin::GetFixedSizes( const FontPath& path, Vector< PointSize26Dot6 >& sizes )
1050 // Empty the caller container
1054 int error = FT_New_Face( mFreeTypeLibrary,
1058 if( FT_Err_Ok != error )
1060 DALI_LOG_ERROR( "FreeType Cannot check font: %s\n", path.c_str() );
1063 // Fetch the number of fixed sizes available
1064 if ( ftFace->num_fixed_sizes && ftFace->available_sizes )
1066 for ( int i = 0; i < ftFace->num_fixed_sizes; ++i )
1068 sizes.PushBack( ftFace->available_sizes[ i ].size );
1073 void FontClient::Plugin::GetFixedSizes( const FontFamily& fontFamily,
1074 const FontStyle& fontStyle,
1075 Vector< PointSize26Dot6 >& sizes )
1077 // Create a font pattern.
1078 FcPattern* fontFamilyPattern = CreateFontFamilyPattern( fontFamily,
1081 FcResult result = FcResultMatch;
1083 // match the pattern
1084 FcPattern* match = FcFontMatch( NULL /* use default configure */, fontFamilyPattern, &result );
1088 // Get the path to the font file name.
1090 GetFcString( match, FC_FILE, path );
1091 GetFixedSizes( path, sizes );
1095 DALI_LOG_ERROR( "FreeType Cannot check font: %s %s\n", fontFamily.c_str(), fontStyle.c_str() );
1097 FcPatternDestroy( match );
1098 FcPatternDestroy( fontFamilyPattern );
1101 } // namespace Internal
1103 } // namespace TextAbstraction