]> git.saurik.com Git - wxWidgets.git/blame - include/wx/encconv.h
BC++ doesn't like periods in resource names
[wxWidgets.git] / include / wx / encconv.h
CommitLineData
c958260b
VS
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
23enum {
24 wxCONVERT_STRICT,
25 wxCONVERT_SUBSTITUTE
26};
27
28
29enum {
30 wxPLATFORM_CURRENT = -1,
b8f72ded 31
c958260b
VS
32 wxPLATFORM_UNIX = 0,
33 wxPLATFORM_WINDOWS,
34 wxPLATFORM_OS2,
b8f72ded 35 wxPLATFORM_MAC
c958260b
VS
36};
37
38WX_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
47class WXDLLEXPORT wxEncodingConverter : public wxObject
48{
49 public:
b8f72ded 50
c958260b
VS
51 wxEncodingConverter();
52 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
b8f72ded 53
c958260b 54 // Initialize convertion. Both output or input encoding may
169267e6 55 // be wxFONTENCODING_UNICODE, but only if wxUSE_UNICODE is set to 1.
c958260b
VS
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 //
b8f72ded 61 // You must call this method before calling Convert. You may call
c958260b
VS
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:
b8f72ded
DW
66 // wxCONVERT_STRICT --
67 // follow behaviour of GNU Recode - just copy unconvertable
68 // characters to output and don't change them (it's integer
c958260b
VS
69 // value will stay the same)
70 // wxCONVERT_SUBSTITUTE --
b8f72ded 71 // try some (lossy) substitutions - e.g. replace
c958260b
VS
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);
b8f72ded 82
c958260b
VS
83 // Convert input string according to settings passed to Init.
84 // Note that you must call Init before using Convert!
c958260b
VS
85 void Convert(const wxChar* input, wxChar* output);
86 void Convert(wxChar* str) { Convert(str, str); }
5b5d025c
VS
87 wxString Convert(const wxString& input);
88
89#if wxUSE_UNICODE // otherwise wxChar === char
90 void Convert(const char* input, wxChar* output);
91 void Convert(const wxChar* input, char* output);
92 void Convert(const char* input, char* output);
93 void Convert(char* str) { Convert(str, str); }
b8f72ded 94#endif
c958260b
VS
95 // Return equivalent(s) for given font that are used
96 // under given platform. wxPLATFORM_CURRENT means the plaform
97 // this binary was compiled for
98 //
99 // Examples:
100 // current platform enc returned value
101 // -----------------------------------------------------
102 // unix CP1250 {ISO8859_2}
103 // unix ISO8859_2 {}
104 // windows ISO8859_2 {CP1250}
105 //
106 // Equivalence is defined in terms of convertibility:
107 // 2 encodings are equivalent if you can convert text between
108 // then without loosing information (it may - and will - happen
109 // that you loose special chars like quotation marks or em-dashes
110 // but you shouldn't loose any diacritics and language-specific
111 // characters when converting between equivalent encodings).
b8f72ded
DW
112 //
113 // Convert() method is not limited to converting between
c958260b
VS
114 // equivalent encodings, it can convert between arbitrary
115 // two encodings!
116 //
117 // Remember that this function does _NOT_ check for presence of
118 // fonts in system. It only tells you what are most suitable
119 // encodings. (It usually returns only one encoding)
120 //
121 // Note that argument enc itself may be present in returned array!
122 // (so that you can -- as a side effect -- detect whether the
123 // encoding is native for this platform or not)
124 static wxFontEncodingArray GetPlatformEquivalents(wxFontEncoding enc, int platform = wxPLATFORM_CURRENT);
125
b8f72ded 126 // Similar to GetPlatformEquivalent, but this one will return ALL
c958260b
VS
127 // equivalent encodings, regardless the platform, including itself.
128 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
129
130 private:
b8f72ded 131
c958260b 132 wxChar *m_Table;
5b5d025c 133 bool m_UnicodeInput, m_UnicodeOutput;
c958260b 134 bool m_JustCopy;
b8f72ded 135
c958260b
VS
136};
137
138
139#endif // __ENCCONV_H__
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156