From: Jeremias Maerki Date: Sat, 2 Jul 2011 10:22:03 +0000 (+0000) Subject: Fixed some FindBugs issues. X-Git-Tag: fop-1_1rc1old~197 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8b266c1f6d4eed7c2f94b1edb7acdbe5099b71c8;p=xmlgraphics-fop.git Fixed some FindBugs issues. Added some generics. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1142192 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java b/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java index cec39bfb9..0180d4540 100644 --- a/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java +++ b/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java @@ -25,9 +25,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.fop.util.CharUtilities; import org.apache.xmlgraphics.fonts.Glyphs; +import org.apache.fop.util.CharUtilities; + /** * A simple implementation of the OneByteEncoding mostly used for encodings that are constructed * on-the-fly. @@ -53,7 +54,7 @@ public class SimpleSingleByteEncoding implements SingleByteEncoding { /** {@inheritDoc} */ public char mapChar(char c) { - Character nc = charMap.get(new Character(c)); + Character nc = charMap.get(Character.valueOf(c)); if (nc != null) { return nc.charValue(); } @@ -118,7 +119,7 @@ public class SimpleSingleByteEncoding implements SingleByteEncoding { } char newSlot = (char)(getLastChar() + 1); this.mapping.add(ch); - this.charMap.put(new Character(ch.getSingleUnicodeValue()), new Character(newSlot)); + this.charMap.put(Character.valueOf(ch.getSingleUnicodeValue()), Character.valueOf(newSlot)); return newSlot; } diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java index b832eec2b..0605cd11e 100644 --- a/src/java/org/apache/fop/fonts/SingleByteFont.java +++ b/src/java/org/apache/fop/fonts/SingleByteFont.java @@ -81,7 +81,7 @@ public class SingleByteFont extends CustomFont { if (i < 256) { int idx = i - getFirstChar(); if (idx >= 0 && idx < width.length) { - return size * width[i - getFirstChar()]; + return size * width[idx]; } } else if (this.additionalEncodings != null) { int encodingIndex = (i / 256) - 1; @@ -89,7 +89,7 @@ public class SingleByteFont extends CustomFont { int codePoint = i % 256; NamedCharacter nc = encoding.getCharacterForIndex(codePoint); UnencodedCharacter uc - = this.unencodedCharacters.get(new Character(nc.getSingleUnicodeValue())); + = this.unencodedCharacters.get(Character.valueOf(nc.getSingleUnicodeValue())); return size * uc.getWidth(); } return 0; @@ -172,7 +172,7 @@ public class SingleByteFont extends CustomFont { private char mapUnencodedChar(char ch) { if (this.unencodedCharacters != null) { - UnencodedCharacter unencoded = this.unencodedCharacters.get(new Character(ch)); + UnencodedCharacter unencoded = this.unencodedCharacters.get(Character.valueOf(ch)); if (unencoded != null) { if (this.additionalEncodings == null) { this.additionalEncodings = new ArrayList(); @@ -294,7 +294,7 @@ public class SingleByteFont extends CustomFont { } if (ch.hasSingleUnicodeValue()) { UnencodedCharacter uc = new UnencodedCharacter(ch, width); - this.unencodedCharacters.put(new Character(ch.getSingleUnicodeValue()), uc); + this.unencodedCharacters.put(Character.valueOf(ch.getSingleUnicodeValue()), uc); } else { //Cannot deal with unicode sequences, so ignore this character } @@ -362,7 +362,7 @@ public class SingleByteFont extends CustomFont { for (int i = 0, c = arr.length; i < c; i++) { NamedCharacter nc = enc.getCharacterForIndex(enc.getFirstChar() + i); UnencodedCharacter uc = this.unencodedCharacters.get( - new Character(nc.getSingleUnicodeValue())); + Character.valueOf(nc.getSingleUnicodeValue())); arr[i] = uc.getWidth(); } return arr; diff --git a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java index d5036de7b..33b4ab0a1 100644 --- a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java +++ b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java @@ -65,6 +65,7 @@ public class Type1FontLoader extends FontLoader { private static final String[] AFM_EXTENSIONS = new String[] {".AFM", ".afm", ".Afm"}; /** {@inheritDoc} */ + @Override protected void read() throws IOException { AFMFile afm = null; PFMFile pfm = null; @@ -173,10 +174,10 @@ public class Type1FontLoader extends FontLoader { } } - private Set toGlyphSet(String[] glyphNames) { - Set glyphSet = new java.util.HashSet(); - for (int i = 0, c = glyphNames.length; i < c; i++) { - glyphSet.add(glyphNames[i]); + private Set toGlyphSet(String[] glyphNames) { + Set glyphSet = new java.util.HashSet(); + for (String name : glyphNames) { + glyphSet.add(name); } return glyphSet; } @@ -188,10 +189,9 @@ public class Type1FontLoader extends FontLoader { */ private void addUnencodedBasedOnEncoding(AFMFile afm) { SingleByteEncoding encoding = singleFont.getEncoding(); - Set glyphNames = toGlyphSet(encoding.getCharNameMap()); - List charMetrics = afm.getCharMetrics(); - for (int i = 0, c = afm.getCharCount(); i < c; i++) { - AFMCharMetrics metrics = (AFMCharMetrics)charMetrics.get(i); + Set glyphNames = toGlyphSet(encoding.getCharNameMap()); + List charMetrics = afm.getCharMetrics(); + for (AFMCharMetrics metrics : charMetrics) { String charName = metrics.getCharName(); if (charName != null && !glyphNames.contains(charName)) { singleFont.addUnencodedCharacter(metrics.getCharacter(), @@ -357,9 +357,7 @@ public class Type1FontLoader extends FontLoader { returnFont.setFirstChar(afm.getFirstChar()); returnFont.setLastChar(afm.getLastChar()); - Iterator iter = afm.getCharMetrics().iterator(); - while (iter.hasNext()) { - AFMCharMetrics chm = (AFMCharMetrics)iter.next(); + for (AFMCharMetrics chm : afm.getCharMetrics()) { if (chm.hasCharCode()) { singleFont.setWidth(chm.getCharCode(), (int)Math.round(chm.getWidthX())); }