Charcode.cs 14 KB

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