]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/fontmap.h
358273c6487314f8c37c6a9fa7be9709bcb704aa
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFontMapper
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 wxFontMapper manages user-definable correspondence between logical font
13 names and the fonts present on the machine.
15 The default implementations of all functions will ask the user if they are
16 not capable of finding the answer themselves and store the answer in a
17 config file (configurable via SetConfigXXX functions). This behaviour may
18 be disabled by giving the value of @false to "interactive" parameter.
20 However, the functions will always consult the config file to allow the
21 user-defined values override the default logic and there is no way to
22 disable this - which shouldn't be ever needed because if "interactive" was
23 never @true, the config file is never created anyhow.
25 In case everything else fails (i.e. there is no record in config file
26 and "interactive" is @false or user denied to choose any replacement),
27 the class queries wxEncodingConverter for "equivalent" encodings
28 (e.g. iso8859-2 and cp1250) and tries them.
31 @section fontmapper_mbconv Using wxFontMapper in conjunction with wxMBConv classes
33 If you need to display text in encoding which is not available at host
34 system (see wxFontMapper::IsEncodingAvailable), you may use these two
35 classes to find font in some similar encoding (see wxFontMapper::GetAltForEncoding)
36 and convert the text to this encoding (wxMBConv classes).
37 Following code snippet demonstrates it:
40 if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
42 wxFontEncoding alternative;
43 if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
46 wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc));
47 wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative));
48 text = wxString(text.mb_str(convFrom), convTo);
51 ...failure (or we may try iso8859-1/7bit ASCII)...
59 @see wxEncodingConverter, @ref overview_nonenglish
68 The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get().
75 virtual ~wxFontMapper();
78 Returns the encoding for the given charset (in the form of RFC 2046) or
79 @c wxFONTENCODING_SYSTEM if couldn't decode it.
81 Be careful when using this function with @a interactive set to @true
82 (default value) as the function then may show a dialog box to the user which
83 may lead to unexpected reentrancies and may also take a significantly longer
84 time than a simple function call. For these reasons, it is almost always a bad
85 idea to call this function from the event handlers for repeatedly generated
86 events such as @c EVT_PAINT.
88 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
89 bool interactive
= true);
92 Get the current font mapper object. If there is no current object, creates one.
96 static wxFontMapper
* Get();
99 Returns the array of all possible names for the given encoding.
101 The array is @NULL-terminated. IF it isn't empty, the first name in it is
102 the canonical encoding name, i.e. the same string as returned by
105 static const wxChar
** GetAllEncodingNames(wxFontEncoding encoding
);
109 Find an alternative for the given encoding (which is supposed to not be
110 available on this system). If successful, return @true and fill info
111 structure with the parameters required to create the font, otherwise
114 The first form is for wxWidgets' internal use while the second one
115 is better suitable for general use -- it returns wxFontEncoding which
116 can consequently be passed to wxFont constructor.
118 bool GetAltForEncoding(wxFontEncoding encoding
,
119 wxNativeEncodingInfo
* info
,
120 const wxString
& facename
= wxEmptyString
,
121 bool interactive
= true);
122 bool GetAltForEncoding(wxFontEncoding encoding
,
123 wxFontEncoding
* alt_encoding
,
124 const wxString
& facename
= wxEmptyString
,
125 bool interactive
= true);
129 Returns the @e n-th supported encoding.
131 Together with GetSupportedEncodingsCount() this method may be used
132 to get all supported encodings.
134 static wxFontEncoding
GetEncoding(size_t n
);
137 Return user-readable string describing the given encoding.
139 static wxString
GetEncodingDescription(wxFontEncoding encoding
);
142 Return the encoding corresponding to the given internal name.
144 This function is the inverse of GetEncodingName() and is intentionally
145 less general than CharsetToEncoding(), i.e. it doesn't try to make any
146 guesses nor ever asks the user. It is meant just as a way of restoring
147 objects previously serialized using GetEncodingName().
149 static wxFontEncoding
GetEncodingFromName(const wxString
& encoding
);
152 Return internal string identifier for the encoding (see also
153 wxFontMapper::GetEncodingDescription).
155 @see GetEncodingFromName()
157 static wxString
GetEncodingName(wxFontEncoding encoding
);
160 Returns the number of the font encodings supported by this class.
161 Together with GetEncoding() this method may be used to get
162 all supported encodings.
164 static size_t GetSupportedEncodingsCount();
167 Check whether given encoding is available in given face or not.
168 If no facename is given, find @e any font in this encoding.
170 virtual bool IsEncodingAvailable(wxFontEncoding encoding
,
171 const wxString
& facename
= wxEmptyString
);
174 Set the current font mapper object and return previous one (may be @NULL).
175 This method is only useful if you want to plug-in an alternative font mapper
180 static wxFontMapper
* Set(wxFontMapper
* mapper
);
183 Set the root config path to use (should be an absolute path).
185 void SetConfigPath(const wxString
& prefix
);
188 The parent window for modal dialogs.
190 void SetDialogParent(wxWindow
* parent
);
193 The title for the dialogs (note that default is quite reasonable).
195 void SetDialogTitle(const wxString
& title
);