| 1 |
// Copyright 2005, FreeHEP. |
| 2 |
package org.freehep.graphics2d.font; |
| 3 |
|
| 4 |
|
| 5 |
public class FontEncoder { |
| 6 |
|
| 7 |
private FontEncoder() { |
| 8 |
} |
| 9 |
|
| 10 |
public static String getEncodedString(String string, String tableName) { |
| 11 |
CharTable charTable = Lookup.getInstance().getTable(tableName); |
| 12 |
return getEncodedString(string, charTable); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Returns an unicode encoded string from an ascii encoded string, using the |
| 17 |
* supplied table. |
| 18 |
*/ |
| 19 |
public static String getEncodedString(String string, CharTable charTable) { |
| 20 |
if (charTable == null) |
| 21 |
return string; |
| 22 |
|
| 23 |
StringBuffer s = new StringBuffer(); |
| 24 |
for (int i = 0; i < string.length(); i++) { |
| 25 |
int enc = string.charAt(i); |
| 26 |
String name = charTable.toName(enc); |
| 27 |
s.append((name != null) ? charTable.toUnicode(name) : (char) enc); |
| 28 |
} |
| 29 |
return s.toString(); |
| 30 |
} |
| 31 |
|
| 32 |
} |