KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fontconfig::FONTCONFIG Class Reference

#include <fontconfig.h>

Public Types

enum class  FF_RESULT {
  FF_OK , FF_ERROR , FF_SUBSTITUTE , FF_MISSING_BOLD ,
  FF_MISSING_ITAL , FF_MISSING_BOLD_ITAL
}
 

Public Member Functions

 FONTCONFIG ()
 
FF_RESULT FindFont (const wxString &aFontName, wxString &aFontFile, int &aFaceIndex, bool aBold, bool aItalic, const std::vector< wxString > *aEmbeddedFiles=nullptr)
 Given a fully-qualified font name ("Times:Bold:Italic") find the closest matching font and return its filepath in aFontFile.
 
void ListFonts (std::vector< std::string > &aFonts, const std::string &aDesiredLang, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForce=false)
 List the current available font families.
 

Static Public Member Functions

static wxString Version ()
 
static void SetReporter (REPORTER *aReporter)
 Set the reporter to use for reporting font substitution warnings.
 

Private Member Functions

bool isLanguageMatch (const wxString &aSearchLang, const wxString &aSupportedLang)
 Matches the two rfc 3306 language entries, used for when searching for matching family names.
 
void getAllFamilyStrings (FONTCONFIG_PAT &aPat, std::unordered_map< std::string, std::string > &aFamStringMap)
 Gets a list of all family name strings maped to lang.
 
std::string getFamilyStringByLang (FONTCONFIG_PAT &APat, const wxString &aDesiredLang)
 Gets a family name based on desired language.
 
std::string getFcString (FONTCONFIG_PAT &aPat, const char *aObj, int aIdx)
 Wrapper of FcPatternGetString to return a std::string.
 

Private Attributes

std::map< std::string, FONTINFOm_fontInfoCache
 
wxString m_fontCacheLastLang
 

Static Private Attributes

static REPORTERs_reporter = nullptr
 

Detailed Description

Definition at line 39 of file fontconfig.h.

Member Enumeration Documentation

◆ FF_RESULT

Enumerator
FF_OK 
FF_ERROR 
FF_SUBSTITUTE 
FF_MISSING_BOLD 
FF_MISSING_ITAL 
FF_MISSING_BOLD_ITAL 

Definition at line 46 of file fontconfig.h.

Constructor & Destructor Documentation

◆ FONTCONFIG()

FONTCONFIG::FONTCONFIG ( )

Definition at line 59 of file fontconfig.cpp.

Member Function Documentation

◆ FindFont()

FONTCONFIG::FF_RESULT FONTCONFIG::FindFont ( const wxString &  aFontName,
wxString &  aFontFile,
int &  aFaceIndex,
bool  aBold,
bool  aItalic,
const std::vector< wxString > *  aEmbeddedFiles = nullptr 
)

Given a fully-qualified font name ("Times:Bold:Italic") find the closest matching font and return its filepath in aFontFile.

A return value of false indicates a serious error in the font system.

Definition at line 200 of file fontconfig.cpp.

References _, config, FF_ERROR, FF_MISSING_BOLD, FF_MISSING_BOLD_ITAL, FF_MISSING_ITAL, FF_OK, FF_SUBSTITUTE, g_fcInitSuccess, getAllFamilyStrings(), REPORTER::Report(), and s_reporter.

◆ getAllFamilyStrings()

void FONTCONFIG::getAllFamilyStrings ( FONTCONFIG_PAT aPat,
std::unordered_map< std::string, std::string > &  aFamStringMap 
)
private

Gets a list of all family name strings maped to lang.

Parameters
aPatreference to FcPattern container
aFamStringMapMap to be populated with key, value pairs representing lang to family name

Definition at line 154 of file fontconfig.cpp.

References getFcString().

Referenced by FindFont(), and getFamilyStringByLang().

◆ getFamilyStringByLang()

std::string FONTCONFIG::getFamilyStringByLang ( FONTCONFIG_PAT APat,
const wxString &  aDesiredLang 
)
private

Gets a family name based on desired language.

This will fallback to english or first available string if no language matching string is found.

Parameters
aPatreference to FcPattern container
aDesiredLangLanguage to research for (RFC3066 format)

Definition at line 177 of file fontconfig.cpp.

References From_UTF8(), getAllFamilyStrings(), and isLanguageMatch().

Referenced by ListFonts().

◆ getFcString()

std::string FONTCONFIG::getFcString ( FONTCONFIG_PAT aPat,
const char *  aObj,
int  aIdx 
)
private

Wrapper of FcPatternGetString to return a std::string.

Parameters
aPatreference to FcPattern container
aObjThe fontconfig property object like FC_FAMILY, FC_STYLE, etc
aIdxThe ith value associated with the property object

Definition at line 142 of file fontconfig.cpp.

References fontconfig::FONTCONFIG_PAT::pat, and res.

Referenced by getAllFamilyStrings().

◆ isLanguageMatch()

bool FONTCONFIG::isLanguageMatch ( const wxString &  aSearchLang,
const wxString &  aSupportedLang 
)
private

Matches the two rfc 3306 language entries, used for when searching for matching family names.

The overall logic is simple, either both language tags matched exactly or one tag is "single" level that the other language tag contains. There's nuances to language tags beyond this but font tags will most likely never be more complex than say "zh-CN" or single tag "en".

Parameters
aSearchLangthe language being searched for
aSupportedLangthe language being offered

Definition at line 112 of file fontconfig.cpp.

References wxStringSplit().

Referenced by getFamilyStringByLang().

◆ ListFonts()

void FONTCONFIG::ListFonts ( std::vector< std::string > &  aFonts,
const std::string &  aDesiredLang,
const std::vector< wxString > *  aEmbeddedFiles = nullptr,
bool  aForce = false 
)

List the current available font families.

Parameters
aDesiredLangThe desired language of font name to report back if available, otherwise it will fallback
aEmbeddedFilesA list of embedded to use for searching fonts, if nullptr, this is not used
aForceIf true, force rebuilding the font cache

Definition at line 371 of file fontconfig.cpp.

References config, From_UTF8(), g_fcInitSuccess, getFamilyStringByLang(), m_fontCacheLastLang, m_fontInfoCache, and traceFonts.

◆ SetReporter()

◆ Version()

wxString FONTCONFIG::Version ( )
static

Definition at line 53 of file fontconfig.cpp.

Referenced by KIFONT::VERSION_INFO::FontConfig().

Member Data Documentation

◆ m_fontCacheLastLang

wxString fontconfig::FONTCONFIG::m_fontCacheLastLang
private

Definition at line 84 of file fontconfig.h.

Referenced by ListFonts().

◆ m_fontInfoCache

std::map<std::string, FONTINFO> fontconfig::FONTCONFIG::m_fontInfoCache
private

Definition at line 83 of file fontconfig.h.

Referenced by ListFonts().

◆ s_reporter

REPORTER * FONTCONFIG::s_reporter = nullptr
staticprivate

Definition at line 85 of file fontconfig.h.

Referenced by FindFont().


The documentation for this class was generated from the following files: