124 if( aSearchLang.Lower() == aSupportedLang.Lower() )
127 if( aSupportedLang.empty() )
130 if( aSearchLang.empty() )
133 wxArrayString supportedLangBits;
134 wxStringSplit( aSupportedLang.Lower(), supportedLangBits, wxS(
'-' ) );
136 wxArrayString searhcLangBits;
137 wxStringSplit( aSearchLang.Lower(), searhcLangBits, wxS(
'-' ) );
141 if( searhcLangBits.size() == 1 || supportedLangBits.size() == 1 )
142 return searhcLangBits[0] == supportedLangBits[0];
209 int& aFaceIndex,
bool aBold,
bool aItalic,
210 const std::vector<wxString>* aEmbeddedFiles )
219 if( aFontName.Lower().Contains( wxS(
"bold" ) )
220 || aFontName.Lower().Contains( wxS(
"heavy" ) )
221 || aFontName.Lower().Contains( wxS(
"black" ) )
222 || aFontName.Lower().Contains( wxS(
"thick" ) )
223 || aFontName.Lower().Contains( wxS(
"dark" ) ) )
228 FcConfig*
config = FcConfigGetCurrent();
232 for(
const wxString& file : *aEmbeddedFiles )
233 FcConfigAppFontAddFile(
config, (
const FcChar8*) file.c_str().AsChar() );
236 const wxString& qualifiedFontName = aFontName;
238 wxScopedCharBuffer
const fcBuffer = qualifiedFontName.ToUTF8();
240 FcPattern* pat = FcPatternCreate();
243 FcPatternAddInteger( pat, FC_WEIGHT, FC_WEIGHT_BOLD );
246 FcPatternAddInteger( pat, FC_SLANT, FC_SLANT_ITALIC );
248 FcPatternAddString( pat, FC_FAMILY, (FcChar8*) fcBuffer.data() );
250 FcConfigSubstitute(
config, pat, FcMatchPattern );
251 FcDefaultSubstitute( pat );
253 FcResult r = FcResultNoMatch;
254 FcPattern* font = FcFontMatch(
config, pat, &r );
257 bool familyMatched =
false;
261 FcChar8* file =
nullptr;
263 if( FcPatternGetString( font, FC_FILE, 0, &file ) == FcResultMatch )
265 aFontFile = wxString::FromUTF8( (
char*) file );
269 FcChar8* family =
nullptr;
270 FcChar8* style =
nullptr;
274 std::unordered_map<std::string, std::string> famStrings;
279 if( FcPatternGetString( font, FC_FAMILY, 0, &family ) == FcResultMatch )
281 FcPatternGetInteger( font, FC_INDEX, 0, &aFaceIndex );
283 fontName = wxString::FromUTF8( (
char*) family );
285 if( FcPatternGetString( font, FC_STYLE, 0, &style ) == FcResultMatch )
287 styleStr = wxString::FromUTF8( (
char*) style );
289 if( !styleStr.IsEmpty() )
291 styleStr.Replace(
' ',
':' );
292 fontName +=
':' + styleStr;
296 bool has_bold =
false;
297 bool has_ital =
false;
298 wxString lower_style = styleStr.Lower();
300 if( lower_style.Contains( wxS(
"thin" ) )
301 || lower_style.Contains( wxS(
"light" ) )
302 || lower_style.Contains( wxS(
"regular" ) )
303 || lower_style.Contains( wxS(
"roman" ) )
304 || lower_style.Contains( wxS(
"book" ) ) )
308 else if( lower_style.Contains( wxS(
"medium" ) )
309 || lower_style.Contains( wxS(
"semibold" ) )
310 || lower_style.Contains( wxS(
"demibold" ) ) )
314 else if( lower_style.Contains( wxS(
"bold" ) )
315 || lower_style.Contains( wxS(
"heavy" ) )
316 || lower_style.Contains( wxS(
"black" ) )
317 || lower_style.Contains( wxS(
"thick" ) )
318 || lower_style.Contains( wxS(
"dark" ) ) )
323 if( lower_style.Contains( wxS(
"italic" ) )
324 || lower_style.Contains( wxS(
"oblique" ) )
325 || lower_style.Contains( wxS(
"slant" ) ) )
330 for(
auto const& [key, val] : famStrings )
333 searchFont = wxString::FromUTF8( (
char*) val.data() );
335 if( searchFont.Lower().StartsWith( aFontName.Lower() ) )
337 familyMatched =
true;
339 if( ( aBold != has_bold ) || ( aItalic != has_ital ) )
349 if( ( aBold && !has_bold ) && ( aItalic && !has_ital ) )
351 else if( aBold && !has_bold )
353 else if( aItalic && !has_ital )
358 FcPatternDestroy( font );
364 s_reporter->Report( wxString::Format(
_(
"Error loading font '%s'." ), qualifiedFontName ) );
368 fontName.Replace(
':',
' ' );
372 if( fontName.CmpNoCase( qualifiedFontName ) == 0 )
379 s_reporter->Report( wxString::Format(
_(
"Font '%s' not found; substituting '%s'." ),
385 FcPatternDestroy( pat );
391 const std::vector<wxString>* aEmbeddedFiles,
bool aForce )
399 FcConfig*
config = FcConfigGetCurrent();
403 for(
const wxString& file : *aEmbeddedFiles )
404 FcConfigAppFontAddFile(
config, (
const FcChar8*) file.c_str().AsChar() );
407 FcPattern* pat = FcPatternCreate();
408 FcObjectSet* os = FcObjectSetBuild( FC_FAMILY, FC_FAMILYLANG, FC_STYLE, FC_LANG, FC_FILE, FC_OUTLINE,
nullptr );
409 FcFontSet* fs = FcFontList(
config, pat, os );
411 for(
int i = 0; fs && i < fs->nfont; ++i )
413 FcPattern* font = fs->fonts[i];
419 if( FcPatternGetString( font, FC_FILE, 0, &file ) == FcResultMatch
420 && FcPatternGetString( font, FC_STYLE, 0, &style ) == FcResultMatch
421 && FcPatternGetLangSet( font, FC_LANG, 0, &langSet ) == FcResultMatch
422 && FcPatternGetBool( font, FC_OUTLINE, 0, &outline ) == FcResultMatch )
438 static std::map<wxString, bool> availableLanguages;
440 FcStrSet* langStrSet = FcLangSetGetLangs( langSet );
441 FcStrList* langStrList = FcStrListCreate( langStrSet );
442 FcChar8* langStr = FcStrListNext( langStrList );
443 bool langSupported =
false;
448 langSupported =
true;
450 else while( langStr )
452 wxString langWxStr(
reinterpret_cast<char *
>( langStr ) );
454 if( availableLanguages.find( langWxStr ) == availableLanguages.end() )
456 const wxLanguageInfo* langInfo = wxLocale::FindLanguageInfo( langWxStr );
457 bool available = langInfo && wxLocale::IsAvailable( langInfo->Language );
459 availableLanguages[ langWxStr ] = available;
462 if( availableLanguages[ langWxStr ] )
464 langSupported =
true;
469 wxLogTrace(
traceFonts, wxS(
"Font '%s' language '%s' not supported by OS." ),
470 theFamily, langWxStr );
473 langStr = FcStrListNext( langStrList );
476 FcStrListDone( langStrList );
477 FcStrSetDestroy( langStrSet );
483 std::string theFile(
reinterpret_cast<char *
>( file ) );
484 std::string theStyle(
reinterpret_cast<char *
>( style ) );
485 FONTINFO fontInfo( std::move( theFile ), std::move( theStyle ), theFamily );
487 if( theFamily.length() > 0 && theFamily.front() ==
'.' )
490 std::map<std::string, FONTINFO>::iterator it =
m_fontInfoCache.find( theFamily );
495 it->second.Children().push_back( fontInfo );
500 FcFontSetDestroy( fs );
505 for(
const std::pair<const std::string, FONTINFO>& entry :
m_fontInfoCache )
506 aFonts.push_back( entry.second.Family() );