From 59cd251daa9b13c05844c80938c765ca136a9ee5 Mon Sep 17 00:00:00 2001 From: Mehdi Houshmand Date: Tue, 10 Apr 2012 08:39:31 +0000 Subject: [PATCH] Bug in AFP font metrics that performed integer arithmetic when it should have been double arithemetic. Also added some generics to the surrounding classes git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1311638 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/afp/fonts/AFPFont.java | 5 +++-- .../fop/afp/fonts/CharacterSetBuilder.java | 4 ++-- .../org/apache/fop/afp/fonts/RasterFont.java | 20 +++++++++---------- status.xml | 4 ++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/fop/afp/fonts/AFPFont.java b/src/java/org/apache/fop/afp/fonts/AFPFont.java index f64410fdd..8a4ae3dc1 100644 --- a/src/java/org/apache/fop/afp/fonts/AFPFont.java +++ b/src/java/org/apache/fop/afp/fonts/AFPFont.java @@ -19,6 +19,7 @@ package org.apache.fop.afp.fonts; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -62,8 +63,8 @@ public abstract class AFPFont extends Typeface { } /** {@inheritDoc} */ - public Set getFamilyNames() { - Set s = new java.util.HashSet(); + public Set getFamilyNames() { + Set s = new HashSet(); s.add(this.name); return s; } diff --git a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java index e6c4e6907..4988bb949 100644 --- a/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java +++ b/src/java/org/apache/fop/afp/fonts/CharacterSetBuilder.java @@ -285,12 +285,12 @@ public abstract class CharacterSetBuilder { CharacterSetOrientation[] characterSetOrientations = processFontOrientation(structuredFieldReader); - int metricNormalizationFactor; + double metricNormalizationFactor; if (fontControl.isRelative()) { metricNormalizationFactor = 1; } else { int dpi = fontControl.getDpi(); - metricNormalizationFactor = 1000 * 72000 + metricNormalizationFactor = 1000.0d * 72000.0d / fontDescriptor.getNominalFontSizeInMillipoints() / dpi; } diff --git a/src/java/org/apache/fop/afp/fonts/RasterFont.java b/src/java/org/apache/fop/afp/fonts/RasterFont.java index da5060ccc..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/**/ charSets - = new java.util.TreeMap/**/(); - private Map/**/ substitutionCharSets; + private final SortedMap charSets = new TreeMap(); + private Map substitutionCharSets; private CharacterSet charSet = null; @@ -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 smallerSizes = charSets.headMap(requestedSize); + SortedMap largerSizes = charSets.tailMap(requestedSize); int smallerSize = smallerSizes.isEmpty() ? 0 : ((Integer)smallerSizes.lastKey()).intValue(); int largerSize = largerSizes.isEmpty() ? Integer.MAX_VALUE @@ -112,7 +112,7 @@ 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(); } substitutionCharSets.put(requestedSize, csm); // do not output the warning if the font size is closer to an integer less than 0.1 @@ -140,9 +140,9 @@ public class RasterFont extends AFPFont { * @return the first character in this font. */ public int getFirstChar() { - Iterator it = charSets.values().iterator(); + Iterator 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(); @@ -157,9 +157,9 @@ public class RasterFont extends AFPFont { */ public int getLastChar() { - Iterator it = charSets.values().iterator(); + Iterator 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(); diff --git a/status.xml b/status.xml index f58f55879..000d611ea 100644 --- a/status.xml +++ b/status.xml @@ -62,6 +62,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Bug in AFP font metrics that performed integer arithmetic when it should have been + double arithemetic. + Bring clone() in line with the recommendations in Object.clone(). -- 2.39.5