| Version: 3.2.5

Public Member Functions | Static Public Member Functions | List of all members
wxFontMapper Class Reference
Class List by Category » Application and System configuration

`#include <wx/fontmap.h>`

## Detailed Description

wxFontMapper manages user-definable correspondence between logical font names and the fonts present on the machine.

The default implementations of all functions will ask the user if they are not capable of finding the answer themselves and store the answer in a config file (configurable via SetConfigXXX functions). This behaviour may be disabled by giving the value of false to "interactive" parameter.

However, the functions will always consult the config file to allow the user-defined values override the default logic and there is no way to disable this - which shouldn't be ever needed because if "interactive" was never true, the config file is never created anyhow.

In case everything else fails (i.e. there is no record in config file and "interactive" is false or user denied to choose any replacement), the class queries wxEncodingConverter for "equivalent" encodings (e.g. iso8859-2 and cp1250) and tries them.

# Using wxFontMapper in conjunction with wxMBConv classes

If you need to display text in encoding which is not available at host system (see wxFontMapper::IsEncodingAvailable), you may use these two classes to find font in some similar encoding (see wxFontMapper::GetAltForEncoding) and convert the text to this encoding (wxMBConv classes). Following code snippet demonstrates it:

if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
{
wxFontEncoding alternative;
if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
facename, false))
{
wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc));
wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative));
text = wxString(text.mb_str(convFrom), convTo);
}
else
...failure (or we may try iso8859-1/7bit ASCII)...
}
...display text...
wxCSConv
This class converts between any character set supported by the system and Unicode.
Definition: strconv.h:480
wxFontMapper::Get
static wxFontMapper * Get()
Get the current font mapper object.
wxFontMapper::GetEncodingName
static wxString GetEncodingName(wxFontEncoding encoding)
Return internal string identifier for the encoding (see also wxFontMapper::GetEncodingDescription).
wxFontMapper::IsEncodingAvailable
virtual bool IsEncodingAvailable(wxFontEncoding encoding, const wxString &facename=wxEmptyString)
Check whether given encoding is available in given face or not.
wxFontMapper::GetAltForEncoding
bool GetAltForEncoding(wxFontEncoding encoding, wxNativeEncodingInfo *info, const wxString &facename=wxEmptyString, bool interactive=true)
Find an alternative for the given encoding (which is supposed to not be available on this system).
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
wxFontEncoding
wxFontEncoding
Font encodings.
Definition: font.h:153

##

Library: wxCore
Category: Application and System configuration

See also
  wxEncodingConverter, Writing Non-English Applications

## Public Member Functions

| wxFontMapper ()
| Default ctor. More...
virtual | ~wxFontMapper ()
| Virtual dtor. More...
virtual wxFontEncoding | CharsetToEncoding (const wxString &charset, bool interactive=true)
| Returns the encoding for the given charset (in the form of RFC 2046) or `wxFONTENCODING_SYSTEM` if couldn't decode it. More...
virtual bool | IsEncodingAvailable (wxFontEncoding encoding, const wxString &facename=wxEmptyString)
| Check whether given encoding is available in given face or not. More...
void | SetConfigPath (const wxString &prefix)
| Set the root config path to use (should be an absolute path). More...
void | SetDialogParent (wxWindow *parent)
| The parent window for modal dialogs. More...
void | SetDialogTitle (const wxString &title)
| The title for the dialogs (note that default is quite reasonable). More...
bool | GetAltForEncoding (wxFontEncoding encoding, wxNativeEncodingInfo *info, const wxString &facename=wxEmptyString, bool interactive=true)
| Find an alternative for the given encoding (which is supposed to not be available on this system). More...
bool | GetAltForEncoding (wxFontEncoding encoding, wxFontEncoding *alt_encoding, const wxString &facename=wxEmptyString, bool interactive=true)
| Find an alternative for the given encoding (which is supposed to not be available on this system). More...

## Static Public Member Functions

static wxFontMapper * | Get ()
| Get the current font mapper object. More...
static const wxChar ** | GetAllEncodingNames (wxFontEncoding encoding)
| Returns the array of all possible names for the given encoding. More...
static wxFontEncoding | GetEncoding (size_t n)
| Returns the n-th supported encoding. More...
static wxString | GetEncodingDescription (wxFontEncoding encoding)
| Return user-readable string describing the given encoding. More...
static wxFontEncoding | GetEncodingFromName (const wxString &encoding)
| Return the encoding corresponding to the given internal name. More...
static wxString | GetEncodingName (wxFontEncoding encoding)
| Return internal string identifier for the encoding (see also wxFontMapper::GetEncodingDescription). More...
static size_t | GetSupportedEncodingsCount ()
| Returns the number of the font encodings supported by this class. More...
static wxFontMapper * | Set (wxFontMapper *mapper)
| Set the current font mapper object and return previous one (may be NULL). More...

## Constructor & Destructor Documentation

## ◆ wxFontMapper()

wxFontMapper::wxFontMapper | ( |  | ) |

Default ctor.

