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