make font conversions work in wxBase

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7017 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-03-31 18:12:32 +00:00
parent 41f8d6eecb
commit 39cd08a993
7 changed files with 137 additions and 91 deletions

View File

@@ -123,7 +123,7 @@ docmdi.cpp C
docview.cpp C docview.cpp C
dynarray.cpp C B dynarray.cpp C B
dynlib.cpp C B dynlib.cpp C B
encconv.cpp C encconv.cpp C B
event.cpp C B event.cpp C B
extended.c C B extended.c C B
ffile.cpp C B ffile.cpp C B
@@ -132,7 +132,7 @@ fileconf.cpp C B
filefn.cpp C B filefn.cpp C B
filesys.cpp C B filesys.cpp C B
fontcmn.cpp C fontcmn.cpp C
fontmap.cpp C fontmap.cpp C B
framecmn.cpp C framecmn.cpp C
fs_inet.cpp C B fs_inet.cpp C B
fs_zip.cpp C B fs_zip.cpp C B
@@ -586,7 +586,7 @@ docview.h W
dragimag.h W dragimag.h W
dynarray.h W B dynarray.h W B
dynlib.h W B dynlib.h W B
encconv.h W encconv.h W B
event.h W B event.h W B
expr.h W expr.h W
ffile.h W B ffile.h W B
@@ -597,10 +597,11 @@ filefn.h W B
filesys.h W B filesys.h W B
font.h W font.h W
fontdlg.h W fontdlg.h W
fontenc.h W B
fontenum.h W fontenum.h W
fontmap.h W fontmap.h W B
fontdlg.h W fontdlg.h W
fontutil.h W fontutil.h W B
frame.h W frame.h W
fs_inet.h W B fs_inet.h W B
fs_zip.h W B fs_zip.h W B

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: encconv.h // Name: wx/encconv.h
// Purpose: wxEncodingConverter class for converting between different // Purpose: wxEncodingConverter class for converting between different
// font encodings // font encodings
// Author: Vaclav Slavik // Author: Vaclav Slavik
@@ -7,26 +7,31 @@
// Licence: wxWindows Licence // Licence: wxWindows Licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __ENCCONV_H__ #ifndef _WX_ENCCONV_H_
#define __ENCCONV_H__ #define _WX_ENCCONV_H_
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "encconv.h" #pragma interface "encconv.h"
#endif #endif
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/font.h" #include "wx/object.h"
#include "wx/fontenc.h"
#include "wx/dynarray.h" #include "wx/dynarray.h"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
enum
enum { {
wxCONVERT_STRICT, wxCONVERT_STRICT,
wxCONVERT_SUBSTITUTE wxCONVERT_SUBSTITUTE
}; };
enum { enum
{
wxPLATFORM_CURRENT = -1, wxPLATFORM_CURRENT = -1,
wxPLATFORM_UNIX = 0, wxPLATFORM_UNIX = 0,
@@ -35,8 +40,11 @@ enum {
wxPLATFORM_MAC wxPLATFORM_MAC
}; };
WX_DEFINE_ARRAY(wxFontEncoding, wxFontEncodingArray); // ----------------------------------------------------------------------------
// types
// ----------------------------------------------------------------------------
WX_DEFINE_ARRAY(wxFontEncoding, wxFontEncodingArray);
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// wxEncodingConverter // wxEncodingConverter
@@ -140,4 +148,4 @@ class WXDLLEXPORT wxEncodingConverter : public wxObject
}; };
#endif // __ENCCONV_H__ #endif // _WX_ENCCONV_H_

View File

