]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: fontmap.h | |
e54c96f1 | 3 | // Purpose: interface of wxFontMapper |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxFontMapper | |
7c913512 | 11 | |
23324ae1 FM |
12 | wxFontMapper manages user-definable correspondence between logical font |
13 | names and the fonts present on the machine. | |
7c913512 | 14 | |
23324ae1 FM |
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. | |
7c913512 | 19 | |
23324ae1 FM |
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. | |
7c913512 | 24 | |
23324ae1 | 25 | In case everything else fails (i.e. there is no record in config file |
7c913512 | 26 | and "interactive" is @false or user denied to choose any replacement), |
674d80a7 FM |
27 | the class queries wxEncodingConverter for "equivalent" encodings |
28 | (e.g. iso8859-2 and cp1250) and tries them. | |
29 | ||
30 | ||
31 | @section fontmapper_mbconv Using wxFontMapper in conjunction with wxMBConv classes | |
32 | ||
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: | |
38 | ||
39 | @code | |
40 | if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename)) | |
41 | { | |
42 | wxFontEncoding alternative; | |
43 | if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative, | |
44 | facename, false)) | |
45 | { | |
46 | wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc)); | |
47 | wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative)); | |
48 | text = wxString(text.mb_str(convFrom), convTo); | |
49 | } | |
50 | else | |
51 | ...failure (or we may try iso8859-1/7bit ASCII)... | |
52 | } | |
53 | ...display text... | |
54 | @endcode | |
7c913512 | 55 | |
23324ae1 | 56 | @library{wxcore} |
3c99e2fd | 57 | @category{cfg} |
7c913512 | 58 | |
3c99e2fd | 59 | @see wxEncodingConverter, @ref overview_nonenglish |
23324ae1 | 60 | */ |
7c913512 | 61 | class wxFontMapper |
23324ae1 FM |
62 | { |
63 | public: | |
64 | /** | |
65 | Default ctor. | |
674d80a7 FM |
66 | |
67 | @note | |
68 | The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get(). | |
23324ae1 FM |
69 | */ |
70 | wxFontMapper(); | |
71 | ||
72 | /** | |
674d80a7 | 73 | Virtual dtor. |
23324ae1 | 74 | */ |
674d80a7 | 75 | virtual ~wxFontMapper(); |
23324ae1 FM |
76 | |
77 | /** | |
78 | Returns the encoding for the given charset (in the form of RFC 2046) or | |
79 | @c wxFONTENCODING_SYSTEM if couldn't decode it. | |
674d80a7 | 80 | |
4cc4bfaf | 81 | Be careful when using this function with @a interactive set to @true |
23324ae1 FM |
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. | |
87 | */ | |
fadc2df6 FM |
88 | virtual wxFontEncoding CharsetToEncoding(const wxString& charset, |
89 | bool interactive = true); | |
23324ae1 FM |
90 | |
91 | /** | |
674d80a7 | 92 | Get the current font mapper object. If there is no current object, creates one. |
3c4f71cc | 93 | |
4cc4bfaf | 94 | @see Set() |
23324ae1 | 95 | */ |
4cc4bfaf | 96 | static wxFontMapper* Get(); |
23324ae1 FM |
97 | |
98 | /** | |
674d80a7 FM |
99 | Returns the array of all possible names for the given encoding. |
100 | ||
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 | |
23324ae1 FM |
103 | GetEncodingName(). |
104 | */ | |
105 | static const wxChar** GetAllEncodingNames(wxFontEncoding encoding); | |
106 | ||
107 | //@{ | |
108 | /** | |
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 | |
112 | return @false. | |
674d80a7 | 113 | |
23324ae1 FM |
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. | |
117 | */ | |
118 | bool GetAltForEncoding(wxFontEncoding encoding, | |
119 | wxNativeEncodingInfo* info, | |
120 | const wxString& facename = wxEmptyString, | |
4cc4bfaf | 121 | bool interactive = true); |
7c913512 FM |
122 | bool GetAltForEncoding(wxFontEncoding encoding, |
123 | wxFontEncoding* alt_encoding, | |
124 | const wxString& facename = wxEmptyString, | |
4cc4bfaf | 125 | bool interactive = true); |
23324ae1 FM |
126 | //@} |
127 | ||
128 | /** | |
674d80a7 FM |
129 | Returns the @e n-th supported encoding. |
130 | ||
131 | Together with GetSupportedEncodingsCount() this method may be used | |
132 | to get all supported encodings. | |
23324ae1 FM |
133 | */ |
134 | static wxFontEncoding GetEncoding(size_t n); | |
135 | ||
136 | /** | |
137 | Return user-readable string describing the given encoding. | |
138 | */ | |
139 | static wxString GetEncodingDescription(wxFontEncoding encoding); | |
140 | ||
141 | /** | |
674d80a7 FM |
142 | Return the encoding corresponding to the given internal name. |
143 | ||
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(). | |
23324ae1 FM |
148 | */ |
149 | static wxFontEncoding GetEncodingFromName(const wxString& encoding); | |
150 | ||
151 | /** | |
7c913512 | 152 | Return internal string identifier for the encoding (see also |
674d80a7 | 153 | wxFontMapper::GetEncodingDescription). |
3c4f71cc | 154 | |
4cc4bfaf | 155 | @see GetEncodingFromName() |
23324ae1 FM |
156 | */ |
157 | static wxString GetEncodingName(wxFontEncoding encoding); | |
158 | ||
159 | /** | |
674d80a7 FM |
160 | Returns the number of the font encodings supported by this class. |
161 | Together with GetEncoding() this method may be used to get | |
23324ae1 FM |
162 | all supported encodings. |
163 | */ | |
164 | static size_t GetSupportedEncodingsCount(); | |
165 | ||
166 | /** | |
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. | |
169 | */ | |
fadc2df6 FM |
170 | virtual bool IsEncodingAvailable(wxFontEncoding encoding, |
171 | const wxString& facename = wxEmptyString); | |
23324ae1 FM |
172 | |
173 | /** | |
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 | |
176 | into wxWidgets. | |
3c4f71cc | 177 | |
4cc4bfaf | 178 | @see Get() |
23324ae1 | 179 | */ |
4cc4bfaf | 180 | static wxFontMapper* Set(wxFontMapper* mapper); |
23324ae1 FM |
181 | |
182 | /** | |
183 | Set the config object to use (may be @NULL to use default). | |
7c913512 | 184 | By default, the global one (from wxConfigBase::Get() will be used) |
674d80a7 FM |
185 | and the default root path for the config settings is the string returned |
186 | by GetDefaultConfigPath(). | |
23324ae1 FM |
187 | */ |
188 | void SetConfig(wxConfigBase* config); | |
189 | ||
190 | /** | |
191 | Set the root config path to use (should be an absolute path). | |
192 | */ | |
193 | void SetConfigPath(const wxString& prefix); | |
194 | ||
195 | /** | |
196 | The parent window for modal dialogs. | |
197 | */ | |
198 | void SetDialogParent(wxWindow* parent); | |
199 | ||
200 | /** | |
201 | The title for the dialogs (note that default is quite reasonable). | |
202 | */ | |
203 | void SetDialogTitle(const wxString& title); | |
204 | }; | |
e54c96f1 | 205 |