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