diff options
author | Jeremias Maerki <jeremias@apache.org> | 2010-05-20 09:52:27 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2010-05-20 09:52:27 +0000 |
commit | 366b45e1f9cf6ad39b45a928fb45c906bfc6dc99 (patch) | |
tree | 416257afc8bbeb83aa2e917d1a919968b2b428c5 | |
parent | aefb5934f6097c0691162a899372b9f9d4532201 (diff) | |
download | xmlgraphics-fop-366b45e1f9cf6ad39b45a928fb45c906bfc6dc99.tar.gz xmlgraphics-fop-366b45e1f9cf6ad39b45a928fb45c906bfc6dc99.zip |
Changed many variables and parameters from "int" to "char" because AFP font support mostly uses Unicode code points unlike Type 1 and TrueType support which use internal character code points (the result of Font.mapChar()). This should improve code readability.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@946585 13f79535-47bb-0310-9956-ffa450edef68
8 files changed, 54 insertions, 38 deletions
diff --git a/src/java/org/apache/fop/afp/fonts/AFPFont.java b/src/java/org/apache/fop/afp/fonts/AFPFont.java index a1c257d3e..944c98f8e 100644 --- a/src/java/org/apache/fop/afp/fonts/AFPFont.java +++ b/src/java/org/apache/fop/afp/fonts/AFPFont.java @@ -115,6 +115,16 @@ public abstract class AFPFont extends Typeface { 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; diff --git a/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java b/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java index 2061e9d82..c1ab6a5fc 100644 --- a/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java +++ b/src/java/org/apache/fop/afp/fonts/AbstractOutlineFont.java @@ -127,7 +127,7 @@ public abstract class AbstractOutlineFont extends AFPFont { * @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; } /** diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSet.java b/src/java/org/apache/fop/afp/fonts/CharacterSet.java index 24c53a1c3..fec2e6741 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSet.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSet.java @@ -219,20 +219,18 @@ public class CharacterSet { /** * 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(); } @@ -268,11 +266,10 @@ public class CharacterSet { * 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); } @@ -393,7 +390,7 @@ public class CharacterSet { * 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) { diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index c05e408da..7d2c46bc6 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -155,6 +155,10 @@ public class CharacterSetBuilder { throw new FileNotFoundException("Invalid filename: " + filename + " (" + e.getMessage() + ")"); } + + if (LOG.isDebugEnabled()) { + LOG.debug("Opening " + uri); + } InputStream inputStream = accessor.createInputStream(uri); return inputStream; } @@ -291,7 +295,7 @@ public class CharacterSetBuilder { * @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, @@ -323,6 +327,10 @@ public class CharacterSetBuilder { 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 { @@ -510,8 +518,8 @@ public class CharacterSetBuilder { 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 @@ -534,7 +542,7 @@ public class CharacterSetBuilder { 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); diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java b/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java index db0908acb..84e4b7a69 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetOrientation.java @@ -58,7 +58,7 @@ public class CharacterSetOrientation { 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; @@ -68,14 +68,14 @@ public class CharacterSetOrientation { 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; /** @@ -138,17 +138,17 @@ public class CharacterSetOrientation { /** * 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; } @@ -183,15 +183,16 @@ public class CharacterSetOrientation { /** * 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]; } /** @@ -234,7 +235,7 @@ public class CharacterSetOrientation { * 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; } @@ -242,17 +243,17 @@ public class CharacterSetOrientation { * 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? diff --git a/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java b/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java index 1d3b03f1f..9f5dcbcf7 100644 --- a/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java +++ b/src/java/org/apache/fop/afp/fonts/DoubleByteFont.java @@ -55,7 +55,7 @@ public class DoubleByteFont extends AbstractOutlineFont { 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; diff --git a/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java b/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java index 42950dc5b..f14a0b381 100644 --- a/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java +++ b/src/java/org/apache/fop/afp/fonts/FopCharacterSet.java @@ -88,7 +88,7 @@ public class FopCharacterSet extends CharacterSet { * The first character in the character set * @return the first character */ - public int getFirstChar() { + public char getFirstChar() { return 0; } @@ -96,7 +96,7 @@ public class FopCharacterSet extends CharacterSet { * The last character in the character set * @return the last character */ - public int getLastChar() { + public char getLastChar() { return 0; } diff --git a/src/java/org/apache/fop/afp/fonts/RasterFont.java b/src/java/org/apache/fop/afp/fonts/RasterFont.java index 115773214..cba608471 100644 --- a/src/java/org/apache/fop/afp/fonts/RasterFont.java +++ b/src/java/org/apache/fop/afp/fonts/RasterFont.java @@ -232,7 +232,7 @@ public class RasterFont extends AFPFont { */ 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); } /** |