]> git.saurik.com Git - wxWidgets.git/blob - include/wx/encconv.h
warning fix
[wxWidgets.git] / include / wx / encconv.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/encconv.h
3 // Purpose: wxEncodingConverter class for converting between different
4 // font encodings
5 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_ENCCONV_H_
11 #define _WX_ENCCONV_H_
12
13 #ifdef __GNUG__
14 #pragma interface "encconv.h"
15 #endif
16
17 #include "wx/defs.h"
18 #include "wx/object.h"
19 #include "wx/fontenc.h"
20 #include "wx/dynarray.h"
21
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25
26 enum
27 {
28 wxCONVERT_STRICT,
29 wxCONVERT_SUBSTITUTE
30 };
31
32
33 enum
34 {
35 wxPLATFORM_CURRENT = -1,
36
37 wxPLATFORM_UNIX = 0,
38 wxPLATFORM_WINDOWS,
39 wxPLATFORM_OS2,
40 wxPLATFORM_MAC
41 };
42
43 // ----------------------------------------------------------------------------
44 // types
45 // ----------------------------------------------------------------------------
46
47 WX_DEFINE_ARRAY(wxFontEncoding, wxFontEncodingArray);
48
49 //--------------------------------------------------------------------------------
50 // wxEncodingConverter
51 // This class is capable of converting strings between any two
52 // 8bit encodings/charsets. It can also convert from/to Unicode
53 //--------------------------------------------------------------------------------
54
55 class WXDLLEXPORT wxEncodingConverter : public wxObject
56 {
57 public:
58
59 wxEncodingConverter();
60 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
61
62 // Initialize convertion. Both output or input encoding may
63 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
64 //
65 // All subsequent calls to Convert() will interpret it's argument
66 // as a string in input_enc encoding and will output string in
67 // output_enc encoding.
68 //
69 // You must call this method before calling Convert. You may call
70 // it more than once in order to switch to another conversion
71 //
72 // Method affects behaviour of Convert() in case input character
73 // cannot be converted because it does not exist in output encoding:
74 // wxCONVERT_STRICT --
75 // follow behaviour of GNU Recode - just copy unconvertable
76 // characters to output and don't change them (it's integer
77 // value will stay the same)
78 // wxCONVERT_SUBSTITUTE --
79 // try some (lossy) substitutions - e.g. replace
80 // unconvertable latin capitals with acute by ordinary
81 // capitals, replace en-dash or em-dash by '-' etc.
82 // both modes gurantee that output string will have same length
83 // as input string
84 //
85 // Returns FALSE if given conversion is impossible, TRUE otherwise
86 // (conversion may be impossible either if you try to convert
87 // to Unicode with non-Unicode build of wxWindows or if input
88 // or output encoding is not supported.)
89 bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT);
90
91 // Convert input string according to settings passed to Init.
92 // Note that you must call Init before using Convert!
93 void Convert(const char* input, char* output);
94 void Convert(char* str) { Convert(str, str); }
95 wxString Convert(const wxString& input);
96
97 #if wxUSE_WCHAR_T
98 void Convert(const char* input, wchar_t* output);
99 void Convert(const wchar_t* input, char* output);
100 void Convert(const wchar_t* input, wchar_t* output);
101 void Convert(wchar_t* str) { Convert(str, str); }
102 #endif
103 // Return equivalent(s) for given font that are used
104 // under given platform. wxPLATFORM_CURRENT means the plaform
105 // this binary was compiled for
106 //
107 // Examples:
108 // current platform enc returned value
109 // -----------------------------------------------------
110 // unix CP1250 {ISO8859_2}
111 // unix ISO8859_2 {}
112 // windows ISO8859_2 {CP1250}
113 //
114 // Equivalence is defined in terms of convertibility:
115 // 2 encodings are equivalent if you can convert text between
116 // then without loosing information (it may - and will - happen
117 // that you loose special chars like quotation marks or em-dashes
118 // but you shouldn't loose any diacritics and language-specific
119 // characters when converting between equivalent encodings).
120 //
121 // Convert() method is not limited to converting between
122 // equivalent encodings, it can convert between arbitrary
123 // two encodings!
124 //
125 // Remember that this function does _NOT_ check for presence of
126 // fonts in system. It only tells you what are most suitable
127 // encodings. (It usually returns only one encoding)
128 //
129 // Note that argument enc itself may be present in returned array!
130 // (so that you can -- as a side effect -- detect whether the
131 // encoding is native for this platform or not)
132 static wxFontEncodingArray GetPlatformEquivalents(wxFontEncoding enc, int platform = wxPLATFORM_CURRENT);
133
134 // Similar to GetPlatformEquivalent, but this one will return ALL
135 // equivalent encodings, regardless the platform, including itself.
136 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
137
138 private:
139
140 #if wxUSE_WCHAR_T
141 wchar_t *m_Table;
142 #else
143 char *m_Table;
144 #endif
145 bool m_UnicodeInput, m_UnicodeOutput;
146 bool m_JustCopy;
147
148 };
149
150
151 #endif // _WX_ENCCONV_H_