]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixed some FindBugs issues.
authorJeremias Maerki <jeremias@apache.org>
Sat, 2 Jul 2011 10:22:03 +0000 (10:22 +0000)
committerJeremias Maerki <jeremias@apache.org>
Sat, 2 Jul 2011 10:22:03 +0000 (10:22 +0000)
Added some generics.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1142192 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java
src/java/org/apache/fop/fonts/SingleByteFont.java
src/java/org/apache/fop/fonts/type1/Type1FontLoader.java

index cec39bfb96072e4fd84d8b18d30ee2146e3aa90e..0180d4540be88ae8c34c1a0cda71b89b7667dc26 100644 (file)
@@ -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;
     }
 
index b832eec2bcd25fe27176b3febeb50a3b436c4d4f..0605cd11e213297554696cfbc8c767a54167c345 100644 (file)
@@ -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<SimpleSingleByteEncoding>();
@@ -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;
index d5036de7ba4c7962a4f893d32a25ca391adddce2..33b4ab0a103e38a3ed8e4d35859adb368f332290 100644 (file)
@@ -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<String> toGlyphSet(String[] glyphNames) {
+        Set<String> glyphSet = new java.util.HashSet<String>();
+        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<String> glyphNames = toGlyphSet(encoding.getCharNameMap());
+        List<AFMCharMetrics> 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()));
                 }