return this.embeddable;
}
+ /**
+ * Maps mapped code points to Unicode code points.
+ * @param character the mapped code point
+ * @return the corresponding Unicode code point
+ */
+ protected static final char toUnicodeCodepoint(int character) {
+ //AFP fonts use Unicode directly as their mapped code points, so we can simply cast to char
+ return (char)character;
+ }
+
/** {@inheritDoc} */
public String toString() {
return "name=" + name;
* @return the width of the character for the specified point size
*/
public int getWidth(int character, int size) {
- return charSet.getWidth(character) * size;
+ return charSet.getWidth(toUnicodeCodepoint(character)) * size;
}
/**
/**
* Returns the first character in the character set
*
- * @return the first character in the character set
+ * @return the first character in the character set (Unicode codepoint)
*/
- public int getFirstChar() {
-
+ public char getFirstChar() {
return getCharacterSetOrientation().getFirstChar();
}
/**
* Returns the last character in the character set
*
- * @return the last character in the character set
+ * @return the last character in the character set (Unicode codepoint)
*/
- public int getLastChar() {
-
+ public char getLastChar() {
return getCharacterSetOrientation().getLastChar();
}
* Get the width (in 1/1000ths of a point size) of the character
* identified by the parameter passed.
*
- * @param character the character from which the width will be calculated
+ * @param character the Unicode character from which the width will be calculated
* @return the width of the character
*/
- public int getWidth(int character) {
-
+ public int getWidth(char character) {
return getCharacterSetOrientation().getWidth(character);
}
* The code tables are already converted to Unicode therefore
* we can use the identity mapping.
*
- * @param c character to map
+ * @param c the Unicode character to map
* @return the mapped character
*/
public char mapChar(char c) {
throw new FileNotFoundException("Invalid filename: "
+ filename + " (" + e.getMessage() + ")");
}
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Opening " + uri);
+ }
InputStream inputStream = accessor.createInputStream(uri);
return inputStream;
}
* @param encoding
* the encoding to use for the character decoding
* @param accessor the resource accessor
- * @return a code page mapping
+ * @return a code page mapping (key: GCGID, value: Unicode character)
* @throws IOException if an I/O exception of some sort has occurred.
*/
protected Map/*<String,String>*/ loadCodePage(String codePage, String encoding,
charBytes[0] = data[index];
String gcgiString = new String(gcgiBytes,
AFPConstants.EBCIDIC_ENCODING);
+ //Use the 8-bit char index to find the Unicode character using the Java encoding
+ //given in the configuration. If the code page and the Java encoding don't
+ //match, a wrong Unicode character will be associated with the AFP GCGID.
+ //Idea: we could use IBM's GCGID to Unicode map and build code pages ourselves.
String charString = new String(charBytes, encoding);
codePages.put(gcgiString, charString);
} else {
byte[] gcgid = new byte[8];
byte[] fiData = new byte[20];
- int lowest = 255;
- int highest = 0;
+ char lowest = 255;
+ char highest = 0;
String firstABCMismatch = null;
// Read data, ignoring bytes 0 - 2
if (idx != null) {
- int cidx = idx.charAt(0);
+ char cidx = idx.charAt(0);
int width = getUBIN(fiData, 0);
int a = getSBIN(fiData, 10);
int b = getUBIN(fiData, 12);
private int capHeight;
/**
- * The character widths in the character set
+ * The character widths in the character set (indexed using Unicode codepoints)
*/
private int[] charsWidths = null;
private int xHeight;
/**
- * The first character
+ * The first character (Unicode codepoint)
*/
- private int firstChar;
+ private char firstChar;
/**
- * The last character
+ * The last character (Unicode codepoint)
*/
- private int lastChar;
+ private char lastChar;
/**
/**
* The first character in the character set
- * @return the first character
+ * @return the first character (Unicode codepoint)
*/
- public int getFirstChar() {
+ public char getFirstChar() {
return firstChar;
}
/**
* The last character in the character set
- * @return the last character
+ * @return the last character (Unicode codepoint)
*/
- public int getLastChar() {
+ public char getLastChar() {
return lastChar;
}
/**
* Get the width (in 1/1000ths of a point size) of the character
* identified by the parameter passed.
- * @param characterIndex the character to evaluate
+ * @param character the Unicode character to evaluate
* @return the widths of the character
*/
- public int getWidth(int characterIndex) {
- if (characterIndex >= charsWidths.length) {
- throw new IllegalArgumentException("Invalid character index: "
- + characterIndex + ", maximum is " + (charsWidths.length - 1));
+ public int getWidth(char character) {
+ if (character >= charsWidths.length) {
+ throw new IllegalArgumentException("Invalid character: "
+ + character + " (" + Integer.toString(character)
+ + "), maximum is " + (charsWidths.length - 1));
}
- return charsWidths[characterIndex];
+ return charsWidths[character];
}
/**
* The first character in the character set
* @param firstChar the first character
*/
- public void setFirstChar(int firstChar) {
+ public void setFirstChar(char firstChar) {
this.firstChar = firstChar;
}
* The last character in the character set
* @param lastChar the last character
*/
- public void setLastChar(int lastChar) {
+ public void setLastChar(char lastChar) {
this.lastChar = lastChar;
}
/**
* Set the width (in 1/1000ths of a point size) of the character
* identified by the parameter passed.
- * @param character the character for which the width is being set
+ * @param character the Unicode character for which the width is being set
* @param width the widths of the character
*/
- public void setWidth(int character, int width) {
+ public void setWidth(char character, int width) {
if (character >= charsWidths.length) {
// Increase the size of the array if necessary
// TODO Can we remove firstChar? surely firstChar==0 at this stage?
public int getWidth(int character, int size) {
int charWidth;
try {
- charWidth = charSet.getWidth(character);
+ charWidth = charSet.getWidth(toUnicodeCodepoint(character));
} catch (IllegalArgumentException e) {
// We shall try and handle characters that have no mapped width metric in font resource
charWidth = -1;
* The first character in the character set
* @return the first character
*/
- public int getFirstChar() {
+ public char getFirstChar() {
return 0;
}
* The last character in the character set
* @return the last character
*/
- public int getLastChar() {
+ public char getLastChar() {
return 0;
}
*/
public int getWidth(int character, int size) {
CharacterSet cs = getCharacterSet(size);
- return metricsToAbsoluteSize(cs, cs.getWidth(character), size);
+ return metricsToAbsoluteSize(cs, cs.getWidth(toUnicodeCodepoint(character)), size);
}
/**