001: /*
002: * $Id: SpecialSymbol.java 2748 2007-05-12 15:11:48Z blowagie $
003: * $Name$
004: *
005: * Copyright 1999, 2000, 2001, 2002 by 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;
052:
053: /**
054: * This class contains the symbols that correspond with special symbols.
055: * <P>
056: * When you construct a <CODE>Phrase</CODE> with Phrase.getInstance using a <CODE>String</CODE>,
057: * this <CODE>String</CODE> can contain special Symbols. These are characters with an int value
058: * between 913 and 937 (except 930) and between 945 and 969. With this class the value of the
059: * corresponding character of the Font Symbol, can be retrieved.
060: *
061: * @see Phrase
062: *
063: * @author Bruno Lowagie
064: * @author Evelyne De Cordier
065: */
066:
067: public class SpecialSymbol {
068:
069: /**
070: * Returns the first occurrence of a special symbol in a <CODE>String</CODE>.
071: *
072: * @param string a <CODE>String</CODE>
073: * @return an index of -1 if no special symbol was found
074: */
075: public static int index(String string) {
076: int length = string.length();
077: for (int i = 0; i < length; i++) {
078: if (getCorrespondingSymbol(string.charAt(i)) != ' ') {
079: return i;
080: }
081: }
082: return -1;
083: }
084:
085: /**
086: * Gets a chunk with a symbol character.
087: * @param c a character that has to be changed into a symbol
088: * @param font Font if there is no SYMBOL character corresponding with c
089: * @return a SYMBOL version of a character
090: */
091: public static Chunk get(char c, Font font) {
092: char greek = SpecialSymbol.getCorrespondingSymbol(c);
093: if (greek == ' ') {
094: return new Chunk(String.valueOf(c), font);
095: }
096: Font symbol = new Font(Font.SYMBOL, font.getSize(), font
097: .getStyle(), font.getColor());
098: String s = String.valueOf(greek);
099: return new Chunk(s, symbol);
100: }
101:
102: /**
103: * Looks for the corresponding symbol in the font Symbol.
104: *
105: * @param c the original ASCII-char
106: * @return the corresponding symbol in font Symbol
107: */
108: public static char getCorrespondingSymbol(char c) {
109: switch (c) {
110: case 913:
111: return 'A'; // ALFA
112: case 914:
113: return 'B'; // BETA
114: case 915:
115: return 'G'; // GAMMA
116: case 916:
117: return 'D'; // DELTA
118: case 917:
119: return 'E'; // EPSILON
120: case 918:
121: return 'Z'; // ZETA
122: case 919:
123: return 'H'; // ETA
124: case 920:
125: return 'Q'; // THETA
126: case 921:
127: return 'I'; // IOTA
128: case 922:
129: return 'K'; // KAPPA
130: case 923:
131: return 'L'; // LAMBDA
132: case 924:
133: return 'M'; // MU
134: case 925:
135: return 'N'; // NU
136: case 926:
137: return 'X'; // XI
138: case 927:
139: return 'O'; // OMICRON
140: case 928:
141: return 'P'; // PI
142: case 929:
143: return 'R'; // RHO
144: case 931:
145: return 'S'; // SIGMA
146: case 932:
147: return 'T'; // TAU
148: case 933:
149: return 'U'; // UPSILON
150: case 934:
151: return 'J'; // PHI
152: case 935:
153: return 'C'; // CHI
154: case 936:
155: return 'Y'; // PSI
156: case 937:
157: return 'W'; // OMEGA
158: case 945:
159: return 'a'; // alfa
160: case 946:
161: return 'b'; // beta
162: case 947:
163: return 'g'; // gamma
164: case 948:
165: return 'd'; // delta
166: case 949:
167: return 'e'; // epsilon
168: case 950:
169: return 'z'; // zeta
170: case 951:
171: return 'h'; // eta
172: case 952:
173: return 'q'; // theta
174: case 953:
175: return 'i'; // iota
176: case 954:
177: return 'k'; // kappa
178: case 955:
179: return 'l'; // lambda
180: case 956:
181: return 'm'; // mu
182: case 957:
183: return 'n'; // nu
184: case 958:
185: return 'x'; // xi
186: case 959:
187: return 'o'; // omicron
188: case 960:
189: return 'p'; // pi
190: case 961:
191: return 'r'; // rho
192: case 962:
193: return 'V'; // sigma
194: case 963:
195: return 's'; // sigma
196: case 964:
197: return 't'; // tau
198: case 965:
199: return 'u'; // upsilon
200: case 966:
201: return 'j'; // phi
202: case 967:
203: return 'c'; // chi
204: case 968:
205: return 'y'; // psi
206: case 969:
207: return 'w'; // omega
208: default:
209: return ' ';
210: }
211: }
212: }
|