]> git.saurik.com Git - wxWidgets.git/blame - include/wx/encconv.h
Put back some code that was commented out for testing
[wxWidgets.git] / include / wx / encconv.h
CommitLineData
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
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
f6bcfd97
BP
10#ifndef _WX_ENCCONV_H_
11#define _WX_ENCCONV_H_
c958260b
VS
12
13#ifdef __GNUG__
14#pragma interface "encconv.h"
15#endif
16
17#include "wx/defs.h"
f6bcfd97
BP
18#include "wx/object.h"
19#include "wx/fontenc.h"
c958260b
VS
20#include "wx/dynarray.h"
21
f6bcfd97
BP
22// ----------------------------------------------------------------------------
23// constants
24// ----------------------------------------------------------------------------
c958260b 25
f6bcfd97
BP
26enum
27{
c958260b
VS
28 wxCONVERT_STRICT,
29 wxCONVERT_SUBSTITUTE
30};
31
32
f6bcfd97
BP
33enum
34{
c958260b 35 wxPLATFORM_CURRENT = -1,
b8f72ded 36
c958260b
VS
37 wxPLATFORM_UNIX = 0,
38 wxPLATFORM_WINDOWS,
39 wxPLATFORM_OS2,
b8f72ded 40 wxPLATFORM_MAC
c958260b
VS
41};
42
f6bcfd97
BP
43// ----------------------------------------------------------------------------
44// types
45// ----------------------------------------------------------------------------
c958260b 46
f6bcfd97 47WX_DEFINE_ARRAY(wxFontEncoding, wxFontEncodingArray);
c958260b
VS
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
55class WXDLLEXPORT wxEncodingConverter : public wxObject
56{
57 public:
b8f72ded 58
c958260b
VS
59 wxEncodingConverter();
60 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
b8f72ded 61
c958260b 62 // Initialize convertion. Both output or input encoding may
f6bcfd97 63 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
c958260b
VS
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 //
b8f72ded 69 // You must call this method before calling Convert. You may call
c958260b
VS
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:
b8f72ded
DW
74 // wxCONVERT_STRICT --
75 // follow behaviour of GNU Recode - just copy unconvertable
76 // characters to output and don't change them (it's integer
c958260b
VS
77 // value will stay the same)
78 // wxCONVERT_SUBSTITUTE --
b8f72ded 79 // try some (lossy) substitutions - e.g. replace
c958260b
VS
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);
b8f72ded 90
c958260b
VS
91 // Convert input string according to settings passed to Init.
92 // Note that you must call Init before using Convert!
5b5d025c
VS
93 void Convert(const char* input, char* output);
94 void Convert(char* str) { Convert(str, str); }
f6bcfd97
BP
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); }
b8f72ded 102#endif
c958260b
VS
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).
b8f72ded
DW
120 //
121 // Convert() method is not limited to converting between
c958260b
VS
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
b8f72ded 134 // Similar to GetPlatformEquivalent, but this one will return ALL
c958260b
VS
135 // equivalent encodings, regardless the platform, including itself.
136 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
137
138 private:
b8f72ded 139
f6bcfd97
BP
140#if wxUSE_WCHAR_T
141 wchar_t *m_Table;
142#else
143 char *m_Table;
144#endif
5b5d025c 145 bool m_UnicodeInput, m_UnicodeOutput;
c958260b 146 bool m_JustCopy;
b8f72ded 147
c958260b
VS
148};
149
150
f6bcfd97 151#endif // _WX_ENCCONV_H_