1999-11-04 20:40:41 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/fontmap.h
|
|
|
|
// Purpose: wxFontMapper class
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04.11.99
|
|
|
|
// Copyright: (c) Vadim Zeitlin
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-11-04 20:40:41 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_FONTMAPPER_H_
|
|
|
|
#define _WX_FONTMAPPER_H_
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if wxUSE_FONTMAP
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#include "wx/fontenc.h" // for wxFontEncoding
|
1999-11-04 20:40:41 +00:00
|
|
|
|
2001-06-26 20:59:19 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
#include "wx/fontutil.h" // for wxNativeEncodingInfo
|
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
2003-07-11 22:06:00 +00:00
|
|
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxConfigBase;
|
2000-07-15 19:51:35 +00:00
|
|
|
#endif // wxUSE_CONFIG
|
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxFontMapper;
|
2003-06-24 00:56:19 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#if wxUSE_GUI
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindow;
|
2000-07-15 19:51:35 +00:00
|
|
|
#endif // wxUSE_GUI
|
1999-11-04 20:40:41 +00:00
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// ============================================================================
|
2004-05-23 14:56:36 +00:00
|
|
|
// wxFontMapper manages user-definable correspondence between wxWidgets font
|
2003-06-24 00:56:19 +00:00
|
|
|
// encodings and the fonts present on the machine.
|
1999-11-04 20:40:41 +00:00
|
|
|
//
|
2003-06-24 00:56:19 +00:00
|
|
|
// This is a singleton class, font mapper objects can only be accessed using
|
|
|
|
// wxFontMapper::Get().
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFontMapperBase: this is a non-interactive class which just uses its built
|
|
|
|
// in knowledge of the encodings equivalence
|
1999-11-04 20:40:41 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxFontMapperBase
|
1999-11-04 20:40:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-06-20 07:44:45 +00:00
|
|
|
// constructor and such
|
2003-06-24 00:56:19 +00:00
|
|
|
// ---------------------
|
|
|
|
|
1999-11-04 20:40:41 +00:00
|
|
|
// default ctor
|
2003-06-24 00:56:19 +00:00
|
|
|
wxFontMapperBase();
|
1999-11-04 20:40:41 +00:00
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// virtual dtor for any base class
|
|
|
|
virtual ~wxFontMapperBase();
|
1999-11-04 20:40:41 +00:00
|
|
|
|
2002-04-06 15:04:27 +00:00
|
|
|
// return instance of the wxFontMapper singleton
|
2005-03-26 07:10:52 +00:00
|
|
|
// wxBase code only cares that it's a wxFontMapperBase
|
2005-03-26 21:47:54 +00:00
|
|
|
// In wxBase, wxFontMapper is only forward declared
|
|
|
|
// so one cannot implicitly cast from it to wxFontMapperBase.
|
2005-03-26 07:10:52 +00:00
|
|
|
static wxFontMapperBase *Get();
|
2003-06-24 00:56:19 +00:00
|
|
|
|
2003-07-11 22:06:00 +00:00
|
|
|
// set the singleton to 'mapper' instance and return previous one
|
2002-04-06 15:04:27 +00:00
|
|
|
static wxFontMapper *Set(wxFontMapper *mapper);
|
|
|
|
|
2006-06-07 17:49:27 +00:00
|
|
|
// delete the existing font mapper if any
|
|
|
|
static void Reset();
|
|
|
|
|
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// translates charset strings to encoding
|
|
|
|
// --------------------------------------
|
2000-01-08 23:45:31 +00:00
|
|
|
|
1999-11-04 20:40:41 +00:00
|
|
|
// returns the encoding for the given charset (in the form of RFC 2046) or
|
|
|
|
// wxFONTENCODING_SYSTEM if couldn't decode it
|
2003-06-24 00:56:19 +00:00
|
|
|
//
|
|
|
|
// interactive parameter is ignored in the base class, we behave as if it
|
|
|
|
// were always false
|
1999-11-04 20:40:41 +00:00
|
|
|
virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
|
2003-06-24 00:56:19 +00:00
|
|
|
bool interactive = true);
|
|
|
|
|
|
|
|
// information about supported encodings
|
|
|
|
// -------------------------------------
|
1999-11-04 20:40:41 +00:00
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// get the number of font encodings we know about
|
|
|
|
static size_t GetSupportedEncodingsCount();
|
|
|
|
|
|
|
|
// get the n-th supported encoding
|
|
|
|
static wxFontEncoding GetEncoding(size_t n);
|
1999-11-05 19:03:19 +00:00
|
|
|
|
2005-09-18 14:01:14 +00:00
|
|
|
// return canonical name of this encoding (this is a short string,
|
|
|
|
// GetEncodingDescription() returns a longer one)
|
1999-11-05 19:03:19 +00:00
|
|
|
static wxString GetEncodingName(wxFontEncoding encoding);
|
|
|
|
|
2005-09-18 14:01:14 +00:00
|
|
|
// return a list of all names of this encoding (see GetEncodingName)
|
|
|
|
static const wxChar** GetAllEncodingNames(wxFontEncoding encoding);
|
|
|
|
|
1999-11-05 19:03:19 +00:00
|
|
|
// return user-readable string describing the given encoding
|
|
|
|
//
|
|
|
|
// NB: hard-coded now, but might change later (read it from config?)
|
|
|
|
static wxString GetEncodingDescription(wxFontEncoding encoding);
|
|
|
|
|
2004-04-11 10:40:04 +00:00
|
|
|
// find the encoding corresponding to the given name, inverse of
|
|
|
|
// GetEncodingName() and less general than CharsetToEncoding()
|
|
|
|
//
|
|
|
|
// returns wxFONTENCODING_MAX if the name is not a supported encoding
|
|
|
|
static wxFontEncoding GetEncodingFromName(const wxString& name);
|
|
|
|
|
1999-11-04 20:40:41 +00:00
|
|
|
|
|
|
|
// functions which allow to configure the config object used: by default,
|
|
|
|
// the global one (from wxConfigBase::Get() will be used) and the default
|
|
|
|
// root path for the config settings is the string returned by
|
|
|
|
// GetDefaultConfigPath()
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2003-07-11 22:06:00 +00:00
|
|
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
1999-11-04 20:40:41 +00:00
|
|
|
// set the root config path to use (should be an absolute path)
|
|
|
|
void SetConfigPath(const wxString& prefix);
|
|
|
|
|
|
|
|
// return default config path
|
2007-06-28 18:57:36 +00:00
|
|
|
static const wxString& GetDefaultConfigPath();
|
2003-06-24 00:56:19 +00:00
|
|
|
#endif // wxUSE_CONFIG
|
1999-11-04 20:40:41 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2006-06-07 17:49:27 +00:00
|
|
|
// returns true for the base class and false for a "real" font mapper object
|
|
|
|
// (implementation-only)
|
|
|
|
virtual bool IsDummy() { return true; }
|
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
protected:
|
2003-07-11 22:06:00 +00:00
|
|
|
#if wxUSE_CONFIG && wxUSE_FILECONFIG
|
2005-12-29 01:49:55 +00:00
|
|
|
// get the config object we're using -- either the global config object
|
|
|
|
// or a wxMemoryConfig object created by this class otherwise
|
1999-11-04 20:40:41 +00:00
|
|
|
wxConfigBase *GetConfig();
|
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// gets the root path for our settings -- if it wasn't set explicitly, use
|
1999-11-04 20:40:41 +00:00
|
|
|
// GetDefaultConfigPath()
|
|
|
|
const wxString& GetConfigPath();
|
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// change to the given (relative) path in the config, return true if ok
|
|
|
|
// (then GetConfig() will return something !NULL), false if no config
|
1999-11-04 20:40:41 +00:00
|
|
|
// object
|
|
|
|
//
|
|
|
|
// caller should provide a pointer to the string variable which should be
|
|
|
|
// later passed to RestorePath()
|
|
|
|
bool ChangePath(const wxString& pathNew, wxString *pathOld);
|
|
|
|
|
|
|
|
// restore the config path after use
|
|
|
|
void RestorePath(const wxString& pathOld);
|
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
// config object and path (in it) to use
|
2005-12-29 01:49:55 +00:00
|
|
|
wxConfigBase *m_configDummy;
|
2003-06-24 00:56:19 +00:00
|
|
|
|
|
|
|
wxString m_configRootPath;
|
|
|
|
#endif // wxUSE_CONFIG
|
|
|
|
|
2003-07-20 18:40:24 +00:00
|
|
|
// the real implementation of the base class version of CharsetToEncoding()
|
|
|
|
//
|
|
|
|
// returns wxFONTENCODING_UNKNOWN if encoding is unknown and we shouldn't
|
|
|
|
// ask the user about it, wxFONTENCODING_SYSTEM if it is unknown but we
|
|
|
|
// should/could ask the user
|
|
|
|
int NonInteractiveCharsetToEncoding(const wxString& charset);
|
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
private:
|
|
|
|
// the global fontmapper object or NULL
|
|
|
|
static wxFontMapper *sm_instance;
|
|
|
|
|
|
|
|
friend class wxFontMapperPathChanger;
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFontMapperBase);
|
2003-06-24 00:56:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFontMapper: interactive extension of wxFontMapperBase
|
|
|
|
//
|
|
|
|
// The default implementations of all functions will ask the user if they are
|
|
|
|
// not capable of finding the answer themselves and store the answer in a
|
|
|
|
// config file (configurable via SetConfigXXX functions). This behaviour may
|
|
|
|
// be disabled by giving the value of false to "interactive" parameter.
|
|
|
|
// However, the functions will always consult the config file to allow the
|
|
|
|
// user-defined values override the default logic and there is no way to
|
|
|
|
// disable this -- which shouldn't be ever needed because if "interactive" was
|
|
|
|
// never true, the config file is never created anyhow.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#if wxUSE_GUI
|
2003-06-24 00:56:19 +00:00
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxFontMapper : public wxFontMapperBase
|
2003-06-24 00:56:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// default ctor
|
|
|
|
wxFontMapper();
|
|
|
|
|
|
|
|
// virtual dtor for a base class
|
|
|
|
virtual ~wxFontMapper();
|
|
|
|
|
|
|
|
// working with the encodings
|
|
|
|
// --------------------------
|
|
|
|
|
|
|
|
// returns the encoding for the given charset (in the form of RFC 2046) or
|
|
|
|
// wxFONTENCODING_SYSTEM if couldn't decode it
|
|
|
|
virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
|
2016-09-25 20:21:28 +00:00
|
|
|
bool interactive = true) wxOVERRIDE;
|
2003-06-24 00:56:19 +00:00
|
|
|
|
|
|
|
// find an alternative for the given encoding (which is supposed to not be
|
|
|
|
// available on this system). If successful, return true and fill info
|
|
|
|
// structure with the parameters required to create the font, otherwise
|
|
|
|
// return false
|
|
|
|
virtual bool GetAltForEncoding(wxFontEncoding encoding,
|
|
|
|
wxNativeEncodingInfo *info,
|
|
|
|
const wxString& facename = wxEmptyString,
|
|
|
|
bool interactive = true);
|
|
|
|
|
|
|
|
// version better suitable for 'public' use. Returns wxFontEcoding
|
|
|
|
// that can be used it wxFont ctor
|
|
|
|
bool GetAltForEncoding(wxFontEncoding encoding,
|
|
|
|
wxFontEncoding *alt_encoding,
|
|
|
|
const wxString& facename = wxEmptyString,
|
|
|
|
bool interactive = true);
|
|
|
|
|
|
|
|
// checks whether given encoding is available in given face or not.
|
2004-04-11 10:40:04 +00:00
|
|
|
//
|
|
|
|
// if no facename is given (default), return true if it's available in any
|
|
|
|
// facename at alll.
|
2003-06-24 00:56:19 +00:00
|
|
|
virtual bool IsEncodingAvailable(wxFontEncoding encoding,
|
|
|
|
const wxString& facename = wxEmptyString);
|
|
|
|
|
|
|
|
|
|
|
|
// configure the appearance of the dialogs we may popup
|
|
|
|
// ----------------------------------------------------
|
|
|
|
|
|
|
|
// the parent window for modal dialogs
|
|
|
|
void SetDialogParent(wxWindow *parent) { m_windowParent = parent; }
|
|
|
|
|
|
|
|
// the title for the dialogs (note that default is quite reasonable)
|
|
|
|
void SetDialogTitle(const wxString& title) { m_titleDialog = title; }
|
|
|
|
|
2005-03-26 08:34:51 +00:00
|
|
|
// GUI code needs to know it's a wxFontMapper because there
|
|
|
|
// are additional methods in the subclass.
|
|
|
|
static wxFontMapper *Get();
|
2003-06-24 00:56:19 +00:00
|
|
|
|
2006-06-07 17:49:27 +00:00
|
|
|
// pseudo-RTTI since we aren't a wxObject.
|
2016-09-25 20:21:28 +00:00
|
|
|
virtual bool IsDummy() wxOVERRIDE { return false; }
|
2006-06-07 17:49:27 +00:00
|
|
|
|
2003-06-24 00:56:19 +00:00
|
|
|
protected:
|
1999-11-05 19:03:19 +00:00
|
|
|
// GetAltForEncoding() helper: tests for the existence of the given
|
|
|
|
// encoding and saves the result in config if ok - this results in the
|
|
|
|
// following (desired) behaviour: when an unknown/unavailable encoding is
|
|
|
|
// requested for the first time, the user is asked about a replacement,
|
|
|
|
// but if he doesn't choose any and the default logic finds one, it will
|
|
|
|
// be saved in the config so that the user won't be asked about it any
|
|
|
|
// more
|
|
|
|
bool TestAltEncoding(const wxString& configEntry,
|
|
|
|
wxFontEncoding encReplacement,
|
|
|
|
wxNativeEncodingInfo *info);
|
|
|
|
|
1999-11-04 20:40:41 +00:00
|
|
|
// the title for our dialogs
|
|
|
|
wxString m_titleDialog;
|
|
|
|
|
|
|
|
// the parent window for our dialogs
|
|
|
|
wxWindow *m_windowParent;
|
1999-11-05 19:03:19 +00:00
|
|
|
|
2002-04-06 15:04:27 +00:00
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxFontMapper);
|
1999-11-04 20:40:41 +00:00
|
|
|
};
|
|
|
|
|
2005-03-26 07:10:52 +00:00
|
|
|
#endif // wxUSE_GUI
|
2003-06-24 00:56:19 +00:00
|
|
|
|
1999-11-05 19:03:19 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// global variables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-05-23 14:56:36 +00:00
|
|
|
// the default font mapper for wxWidgets programs do NOT use! This is for
|
2003-06-24 00:56:19 +00:00
|
|
|
// backward compatibility, use wxFontMapper::Get() instead
|
2002-04-06 15:04:27 +00:00
|
|
|
#define wxTheFontMapper (wxFontMapper::Get())
|
1999-11-05 19:03:19 +00:00
|
|
|
|
2003-05-01 16:52:17 +00:00
|
|
|
#else // !wxUSE_FONTMAP
|
|
|
|
|
|
|
|
#if wxUSE_GUI
|
|
|
|
// wxEncodingToCodepage (utils.cpp) needs wxGetNativeFontEncoding
|
2003-06-01 12:42:49 +00:00
|
|
|
#include "wx/fontutil.h"
|
2003-05-01 16:52:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
|
2001-06-26 20:59:19 +00:00
|
|
|
|
1999-11-04 20:40:41 +00:00
|
|
|
#endif // _WX_FONTMAPPER_H_
|
2003-06-24 00:56:19 +00:00
|
|
|
|