wxRuby Documentation Home

Wx::FontMapper

FontMapper 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 EncodingConverter for “equivalent” encodings (e.g. iso8859-2 and cp1250) and tries them.

Using FontMapper in conjunction with MBConv classes

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

Following code snippet demonstrates it:

if (!FontMapper::Get()->IsEncodingAvailable(enc, facename))
{
   FontEncoding alternative;
   if (FontMapper::Get()->GetAltForEncoding(enc, &alternative,
                                              facename, false))
   {
       CSConv convFrom(FontMapper::Get()->GetEncodingName(enc));
       CSConv convTo(FontMapper::Get()->GetEncodingName(alternative));
       text = String(text.mb_str(convFrom), convTo);
   }
   else
       ...failure (or we may try iso8859-1/7bit ASCII)...
}
...display text...

Derived from

No base class

See also

EncodingConverter, Writing non-English applications

Methods

FontMapper.new

Note

The preferred way of creating a FontMapper instance is to call FontMapper#get.

destructor()

Virtual dtor for a base class.

FontMapper#charset_to_encoding

FontEncoding charset_to_encoding(String charset, 
                                   Boolean interactive = true)

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

Be careful when using this function with interactive set to (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.

FontMapper#get

FontMapper get()

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

See also

FontMapper#set

FontMapper#get_all_encoding_names

Char *get_all_encoding_names(FontEncoding encoding)

Returns the array of all possible names for the given encoding. The array is -terminated. IF it isn’t empty, the first name in it is the canonical encoding name, i.e. the same string as returned by get_encoding_name()().

FontMapper#get_alt_for_encoding

Boolean get_alt_for_encoding(FontEncoding encoding, 
                             NativeEncodingInfo info,  String facename = '', 
                             Boolean interactive = true)
Boolean get_alt_for_encoding(FontEncoding encoding, 
                             FontEncoding alt_encoding,  String facename = '', 
                             Boolean 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 Widgets’ internal use while the second one is better suitable for general use—it returns FontEncoding which can consequently be passed to Font constructor.

FontMapper#get_encoding

FontEncoding get_encoding(Integer n)

Returns the n-th supported encoding. Together with get_supported_encodings_count()() this method may be used to get all supported encodings.

FontMapper#get_encoding_description

String get_encoding_description(FontEncoding encoding)

Return user-readable string describing the given encoding.

FontMapper#get_encoding_from_name

FontEncoding get_encoding_from_name(String encoding)

Return the encoding corresponding to the given internal name. This function is the inverse of get_encoding_name and is intentionally less general than charset_to_encoding, 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 get_encoding_name.

FontMapper#get_encoding_name

String get_encoding_name(FontEncoding encoding)

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

See also

get_encoding_from_name

FontMapper#get_supported_encodings_count

Integer get_supported_encodings_count()

Returns the number of the font encodings supported by this class. Together with get_encoding this method may be used to get all supported encodings.

FontMapper#is_encoding_available

Boolean is_encoding_available(FontEncoding encoding, 
                              String facename = '')

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

FontMapper#set_dialog_parent

set_dialog_parent(Window parent)

The parent window for modal dialogs.

FontMapper#set_dialog_title

set_dialog_title(String title)

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

FontMapper#set

FontMapper set(FontMapper 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 Widgets.

See also

FontMapper#get

FontMapper#set_config

set_config(ConfigBase config)

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

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

FontMapper#set_config_path

set_config_path(String prefix)

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

[This page automatically generated from the Textile source at Fri Oct 31 16:06:42 +0000 2008]