001: /*
002: * $Id: EntitiesToSymbol.java 2748 2007-05-12 15:11:48Z blowagie $
003: * $Name$
004: *
005: * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie.
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: */
050:
051: package com.lowagie.text.xml.simpleparser;
052:
053: import java.util.HashMap;
054:
055: import com.lowagie.text.Chunk;
056: import com.lowagie.text.Font;
057:
058: /**
059: * This class contains entities that can be used in an entity tag.
060: */
061:
062: public class EntitiesToSymbol {
063:
064: /**
065: * This is a map that contains all possible id values of the entity tag
066: * that can be translated to a character in font Symbol.
067: */
068: public static final HashMap map;
069:
070: static {
071: map = new HashMap();
072: map.put("169", new Character((char) 227));
073: map.put("172", new Character((char) 216));
074: map.put("174", new Character((char) 210));
075: map.put("177", new Character((char) 177));
076: map.put("215", new Character((char) 180));
077: map.put("247", new Character((char) 184));
078: map.put("8230", new Character((char) 188));
079: map.put("8242", new Character((char) 162));
080: map.put("8243", new Character((char) 178));
081: map.put("8260", new Character((char) 164));
082: map.put("8364", new Character((char) 240));
083: map.put("8465", new Character((char) 193));
084: map.put("8472", new Character((char) 195));
085: map.put("8476", new Character((char) 194));
086: map.put("8482", new Character((char) 212));
087: map.put("8501", new Character((char) 192));
088: map.put("8592", new Character((char) 172));
089: map.put("8593", new Character((char) 173));
090: map.put("8594", new Character((char) 174));
091: map.put("8595", new Character((char) 175));
092: map.put("8596", new Character((char) 171));
093: map.put("8629", new Character((char) 191));
094: map.put("8656", new Character((char) 220));
095: map.put("8657", new Character((char) 221));
096: map.put("8658", new Character((char) 222));
097: map.put("8659", new Character((char) 223));
098: map.put("8660", new Character((char) 219));
099: map.put("8704", new Character((char) 34));
100: map.put("8706", new Character((char) 182));
101: map.put("8707", new Character((char) 36));
102: map.put("8709", new Character((char) 198));
103: map.put("8711", new Character((char) 209));
104: map.put("8712", new Character((char) 206));
105: map.put("8713", new Character((char) 207));
106: map.put("8717", new Character((char) 39));
107: map.put("8719", new Character((char) 213));
108: map.put("8721", new Character((char) 229));
109: map.put("8722", new Character((char) 45));
110: map.put("8727", new Character((char) 42));
111: map.put("8729", new Character((char) 183));
112: map.put("8730", new Character((char) 214));
113: map.put("8733", new Character((char) 181));
114: map.put("8734", new Character((char) 165));
115: map.put("8736", new Character((char) 208));
116: map.put("8743", new Character((char) 217));
117: map.put("8744", new Character((char) 218));
118: map.put("8745", new Character((char) 199));
119: map.put("8746", new Character((char) 200));
120: map.put("8747", new Character((char) 242));
121: map.put("8756", new Character((char) 92));
122: map.put("8764", new Character((char) 126));
123: map.put("8773", new Character((char) 64));
124: map.put("8776", new Character((char) 187));
125: map.put("8800", new Character((char) 185));
126: map.put("8801", new Character((char) 186));
127: map.put("8804", new Character((char) 163));
128: map.put("8805", new Character((char) 179));
129: map.put("8834", new Character((char) 204));
130: map.put("8835", new Character((char) 201));
131: map.put("8836", new Character((char) 203));
132: map.put("8838", new Character((char) 205));
133: map.put("8839", new Character((char) 202));
134: map.put("8853", new Character((char) 197));
135: map.put("8855", new Character((char) 196));
136: map.put("8869", new Character((char) 94));
137: map.put("8901", new Character((char) 215));
138: map.put("8992", new Character((char) 243));
139: map.put("8993", new Character((char) 245));
140: map.put("9001", new Character((char) 225));
141: map.put("9002", new Character((char) 241));
142: map.put("913", new Character((char) 65));
143: map.put("914", new Character((char) 66));
144: map.put("915", new Character((char) 71));
145: map.put("916", new Character((char) 68));
146: map.put("917", new Character((char) 69));
147: map.put("918", new Character((char) 90));
148: map.put("919", new Character((char) 72));
149: map.put("920", new Character((char) 81));
150: map.put("921", new Character((char) 73));
151: map.put("922", new Character((char) 75));
152: map.put("923", new Character((char) 76));
153: map.put("924", new Character((char) 77));
154: map.put("925", new Character((char) 78));
155: map.put("926", new Character((char) 88));
156: map.put("927", new Character((char) 79));
157: map.put("928", new Character((char) 80));
158: map.put("929", new Character((char) 82));
159: map.put("931", new Character((char) 83));
160: map.put("932", new Character((char) 84));
161: map.put("933", new Character((char) 85));
162: map.put("934", new Character((char) 70));
163: map.put("935", new Character((char) 67));
164: map.put("936", new Character((char) 89));
165: map.put("937", new Character((char) 87));
166: map.put("945", new Character((char) 97));
167: map.put("946", new Character((char) 98));
168: map.put("947", new Character((char) 103));
169: map.put("948", new Character((char) 100));
170: map.put("949", new Character((char) 101));
171: map.put("950", new Character((char) 122));
172: map.put("951", new Character((char) 104));
173: map.put("952", new Character((char) 113));
174: map.put("953", new Character((char) 105));
175: map.put("954", new Character((char) 107));
176: map.put("955", new Character((char) 108));
177: map.put("956", new Character((char) 109));
178: map.put("957", new Character((char) 110));
179: map.put("958", new Character((char) 120));
180: map.put("959", new Character((char) 111));
181: map.put("960", new Character((char) 112));
182: map.put("961", new Character((char) 114));
183: map.put("962", new Character((char) 86));
184: map.put("963", new Character((char) 115));
185: map.put("964", new Character((char) 116));
186: map.put("965", new Character((char) 117));
187: map.put("966", new Character((char) 102));
188: map.put("967", new Character((char) 99));
189: map.put("9674", new Character((char) 224));
190: map.put("968", new Character((char) 121));
191: map.put("969", new Character((char) 119));
192: map.put("977", new Character((char) 74));
193: map.put("978", new Character((char) 161));
194: map.put("981", new Character((char) 106));
195: map.put("982", new Character((char) 118));
196: map.put("9824", new Character((char) 170));
197: map.put("9827", new Character((char) 167));
198: map.put("9829", new Character((char) 169));
199: map.put("9830", new Character((char) 168));
200: map.put("Alpha", new Character((char) 65));
201: map.put("Beta", new Character((char) 66));
202: map.put("Chi", new Character((char) 67));
203: map.put("Delta", new Character((char) 68));
204: map.put("Epsilon", new Character((char) 69));
205: map.put("Eta", new Character((char) 72));
206: map.put("Gamma", new Character((char) 71));
207: map.put("Iota", new Character((char) 73));
208: map.put("Kappa", new Character((char) 75));
209: map.put("Lambda", new Character((char) 76));
210: map.put("Mu", new Character((char) 77));
211: map.put("Nu", new Character((char) 78));
212: map.put("Omega", new Character((char) 87));
213: map.put("Omicron", new Character((char) 79));
214: map.put("Phi", new Character((char) 70));
215: map.put("Pi", new Character((char) 80));
216: map.put("Prime", new Character((char) 178));
217: map.put("Psi", new Character((char) 89));
218: map.put("Rho", new Character((char) 82));
219: map.put("Sigma", new Character((char) 83));
220: map.put("Tau", new Character((char) 84));
221: map.put("Theta", new Character((char) 81));
222: map.put("Upsilon", new Character((char) 85));
223: map.put("Xi", new Character((char) 88));
224: map.put("Zeta", new Character((char) 90));
225: map.put("alefsym", new Character((char) 192));
226: map.put("alpha", new Character((char) 97));
227: map.put("and", new Character((char) 217));
228: map.put("ang", new Character((char) 208));
229: map.put("asymp", new Character((char) 187));
230: map.put("beta", new Character((char) 98));
231: map.put("cap", new Character((char) 199));
232: map.put("chi", new Character((char) 99));
233: map.put("clubs", new Character((char) 167));
234: map.put("cong", new Character((char) 64));
235: map.put("copy", new Character((char) 211));
236: map.put("crarr", new Character((char) 191));
237: map.put("cup", new Character((char) 200));
238: map.put("dArr", new Character((char) 223));
239: map.put("darr", new Character((char) 175));
240: map.put("delta", new Character((char) 100));
241: map.put("diams", new Character((char) 168));
242: map.put("divide", new Character((char) 184));
243: map.put("empty", new Character((char) 198));
244: map.put("epsilon", new Character((char) 101));
245: map.put("equiv", new Character((char) 186));
246: map.put("eta", new Character((char) 104));
247: map.put("euro", new Character((char) 240));
248: map.put("exist", new Character((char) 36));
249: map.put("forall", new Character((char) 34));
250: map.put("frasl", new Character((char) 164));
251: map.put("gamma", new Character((char) 103));
252: map.put("ge", new Character((char) 179));
253: map.put("hArr", new Character((char) 219));
254: map.put("harr", new Character((char) 171));
255: map.put("hearts", new Character((char) 169));
256: map.put("hellip", new Character((char) 188));
257: map.put("horizontal arrow extender", new Character((char) 190));
258: map.put("image", new Character((char) 193));
259: map.put("infin", new Character((char) 165));
260: map.put("int", new Character((char) 242));
261: map.put("iota", new Character((char) 105));
262: map.put("isin", new Character((char) 206));
263: map.put("kappa", new Character((char) 107));
264: map.put("lArr", new Character((char) 220));
265: map.put("lambda", new Character((char) 108));
266: map.put("lang", new Character((char) 225));
267: map.put("large brace extender", new Character((char) 239));
268: map.put("large integral extender", new Character((char) 244));
269: map.put("large left brace (bottom)", new Character((char) 238));
270: map.put("large left brace (middle)", new Character((char) 237));
271: map.put("large left brace (top)", new Character((char) 236));
272: map.put("large left bracket (bottom)",
273: new Character((char) 235));
274: map.put("large left bracket (extender)", new Character(
275: (char) 234));
276: map.put("large left bracket (top)", new Character((char) 233));
277: map.put("large left parenthesis (bottom)", new Character(
278: (char) 232));
279: map.put("large left parenthesis (extender)", new Character(
280: (char) 231));
281: map.put("large left parenthesis (top)", new Character(
282: (char) 230));
283: map
284: .put("large right brace (bottom)", new Character(
285: (char) 254));
286: map
287: .put("large right brace (middle)", new Character(
288: (char) 253));
289: map.put("large right brace (top)", new Character((char) 252));
290: map.put("large right bracket (bottom)", new Character(
291: (char) 251));
292: map.put("large right bracket (extender)", new Character(
293: (char) 250));
294: map.put("large right bracket (top)", new Character((char) 249));
295: map.put("large right parenthesis (bottom)", new Character(
296: (char) 248));
297: map.put("large right parenthesis (extender)", new Character(
298: (char) 247));
299: map.put("large right parenthesis (top)", new Character(
300: (char) 246));
301: map.put("larr", new Character((char) 172));
302: map.put("le", new Character((char) 163));
303: map.put("lowast", new Character((char) 42));
304: map.put("loz", new Character((char) 224));
305: map.put("minus", new Character((char) 45));
306: map.put("mu", new Character((char) 109));
307: map.put("nabla", new Character((char) 209));
308: map.put("ne", new Character((char) 185));
309: map.put("not", new Character((char) 216));
310: map.put("notin", new Character((char) 207));
311: map.put("nsub", new Character((char) 203));
312: map.put("nu", new Character((char) 110));
313: map.put("omega", new Character((char) 119));
314: map.put("omicron", new Character((char) 111));
315: map.put("oplus", new Character((char) 197));
316: map.put("or", new Character((char) 218));
317: map.put("otimes", new Character((char) 196));
318: map.put("part", new Character((char) 182));
319: map.put("perp", new Character((char) 94));
320: map.put("phi", new Character((char) 102));
321: map.put("pi", new Character((char) 112));
322: map.put("piv", new Character((char) 118));
323: map.put("plusmn", new Character((char) 177));
324: map.put("prime", new Character((char) 162));
325: map.put("prod", new Character((char) 213));
326: map.put("prop", new Character((char) 181));
327: map.put("psi", new Character((char) 121));
328: map.put("rArr", new Character((char) 222));
329: map.put("radic", new Character((char) 214));
330: map.put("radical extender", new Character((char) 96));
331: map.put("rang", new Character((char) 241));
332: map.put("rarr", new Character((char) 174));
333: map.put("real", new Character((char) 194));
334: map.put("reg", new Character((char) 210));
335: map.put("rho", new Character((char) 114));
336: map.put("sdot", new Character((char) 215));
337: map.put("sigma", new Character((char) 115));
338: map.put("sigmaf", new Character((char) 86));
339: map.put("sim", new Character((char) 126));
340: map.put("spades", new Character((char) 170));
341: map.put("sub", new Character((char) 204));
342: map.put("sube", new Character((char) 205));
343: map.put("sum", new Character((char) 229));
344: map.put("sup", new Character((char) 201));
345: map.put("supe", new Character((char) 202));
346: map.put("tau", new Character((char) 116));
347: map.put("there4", new Character((char) 92));
348: map.put("theta", new Character((char) 113));
349: map.put("thetasym", new Character((char) 74));
350: map.put("times", new Character((char) 180));
351: map.put("trade", new Character((char) 212));
352: map.put("uArr", new Character((char) 221));
353: map.put("uarr", new Character((char) 173));
354: map.put("upsih", new Character((char) 161));
355: map.put("upsilon", new Character((char) 117));
356: map.put("vertical arrow extender", new Character((char) 189));
357: map.put("weierp", new Character((char) 195));
358: map.put("xi", new Character((char) 120));
359: map.put("zeta", new Character((char) 122));
360: }
361:
362: /**
363: * Gets a chunk with a symbol character.
364: * @param e a symbol value (see Entities class: alfa is greek alfa,...)
365: * @param font the font if the symbol isn't found (otherwise Font.SYMBOL)
366: * @return a Chunk
367: */
368: public static Chunk get(String e, Font font) {
369: char s = getCorrespondingSymbol(e);
370: if (s == (char) 0) {
371: try {
372: return new Chunk(String.valueOf((char) Integer
373: .parseInt(e)), font);
374: } catch (Exception exception) {
375: return new Chunk(e, font);
376: }
377: }
378: Font symbol = new Font(Font.SYMBOL, font.getSize(), font
379: .getStyle(), font.getColor());
380: return new Chunk(String.valueOf(s), symbol);
381: }
382:
383: /**
384: * Looks for the corresponding symbol in the font Symbol.
385: *
386: * @param name the name of the entity
387: * @return the corresponding character in font Symbol
388: */
389: public static char getCorrespondingSymbol(String name) {
390: Character symbol = (Character) map.get(name);
391: if (symbol == null) {
392: return (char) 0;
393: }
394: return symbol.charValue();
395: }
396: }
|