Contents Up Previous Next 原文へのリンク

wxFontMapper

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 wxEncodingConverter

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

Following code snippet demonstrates it:

if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
{
   wxFontEncoding alternative;
   if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
                                              facename, FALSE))
   {
       wxEncodingConverter encconv;
       if (!encconv.Init(enc, alternative))
           ...failure...
       else
           text = encconv.Convert(text);
   }
   else
       ...failure (or we may try iso8859-1/7bit ASCII)...
}
...display text...
Derived from

No base class

Include files

<wx/fontmap.h>

See also

wxEncodingConverter, Writing non-English applications

Members

wxFontMapper::wxFontMapper
wxFontMapper::~wxFontMapper
wxFontMapper::Get
wxFontMapper::GetAltForEncoding
wxFontMapper::IsEncodingAvailable
wxFontMapper::CharsetToEncoding
wxFontMapper::GetEncodingName
wxFontMapper::GetEncodingDescription
wxFontMapper::SetDialogParent
wxFontMapper::SetDialogTitle
wxFontMapper::Set
wxFontMapper::SetConfig
wxFontMapper::SetConfigPath


wxFontMapper::wxFontMapper

wxFontMapper()

Default ctor.

Note

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


wxFontMapper::~wxFontMapper

~wxFontMapper()

Virtual dtor for a base class.


wxFontMapper::Get

static wxFontMapper * Get()

Get the current font mapper object. If there is no current object, creates one.

See also

wxFontMapper::Set


wxFontMapper::GetAltForEncoding

bool GetAltForEncoding(wxFontEncoding encoding, wxNativeEncodingInfo* info, const wxString& facename = wxEmptyString, bool interactive = TRUE)

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). 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.


wxFontMapper::IsEncodingAvailable

bool IsEncodingAvailable(wxFontEncoding encoding, const wxString& facename = wxEmptyString)

Check whether given encoding is available in given face or not. If no facename is given, find any font in this encoding.


wxFontMapper::CharsetToEncoding

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.


wxFontMapper::GetEncodingName

static wxString GetEncodingName(wxFontEncoding encoding)

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


wxFontMapper::GetEncodingDescription

static wxString GetEncodingDescription(wxFontEncoding encoding)

Return user-readable string describing the given encoding.


wxFontMapper::SetDialogParent

void SetDialogParent(wxWindow* parent)

The parent window for modal dialogs.


wxFontMapper::SetDialogTitle

void SetDialogTitle(const wxString& title)

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


wxFontMapper::Set

static wxFontMapper * Set(wxFontMapper *mapper)

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

wxFontMapper::Get


wxFontMapper::SetConfig

void SetConfig(wxConfigBase* config)

Set the config object to use (may be NULL to use default).

By default, the global one (from wxConfigBase::Get() will be used) and the default root path for the config settings is the string returned by GetDefaultConfigPath().


wxFontMapper::SetConfigPath

void SetConfigPath(const wxString& prefix)

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