]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/encconv.h
A few tweaks and cleanups
[wxWidgets.git] / include / wx / encconv.h
... / ...
CommitLineData
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
19#if wxUSE_FONTMAP
20
21#include "wx/object.h"
22#include "wx/fontenc.h"
23#include "wx/dynarray.h"
24
25// ----------------------------------------------------------------------------
26// constants
27// ----------------------------------------------------------------------------
28
29enum
30{
31 wxCONVERT_STRICT,
32 wxCONVERT_SUBSTITUTE
33};
34
35
36enum
37{
38 wxPLATFORM_CURRENT = -1,
39
40 wxPLATFORM_UNIX = 0,
41 wxPLATFORM_WINDOWS,
42 wxPLATFORM_OS2,
43 wxPLATFORM_MAC
44};
45
46// ----------------------------------------------------------------------------
47// types
48// ----------------------------------------------------------------------------
49
50WX_DEFINE_ARRAY_INT(wxFontEncoding, wxFontEncodingArray);
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
58class WXDLLEXPORT wxEncodingConverter : public wxObject
59{
60 public:
61
62 wxEncodingConverter();
63 ~wxEncodingConverter() { if (m_Table) delete[] m_Table; }
64
65 // Initialize convertion. Both output or input encoding may
66 // be wxFONTENCODING_UNICODE, but only if wxUSE_WCHAR_T is set to 1.
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 //
72 // You must call this method before calling Convert. You may call
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:
77 // wxCONVERT_STRICT --
78 // follow behaviour of GNU Recode - just copy unconvertable
79 // characters to output and don't change them (it's integer
80 // value will stay the same)
81 // wxCONVERT_SUBSTITUTE --
82 // try some (lossy) substitutions - e.g. replace
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
90 // to Unicode with non-Unicode build of wxWindows or if input
91 // or output encoding is not supported.)
92 bool Init(wxFontEncoding input_enc, wxFontEncoding output_enc, int method = wxCONVERT_STRICT);
93
94 // Convert input string according to settings passed to Init.
95 // Note that you must call Init before using Convert!
96 void Convert(const char* input, char* output);
97 void Convert(char* str) { Convert(str, str); }
98 wxString Convert(const wxString& input);
99
100#if wxUSE_WCHAR_T
101 void Convert(const char* input, wchar_t* output);
102 void Convert(const wchar_t* input, char* output);
103 void Convert(const wchar_t* input, wchar_t* output);
104 void Convert(wchar_t* str) { Convert(str, str); }
105#endif
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).
123 //
124 // Convert() method is not limited to converting between
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
137 // Similar to GetPlatformEquivalent, but this one will return ALL
138 // equivalent encodings, regardless the platform, including itself.
139 static wxFontEncodingArray GetAllEquivalents(wxFontEncoding enc);
140
141 private:
142
143#if wxUSE_WCHAR_T
144 wchar_t *m_Table;
145#else
146 char *m_Table;
147#endif
148 bool m_UnicodeInput, m_UnicodeOutput;
149 bool m_JustCopy;
150
151};
152
153#endif // wxUSE_FONTMAP
154
155#endif // _WX_ENCCONV_H_