]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/fontmap.h
move TestTextInputStream() function in CppUnit's TextStreamTestCase class
[wxWidgets.git] / interface / wx / fontmap.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: fontmap.h
3 // Purpose: interface of wxFontMapper
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxFontMapper
11
12 wxFontMapper manages user-definable correspondence between logical font
13 names and the fonts present on the machine.
14
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.
19
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.
24
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.
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
55
56 @library{wxcore}
57 @category{cfg}
58
59 @see wxEncodingConverter, @ref overview_nonenglish
60 */
61 class wxFontMapper
62 {
63 public:
64 /**
65 Default ctor.
66
67 @note
68 The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get().
69 */
70 wxFontMapper();
71
72 /**
73 Virtual dtor.
74 */
75 virtual ~wxFontMapper();
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.
80
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.
87 */
88 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
89 bool interactive = true);
90
91 /**
92 Get the current font mapper object. If there is no current object, creates one.
93
94 @see Set()
95 */
96 static wxFontMapper* Get();
97
98 /**
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
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.
113
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,
121 bool interactive = true);
122 bool GetAltForEncoding(wxFontEncoding encoding,
123 wxFontEncoding* alt_encoding,
124 const wxString& facename = wxEmptyString,
125 bool interactive = true);
126 //@}
127
128 /**
129 Returns the @e n-th supported encoding.
130
131 Together with GetSupportedEncodingsCount() this method may be used
132 to get all supported encodings.
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 /**
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().
148 */
149 static wxFontEncoding GetEncodingFromName(const wxString& encoding);
150
151 /**
152 Return internal string identifier for the encoding (see also
153 wxFontMapper::GetEncodingDescription).
154
155 @see GetEncodingFromName()
156 */
157 static wxString GetEncodingName(wxFontEncoding encoding);
158
159 /**
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.
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 */
170 virtual bool IsEncodingAvailable(wxFontEncoding encoding,
171 const wxString& facename = wxEmptyString);
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.
177
178 @see Get()
179 */
180 static wxFontMapper* Set(wxFontMapper* mapper);
181
182 /**
183 Set the config object to use (may be @NULL to use default).
184 By default, the global one (from wxConfigBase::Get() will be used)
185 and the default root path for the config settings is the string returned
186 by GetDefaultConfigPath().
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 };
205