Charcode.cs 16 KB

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