1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontMapper class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_FONTMAPPER_H_
13 #define _WX_FONTMAPPER_H_
16 #pragma interface "fontmap.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 #include "wx/fontenc.h" // for wxFontEncoding
25 #include "wx/fontutil.h" // for wxNativeEncodingInfo
29 class WXDLLEXPORT wxConfigBase
;
30 #endif // wxUSE_CONFIG
33 class WXDLLEXPORT wxWindow
;
36 // ----------------------------------------------------------------------------
37 // wxFontMapper manages user-definable correspondence between logical font
38 // names and the fonts present on the machine.
40 // The default implementations of all functions will ask the user if they are
41 // not capable of finding the answer themselves and store the answer in a
42 // config file (configurable via SetConfigXXX functions). This behaviour may
43 // be disabled by giving the value of FALSE to "interactive" parameter.
44 // However, the functions will always consult the config file to allow the
45 // user-defined values override the default logic and there is no way to
46 // disable this - which shouldn't be ever needed because if "interactive" was
47 // never TRUE, the config file is never created anyhow.
48 // ----------------------------------------------------------------------------
50 class WXDLLEXPORT wxFontMapper
56 // virtual dtor for a base class
57 virtual ~wxFontMapper();
60 // find an alternative for the given encoding (which is supposed to not be
61 // available on this system). If successful, return TRUE and fill info
62 // structure with the parameters required to create the font, otherwise
64 virtual bool GetAltForEncoding(wxFontEncoding encoding
,
65 wxNativeEncodingInfo
*info
,
66 const wxString
& facename
= wxEmptyString
,
67 bool interactive
= TRUE
);
69 // version better suitable for 'public' use. Returns wxFontEcoding
70 // that can be used it wxFont ctor
71 bool GetAltForEncoding(wxFontEncoding encoding
,
72 wxFontEncoding
*alt_encoding
,
73 const wxString
& facename
= wxEmptyString
,
74 bool interactive
= TRUE
);
76 // checks whether given encoding is available in given face or not.
77 // If no facename is given,
78 virtual bool IsEncodingAvailable(wxFontEncoding encoding
,
79 const wxString
& facename
= wxEmptyString
);
82 // returns the encoding for the given charset (in the form of RFC 2046) or
83 // wxFONTENCODING_SYSTEM if couldn't decode it
84 virtual wxFontEncoding
CharsetToEncoding(const wxString
& charset
,
85 bool interactive
= TRUE
);
90 // return internal string identifier for the encoding (see also
91 // GetEncodingDescription())
92 static wxString
GetEncodingName(wxFontEncoding encoding
);
94 // return user-readable string describing the given encoding
96 // NB: hard-coded now, but might change later (read it from config?)
97 static wxString
GetEncodingDescription(wxFontEncoding encoding
);
99 // configure the appearance of the dialogs we may popup
100 // ----------------------------------------------------
103 // the parent window for modal dialogs
104 void SetDialogParent(wxWindow
*parent
) { m_windowParent
= parent
; }
106 // the title for the dialogs (note that default is quite reasonable)
107 void SetDialogTitle(const wxString
& title
) { m_titleDialog
= title
; }
110 // functions which allow to configure the config object used: by default,
111 // the global one (from wxConfigBase::Get() will be used) and the default
112 // root path for the config settings is the string returned by
113 // GetDefaultConfigPath()
114 // ----------------------------------------------------------------------
117 // set the config object to use (may be NULL to use default)
118 void SetConfig(wxConfigBase
*config
) { m_config
= config
; }
120 // set the root config path to use (should be an absolute path)
121 void SetConfigPath(const wxString
& prefix
);
123 // return default config path
124 static const wxChar
*GetDefaultConfigPath();
130 // get the config object we're using - if it wasn't set explicitly, this
131 // function will use wxConfig::Get() to get the global one
132 wxConfigBase
*GetConfig();
134 // gets the root path for our settings - if itwasn't set explicitly, use
135 // GetDefaultConfigPath()
136 const wxString
& GetConfigPath();
139 // change to the given (relative) path in the config, return TRUE if ok
140 // (then GetConfig() will return something !NULL), FALSE if no config
143 // caller should provide a pointer to the string variable which should be
144 // later passed to RestorePath()
145 bool ChangePath(const wxString
& pathNew
, wxString
*pathOld
);
147 // restore the config path after use
148 void RestorePath(const wxString
& pathOld
);
151 // GetAltForEncoding() helper: tests for the existence of the given
152 // encoding and saves the result in config if ok - this results in the
153 // following (desired) behaviour: when an unknown/unavailable encoding is
154 // requested for the first time, the user is asked about a replacement,
155 // but if he doesn't choose any and the default logic finds one, it will
156 // be saved in the config so that the user won't be asked about it any
158 bool TestAltEncoding(const wxString
& configEntry
,
159 wxFontEncoding encReplacement
,
160 wxNativeEncodingInfo
*info
);
164 // config object and path (in it) to use
165 wxConfigBase
*m_config
;
168 wxString m_configRootPath
;
171 // the title for our dialogs
172 wxString m_titleDialog
;
174 // the parent window for our dialogs
175 wxWindow
*m_windowParent
;
178 friend class wxFontMapperPathChanger
;
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 // the default font mapper for wxWindows programs
186 WXDLLEXPORT_DATA(extern wxFontMapper
*) wxTheFontMapper
;
188 #endif // _WX_FONTMAPPER_H_