2007-01-16 Rolf Bjarne Kvinge <RKvinge@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.RTF / Charcode.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    (pbartok@novell.com)
24 //
25 //
26
27 // COMPLETE
28
29 using System.Collections;
30
31 namespace System.Windows.Forms.RTF {
32         internal class Charcode {
33                 #region Local Variables
34                 private StandardCharCode[]      codes;
35                 private Hashtable               reverse;
36                 private int                     size;
37                 #endregion      // Local Variables
38
39                 #region Public Constructors
40                 public Charcode() : this(256) {
41                 }
42
43                 private Charcode(int size) {
44                         this.size = size;
45                         this.codes = new StandardCharCode[size];
46                         this.reverse = new Hashtable(size);
47
48                         for (int i = 0; i < size; i++) {
49                                 codes[i] = StandardCharCode.nothing;
50                         }
51                 }
52                 #endregion      // Public Constructors
53
54                 #region Public Instance Properties
55                 public int this[StandardCharCode c] {
56                         get {
57                                 object obj;
58
59                                 obj = reverse[c];
60                                 if (obj != null) {
61                                         return (int)obj;
62                                 }
63                                 for (int i = 0; i < size; i++) {
64                                         if (codes[i] == c) {
65                                                 return i;
66                                         }
67                                 }
68
69                                 return -1;
70                         }
71                 }
72
73                 public StandardCharCode this[int c] {
74                         get {
75                                 if (c < 0 || c >= size) {
76                                         return StandardCharCode.nothing;
77                                 }
78
79                                 return codes[c];
80                         }
81
82                         set {
83                                 if (c < 0 || c >= size) {
84                                         return;
85                                 }
86
87                                 codes[c] = value;
88                                 reverse[value] = c;
89                         }
90                 }
91                 #endregion      // Public Instance Properties
92
93                 #region Public Instance Methods
94                 #endregion      // Public Instance Methods
95
96                 #region Public Static Methods
97                 public static Charcode AnsiGeneric {
98                         get {
99                                 Charcode code = new Charcode(256);
100
101                                 code[0x06] = StandardCharCode.formula;
102                                 code[0x1e] =  StandardCharCode.nobrkhyphen;
103                                 code[0x1f] = StandardCharCode.opthyphen;
104                                 code[' '] = StandardCharCode.space;
105                                 code['!'] = StandardCharCode.exclam;
106                                 code['"'] = StandardCharCode.quotedbl;
107                                 code['#'] = StandardCharCode.numbersign;
108                                 code['$'] = StandardCharCode.dollar;
109                                 code['%'] = StandardCharCode.percent;
110                                 code['&'] = StandardCharCode.ampersand;
111                                 code['\\'] = StandardCharCode.quoteright;
112                                 code['('] = StandardCharCode.parenleft;
113                                 code[')'] = StandardCharCode.parenright;
114                                 code['*'] = StandardCharCode.asterisk;
115                                 code['+'] = StandardCharCode.plus;
116                                 code[','] = StandardCharCode.comma;
117                                 code['-'] = StandardCharCode.hyphen;
118                                 code['.'] = StandardCharCode.period;
119                                 code['/'] = StandardCharCode.slash;
120                                 code['0'] = StandardCharCode.zero;
121                                 code['1'] = StandardCharCode.one;
122                                 code['2'] = StandardCharCode.two;
123                                 code['3'] = StandardCharCode.three;
124                                 code['4'] = StandardCharCode.four;
125                                 code['5'] = StandardCharCode.five;
126                                 code['6'] = StandardCharCode.six;
127                                 code['7'] = StandardCharCode.seven;
128                                 code['8'] = StandardCharCode.eight;
129                                 code['9'] = StandardCharCode.nine;
130                                 code[':'] = StandardCharCode.colon;
131                                 code[';'] = StandardCharCode.semicolon;
132                                 code['<'] = StandardCharCode.less;
133                                 code['='] = StandardCharCode.equal;
134                                 code['>'] = StandardCharCode.greater;
135                                 code['?'] = StandardCharCode.question;
136                                 code['@'] = StandardCharCode.at;
137                                 code['A'] = StandardCharCode.A;
138                                 code['B'] = StandardCharCode.B;
139                                 code['C'] = StandardCharCode.C;
140                                 code['D'] = StandardCharCode.D;
141                                 code['E'] = StandardCharCode.E;
142                                 code['F'] = StandardCharCode.F;
143                                 code['G'] = StandardCharCode.G;
144                                 code['H'] = StandardCharCode.H;
145                                 code['I'] = StandardCharCode.I;
146                                 code['J'] = StandardCharCode.J;
147                                 code['K'] = StandardCharCode.K;
148                                 code['L'] = StandardCharCode.L;
149                                 code['M'] = StandardCharCode.M;
150                                 code['N'] = StandardCharCode.N;
151                                 code['O'] = StandardCharCode.O;
152                                 code['P'] = StandardCharCode.P;
153                                 code['Q'] = StandardCharCode.Q;
154                                 code['R'] = StandardCharCode.R;
155                                 code['S'] = StandardCharCode.S;
156                                 code['T'] = StandardCharCode.T;
157                                 code['U'] = StandardCharCode.U;
158                                 code['V'] = StandardCharCode.V;
159                                 code['W'] = StandardCharCode.W;
160                                 code['X'] = StandardCharCode.X;
161                                 code['Y'] = StandardCharCode.Y;
162                                 code['Z'] = StandardCharCode.Z;
163                                 code['['] = StandardCharCode.bracketleft;
164                                 code['\\'] = StandardCharCode.backslash;
165                                 code[']'] = StandardCharCode.bracketright;
166                                 code['^'] = StandardCharCode.asciicircum;
167                                 code['_'] = StandardCharCode.underscore;
168                                 code['`'] = StandardCharCode.quoteleft;
169                                 code['a'] = StandardCharCode.a;
170                                 code['b'] = StandardCharCode.b;
171                                 code['c'] = StandardCharCode.c;
172                                 code['d'] = StandardCharCode.d;
173                                 code['e'] = StandardCharCode.e;
174                                 code['f'] = StandardCharCode.f;
175                                 code['g'] = StandardCharCode.g;
176                                 code['h'] = StandardCharCode.h;
177                                 code['i'] = StandardCharCode.i;
178                                 code['j'] = StandardCharCode.j;
179                                 code['k'] = StandardCharCode.k;
180                                 code['l'] = StandardCharCode.l;
181                                 code['m'] = StandardCharCode.m;
182                                 code['n'] = StandardCharCode.n;
183                                 code['o'] = StandardCharCode.o;
184                                 code['p'] = StandardCharCode.p;
185                                 code['q'] = StandardCharCode.q;
186                                 code['r'] = StandardCharCode.r;
187                                 code['s'] = StandardCharCode.s;
188                                 code['t'] = StandardCharCode.t;
189                                 code['u'] = StandardCharCode.u;
190                                 code['v'] = StandardCharCode.v;
191                                 code['w'] = StandardCharCode.w;
192                                 code['x'] = StandardCharCode.x;
193                                 code['y'] = StandardCharCode.y;
194                                 code['z'] = StandardCharCode.z;
195                                 code['{'] = StandardCharCode.braceleft;
196                                 code['|'] = StandardCharCode.bar;
197                                 code['}'] = StandardCharCode.braceright;
198                                 code['~'] = StandardCharCode.asciitilde;
199                                 code[0xa0] = StandardCharCode.nobrkspace;
200                                 code[0xa1] = StandardCharCode.exclamdown;
201                                 code[0xa2] = StandardCharCode.cent;
202                                 code[0xa3] = StandardCharCode.sterling;
203                                 code[0xa4] = StandardCharCode.currency;
204                                 code[0xa5] = StandardCharCode.yen;
205                                 code[0xa6] = StandardCharCode.brokenbar;
206                                 code[0xa7] = StandardCharCode.section;
207                                 code[0xa8] = StandardCharCode.dieresis;
208                                 code[0xa9] = StandardCharCode.copyright;
209                                 code[0xaa] = StandardCharCode.ordfeminine;
210                                 code[0xab] = StandardCharCode.guillemotleft;
211                                 code[0xac] = StandardCharCode.logicalnot;
212                                 code[0xad] = StandardCharCode.opthyphen;
213                                 code[0xae] = StandardCharCode.registered;
214                                 code[0xaf] = StandardCharCode.macron;
215                                 code[0xb0] = StandardCharCode.degree;
216                                 code[0xb1] = StandardCharCode.plusminus;
217                                 code[0xb2] = StandardCharCode.twosuperior;
218                                 code[0xb3] = StandardCharCode.threesuperior;
219                                 code[0xb4] = StandardCharCode.acute;
220                                 code[0xb5] = StandardCharCode.mu;
221                                 code[0xb6] = StandardCharCode.paragraph;
222                                 code[0xb7] = StandardCharCode.periodcentered;
223                                 code[0xb8] = StandardCharCode.cedilla;
224                                 code[0xb9] = StandardCharCode.onesuperior;
225                                 code[0xba] = StandardCharCode.ordmasculine;
226                                 code[0xbb] = StandardCharCode.guillemotright;
227                                 code[0xbc] = StandardCharCode.onequarter;
228                                 code[0xbd] = StandardCharCode.onehalf;
229                                 code[0xbe] = StandardCharCode.threequarters;
230                                 code[0xbf] = StandardCharCode.questiondown;
231                                 code[0xc0] = StandardCharCode.Agrave;
232                                 code[0xc1] = StandardCharCode.Aacute;
233                                 code[0xc2] = StandardCharCode.Acircumflex;
234                                 code[0xc3] = StandardCharCode.Atilde;
235                                 code[0xc4] = StandardCharCode.Adieresis;
236                                 code[0xc5] = StandardCharCode.Aring;
237                                 code[0xc6] = StandardCharCode.AE;
238                                 code[0xc7] = StandardCharCode.Ccedilla;
239                                 code[0xc8] = StandardCharCode.Egrave;
240                                 code[0xc9] = StandardCharCode.Eacute;
241                                 code[0xca] = StandardCharCode.Ecircumflex;
242                                 code[0xcb] = StandardCharCode.Edieresis;
243                                 code[0xcc] = StandardCharCode.Igrave;
244                                 code[0xcd] = StandardCharCode.Iacute;
245                                 code[0xce] = StandardCharCode.Icircumflex;
246                                 code[0xcf] = StandardCharCode.Idieresis;
247                                 code[0xd0] = StandardCharCode.Eth;
248                                 code[0xd1] = StandardCharCode.Ntilde;
249                                 code[0xd2] = StandardCharCode.Ograve;
250                                 code[0xd3] = StandardCharCode.Oacute;
251                                 code[0xd4] = StandardCharCode.Ocircumflex;
252                                 code[0xd5] = StandardCharCode.Otilde;
253                                 code[0xd6] = StandardCharCode.Odieresis;
254                                 code[0xd7] = StandardCharCode.multiply;
255                                 code[0xd8] = StandardCharCode.Oslash;
256                                 code[0xd9] = StandardCharCode.Ugrave;
257                                 code[0xda] = StandardCharCode.Uacute;
258                                 code[0xdb] = StandardCharCode.Ucircumflex;
259                                 code[0xdc] = StandardCharCode.Udieresis;
260                                 code[0xdd] = StandardCharCode.Yacute;
261                                 code[0xde] = StandardCharCode.Thorn;
262                                 code[0xdf] = StandardCharCode.germandbls;
263                                 code[0xe0] = StandardCharCode.agrave;
264                                 code[0xe1] = StandardCharCode.aacute;
265                                 code[0xe2] = StandardCharCode.acircumflex;
266                                 code[0xe3] = StandardCharCode.atilde;
267                                 code[0xe4] = StandardCharCode.adieresis;
268                                 code[0xe5] = StandardCharCode.aring;
269                                 code[0xe6] = StandardCharCode.ae;
270                                 code[0xe7] = StandardCharCode.ccedilla;
271                                 code[0xe8] = StandardCharCode.egrave;
272                                 code[0xe9] = StandardCharCode.eacute;
273                                 code[0xea] = StandardCharCode.ecircumflex;
274                                 code[0xeb] = StandardCharCode.edieresis;
275                                 code[0xec] = StandardCharCode.igrave;
276                                 code[0xed] = StandardCharCode.iacute;
277                                 code[0xee] = StandardCharCode.icircumflex;
278                                 code[0xef] = StandardCharCode.idieresis;
279                                 code[0xf0] = StandardCharCode.eth;
280                                 code[0xf1] = StandardCharCode.ntilde;
281                                 code[0xf2] = StandardCharCode.ograve;
282                                 code[0xf3] = StandardCharCode.oacute;
283                                 code[0xf4] = StandardCharCode.ocircumflex;
284                                 code[0xf5] = StandardCharCode.otilde;
285                                 code[0xf6] = StandardCharCode.odieresis;
286                                 code[0xf7] = StandardCharCode.divide;
287                                 code[0xf8] = StandardCharCode.oslash;
288                                 code[0xf9] = StandardCharCode.ugrave;
289                                 code[0xfa] = StandardCharCode.uacute;
290                                 code[0xfb] = StandardCharCode.ucircumflex;
291                                 code[0xfc] = StandardCharCode.udieresis;
292                                 code[0xfd] = StandardCharCode.yacute;
293                                 code[0xfe] = StandardCharCode.thorn;
294                                 code[0xff] = StandardCharCode.ydieresis;
295
296                                 return code;
297                         }
298                 }
299
300                 public static Charcode AnsiSymbol {
301                         get {
302                                 Charcode code = new Charcode(256);
303
304                                 code[0x06] = StandardCharCode.formula;
305                                 code[0x1e] = StandardCharCode.nobrkhyphen;
306                                 code[0x1f] = StandardCharCode.opthyphen;
307                                 code[' '] = StandardCharCode.space;
308                                 code['!'] = StandardCharCode.exclam;
309                                 code['"'] = StandardCharCode.universal;
310                                 code['#'] = StandardCharCode.mathnumbersign;
311                                 code['$'] = StandardCharCode.existential;
312                                 code['%'] = StandardCharCode.percent;
313                                 code['&'] = StandardCharCode.ampersand;
314                                 code['\\'] = StandardCharCode.suchthat;
315                                 code['('] = StandardCharCode.parenleft;
316                                 code[')'] = StandardCharCode.parenright;
317                                 code['*'] = StandardCharCode.mathasterisk;
318                                 code['+'] = StandardCharCode.mathplus;
319                                 code[','] = StandardCharCode.comma;
320                                 code['-'] = StandardCharCode.mathminus;
321                                 code['.'] = StandardCharCode.period;
322                                 code['/'] = StandardCharCode.slash;
323                                 code['0'] = StandardCharCode.zero;
324                                 code['1'] = StandardCharCode.one;
325                                 code['2'] = StandardCharCode.two;
326                                 code['3'] = StandardCharCode.three;
327                                 code['4'] = StandardCharCode.four;
328                                 code['5'] = StandardCharCode.five;
329                                 code['6'] = StandardCharCode.six;
330                                 code['7'] = StandardCharCode.seven;
331                                 code['8'] = StandardCharCode.eight;
332                                 code['9'] = StandardCharCode.nine;
333                                 code[':'] = StandardCharCode.colon;
334                                 code[';'] = StandardCharCode.semicolon;
335                                 code['<'] = StandardCharCode.less;
336                                 code['='] = StandardCharCode.mathequal;
337                                 code['>'] = StandardCharCode.greater;
338                                 code['?'] = StandardCharCode.question;
339                                 code['@'] = StandardCharCode.congruent;
340                                 code['A'] = StandardCharCode.Alpha;
341                                 code['B'] = StandardCharCode.Beta;
342                                 code['C'] = StandardCharCode.Chi;
343                                 code['D'] = StandardCharCode.Delta;
344                                 code['E'] = StandardCharCode.Epsilon;
345                                 code['F'] = StandardCharCode.Phi;
346                                 code['G'] = StandardCharCode.Gamma;
347                                 code['H'] = StandardCharCode.Eta;
348                                 code['I'] = StandardCharCode.Iota;
349                                 code['K'] = StandardCharCode.Kappa;
350                                 code['L'] = StandardCharCode.Lambda;
351                                 code['M'] = StandardCharCode.Mu;
352                                 code['N'] = StandardCharCode.Nu;
353                                 code['O'] = StandardCharCode.Omicron;
354                                 code['P'] = StandardCharCode.Pi;
355                                 code['Q'] = StandardCharCode.Theta;
356                                 code['R'] = StandardCharCode.Rho;
357                                 code['S'] = StandardCharCode.Sigma;
358                                 code['T'] = StandardCharCode.Tau;
359                                 code['U'] = StandardCharCode.Upsilon;
360                                 code['V'] = StandardCharCode.varsigma;
361                                 code['W'] = StandardCharCode.Omega;
362                                 code['X'] = StandardCharCode.Xi;
363                                 code['Y'] = StandardCharCode.Psi;
364                                 code['Z'] = StandardCharCode.Zeta;
365                                 code['['] = StandardCharCode.bracketleft;
366                                 code['\\'] = StandardCharCode.backslash;
367                                 code[']'] = StandardCharCode.bracketright;
368                                 code['^'] = StandardCharCode.asciicircum;
369                                 code['_'] = StandardCharCode.underscore;
370                                 code['`'] = StandardCharCode.quoteleft;
371                                 code['a'] = StandardCharCode.alpha;
372                                 code['b'] = StandardCharCode.beta;
373                                 code['c'] = StandardCharCode.chi;
374                                 code['d'] = StandardCharCode.delta;
375                                 code['e'] = StandardCharCode.epsilon;
376                                 code['f'] = StandardCharCode.phi;
377                                 code['g'] = StandardCharCode.gamma;
378                                 code['h'] = StandardCharCode.eta;
379                                 code['i'] = StandardCharCode.iota;
380                                 code['k'] = StandardCharCode.kappa;
381                                 code['l'] = StandardCharCode.lambda;
382                                 code['m'] = StandardCharCode.mu;
383                                 code['n'] = StandardCharCode.nu;
384                                 code['o'] = StandardCharCode.omicron;
385                                 code['p'] = StandardCharCode.pi;
386                                 code['q'] = StandardCharCode.theta;
387                                 code['r'] = StandardCharCode.rho;
388                                 code['s'] = StandardCharCode.sigma;
389                                 code['t'] = StandardCharCode.tau;
390                                 code['u'] = StandardCharCode.upsilon;
391                                 code['w'] = StandardCharCode.omega;
392                                 code['x'] = StandardCharCode.xi;
393                                 code['y'] = StandardCharCode.psi;
394                                 code['z'] = StandardCharCode.zeta;
395                                 code['{'] = StandardCharCode.braceleft;
396                                 code['|'] = StandardCharCode.bar;
397                                 code['}'] = StandardCharCode.braceright;
398                                 code['~'] = StandardCharCode.mathtilde;
399
400                                 return code;
401                         }
402                 }
403                 #endregion      // Public Static Methods
404         }
405 }