diff options
Diffstat (limited to 'src/java/org/apache/fop/afp/fonts/RasterFont.java')
-rw-r--r-- | src/java/org/apache/fop/afp/fonts/RasterFont.java | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/java/org/apache/fop/afp/fonts/RasterFont.java b/src/java/org/apache/fop/afp/fonts/RasterFont.java index 2a4d5d270..30704b2b0 100644 --- a/src/java/org/apache/fop/afp/fonts/RasterFont.java +++ b/src/java/org/apache/fop/afp/fonts/RasterFont.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.SortedMap; +import java.util.TreeMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,9 +40,8 @@ public class RasterFont extends AFPFont { /** Static logging instance */ protected static final Log LOG = LogFactory.getLog("org.apache.fop.afp.fonts"); - private final SortedMap/*<Integer,CharacterSet>*/ charSets - = new java.util.TreeMap/*<Integer,CharacterSet>*/(); - private Map/*<Integer,CharacterSet>*/ substitutionCharSets; + private final SortedMap<Integer, CharacterSet> charSets = new TreeMap<Integer, CharacterSet>(); + private Map<Integer, CharacterSet> substitutionCharSets; private CharacterSet charSet = null; @@ -70,14 +70,14 @@ public class RasterFont extends AFPFont { /** * Get the character set metrics for the specified point size. * - * @param size the point size (in mpt) + * @param sizeInMpt the point size (in mpt) * @return the character set metrics */ - public CharacterSet getCharacterSet(int size) { + public CharacterSet getCharacterSet(int sizeInMpt) { - //TODO: replace with Integer.valueOf() once we switch to Java 5 - Integer requestedSize = new Integer(size); + Integer requestedSize = Integer.valueOf(sizeInMpt); CharacterSet csm = (CharacterSet) charSets.get(requestedSize); + double sizeInPt = sizeInMpt / 1000.0; if (csm != null) { return csm; @@ -92,8 +92,8 @@ public class RasterFont extends AFPFont { // No match or substitution found, but there exist entries // for other sizes // Get char set with nearest, smallest font size - SortedMap smallerSizes = charSets.headMap(requestedSize); - SortedMap largerSizes = charSets.tailMap(requestedSize); + SortedMap<Integer, CharacterSet> smallerSizes = charSets.headMap(requestedSize); + SortedMap<Integer, CharacterSet> largerSizes = charSets.tailMap(requestedSize); int smallerSize = smallerSizes.isEmpty() ? 0 : ((Integer)smallerSizes.lastKey()).intValue(); int largerSize = largerSizes.isEmpty() ? Integer.MAX_VALUE @@ -101,10 +101,10 @@ public class RasterFont extends AFPFont { Integer fontSize; if (!smallerSizes.isEmpty() - && (size - smallerSize) <= (largerSize - size)) { - fontSize = new Integer(smallerSize); + && (sizeInMpt - smallerSize) <= (largerSize - sizeInMpt)) { + fontSize = Integer.valueOf(smallerSize); } else { - fontSize = new Integer(largerSize); + fontSize = Integer.valueOf(largerSize); } csm = (CharacterSet) charSets.get(fontSize); @@ -112,19 +112,21 @@ public class RasterFont extends AFPFont { // Add the substitute mapping, so subsequent calls will // find it immediately if (substitutionCharSets == null) { - substitutionCharSets = new HashMap(); + substitutionCharSets = new HashMap<Integer, CharacterSet>(); } substitutionCharSets.put(requestedSize, csm); - String msg = "No " + (size / 1000f) + "pt font " + getFontName() - + " found, substituted with " + fontSize.intValue() / 1000f + "pt font"; - LOG.warn(msg); + // do not output the warning if the font size is closer to an integer less than 0.1 + if (!(Math.abs(fontSize.intValue() / 1000.0 - sizeInPt) < 0.1)) { + String msg = "No " + sizeInPt + "pt font " + getFontName() + + " found, substituted with " + fontSize.intValue() / 1000f + "pt font"; + LOG.warn(msg); + } } } if (csm == null) { // Still no match -> error - String msg = "No font found for font " + getFontName() - + " with point size " + size / 1000f; + String msg = "No font found for font " + getFontName() + " with point size " + sizeInPt; LOG.error(msg); throw new FontRuntimeException(msg); } @@ -138,9 +140,9 @@ public class RasterFont extends AFPFont { * @return the first character in this font. */ public int getFirstChar() { - Iterator it = charSets.values().iterator(); + Iterator<CharacterSet> it = charSets.values().iterator(); if (it.hasNext()) { - CharacterSet csm = (CharacterSet) it.next(); + CharacterSet csm = it.next(); return csm.getFirstChar(); } else { String msg = "getFirstChar() - No character set found for font:" + getFontName(); @@ -155,9 +157,9 @@ public class RasterFont extends AFPFont { */ public int getLastChar() { - Iterator it = charSets.values().iterator(); + Iterator<CharacterSet> it = charSets.values().iterator(); if (it.hasNext()) { - CharacterSet csm = (CharacterSet) it.next(); + CharacterSet csm = it.next(); return csm.getLastChar(); } else { String msg = "getLastChar() - No character set found for font:" + getFontName(); |