@@ -21,6 +21,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include "wx/defs.h" // for wxDEFAULT &c #include "wx/defs.h" // for wxDEFAULT &c
#include "wx/fontenc.h" // the font encoding constants
#include "wx/gdiobj.h" // the base class #include "wx/gdiobj.h" // the base class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -66,62 +67,6 @@ enum wxFontWeight
wxFONTWEIGHT_MAX wxFONTWEIGHT_MAX
}; };
// font encodings
enum wxFontEncoding
{
wxFONTENCODING_SYSTEM = -1, // system default
wxFONTENCODING_DEFAULT, // current default encoding
// ISO8859 standard defines a number of single-byte charsets
wxFONTENCODING_ISO8859_1, // West European (Latin1)
wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
wxFONTENCODING_ISO8859_4, // Baltic languages (Estonian) (Latin4)
wxFONTENCODING_ISO8859_5, // Cyrillic
wxFONTENCODING_ISO8859_6, // Arabic
wxFONTENCODING_ISO8859_7, // Greek
wxFONTENCODING_ISO8859_8, // Hebrew
wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
wxFONTENCODING_ISO8859_11, // Thai
wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
// here anyhow to make all ISO8859
// consecutive numbers
wxFONTENCODING_ISO8859_13, // Latin7
wxFONTENCODING_ISO8859_14, // Latin8
wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
wxFONTENCODING_ISO8859_MAX,
// Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
wxFONTENCODING_KOI8, // we don't support any of KOI8 variants
wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
// what would we do without Microsoft? They have their own encodings
// for DOS
wxFONTENCODING_CP437, // original MS-DOS codepage
wxFONTENCODING_CP850, // CP437 merged with Latin1
wxFONTENCODING_CP852, // CP437 merged with Latin2
wxFONTENCODING_CP855, // another cyrillic encoding
wxFONTENCODING_CP866, // and another one
// and for Windows
wxFONTENCODING_CP874, // WinThai
wxFONTENCODING_CP1250, // WinLatin2
wxFONTENCODING_CP1251, // WinCyrillic
wxFONTENCODING_CP1252, // WinLatin1
wxFONTENCODING_CP1253, // WinGreek (8859-7)
wxFONTENCODING_CP1254, // WinTurkish
wxFONTENCODING_CP1255, // WinHebrew
wxFONTENCODING_CP1256, // WinArabic
wxFONTENCODING_CP1257, // WinBaltic (same as Latin 7)
wxFONTENCODING_CP12_MAX,
wxFONTENCODING_UNICODE, // Unicode - currently used only by
// wxEncodingConverter class
wxFONTENCODING_MAX
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFontBase represents a font object // wxFontBase represents a font object
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

71
include/wx/fontenc.h Normal file
View File

@@ -0,0 +1,71 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/fontenc.h
// Purpose: wxFontEncoding constants
// Author: Vadim Zeitlin
// Modified by:
// Created: 29.03.00
// RCS-ID: $Id$
// Copyright: (c) Vadim Zeitlin
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_FONTENC_H_
#define _WX_FONTENC_H_
// font encodings
enum wxFontEncoding
{
wxFONTENCODING_SYSTEM = -1, // system default
wxFONTENCODING_DEFAULT, // current default encoding
// ISO8859 standard defines a number of single-byte charsets
wxFONTENCODING_ISO8859_1, // West European (Latin1)
wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
wxFONTENCODING_ISO8859_4, // Baltic languages (Estonian) (Latin4)
wxFONTENCODING_ISO8859_5, // Cyrillic
wxFONTENCODING_ISO8859_6, // Arabic
wxFONTENCODING_ISO8859_7, // Greek
wxFONTENCODING_ISO8859_8, // Hebrew
wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
wxFONTENCODING_ISO8859_11, // Thai
wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
// here anyhow to make all ISO8859
// consecutive numbers
wxFONTENCODING_ISO8859_13, // Latin7
wxFONTENCODING_ISO8859_14, // Latin8
wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
wxFONTENCODING_ISO8859_MAX,
// Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
wxFONTENCODING_KOI8, // we don't support any of KOI8 variants
wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
// what would we do without Microsoft? They have their own encodings
// for DOS
wxFONTENCODING_CP437, // original MS-DOS codepage
wxFONTENCODING_CP850, // CP437 merged with Latin1
wxFONTENCODING_CP852, // CP437 merged with Latin2
wxFONTENCODING_CP855, // another cyrillic encoding
wxFONTENCODING_CP866, // and another one
// and for Windows
wxFONTENCODING_CP874, // WinThai
wxFONTENCODING_CP1250, // WinLatin2
wxFONTENCODING_CP1251, // WinCyrillic
wxFONTENCODING_CP1252, // WinLatin1
wxFONTENCODING_CP1253, // WinGreek (8859-7)
wxFONTENCODING_CP1254, // WinTurkish
wxFONTENCODING_CP1255, // WinHebrew
wxFONTENCODING_CP1256, // WinArabic
wxFONTENCODING_CP1257, // WinBaltic (same as Latin 7)
wxFONTENCODING_CP12_MAX,
wxFONTENCODING_UNICODE, // Unicode - currently used only by
// wxEncodingConverter class
wxFONTENCODING_MAX
};
#endif // _WX_FONTENC_H_

View File

@@ -20,14 +20,18 @@
// headers // headers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include "wx/font.h" // for wxFont and wxFontEncoding #include "wx/fontenc.h" // for wxFontEncoding
#if wxUSE_GUI
#include "wx/fontutil.h" // for wxNativeEncodingInfo #include "wx/fontutil.h" // for wxNativeEncodingInfo
#endif // wxUSE_GUI
#if wxUSE_CONFIG #if wxUSE_CONFIG
class WXDLLEXPORT wxConfigBase; class WXDLLEXPORT wxConfigBase;
#endif #endif // wxUSE_CONFIG
#if wxUSE_GUI
class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxWindow;
#endif // wxUSE_GUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFontMapper manages user-definable correspondence between logical font // wxFontMapper manages user-definable correspondence between logical font
@@ -52,6 +56,7 @@ public:
// virtual dtor for a base class // virtual dtor for a base class
virtual ~wxFontMapper(); virtual ~wxFontMapper();
#if wxUSE_GUI
// find an alternative for the given encoding (which is supposed to not be // find an alternative for the given encoding (which is supposed to not be
// available on this system). If successful, return TRUE and fill info // available on this system). If successful, return TRUE and fill info
// structure with the parameters required to create the font, otherwise // structure with the parameters required to create the font, otherwise
@@ -72,6 +77,7 @@ public:
// If no facename is given, // If no facename is given,
virtual bool IsEncodingAvailable(wxFontEncoding encoding, virtual bool IsEncodingAvailable(wxFontEncoding encoding,
const wxString& facename = wxEmptyString); const wxString& facename = wxEmptyString);
#endif // wxUSE_GUI
// returns the encoding for the given charset (in the form of RFC 2046) or // returns the encoding for the given charset (in the form of RFC 2046) or
// wxFONTENCODING_SYSTEM if couldn't decode it // wxFONTENCODING_SYSTEM if couldn't decode it
@@ -93,11 +99,13 @@ public:
// configure the appearance of the dialogs we may popup // configure the appearance of the dialogs we may popup
// ---------------------------------------------------- // ----------------------------------------------------
#if wxUSE_GUI
// the parent window for modal dialogs // the parent window for modal dialogs
void SetDialogParent(wxWindow *parent) { m_windowParent = parent; } void SetDialogParent(wxWindow *parent) { m_windowParent = parent; }
// the title for the dialogs (note that default is quite reasonable) // the title for the dialogs (note that default is quite reasonable)
void SetDialogTitle(const wxString& title) { m_titleDialog = title; } void SetDialogTitle(const wxString& title) { m_titleDialog = title; }
#endif // wxUSE_GUI
// functions which allow to configure the config object used: by default, // functions which allow to configure the config object used: by default,
// the global one (from wxConfigBase::Get() will be used) and the default // the global one (from wxConfigBase::Get() will be used) and the default
@@ -139,6 +147,7 @@ protected:
// restore the config path after use // restore the config path after use
void RestorePath(const wxString& pathOld); void RestorePath(const wxString& pathOld);
#if wxUSE_GUI
// GetAltForEncoding() helper: tests for the existence of the given // GetAltForEncoding() helper: tests for the existence of the given
// encoding and saves the result in config if ok - this results in the // encoding and saves the result in config if ok - this results in the
// following (desired) behaviour: when an unknown/unavailable encoding is // following (desired) behaviour: when an unknown/unavailable encoding is
@@ -149,6 +158,7 @@ protected:
bool TestAltEncoding(const wxString& configEntry, bool TestAltEncoding(const wxString& configEntry,
wxFontEncoding encReplacement, wxFontEncoding encReplacement,
wxNativeEncodingInfo *info); wxNativeEncodingInfo *info);
#endif // wxUSE_GUI
#if wxUSE_CONFIG #if wxUSE_CONFIG
// config object and path (in it) to use // config object and path (in it) to use
@@ -157,11 +167,13 @@ protected:
wxString m_configRootPath; wxString m_configRootPath;
#if wxUSE_GUI
// the title for our dialogs // the title for our dialogs
wxString m_titleDialog; wxString m_titleDialog;
// the parent window for our dialogs // the parent window for our dialogs
wxWindow *m_windowParent; wxWindow *m_windowParent;
#endif // wxUSE_GUI
friend class wxFontMapperPathChanger; friend class wxFontMapperPathChanger;
}; };

