KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > SpecialSymbol


1 /*
2  * $Id: SpecialSymbol.java 2748 2007-05-12 15:11:48Z blowagie $
3  * $Name$
4  *
5  * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text;
52
53 /**
54  * This class contains the symbols that correspond with special symbols.
55  * <P>
56  * When you construct a <CODE>Phrase</CODE> with Phrase.getInstance using a <CODE>String</CODE>,
57  * this <CODE>String</CODE> can contain special Symbols. These are characters with an int value
58  * between 913 and 937 (except 930) and between 945 and 969. With this class the value of the
59  * corresponding character of the Font Symbol, can be retrieved.
60  *
61  * @see Phrase
62  *
63  * @author Bruno Lowagie
64  * @author Evelyne De Cordier
65  */

66
67 public class SpecialSymbol {
68     
69     /**
70      * Returns the first occurrence of a special symbol in a <CODE>String</CODE>.
71      *
72      * @param string a <CODE>String</CODE>
73      * @return an index of -1 if no special symbol was found
74      */

75     public static int index(String JavaDoc string) {
76         int length = string.length();
77         for (int i = 0; i < length; i++) {
78             if (getCorrespondingSymbol(string.charAt(i)) != ' ') {
79                 return i;
80             }
81         }
82         return -1;
83     }
84     
85     /**
86      * Gets a chunk with a symbol character.
87      * @param c a character that has to be changed into a symbol
88      * @param font Font if there is no SYMBOL character corresponding with c
89      * @return a SYMBOL version of a character
90      */

91     public static Chunk get(char c, Font font) {
92         char greek = SpecialSymbol.getCorrespondingSymbol(c);
93         if (greek == ' ') {
94             return new Chunk(String.valueOf(c), font);
95         }
96         Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
97         String JavaDoc s = String.valueOf(greek);
98         return new Chunk(s, symbol);
99     }
100     
101     /**
102      * Looks for the corresponding symbol in the font Symbol.
103      *
104      * @param c the original ASCII-char
105      * @return the corresponding symbol in font Symbol
106      */

107     public static char getCorrespondingSymbol(char c) {
108         switch(c) {
109             case 913:
110                 return 'A'; // ALFA
111
case 914:
112                 return 'B'; // BETA
113
case 915:
114                 return 'G'; // GAMMA
115
case 916:
116                 return 'D'; // DELTA
117
case 917:
118                 return 'E'; // EPSILON
119
case 918:
120                 return 'Z'; // ZETA
121
case 919:
122                 return 'H'; // ETA
123
case 920:
124                 return 'Q'; // THETA
125
case 921:
126                 return 'I'; // IOTA
127
case 922:
128                 return 'K'; // KAPPA
129
case 923:
130                 return 'L'; // LAMBDA
131
case 924:
132                 return 'M'; // MU
133
case 925:
134                 return 'N'; // NU
135
case 926:
136                 return 'X'; // XI
137
case 927:
138                 return 'O'; // OMICRON
139
case 928:
140                 return 'P'; // PI
141
case 929:
142                 return 'R'; // RHO
143
case 931:
144                 return 'S'; // SIGMA
145
case 932:
146                 return 'T'; // TAU
147
case 933:
148                 return 'U'; // UPSILON
149
case 934:
150                 return 'J'; // PHI
151
case 935:
152                 return 'C'; // CHI
153
case 936:
154                 return 'Y'; // PSI
155
case 937:
156                 return 'W'; // OMEGA
157
case 945:
158                 return 'a'; // alfa
159
case 946:
160                 return 'b'; // beta
161
case 947:
162                 return 'g'; // gamma
163
case 948:
164                 return 'd'; // delta
165
case 949:
166                 return 'e'; // epsilon
167
case 950:
168                 return 'z'; // zeta
169
case 951:
170                 return 'h'; // eta
171
case 952:
172                 return 'q'; // theta
173
case 953:
174                 return 'i'; // iota
175
case 954:
176                 return 'k'; // kappa
177
case 955:
178                 return 'l'; // lambda
179
case 956:
180                 return 'm'; // mu
181
case 957:
182                 return 'n'; // nu
183
case 958:
184                 return 'x'; // xi
185
case 959:
186                 return 'o'; // omicron
187
case 960:
188                 return 'p'; // pi
189
case 961:
190                 return 'r'; // rho
191
case 962:
192                 return 'V'; // sigma
193
case 963:
194                 return 's'; // sigma
195
case 964:
196                 return 't'; // tau
197
case 965:
198                 return 'u'; // upsilon
199
case 966:
200                 return 'j'; // phi
201
case 967:
202                 return 'c'; // chi
203
case 968:
204                 return 'y'; // psi
205
case 969:
206                 return 'w'; // omega
207
default:
208                     return ' ';
209         }
210     }
211 }
Popular Tags