| 1 |
//Copyright 2001-2005 FreeHEP. |
| 2 |
package org.freehep.graphics2d.font; |
| 3 |
|
| 4 |
/** |
| 5 |
* Lookup class provides conversion between different encodings and character |
| 6 |
* tables using character name, encoding index, and unicode. In order to add new |
| 7 |
* tables original code should be modified. |
| 8 |
* |
| 9 |
* @author Sami Kama |
| 10 |
* @version $Id: freehep-graphics2d/src/main/java/org/freehep/graphics2d/font/Lookup.java 7aee336a8992 2005/11/25 23:19:05 duns $ |
| 11 |
*/ |
| 12 |
public class Lookup { |
| 13 |
private static Lookup instance; |
| 14 |
|
| 15 |
private CharTable[] tables; |
| 16 |
|
| 17 |
public static Lookup getInstance() { |
| 18 |
if (instance == null) { |
| 19 |
instance = new Lookup(); |
| 20 |
} |
| 21 |
return (instance); |
| 22 |
} |
| 23 |
|
| 24 |
private int ntables = 8; |
| 25 |
|
| 26 |
private Lookup() { |
| 27 |
tables = new CharTable[ntables]; |
| 28 |
tables[0] = new Symbol(); |
| 29 |
tables[1] = new Expert(); |
| 30 |
tables[2] = new Zapfdingbats(); |
| 31 |
tables[3] = new STDLatin(); |
| 32 |
tables[4] = new MACLatin(); |
| 33 |
tables[5] = new WINLatin(); |
| 34 |
tables[6] = new PDFLatin(); |
| 35 |
tables[7] = new ISOLatin(); |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Converts a name to unicode. This method takes name of the character and |
| 41 |
* returns character as a unicode character. |
| 42 |
* |
| 43 |
* @return requested unicode character. |
| 44 |
*/ |
| 45 |
public char toUnicode(String name) { |
| 46 |
for (int i = 0; i < ntables; i++) { |
| 47 |
char uc = tables[i].toUnicode(name); |
| 48 |
if (uc != '\uffff') |
| 49 |
return (uc); |
| 50 |
} |
| 51 |
return ('\uffff'); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Converts a unicode character to name. |
| 56 |
* |
| 57 |
* @return requested character name. |
| 58 |
*/ |
| 59 |
public String toName(char uc) { |
| 60 |
for (int i = 0; i < ntables; i++) { |
| 61 |
String name = tables[i].toName(uc); |
| 62 |
if (name != null) |
| 63 |
return (name); |
| 64 |
} |
| 65 |
return (null); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Converts a unicode character to name. |
| 70 |
* |
| 71 |
* @return requested character name. |
| 72 |
*/ |
| 73 |
public String toName(Character uc) { |
| 74 |
for (int i = 0; i < ntables; i++) { |
| 75 |
String name = tables[i].toName(uc); |
| 76 |
if (name != null) |
| 77 |
return (name); |
| 78 |
} |
| 79 |
return (null); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Gives the requested encoding table Valid table names can be requested |
| 84 |
* with a call to |
| 85 |
* |
| 86 |
* @see #getTableNames(). |
| 87 |
* |
| 88 |
* @return requested encoding. |
| 89 |
*/ |
| 90 |
public CharTable getTable(String tableName) { |
| 91 |
for (int i = 0; i < ntables; i++) { |
| 92 |
String tblName = tables[i].getEncoding() + tables[i].getName(); |
| 93 |
if (tblName.equalsIgnoreCase(tableName)) |
| 94 |
return (tables[i]); |
| 95 |
} |
| 96 |
return (null); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Gives the total number of tables included in the file |
| 101 |
* |
| 102 |
* @return number of tables |
| 103 |
*/ |
| 104 |
public int getNumberOfTables() { |
| 105 |
return (ntables); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Gives the names of tables that can be used in a string array. |
| 110 |
* |
| 111 |
* @return An array of String[] containing the table names |
| 112 |
*/ |
| 113 |
public String[] getTableNames() { |
| 114 |
String[] tblnames = new String[ntables]; |
| 115 |
for (int i = 0; i < ntables; i++) { |
| 116 |
tblnames[i] = tables[i].getEncoding() + tables[i].getName(); |
| 117 |
} |
| 118 |
return tblnames; |
| 119 |
} |
| 120 |
} |