1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: fontmap.h 3 // Purpose: interface of wxFontMapper 4 // Author: wxWidgets team 5 // Licence: wxWindows licence 6 ///////////////////////////////////////////////////////////////////////////// 7 8 /** 9 @class wxFontMapper 10 11 wxFontMapper manages user-definable correspondence between logical font 12 names and the fonts present on the machine. 13 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. 18 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. 23 24 In case everything else fails (i.e. there is no record in config file 25 and "interactive" is @false or user denied to choose any replacement), 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 54 55 @library{wxcore} 56 @category{cfg} 57 58 @see wxEncodingConverter, @ref overview_nonenglish 59 */ 60 class wxFontMapper 61 { 62 public: 63 /** 64 Default ctor. 65 66 @note 67 The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get(). 68 */ 69 wxFontMapper(); 70 71 /** 72 Virtual dtor. 73 */ 74 virtual ~wxFontMapper(); 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. 79 80 Be careful when using this function with @a interactive set to @true 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 */ 87 virtual wxFontEncoding CharsetToEncoding(const wxString& charset, 88 bool interactive = true); 89 90 /** 91 Get the current font mapper object. If there is no current object, creates one. 92 93 @see Set() 94 */ 95 static wxFontMapper* Get(); 96 97 /** 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 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. 112 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, 120 bool interactive = true); 121 bool GetAltForEncoding(wxFontEncoding encoding, 122 wxFontEncoding* alt_encoding, 123 const wxString& facename = wxEmptyString, 124 bool interactive = true); 125 //@} 126 127 /** 128 Returns the @e n-th supported encoding. 129 130 Together with GetSupportedEncodingsCount() this method may be used 131 to get all supported encodings. 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 /** 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(). 147 */ 148 static wxFontEncoding GetEncodingFromName(const wxString& encoding); 149 150 /** 151 Return internal string identifier for the encoding (see also 152 wxFontMapper::GetEncodingDescription). 153 154 @see GetEncodingFromName() 155 */ 156 static wxString GetEncodingName(wxFontEncoding encoding); 157 158 /** 159 Returns the number of the font encodings supported by this class. 160 Together with GetEncoding() this method may be used to get 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 */ 169 virtual bool IsEncodingAvailable(wxFontEncoding encoding, 170 const wxString& facename = wxEmptyString); 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. 176 177 @see Get() 178 */ 179 static wxFontMapper* Set(wxFontMapper* mapper); 180 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 }; 196 197