View File

@@ -41,9 +41,12 @@
#include "wx/memconf.h" #include "wx/memconf.h"
#endif #endif
#if wxUSE_GUI
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#include "wx/fontdlg.h" #include "wx/fontdlg.h"
#include "wx/choicdlg.h" #include "wx/choicdlg.h"
#endif // wxUSE_GUI
#include "wx/encconv.h" #include "wx/encconv.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -54,7 +57,9 @@
static const wxChar* FONTMAPPER_ROOT_PATH = wxT("wxWindows/FontMapper"); static const wxChar* FONTMAPPER_ROOT_PATH = wxT("wxWindows/FontMapper");
static const wxChar* FONTMAPPER_CHARSET_PATH = wxT("Charsets"); static const wxChar* FONTMAPPER_CHARSET_PATH = wxT("Charsets");
static const wxChar* FONTMAPPER_CHARSET_ALIAS_PATH = wxT("Aliases"); static const wxChar* FONTMAPPER_CHARSET_ALIAS_PATH = wxT("Aliases");
#if wxUSE_GUI
static const wxChar* FONTMAPPER_FONT_FROM_ENCODING_PATH = wxT("Encodings"); static const wxChar* FONTMAPPER_FONT_FROM_ENCODING_PATH = wxT("Encodings");
#endif // wxUSE_GUI
// encodings supported by GetEncodingDescription // encodings supported by GetEncodingDescription
static wxFontEncoding gs_encodings[] = static wxFontEncoding gs_encodings[] =
@@ -193,9 +198,11 @@ wxFontMapper::wxFontMapper()
{ {
#if wxUSE_CONFIG #if wxUSE_CONFIG
m_config = NULL; m_config = NULL;
#endif #endif // wxUSE_CONFIG
#if wxUSE_GUI
m_windowParent = NULL; m_windowParent = NULL;
#endif // wxUSE_GUI
} }
wxFontMapper::~wxFontMapper() wxFontMapper::~wxFontMapper()
@@ -440,6 +447,7 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset,
//else: unknown //else: unknown
} }
#if wxUSE_GUI
// if still no luck, ask the user - unless disabled // if still no luck, ask the user - unless disabled
if ( (encoding == wxFONTENCODING_SYSTEM) && interactive ) if ( (encoding == wxFONTENCODING_SYSTEM) && interactive )
{ {
@@ -498,10 +506,11 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset,
RestorePath(pathOld); RestorePath(pathOld);
} }
#endif #endif // wxUSE_CONFIG
} }
//else: cancelled //else: cancelled
} }
#endif // wxUSE_GUI
return encoding; return encoding;
} }
@@ -512,6 +521,8 @@ wxFontEncoding wxFontMapper::CharsetToEncoding(const wxString& charset,
// correspond to which is used by GetFontForEncoding() function // correspond to which is used by GetFontForEncoding() function
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxUSE_GUI
bool wxFontMapper::TestAltEncoding(const wxString& configEntry, bool wxFontMapper::TestAltEncoding(const wxString& configEntry,
wxFontEncoding encReplacement, wxFontEncoding encReplacement,
wxNativeEncodingInfo *info) wxNativeEncodingInfo *info)
@@ -527,7 +538,7 @@ bool wxFontMapper::TestAltEncoding(const wxString& configEntry,
{ {
GetConfig()->Write(configEntry, info->ToString()); GetConfig()->Write(configEntry, info->ToString());
} }
#endif #endif // wxUSE_CONFIG
return TRUE; return TRUE;
} }
@@ -567,7 +578,6 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
configEntry += encName; configEntry += encName;
#if wxUSE_CONFIG #if wxUSE_CONFIG
// do we have a font spec for this encoding? // do we have a font spec for this encoding?
wxString pathOld; wxString pathOld;
if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) ) if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) )
@@ -602,7 +612,7 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
} }
//else: there is no information in config about this encoding //else: there is no information in config about this encoding
} }
#endif #endif // wxUSE_CONFIG
// ask the user // ask the user
if ( interactive ) if ( interactive )
@@ -653,7 +663,6 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
} }
//else: we're in non-interactive mode //else: we're in non-interactive mode
// now try the default mappings: // now try the default mappings:
wxFontEncodingArray equiv = wxEncodingConverter::GetAllEquivalents(encoding); wxFontEncodingArray equiv = wxEncodingConverter::GetAllEquivalents(encoding);
size_t count = equiv.GetCount(); size_t count = equiv.GetCount();
@@ -666,8 +675,6 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
return FALSE; return FALSE;
} }
bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding, bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
wxFontEncoding *alt_encoding, wxFontEncoding *alt_encoding,
const wxString& facename, const wxString& facename,
@@ -679,8 +686,6 @@ bool wxFontMapper::GetAltForEncoding(wxFontEncoding encoding,
return r; return r;
} }
bool wxFontMapper::IsEncodingAvailable(wxFontEncoding encoding, bool wxFontMapper::IsEncodingAvailable(wxFontEncoding encoding,
const wxString& facename) const wxString& facename)
{ {
@@ -694,3 +699,5 @@ bool wxFontMapper::IsEncodingAvailable(wxFontEncoding encoding,
else else
return FALSE; return FALSE;
} }
#endif // wxUSE_GUI

View File

@@ -137,6 +137,8 @@ ALL_HEADERS = \
protocol/protocol.h protocol/protocol.h
BASE_OBJS = \ BASE_OBJS = \
fontmap.o \
encconv.o \
init.o \ init.o \
appcmn.o \ appcmn.o \
cmdline.o \ cmdline.o \