+void FontClient::Plugin::CacheFontPath( FT_Face ftFace, FontId id, PointSize26Dot6 requestedPointSize, const FontPath& path )
+{
+ FontDescription description;
+ description.path = path;
+ description.family = FontFamily( ftFace->family_name );
+ description.weight = FontWeight::NONE;
+ description.width = FontWidth::NONE;
+ description.slant = FontSlant::NONE;
+
+ // Note FreeType doesn't give too much info to build a proper font style.
+ if( ftFace->style_flags & FT_STYLE_FLAG_ITALIC )
+ {
+ description.slant = FontSlant::ITALIC;
+ }
+ if( ftFace->style_flags & FT_STYLE_FLAG_BOLD )
+ {
+ description.weight = FontWeight::BOLD;
+ }
+
+ FontDescriptionId validatedFontId = 0u;
+ if( !FindValidatedFont( description,
+ validatedFontId ) )
+ {
+ // Set the index to the vector of paths to font file names.
+ validatedFontId = mFontDescriptionCache.size();
+
+ FcPattern* pattern = CreateFontFamilyPattern( description );
+
+ FcResult result = FcResultMatch;
+ FcPattern* match = FcFontMatch( NULL, pattern, &result );
+
+ FcCharSet* characterSet = NULL;
+ FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
+
+ FcPatternDestroy( match );
+ FcPatternDestroy( pattern );
+
+ mFontCache[id-1u].mCharacterSet = characterSet;
+
+ // Add the path to the cache.
+ mFontDescriptionCache.push_back( description );
+ mCharacterSetCache.PushBack( characterSet );
+
+ // Cache the index and the font's description.
+ FontDescriptionCacheItem item( description,
+ validatedFontId );
+
+ mValidatedFontCache.push_back( item );
+
+ // Cache the pair 'validatedFontId, requestedPointSize' to improve the following queries.
+ mFontIdCache.push_back( FontIdCacheItem( validatedFontId,
+ requestedPointSize,
+ id ) );
+ }
+}
+
+FcCharSet* FontClient::Plugin::CreateCharacterSetFromDescription( const FontDescription& description ) const
+{
+ FcCharSet* characterSet = NULL;
+
+ FcPattern* pattern = CreateFontFamilyPattern( description );
+
+ if( NULL != pattern )
+ {
+ FcResult result = FcResultMatch;
+ FcPattern* match = FcFontMatch( NULL, pattern, &result );
+
+ FcPatternGetCharSet( match, FC_CHARSET, 0u, &characterSet );
+
+ FcPatternDestroy( match );
+ FcPatternDestroy( pattern );
+ }
+
+ return characterSet;
+}
+