001/* 002 * $Id: SpecialSymbol.java 4784 2011-03-15 08:33:00Z blowagie $ 003 * 004 * This file is part of the iText (R) project. 005 * Copyright (c) 1998-2011 1T3XT BVBA 006 * Authors: Bruno Lowagie, Paulo Soares, et al. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Affero General Public License version 3 010 * as published by the Free Software Foundation with the addition of the 011 * following permission added to Section 15 as permitted in Section 7(a): 012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT, 013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 014 * 015 * This program is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 017 * or FITNESS FOR A PARTICULAR PURPOSE. 018 * See the GNU Affero General Public License for more details. 019 * You should have received a copy of the GNU Affero General Public License 020 * along with this program; if not, see http://www.gnu.org/licenses or write to 021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 022 * Boston, MA, 02110-1301 USA, or download the license from the following URL: 023 * http://itextpdf.com/terms-of-use/ 024 * 025 * The interactive user interfaces in modified source and object code versions 026 * of this program must display Appropriate Legal Notices, as required under 027 * Section 5 of the GNU Affero General Public License. 028 * 029 * In accordance with Section 7(b) of the GNU Affero General Public License, 030 * a covered work must retain the producer line in every PDF that is created 031 * or manipulated using iText. 032 * 033 * You can be released from the requirements of the license by purchasing 034 * a commercial license. Buying such a license is mandatory as soon as you 035 * develop commercial activities involving the iText software without 036 * disclosing the source code of your own applications. 037 * These activities include: offering paid services to customers as an ASP, 038 * serving PDFs on the fly in a web application, shipping iText with a closed 039 * source product. 040 * 041 * For more information, please contact iText Software Corp. at this 042 * address: sales@itextpdf.com 043 */ 044package com.itextpdf.text; 045 046import com.itextpdf.text.Font.FontFamily; 047 048/** 049 * This class contains the symbols that correspond with special symbols. 050 * <P> 051 * When you construct a <CODE>Phrase</CODE> with Phrase.getInstance using a <CODE>String</CODE>, 052 * this <CODE>String</CODE> can contain special Symbols. These are characters with an int value 053 * between 913 and 937 (except 930) and between 945 and 969. With this class the value of the 054 * corresponding character of the Font Symbol, can be retrieved. 055 * 056 * @see Phrase 057 * 058 * @author Bruno Lowagie 059 * @author Evelyne De Cordier 060 */ 061 062public class SpecialSymbol { 063 064 /** 065 * Returns the first occurrence of a special symbol in a <CODE>String</CODE>. 066 * 067 * @param string a <CODE>String</CODE> 068 * @return an index of -1 if no special symbol was found 069 */ 070 public static int index(String string) { 071 int length = string.length(); 072 for (int i = 0; i < length; i++) { 073 if (getCorrespondingSymbol(string.charAt(i)) != ' ') { 074 return i; 075 } 076 } 077 return -1; 078 } 079 080 /** 081 * Gets a chunk with a symbol character. 082 * @param c a character that has to be changed into a symbol 083 * @param font Font if there is no SYMBOL character corresponding with c 084 * @return a SYMBOL version of a character 085 */ 086 public static Chunk get(char c, Font font) { 087 char greek = SpecialSymbol.getCorrespondingSymbol(c); 088 if (greek == ' ') { 089 return new Chunk(String.valueOf(c), font); 090 } 091 Font symbol = new Font(FontFamily.SYMBOL, font.getSize(), font.getStyle(), font.getColor()); 092 String s = String.valueOf(greek); 093 return new Chunk(s, symbol); 094 } 095 096 /** 097 * Looks for the corresponding symbol in the font Symbol. 098 * 099 * @param c the original ASCII-char 100 * @return the corresponding symbol in font Symbol 101 */ 102 public static char getCorrespondingSymbol(char c) { 103 switch(c) { 104 case 913: 105 return 'A'; // ALFA 106 case 914: 107 return 'B'; // BETA 108 case 915: 109 return 'G'; // GAMMA 110 case 916: 111 return 'D'; // DELTA 112 case 917: 113 return 'E'; // EPSILON 114 case 918: 115 return 'Z'; // ZETA 116 case 919: 117 return 'H'; // ETA 118 case 920: 119 return 'Q'; // THETA 120 case 921: 121 return 'I'; // IOTA 122 case 922: 123 return 'K'; // KAPPA 124 case 923: 125 return 'L'; // LAMBDA 126 case 924: 127 return 'M'; // MU 128 case 925: 129 return 'N'; // NU 130 case 926: 131 return 'X'; // XI 132 case 927: 133 return 'O'; // OMICRON 134 case 928: 135 return 'P'; // PI 136 case 929: 137 return 'R'; // RHO 138 case 931: 139 return 'S'; // SIGMA 140 case 932: 141 return 'T'; // TAU 142 case 933: 143 return 'U'; // UPSILON 144 case 934: 145 return 'F'; // PHI 146 case 935: 147 return 'C'; // CHI 148 case 936: 149 return 'Y'; // PSI 150 case 937: 151 return 'W'; // OMEGA 152 case 945: 153 return 'a'; // alfa 154 case 946: 155 return 'b'; // beta 156 case 947: 157 return 'g'; // gamma 158 case 948: 159 return 'd'; // delta 160 case 949: 161 return 'e'; // epsilon 162 case 950: 163 return 'z'; // zeta 164 case 951: 165 return 'h'; // eta 166 case 952: 167 return 'q'; // theta 168 case 953: 169 return 'i'; // iota 170 case 954: 171 return 'k'; // kappa 172 case 955: 173 return 'l'; // lambda 174 case 956: 175 return 'm'; // mu 176 case 957: 177 return 'n'; // nu 178 case 958: 179 return 'x'; // xi 180 case 959: 181 return 'o'; // omicron 182 case 960: 183 return 'p'; // pi 184 case 961: 185 return 'r'; // rho 186 case 962: 187 return 'V'; // sigma 188 case 963: 189 return 's'; // sigma 190 case 964: 191 return 't'; // tau 192 case 965: 193 return 'u'; // upsilon 194 case 966: 195 return 'f'; // phi 196 case 967: 197 return 'c'; // chi 198 case 968: 199 return 'y'; // psi 200 case 969: 201 return 'w'; // omega 202 default: 203 return ' '; 204 } 205 } 206}