]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: fontmap.h | |
e54c96f1 | 3 | // Purpose: interface of wxFontMapper |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
8 | /** | |
9 | @class wxFontMapper | |
7c913512 | 10 | |
23324ae1 FM |
11 | wxFontMapper manages user-definable correspondence between logical font |
12 | names and the fonts present on the machine. | |
7c913512 | 13 | |
23324ae1 FM |
14 | The default implementations of all functions will ask the user if they are |
15 | not capable of finding the answer themselves and store the answer in a | |
16 | config file (configurable via SetConfigXXX functions). This behaviour may | |
17 | be disabled by giving the value of @false to "interactive" parameter. | |
7c913512 | 18 | |
23324ae1 FM |
19 | However, the functions will always consult the config file to allow the |
20 | user-defined values override the default logic and there is no way to | |
21 | disable this - which shouldn't be ever needed because if "interactive" was | |
22 | never @true, the config file is never created anyhow. | |
7c913512 | 23 | |
23324ae1 | 24 | In case everything else fails (i.e. there is no record in config file |
7c913512 | 25 | and "interactive" is @false or user denied to choose any replacement), |
674d80a7 FM |
26 | the class queries wxEncodingConverter for "equivalent" encodings |
27 | (e.g. iso8859-2 and cp1250) and tries them. | |
28 | ||
29 | ||
30 | @section fontmapper_mbconv Using wxFontMapper in conjunction with wxMBConv classes | |
31 | ||
32 | If you need to display text in encoding which is not available at host | |
33 | system (see wxFontMapper::IsEncodingAvailable), you may use these two | |
34 | classes to find font in some similar encoding (see wxFontMapper::GetAltForEncoding) | |
35 | and convert the text to this encoding (wxMBConv classes). | |
36 | Following code snippet demonstrates it: | |
37 | ||
38 | @code | |
39 | if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename)) | |
40 | { | |
41 | wxFontEncoding alternative; | |
42 | if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative, | |
43 | facename, false)) | |
44 | { | |
45 | wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc)); | |
46 | wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative)); | |
47 | text = wxString(text.mb_str(convFrom), convTo); | |
48 | } | |
49 | else | |
50 | ...failure (or we may try iso8859-1/7bit ASCII)... | |
51 | } | |
52 | ...display text... | |
53 | @endcode | |
7c913512 | 54 | |
23324ae1 | 55 | @library{wxcore} |
3c99e2fd | 56 | @category{cfg} |
7c913512 | 57 | |
3c99e2fd | 58 | @see wxEncodingConverter, @ref overview_nonenglish |
23324ae1 | 59 | */ |
7c913512 | 60 | class wxFontMapper |
23324ae1 FM |
61 | { |
62 | public: | |
63 | /** | |
64 | Default ctor. | |
674d80a7 FM |
65 | |
66 | @note | |
67 | The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get(). | |
23324ae1 FM |
68 | */ |
69 | wxFontMapper(); | |
70 | ||
71 | /** | |
674d80a7 | 72 | Virtual dtor. |
23324ae1 | 73 | */ |
674d80a7 | 74 | virtual ~wxFontMapper(); |
23324ae1 FM |
75 | |
76 | /** | |
77 | Returns the encoding for the given charset (in the form of RFC 2046) or | |
78 | @c wxFONTENCODING_SYSTEM if couldn't decode it. | |
674d80a7 | 79 | |
4cc4bfaf | 80 | Be careful when using this function with @a interactive set to @true |
23324ae1 FM |
81 | (default value) as the function then may show a dialog box to the user which |
82 | may lead to unexpected reentrancies and may also take a significantly longer | |
83 | time than a simple function call. For these reasons, it is almost always a bad | |
84 | idea to call this function from the event handlers for repeatedly generated | |
85 | events such as @c EVT_PAINT. | |
86 | */ | |
fadc2df6 FM |
87 | virtual wxFontEncoding CharsetToEncoding(const wxString& charset, |
88 | bool interactive = true); | |
23324ae1 FM |
89 | |
90 | /** | |
674d80a7 | 91 | Get the current font mapper object. If there is no current object, creates one. |
3c4f71cc | 92 | |
4cc4bfaf | 93 | @see Set() |
23324ae1 | 94 | */ |
4cc4bfaf | 95 | static wxFontMapper* Get(); |
23324ae1 FM |
96 | |
97 | /** | |
674d80a7 FM |
98 | Returns the array of all possible names for the given encoding. |
99 | ||
100 | The array is @NULL-terminated. IF it isn't empty, the first name in it is | |
101 | the canonical encoding name, i.e. the same string as returned by | |
23324ae1 FM |
102 | GetEncodingName(). |
103 | */ | |
104 | static const wxChar** GetAllEncodingNames(wxFontEncoding encoding); | |
105 | ||
106 | //@{ | |
107 | /** | |
108 | Find an alternative for the given encoding (which is supposed to not be | |
109 | available on this system). If successful, return @true and fill info | |
110 | structure with the parameters required to create the font, otherwise | |
111 | return @false. | |
674d80a7 | 112 | |
23324ae1 FM |
113 | The first form is for wxWidgets' internal use while the second one |
114 | is better suitable for general use -- it returns wxFontEncoding which | |
115 | can consequently be passed to wxFont constructor. | |
116 | */ | |
117 | bool GetAltForEncoding(wxFontEncoding encoding, | |
118 | wxNativeEncodingInfo* info, | |
119 | const wxString& facename = wxEmptyString, | |
4cc4bfaf | 120 | bool interactive = true); |
7c913512 FM |
121 | bool GetAltForEncoding(wxFontEncoding encoding, |
122 | wxFontEncoding* alt_encoding, | |
123 | const wxString& facename = wxEmptyString, | |
4cc4bfaf | 124 | bool interactive = true); |
23324ae1 FM |
125 | //@} |
126 | ||
127 | /** | |
674d80a7 FM |
128 | Returns the @e n-th supported encoding. |
129 | ||
130 | Together with GetSupportedEncodingsCount() this method may be used | |
131 | to get all supported encodings. | |
23324ae1 FM |
132 | */ |
133 | static wxFontEncoding GetEncoding(size_t n); | |
134 | ||
135 | /** | |
136 | Return user-readable string describing the given encoding. | |
137 | */ | |
138 | static wxString GetEncodingDescription(wxFontEncoding encoding); | |
139 | ||
140 | /** | |
674d80a7 FM |
141 | Return the encoding corresponding to the given internal name. |
142 | ||
143 | This function is the inverse of GetEncodingName() and is intentionally | |
144 | less general than CharsetToEncoding(), i.e. it doesn't try to make any | |
145 | guesses nor ever asks the user. It is meant just as a way of restoring | |
146 | objects previously serialized using GetEncodingName(). | |
23324ae1 FM |
147 | */ |
148 | static wxFontEncoding GetEncodingFromName(const wxString& encoding); | |
149 | ||
150 | /** | |
7c913512 | 151 | Return internal string identifier for the encoding (see also |
674d80a7 | 152 | wxFontMapper::GetEncodingDescription). |
3c4f71cc | 153 | |
4cc4bfaf | 154 | @see GetEncodingFromName() |
23324ae1 FM |
155 | */ |
156 | static wxString GetEncodingName(wxFontEncoding encoding); | |
157 | ||
158 | /** | |
674d80a7 FM |
159 | Returns the number of the font encodings supported by this class. |
160 | Together with GetEncoding() this method may be used to get | |
23324ae1 FM |
161 | all supported encodings. |
162 | */ | |
163 | static size_t GetSupportedEncodingsCount(); | |
164 | ||
165 | /** | |
166 | Check whether given encoding is available in given face or not. | |
167 | If no facename is given, find @e any font in this encoding. | |
168 | */ | |
fadc2df6 FM |
169 | virtual bool IsEncodingAvailable(wxFontEncoding encoding, |
170 | const wxString& facename = wxEmptyString); | |
23324ae1 FM |
171 | |
172 | /** | |
173 | Set the current font mapper object and return previous one (may be @NULL). | |
174 | This method is only useful if you want to plug-in an alternative font mapper | |
175 | into wxWidgets. | |
3c4f71cc | 176 | |
4cc4bfaf | 177 | @see Get() |
23324ae1 | 178 | */ |
4cc4bfaf | 179 | static wxFontMapper* Set(wxFontMapper* mapper); |
23324ae1 | 180 | |
23324ae1 FM |
181 | /** |
182 | Set the root config path to use (should be an absolute path). | |
183 | */ | |
184 | void SetConfigPath(const wxString& prefix); | |
185 | ||
186 | /** | |
187 | The parent window for modal dialogs. | |
188 | */ | |
189 | void SetDialogParent(wxWindow* parent); | |
190 | ||
191 | /** | |
192 | The title for the dialogs (note that default is quite reasonable). | |
193 | */ | |
194 | void SetDialogTitle(const wxString& title); | |
195 | }; | |
e54c96f1 | 196 |