Note
  The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get().

## ◆ ~wxFontMapper()

virtual wxFontMapper::~wxFontMapper | ( |  | ) |

virtual

Virtual dtor.

## Member Function Documentation

## ◆ CharsetToEncoding()

virtual wxFontEncoding wxFontMapper::CharsetToEncoding | ( | const wxString & | charset,
|  | bool | interactive = `true`
| ) |  |

virtual

Returns the encoding for the given charset (in the form of RFC 2046) or `wxFONTENCODING_SYSTEM` if couldn't decode it.

Be careful when using this function with interactive set to true (default value) as the function then may show a dialog box to the user which may lead to unexpected reentrancies and may also take a significantly longer time than a simple function call. For these reasons, it is almost always a bad idea to call this function from the event handlers for repeatedly generated events such as `EVT_PAINT`.

## ◆ Get()

static wxFontMapper* wxFontMapper::Get | ( |  | ) |

static

Get the current font mapper object.

If there is no current object, creates one.

See also
  Set()

## ◆ GetAllEncodingNames()

static const wxChar** wxFontMapper::GetAllEncodingNames | ( | wxFontEncoding | encoding | ) |

static

Returns the array of all possible names for the given encoding.

The array is NULL-terminated. IF it isn't empty, the first name in it is the canonical encoding name, i.e. the same string as returned by GetEncodingName().

## ◆ GetAltForEncoding() [1/2]

bool wxFontMapper::GetAltForEncoding | ( | wxFontEncoding | encoding,
|  | wxFontEncoding * | alt_encoding,
|  | const wxString & | facename = `wxEmptyString`,
|  | bool | interactive = `true`
| ) |  |

Find an alternative for the given encoding (which is supposed to not be available on this system).

If successful, return true and fill info structure with the parameters required to create the font, otherwise return false.

The first form is for wxWidgets' internal use while the second one is better suitable for general use – it returns wxFontEncoding which can consequently be passed to wxFont constructor.

## ◆ GetAltForEncoding() [2/2]

bool wxFontMapper::GetAltForEncoding | ( | wxFontEncoding | encoding,
|  | wxNativeEncodingInfo * | info,
|  | const wxString & | facename = `wxEmptyString`,
|  | bool | interactive = `true`
| ) |  |

Find an alternative for the given encoding (which is supposed to not be available on this system).

If successful, return true and fill info structure with the parameters required to create the font, otherwise return false.

The first form is for wxWidgets' internal use while the second one is better suitable for general use – it returns wxFontEncoding which can consequently be passed to wxFont constructor.

## ◆ GetEncoding()

static wxFontEncoding wxFontMapper::GetEncoding | ( | size_t | n | ) |

static

Returns the n-th supported encoding.

Together with GetSupportedEncodingsCount() this method may be used to get all supported encodings.

## ◆ GetEncodingDescription()

static wxString wxFontMapper::GetEncodingDescription | ( | wxFontEncoding | encoding | ) |

static

Return user-readable string describing the given encoding.

## ◆ GetEncodingFromName()

static wxFontEncoding wxFontMapper::GetEncodingFromName | ( | const wxString & | encoding | ) |

static

Return the encoding corresponding to the given internal name.

This function is the inverse of GetEncodingName() and is intentionally less general than CharsetToEncoding(), i.e. it doesn't try to make any guesses nor ever asks the user. It is meant just as a way of restoring objects previously serialized using GetEncodingName().

## ◆ GetEncodingName()

static wxString wxFontMapper::GetEncodingName | ( | wxFontEncoding | encoding | ) |

static

Return internal string identifier for the encoding (see also wxFontMapper::GetEncodingDescription).

See also
  GetEncodingFromName()

## ◆ GetSupportedEncodingsCount()

static size_t wxFontMapper::GetSupportedEncodingsCount | ( |  | ) |

static

Returns the number of the font encodings supported by this class.

Together with GetEncoding() this method may be used to get all supported encodings.

## ◆ IsEncodingAvailable()

virtual bool wxFontMapper::IsEncodingAvailable | ( | wxFontEncoding | encoding,
|  | const wxString & | facename = `wxEmptyString`
| ) |  |

virtual

Check whether given encoding is available in given face or not.

If no facename is given, find any font in this encoding.

## ◆ Set()

static wxFontMapper* wxFontMapper::Set | ( | wxFontMapper * | mapper | ) |

static

Set the current font mapper object and return previous one (may be NULL).

This method is only useful if you want to plug-in an alternative font mapper into wxWidgets.

See also
  Get()

## ◆ SetConfigPath()

void wxFontMapper::SetConfigPath | ( | const wxString & | prefix | ) |

Set the root config path to use (should be an absolute path).

## ◆ SetDialogParent()

void wxFontMapper::SetDialogParent | ( | wxWindow * | parent | ) |

The parent window for modal dialogs.

## ◆ SetDialogTitle()

void wxFontMapper::SetDialogTitle | ( | const wxString & | title | ) |

The title for the dialogs (note that default is quite reasonable).