diff options
author | Simon Pepping <spepping@apache.org> | 2010-11-26 13:40:27 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2010-11-26 13:40:27 +0000 |
commit | dbe01e0fa2bf8916be0d5d5f9a9bd83b2a726462 (patch) | |
tree | b73ba8aa9b095ba3a366eea7e4d221973fc86e68 | |
parent | 3231a8001e858244acec7fe09776b8ffb027e11d (diff) | |
download | xmlgraphics-fop-dbe01e0fa2bf8916be0d5d5f9a9bd83b2a726462.tar.gz xmlgraphics-fop-dbe01e0fa2bf8916be0d5d5f9a9bd83b2a726462.zip |
Partial application of patch 50245 by Mehdi Houshmand
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1039350 13f79535-47bb-0310-9956-ffa450edef68
36 files changed, 354 insertions, 340 deletions
diff --git a/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java b/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java index f03d4beab..71415faa3 100644 --- a/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java +++ b/src/java/org/apache/fop/fonts/AbstractCodePointMapping.java @@ -20,24 +20,25 @@ package org.apache.fop.fonts; import java.util.Arrays; +import java.util.HashMap; import java.util.Map; -import org.apache.xmlgraphics.fonts.Glyphs; - import org.apache.fop.util.CharUtilities; +import org.apache.xmlgraphics.fonts.Glyphs; /** * Abstract base class for code point mapping classes (1-byte character encodings). */ public class AbstractCodePointMapping implements SingleByteEncoding { - private String name; + private final String name; private char[] latin1Map; private char[] characters; private char[] codepoints; private char[] unicodeMap; //code point to Unicode char private String[] charNameMap; //all character names in the encoding - private Map fallbackMap; //Here we accumulate all mappings we have found through substitution + //Here we accumulate all mappings we have found through substitution + private Map<Character, Character> fallbackMap; /** * Main constructor. @@ -144,7 +145,7 @@ public class AbstractCodePointMapping implements SingleByteEncoding { //Fallback: using cache synchronized (this) { if (fallbackMap != null) { - Character fallback = (Character)fallbackMap.get(new Character(c)); + Character fallback = fallbackMap.get(new Character(c)); if (fallback != null) { return fallback.charValue(); } @@ -172,7 +173,7 @@ public class AbstractCodePointMapping implements SingleByteEncoding { private void putFallbackCharacter(char c, char mapTo) { synchronized (this) { if (this.fallbackMap == null) { - this.fallbackMap = new java.util.HashMap(); + this.fallbackMap = new HashMap<Character, Character>(); } this.fallbackMap.put(new Character(c), new Character(mapTo)); } @@ -239,6 +240,7 @@ public class AbstractCodePointMapping implements SingleByteEncoding { } /** {@inheritDoc} */ + @Override public String toString() { return getName(); } diff --git a/src/java/org/apache/fop/fonts/CIDSubset.java b/src/java/org/apache/fop/fonts/CIDSubset.java index 778521517..b152ad38e 100644 --- a/src/java/org/apache/fop/fonts/CIDSubset.java +++ b/src/java/org/apache/fop/fonts/CIDSubset.java @@ -21,7 +21,7 @@ package org.apache.fop.fonts; import java.util.BitSet; import java.util.Collections; -import java.util.Iterator; +import java.util.HashMap; import java.util.Map; import org.apache.fop.util.CharUtilities; @@ -42,18 +42,18 @@ public class CIDSubset { /** * usedGlyphs contains orginal, new glyph index (glyph index -> char selector) */ - private Map/*<Integer, Integer>*/ usedGlyphs = new java.util.HashMap(); + private Map<Integer, Integer> usedGlyphs = new HashMap<Integer, Integer>(); /** * usedGlyphsIndex contains new glyph, original index (char selector -> glyph index) */ - private Map/*<Integer, Integer>*/ usedGlyphsIndex = new java.util.HashMap(); + private Map<Integer, Integer> usedGlyphsIndex = new HashMap<Integer, Integer>(); private int usedGlyphsCount = 0; /** * usedCharsIndex contains new glyph, original char (char selector -> Unicode) */ - private Map/*<Integer, Character>*/ usedCharsIndex = new java.util.HashMap(); + private Map<Integer, Character> usedCharsIndex = new HashMap<Integer, Character>(); /** * Default constructor. @@ -84,7 +84,7 @@ public class CIDSubset { * @return the original index (or -1 if no glyph index is available for the subset index) */ public int getGlyphIndexForSubsetIndex(int subsetIndex) { - Integer glyphIndex = (Integer)usedGlyphsIndex.get(new Integer(subsetIndex)); + Integer glyphIndex = usedGlyphsIndex.get(new Integer(subsetIndex)); if (glyphIndex != null) { return glyphIndex.intValue(); } else { @@ -99,7 +99,7 @@ public class CIDSubset { * @return the Unicode value or "NOT A CHARACTER" (0xFFFF) */ public char getUnicodeForSubsetIndex(int subsetIndex) { - Character mapValue = (Character)usedCharsIndex.get(new Integer(subsetIndex)); + Character mapValue = usedCharsIndex.get(new Integer(subsetIndex)); if (mapValue != null) { return mapValue.charValue(); } else { @@ -118,7 +118,7 @@ public class CIDSubset { public int mapSubsetChar(int glyphIndex, char unicode) { // Reencode to a new subset font or get the reencoded value // IOW, accumulate the accessed characters and build a character map for them - Integer subsetCharSelector = (Integer)usedGlyphs.get(new Integer(glyphIndex)); + Integer subsetCharSelector = usedGlyphs.get(new Integer(glyphIndex)); if (subsetCharSelector == null) { int selector = usedGlyphsCount; usedGlyphs.put(new Integer(glyphIndex), @@ -139,7 +139,7 @@ public class CIDSubset { * character selector (i.e. the subset index in this case). * @return Map Map<Integer, Integer> of the font subset */ - public Map/*<Integer, Integer>*/ getSubsetGlyphs() { + public Map<Integer, Integer> getSubsetGlyphs() { return Collections.unmodifiableMap(this.usedGlyphs); } @@ -169,9 +169,7 @@ public class CIDSubset { */ public BitSet getGlyphIndexBitSet() { BitSet bitset = new BitSet(); - Iterator iter = usedGlyphsIndex.keySet().iterator(); - while (iter.hasNext()) { - Integer cid = (Integer)iter.next(); + for (Integer cid : usedGlyphs.keySet()) { bitset.set(cid.intValue()); } return bitset; diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java index 4cf24ae16..4432fccef 100644 --- a/src/java/org/apache/fop/fonts/CustomFont.java +++ b/src/java/org/apache/fop/fonts/CustomFont.java @@ -21,6 +21,8 @@ package org.apache.fop.fonts; import java.io.IOException; import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -35,7 +37,7 @@ public abstract class CustomFont extends Typeface private String fontName = null; private String fullName = null; - private Set familyNames = null; //Set<String> + private Set<String> familyNames = null; private String fontSubName = null; private String embedFileName = null; private String embedResourceName = null; @@ -55,7 +57,7 @@ public abstract class CustomFont extends Typeface private int firstChar = 0; private int lastChar = 255; - private Map kerning; + private Map<Integer, Map<Integer, Integer>> kerning; private boolean useKerning = true; @@ -78,7 +80,7 @@ public abstract class CustomFont extends Typeface * Returns the font family names. * @return the font family names (a Set of Strings) */ - public Set getFamilyNames() { + public Set<String> getFamilyNames() { return Collections.unmodifiableSet(this.familyNames); } @@ -275,11 +277,11 @@ public abstract class CustomFont extends Typeface /** * {@inheritDoc} */ - public final Map getKerningInfo() { + public final Map<Integer, Map<Integer, Integer>> getKerningInfo() { if (hasKerningInfo()) { return kerning; } else { - return java.util.Collections.EMPTY_MAP; + return Collections.emptyMap(); } } @@ -296,8 +298,8 @@ public abstract class CustomFont extends Typeface } /** {@inheritDoc} */ - public void setFamilyNames(Set names) { - this.familyNames = new java.util.HashSet(names); + public void setFamilyNames(Set<String> names) { + this.familyNames = new HashSet<String>(names); } /** @@ -434,9 +436,9 @@ public abstract class CustomFont extends Typeface } /** {@inheritDoc} */ - public void putKerningEntry(Integer key, Map value) { + public void putKerningEntry(Integer key, Map<Integer, Integer> value) { if (kerning == null) { - kerning = new java.util.HashMap(); + kerning = new HashMap<Integer, Map<Integer, Integer>>(); } this.kerning.put(key, value); } @@ -446,9 +448,9 @@ public abstract class CustomFont extends Typeface * @param kerningMap the kerning map (Map<Integer, Map<Integer, Integer>, the integers are * character codes) */ - public void replaceKerningMap(Map kerningMap) { + public void replaceKerningMap(Map<Integer, Map<Integer, Integer>> kerningMap) { if (kerningMap == null) { - this.kerning = Collections.EMPTY_MAP; + this.kerning = Collections.emptyMap(); } else { this.kerning = kerningMap; } diff --git a/src/java/org/apache/fop/fonts/CustomFontCollection.java b/src/java/org/apache/fop/fonts/CustomFontCollection.java index 5a0bba782..9f98814a3 100644 --- a/src/java/org/apache/fop/fonts/CustomFontCollection.java +++ b/src/java/org/apache/fop/fonts/CustomFontCollection.java @@ -27,7 +27,7 @@ import java.util.List; public class CustomFontCollection implements FontCollection { private FontResolver fontResolver; - private List/*<EmbedFontInfo>*/ embedFontInfoList; + private final List<EmbedFontInfo> embedFontInfoList; /** * Main constructor. @@ -35,7 +35,7 @@ public class CustomFontCollection implements FontCollection { * @param customFonts the list of custom fonts */ public CustomFontCollection(FontResolver fontResolver, - List/*<EmbedFontInfo>*/ customFonts) { + List<EmbedFontInfo> customFonts) { this.fontResolver = fontResolver; if (this.fontResolver == null) { //Ensure that we have minimal font resolution capabilities @@ -54,7 +54,7 @@ public class CustomFontCollection implements FontCollection { //FontReader reader = null; for (int i = 0; i < embedFontInfoList.size(); i++) { - EmbedFontInfo embedFontInfo = (EmbedFontInfo)embedFontInfoList.get(i); + EmbedFontInfo embedFontInfo = embedFontInfoList.get(i); //String metricsFile = configFontInfo.getMetricsFile(); internalName = "F" + num; @@ -69,7 +69,7 @@ public class CustomFontCollection implements FontCollection { LazyFont font = new LazyFont(embedFontInfo, this.fontResolver); fontInfo.addMetrics(internalName, font); - List triplets = embedFontInfo.getFontTriplets(); + List<FontTriplet> triplets = embedFontInfo.getFontTriplets(); for (int tripletIndex = 0; tripletIndex < triplets.size(); tripletIndex++) { FontTriplet triplet = (FontTriplet) triplets.get(tripletIndex); fontInfo.addFontProperties(internalName, triplet); diff --git a/src/java/org/apache/fop/fonts/EmbedFontInfo.java b/src/java/org/apache/fop/fonts/EmbedFontInfo.java index aa464c21d..b53cdfdd6 100644 --- a/src/java/org/apache/fop/fonts/EmbedFontInfo.java +++ b/src/java/org/apache/fop/fonts/EmbedFontInfo.java @@ -46,7 +46,7 @@ public class EmbedFontInfo implements Serializable { protected String subFontName = null; /** the list of associated font triplets */ - private List/*<FontTriplet>*/ fontTriplets = null; + private List<FontTriplet> fontTriplets = null; private transient boolean embedded = true; @@ -59,7 +59,7 @@ public class EmbedFontInfo implements Serializable { * @param subFontName the sub-fontname used for TrueType Collections (null otherwise) */ public EmbedFontInfo(String metricsFile, boolean kerning, - List/*<FontTriplet>*/ fontTriplets, String embedFile, String subFontName) { + List<FontTriplet> fontTriplets, String embedFile, String subFontName) { this.metricsFile = metricsFile; this.embedFile = embedFile; this.kerning = kerning; @@ -120,7 +120,7 @@ public class EmbedFontInfo implements Serializable { * Returns the list of font triplets associated with this font. * @return List of font triplets */ - public List/*<FontTriplet>*/ getFontTriplets() { + public List<FontTriplet> getFontTriplets() { return fontTriplets; } diff --git a/src/java/org/apache/fop/fonts/Font.java b/src/java/org/apache/fop/fonts/Font.java index d0a87efbf..7d6004fa0 100644 --- a/src/java/org/apache/fop/fonts/Font.java +++ b/src/java/org/apache/fop/fonts/Font.java @@ -19,11 +19,11 @@ package org.apache.fop.fonts; +import java.util.Collections; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.fonts.CodePointMapping; /** * This class holds font state information and provides access to the font @@ -160,11 +160,11 @@ public class Font { * Returns the font's kerning table * @return the kerning table */ - public Map getKerning() { + public Map<Integer, Map<Integer, Integer>> getKerning() { if (metric.hasKerningInfo()) { return metric.getKerningInfo(); } else { - return java.util.Collections.EMPTY_MAP; + return Collections.emptyMap(); } } @@ -178,9 +178,9 @@ public class Font { * @return the distance to adjust for kerning, 0 if there's no kerning */ public int getKernValue(char ch1, char ch2) { - Map kernPair = (Map)getKerning().get(new Integer(ch1)); + Map<Integer, Integer> kernPair = getKerning().get(new Integer(ch1)); if (kernPair != null) { - Integer width = (Integer)kernPair.get(new Integer(ch2)); + Integer width = kernPair.get(new Integer(ch2)); if (width != null) { return width.intValue() * getFontSize() / 1000; } @@ -239,6 +239,7 @@ public class Font { /** * {@inheritDoc} */ + @Override public String toString() { StringBuffer sbuf = new StringBuffer(); sbuf.append('('); diff --git a/src/java/org/apache/fop/fonts/FontCache.java b/src/java/org/apache/fop/fonts/FontCache.java index 61eca0963..87298a707 100644 --- a/src/java/org/apache/fop/fonts/FontCache.java +++ b/src/java/org/apache/fop/fonts/FontCache.java @@ -31,6 +31,7 @@ import java.io.Serializable; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.util.HashMap; import java.util.Map; import org.apache.commons.io.FileUtils; @@ -71,13 +72,13 @@ public final class FontCache implements Serializable { * master mapping of font url -> font info. This needs to be a list, since a * TTC file may contain more than 1 font. */ - private Map/* <String, CachedFontFile> */fontfileMap = null; + private Map<String, CachedFontFile> fontfileMap = null; /** * mapping of font url -> file modified date (for all fonts that have failed * to load) */ - private Map failedFontMap/* <String, Long>*/ = null; + private Map<String, Long> failedFontMap = null; /** * Default constructor @@ -304,9 +305,9 @@ public final class FontCache implements Serializable { return null; } - private Map/* <String, CachedFontFile> */getFontFileMap() { + private Map<String, CachedFontFile> getFontFileMap() { if (fontfileMap == null) { - fontfileMap = new java.util.HashMap/* <String, CachedFontFile> */(); + fontfileMap = new HashMap<String, CachedFontFile>(); } return fontfileMap; } @@ -322,8 +323,7 @@ public final class FontCache implements Serializable { synchronized (changeLock) { CachedFontFile cachedFontFile; if (containsFont(cacheKey)) { - cachedFontFile = (CachedFontFile) getFontFileMap() - .get(cacheKey); + cachedFontFile = getFontFileMap().get(cacheKey); if (!cachedFontFile.containsFont(fontInfo)) { cachedFontFile.put(fontInfo); } @@ -352,8 +352,7 @@ public final class FontCache implements Serializable { * @return CachedFontFile object */ public CachedFontFile getFontFile(String embedUrl) { - return containsFont(embedUrl) ? (CachedFontFile) getFontFileMap().get( - embedUrl) : null; + return containsFont(embedUrl) ? getFontFileMap().get(embedUrl) : null; } /** @@ -408,8 +407,8 @@ public final class FontCache implements Serializable { public boolean isFailedFont(String embedUrl, long lastModified) { synchronized (changeLock) { if (getFailedFontMap().containsKey(embedUrl)) { - long failedLastModified = ((Long) getFailedFontMap().get( - embedUrl)).longValue(); + long failedLastModified = getFailedFontMap().get( + embedUrl).longValue(); if (lastModified != failedLastModified) { // this font has been changed so lets remove it // from failed font map for now @@ -440,9 +439,9 @@ public final class FontCache implements Serializable { } } - private Map/* <String, Long> */getFailedFontMap() { + private Map<String, Long> getFailedFontMap() { if (failedFontMap == null) { - failedFontMap = new java.util.HashMap/* <String, Long> */(); + failedFontMap = new HashMap<String, Long>(); } return failedFontMap; } @@ -491,15 +490,15 @@ public final class FontCache implements Serializable { /** file modify date (if available) */ private long lastModified = -1; - private Map/* <String, EmbedFontInfo> */filefontsMap = null; + private Map<String, EmbedFontInfo> filefontsMap = null; public CachedFontFile(long lastModified) { setLastModified(lastModified); } - private Map/* <String, EmbedFontInfo> */getFileFontsMap() { + private Map<String, EmbedFontInfo> getFileFontsMap() { if (filefontsMap == null) { - filefontsMap = new java.util.HashMap/* <String, EmbedFontInfo> */(); + filefontsMap = new HashMap<String, EmbedFontInfo>(); } return filefontsMap; } @@ -514,7 +513,7 @@ public final class FontCache implements Serializable { } public EmbedFontInfo[] getEmbedFontInfos() { - return (EmbedFontInfo[]) getFileFontsMap().values().toArray( + return getFileFontsMap().values().toArray( new EmbedFontInfo[getFileFontsMap().size()]); } diff --git a/src/java/org/apache/fop/fonts/FontDetector.java b/src/java/org/apache/fop/fonts/FontDetector.java index 5450b4ff9..d69dfc9bd 100644 --- a/src/java/org/apache/fop/fonts/FontDetector.java +++ b/src/java/org/apache/fop/fonts/FontDetector.java @@ -63,7 +63,7 @@ public class FontDetector { * @param fontInfoList a list of fontinfo to populate * @throws FOPException thrown if a problem occurred during detection */ - public void detect(List/*<EmbedFontInfo>*/ fontInfoList) throws FOPException { + public void detect(List<EmbedFontInfo> fontInfoList) throws FOPException { // search in font base if it is defined and // is a directory but don't recurse FontFileFinder fontFileFinder = new FontFileFinder(); diff --git a/src/java/org/apache/fop/fonts/FontInfo.java b/src/java/org/apache/fop/fonts/FontInfo.java index e36b5ff68..c0bf8db8d 100644 --- a/src/java/org/apache/fop/fonts/FontInfo.java +++ b/src/java/org/apache/fop/fonts/FontInfo.java @@ -19,12 +19,15 @@ package org.apache.fop.fonts; -import java.util.Collection; +import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -44,26 +47,26 @@ public class FontInfo { protected static final Log log = LogFactory.getLog(FontInfo.class); /** Map containing fonts that have been used */ - private Map/*<String,FontMetrics>*/ usedFonts = null; //(String = font key) + private Map<String, Typeface> usedFonts = null; //(String = font key) /** look up a font-triplet to find a font-name */ - private Map/*<FontTriplet,String>*/ triplets = null; //(String = font key) + private Map<FontTriplet, String> triplets = null; //(String = font key) /** look up a font-triplet to find its priority * (only used inside addFontProperties()) */ - private Map/*<FontTriplet,Integer>*/ tripletPriorities = null; //Map<FontTriplet,Integer> + private Map<FontTriplet, Integer> tripletPriorities = null; //Map<FontTriplet,Integer> /** look up a font-name to get a font (that implements FontMetrics at least) */ - private Map/*<String,FontMetrics>*/ fonts = null; //(String = font key) + private Map<String, Typeface> fonts = null; //(String = font key) /** * a collection of missing fonts; used to make sure the user gets * a warning for a missing font only once (not every time the font is used) */ - private Set/*<FontTriplet>*/ loggedFontKeys = null; + private Set<FontTriplet> loggedFontKeys = null; /** Cache for Font instances. */ - private Map/*<FontTriplet, Map>*/ fontInstanceCache = null; + private Map<FontTriplet, Map<Integer, Font>> fontInstanceCache = null; /** Event listener for font events */ private FontEventListener eventListener = null; @@ -72,10 +75,10 @@ public class FontInfo { * Main constructor */ public FontInfo() { - this.triplets = new java.util.HashMap/*<FontTriplet, String>*/(); - this.tripletPriorities = new java.util.HashMap/*<FontTriplet, Integer>*/(); - this.fonts = new java.util.HashMap/*<String, FontMetrics>*/(); - this.usedFonts = new java.util.HashMap/*<String,FontMetrics>*/(); + this.triplets = new HashMap<FontTriplet, String>(); + this.tripletPriorities = new HashMap<FontTriplet, Integer>(); + this.fonts = new HashMap<String, Typeface>(); + this.usedFonts = new HashMap<String, Typeface>(); } /** @@ -135,10 +138,10 @@ public class FontInfo { if (log.isDebugEnabled()) { log.debug("Registering: " + triplet + " under " + internalFontKey); } - String oldName = (String)triplets.get(triplet); + String oldName = triplets.get(triplet); int newPriority = triplet.getPriority(); if (oldName != null) { - int oldPriority = ((Integer)tripletPriorities.get(triplet)).intValue(); + int oldPriority = tripletPriorities.get(triplet).intValue(); if (oldPriority < newPriority) { logDuplicateFont(triplet, false, oldName, oldPriority, internalFontKey, newPriority); @@ -168,9 +171,9 @@ public class FontInfo { if (log.isDebugEnabled()) { log.debug(triplet + (replacing ? ": Replacing " : ": Not replacing ") - + ((FontMetrics)fonts.get(triplets.get(triplet))).getFullName() + + fonts.get(triplets.get(triplet)).getFullName() + " (priority=" + oldPriority + ") by " - + ((FontMetrics)fonts.get(newKey)).getFullName() + + fonts.get(newKey).getFullName() + " (priority=" + newPriority + ")"); } } @@ -186,7 +189,7 @@ public class FontInfo { if (metrics instanceof Typeface) { ((Typeface)metrics).setEventListener(this.eventListener); } - this.fonts.put(internalFontKey, metrics); + this.fonts.put(internalFontKey, (Typeface)metrics); } /** @@ -292,9 +295,9 @@ public class FontInfo { usedFonts.put(internalName, fonts.get(internalName)); } - private Map/*<FontTriplet,Map<Integer,Font>>*/ getFontInstanceCache() { + private Map<FontTriplet, Map<Integer, Font>> getFontInstanceCache() { if (fontInstanceCache == null) { - fontInstanceCache = new java.util.HashMap/*<FontTriplet, Map<Integer,Font>>*/(); + fontInstanceCache = new HashMap<FontTriplet, Map<Integer, Font>>(); } return fontInstanceCache; } @@ -307,14 +310,14 @@ public class FontInfo { * @return the requested Font instance */ public Font getFontInstance(FontTriplet triplet, int fontSize) { - Map/*<Integer,Font>*/ sizes - = (Map/*<Integer,Font>*/)getFontInstanceCache().get(triplet); + Map<Integer, Font> sizes + = getFontInstanceCache().get(triplet); if (sizes == null) { - sizes = new java.util.HashMap/*<Integer,Font>*/(); + sizes = new HashMap<Integer, Font>(); getFontInstanceCache().put(triplet, sizes); } Integer size = new Integer(fontSize); - Font font = (Font)sizes.get(size); + Font font = sizes.get(size); if (font == null) { String fontKey = getInternalFontKey(triplet); useFont(fontKey); @@ -325,11 +328,9 @@ public class FontInfo { return font; } - private List/*<FontTriplet>*/ getTripletsForName(String fontName) { - List/*<FontTriplet>*/ matchedTriplets = new java.util.ArrayList/*<FontTriplet>*/(); - Iterator it = triplets.keySet().iterator(); - while (it.hasNext()) { - FontTriplet triplet = (FontTriplet)it.next(); + private List<FontTriplet> getTripletsForName(String fontName) { + List<FontTriplet> matchedTriplets = new ArrayList<FontTriplet>(); + for (FontTriplet triplet : triplets.keySet()) { String tripletName = triplet.getName(); if (tripletName.toLowerCase().equals(fontName.toLowerCase())) { matchedTriplets.add(triplet); @@ -351,11 +352,9 @@ public class FontInfo { int awtFontWeight = awtFont.isBold() ? Font.WEIGHT_BOLD : Font.WEIGHT_NORMAL; FontTriplet matchedTriplet = null; - List/*<FontTriplet>*/ triplets = getTripletsForName(awtFontName); + List<FontTriplet> triplets = getTripletsForName(awtFontName); if (!triplets.isEmpty()) { - Iterator it = triplets.iterator(); - while (it.hasNext()) { - FontTriplet triplet = (FontTriplet)it.next(); + for (FontTriplet triplet : triplets) { boolean styleMatched = triplet.getStyle().equals(awtFontStyle); boolean weightMatched = triplet.getWeight() == awtFontWeight; if (styleMatched && weightMatched) { @@ -393,9 +392,9 @@ public class FontInfo { return fontLookup(family, style, weight, true); } - private List/*<FontTriplet>*/ fontLookup(String[] families, String style, + private List<FontTriplet> fontLookup(String[] families, String style, int weight, boolean substitutable) { - List/*<FontTriplet>*/ matchingTriplets = new java.util.ArrayList/*<FontTriplet>*/(); + List<FontTriplet> matchingTriplets = new ArrayList<FontTriplet>(); FontTriplet triplet = null; for (int i = 0; i < families.length; i++) { triplet = fontLookup(families[i], style, weight, substitutable); @@ -426,7 +425,7 @@ public class FontInfo { } // try matching without substitutions - List/*<FontTriplet>*/ matchedTriplets = fontLookup(families, style, weight, false); + List<FontTriplet> matchedTriplets = fontLookup(families, style, weight, false); // if there are no matching font triplets found try with substitutions if (matchedTriplets.size() == 0) { @@ -454,9 +453,9 @@ public class FontInfo { return fontTriplets; } - private Set/*<FontTriplet>*/ getLoggedFontKeys() { + private Set<FontTriplet> getLoggedFontKeys() { if (loggedFontKeys == null) { - loggedFontKeys = new java.util.HashSet/*<FontTriplet>*/(); + loggedFontKeys = new HashSet<FontTriplet>(); } return loggedFontKeys; } @@ -544,7 +543,7 @@ public class FontInfo { * @return the associated internal key or null, if not found */ public String getInternalFontKey(FontTriplet triplet) { - return (String)triplets.get(triplet); + return triplets.get(triplet); } /** @@ -563,15 +562,15 @@ public class FontInfo { * Gets a Map of all registered fonts. * @return a read-only Map with font key/FontMetrics pairs */ - public Map/*<String,FontMetrics>*/ getFonts() { - return java.util.Collections.unmodifiableMap(this.fonts); + public Map<String, Typeface> getFonts() { + return Collections.unmodifiableMap(this.fonts); } /** * Gets a Map of all registered font triplets. * @return a Map with FontTriplet/font key pairs */ - public Map/*<FontTriplet,String>*/ getFontTriplets() { + public Map<FontTriplet, String> getFontTriplets() { return this.triplets; } @@ -581,7 +580,7 @@ public class FontInfo { * This is for embedded font or creating a list of used fonts. * @return a read-only Map with font key/FontMetrics pairs */ - public Map/*<String,FontMetrics>*/ getUsedFonts() { + public Map<String, Typeface> getUsedFonts() { return this.usedFonts; } @@ -591,7 +590,7 @@ public class FontInfo { * @return font metrics */ public FontMetrics getMetricsFor(String fontName) { - FontMetrics metrics = (FontMetrics)fonts.get(fontName); + Typeface metrics = fonts.get(fontName); usedFonts.put(fontName, metrics); return metrics; } @@ -601,10 +600,9 @@ public class FontInfo { * @param fontName The font name we are looking for * @return A list of matching font triplets */ - public List/*<FontTriplet>*/ getTripletsFor(String fontName) { - List/*<FontTriplet>*/ foundTriplets = new java.util.ArrayList(); - for (Iterator iter = triplets.entrySet().iterator(); iter.hasNext();) { - Map.Entry tripletEntry = (Map.Entry) iter.next(); + public List<FontTriplet> getTripletsFor(String fontName) { + List<FontTriplet> foundTriplets = new ArrayList<FontTriplet> (); + for (Map.Entry<FontTriplet, String> tripletEntry : triplets.entrySet()) { if (fontName.equals((tripletEntry.getValue()))) { foundTriplets.add(tripletEntry.getKey()); } @@ -620,10 +618,10 @@ public class FontInfo { * @return The first triplet for the given font name */ public FontTriplet getTripletFor(String fontName) { - List/*<FontTriplet>*/ foundTriplets = getTripletsFor(fontName); + List<FontTriplet> foundTriplets = getTripletsFor(fontName); if (foundTriplets.size() > 0) { Collections.sort(foundTriplets); - return (FontTriplet)foundTriplets.get(0); + return foundTriplets.get(0); } return null; } @@ -672,18 +670,17 @@ public class FontInfo { /** * {@inheritDoc} */ + @Override public String toString() { - Collection entries = new java.util.TreeSet(); - Iterator iter = this.triplets.keySet().iterator(); - while (iter.hasNext()) { - FontTriplet triplet = (FontTriplet)iter.next(); + SortedSet<String> entries = new TreeSet<String>(); + for (FontTriplet triplet : this.triplets.keySet()) { String key = getInternalFontKey(triplet); FontMetrics metrics = getMetricsFor(key); entries.add(triplet.toString() + " -> " + key + " -> " + metrics.getFontName() + "\n"); } StringBuffer stringBuffer = new StringBuffer(); - for (iter = entries.iterator(); iter.hasNext();) { - stringBuffer.append(iter.next()); + for (String str : entries) { + stringBuffer.append(str); } return stringBuffer.toString(); } diff --git a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java index 911e57646..adbcd1260 100644 --- a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java @@ -33,7 +33,6 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.fop.apps.FOPException; import org.apache.fop.fonts.autodetect.FontFileFinder; import org.apache.fop.fonts.autodetect.FontInfoFinder; @@ -46,11 +45,11 @@ public class FontInfoConfigurator { /** logger instance */ protected static final Log log = LogFactory.getLog(FontInfoConfigurator.class); - private Configuration cfg; - private FontManager fontManager; - private FontResolver fontResolver; - private FontEventListener listener; - private boolean strict; + private final Configuration cfg; + private final FontManager fontManager; + private final FontResolver fontResolver; + private final FontEventListener listener; + private final boolean strict; /** * Main constructor @@ -74,7 +73,8 @@ public class FontInfoConfigurator { * @param fontInfoList a font info list * @throws FOPException if an exception occurs while processing the configuration */ - public void configure(List/*<EmbedFontInfo>*/ fontInfoList) throws FOPException { + public void configure(List<EmbedFontInfo> fontInfoList) + throws FOPException { Configuration fontsCfg = cfg.getChild("fonts", false); if (fontsCfg != null) { long start = 0; @@ -120,7 +120,7 @@ public class FontInfoConfigurator { } private void addDirectories(Configuration fontsCfg, - FontAdder fontAdder, List/*<URL>*/ fontInfoList) throws FOPException { + FontAdder fontAdder, List<EmbedFontInfo> fontInfoList) throws FOPException { // directory (multiple font) configuration Configuration[] directories = fontsCfg.getChildren("directory"); for (int i = 0; i < directories.length; i++) { @@ -158,7 +158,7 @@ public class FontInfoConfigurator { * @throws FOPException if an exception occurs while processing the configuration */ protected void addFonts(Configuration fontsCfg, FontCache fontCache, - List/*<EmbedFontInfo>*/ fontInfoList) throws FOPException { + List<EmbedFontInfo> fontInfoList) throws FOPException { // font file (singular) configuration Configuration[] font = fontsCfg.getChildren("font"); for (int i = 0; i < font.length; i++) { @@ -186,9 +186,8 @@ public class FontInfoConfigurator { * @return the embedded font info * @throws FOPException if something's wrong with the config data */ - protected EmbedFontInfo getFontInfo( - Configuration fontCfg, FontCache fontCache) - throws FOPException { + protected EmbedFontInfo getFontInfo(Configuration fontCfg, FontCache fontCache) + throws FOPException { String metricsUrl = fontCfg.getAttribute("metrics-url", null); String embedUrl = fontCfg.getAttribute("embed-url", null); String subFont = fontCfg.getAttribute("sub-font", null); diff --git a/src/java/org/apache/fop/fonts/FontManager.java b/src/java/org/apache/fop/fonts/FontManager.java index 44b2f030b..51516e231 100644 --- a/src/java/org/apache/fop/fonts/FontManager.java +++ b/src/java/org/apache/fop/fonts/FontManager.java @@ -21,7 +21,6 @@ package org.apache.fop.fonts; import java.io.File; import java.net.MalformedURLException; -import java.util.Iterator; import java.util.List; import javax.xml.transform.Source; @@ -260,7 +259,7 @@ public class FontManager { * ({@link #getReferencedFontsMatcher()}). * @param fontInfoList a font info list */ - public void updateReferencedFonts(List fontInfoList) { + public void updateReferencedFonts(List<EmbedFontInfo> fontInfoList) { Matcher matcher = getReferencedFontsMatcher(); updateReferencedFonts(fontInfoList, matcher); } @@ -270,16 +269,12 @@ public class FontManager { * @param fontInfoList a font info list * @param matcher the font triplet matcher to use */ - public void updateReferencedFonts(List fontInfoList, Matcher matcher) { + public void updateReferencedFonts(List<EmbedFontInfo> fontInfoList, Matcher matcher) { if (matcher == null) { return; //No referenced fonts } - Iterator iter = fontInfoList.iterator(); - while (iter.hasNext()) { - EmbedFontInfo fontInfo = (EmbedFontInfo)iter.next(); - Iterator triplets = fontInfo.getFontTriplets().iterator(); - while (triplets.hasNext()) { - FontTriplet triplet = (FontTriplet)triplets.next(); + for (EmbedFontInfo fontInfo : fontInfoList) { + for (FontTriplet triplet : fontInfo.getFontTriplets()) { if (matcher.matches(triplet)) { fontInfo.setEmbedded(false); break; diff --git a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java index b0a4aada0..421c99051 100644 --- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java @@ -28,7 +28,6 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.fop.apps.FOPException; import org.apache.fop.fonts.substitute.FontSubstitutions; import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator; @@ -42,7 +41,7 @@ public class FontManagerConfigurator { /** logger instance */ private static Log log = LogFactory.getLog(FontManagerConfigurator.class); - private Configuration cfg; + private final Configuration cfg; /** * Main constructor @@ -114,7 +113,7 @@ public class FontManagerConfigurator { */ public static FontTriplet.Matcher createFontsMatcher( Configuration cfg, boolean strict) throws FOPException { - List matcherList = new java.util.ArrayList(); + List<FontTriplet.Matcher> matcherList = new java.util.ArrayList<FontTriplet.Matcher>(); Configuration[] matches = cfg.getChildren("match"); for (int i = 0; i < matches.length; i++) { try { @@ -126,14 +125,13 @@ public class FontManagerConfigurator { } } FontTriplet.Matcher orMatcher = new OrFontTripletMatcher( - (FontTriplet.Matcher[])matcherList.toArray( - new FontTriplet.Matcher[matcherList.size()])); + matcherList.toArray(new FontTriplet.Matcher[matcherList.size()])); return orMatcher; } private static class OrFontTripletMatcher implements FontTriplet.Matcher { - private FontTriplet.Matcher[] matchers; + private final FontTriplet.Matcher[] matchers; public OrFontTripletMatcher(FontTriplet.Matcher[] matchers) { this.matchers = matchers; @@ -153,7 +151,7 @@ public class FontManagerConfigurator { private static class FontFamilyRegExFontTripletMatcher implements FontTriplet.Matcher { - private Pattern regex; + private final Pattern regex; public FontFamilyRegExFontTripletMatcher(String regex) { this.regex = Pattern.compile(regex); diff --git a/src/java/org/apache/fop/fonts/FontMetrics.java b/src/java/org/apache/fop/fonts/FontMetrics.java index 29ade1ef3..ff32d7305 100644 --- a/src/java/org/apache/fop/fonts/FontMetrics.java +++ b/src/java/org/apache/fop/fonts/FontMetrics.java @@ -45,7 +45,7 @@ public interface FontMetrics { * Returns the font's family names as a Set of Strings (Example: "Helvetica"). * @return the font's family names (a Set of Strings) */ - Set getFamilyNames(); + Set<String> getFamilyNames(); /** * Returns the font name for font embedding (may include a prefix, Example: "1E28bcArialMT"). @@ -129,6 +129,6 @@ public interface FontMetrics { * Returns the kerning map for the font. * @return the kerning map */ - Map getKerningInfo(); + Map<Integer, Map<Integer, Integer>> getKerningInfo(); } diff --git a/src/java/org/apache/fop/fonts/FontReader.java b/src/java/org/apache/fop/fonts/FontReader.java index 16da99baa..e9b88ec16 100644 --- a/src/java/org/apache/fop/fonts/FontReader.java +++ b/src/java/org/apache/fop/fonts/FontReader.java @@ -21,6 +21,9 @@ package org.apache.fop.fonts; //Java import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -56,12 +59,12 @@ public class FontReader extends DefaultHandler { private SingleByteFont singleFont = null; private StringBuffer text = new StringBuffer(); - private List cidWidths = null; + private List<Integer> cidWidths = null; private int cidWidthIndex = 0; - private Map currentKerning = null; + private Map<Integer, Integer> currentKerning = null; - private List bfranges = null; + private List<BFEntry> bfranges = null; private void createFont(InputSource source) throws FOPException { XMLReader parser = null; @@ -181,13 +184,13 @@ public class FontReader extends DefaultHandler { returnFont.setEmbedResourceName(attributes.getValue("class")); } else if ("cid-widths".equals(localName)) { cidWidthIndex = getInt(attributes.getValue("start-index")); - cidWidths = new java.util.ArrayList(); + cidWidths = new ArrayList<Integer>(); } else if ("kerning".equals(localName)) { - currentKerning = new java.util.HashMap(); + currentKerning = new HashMap<Integer, Integer>(); returnFont.putKerningEntry(new Integer(attributes.getValue("kpx1")), currentKerning); } else if ("bfranges".equals(localName)) { - bfranges = new java.util.ArrayList(); + bfranges = new ArrayList<BFEntry>(); } else if ("bf".equals(localName)) { BFEntry entry = new BFEntry(getInt(attributes.getValue("us")), getInt(attributes.getValue("ue")), @@ -231,7 +234,7 @@ public class FontReader extends DefaultHandler { } else if ("full-name".equals(localName)) { returnFont.setFullName(content); } else if ("family-name".equals(localName)) { - Set s = new java.util.HashSet(); + Set<String> s = new HashSet<String>(); s.add(content); returnFont.setFamilyNames(s); } else if ("ttc-name".equals(localName) && isCID) { @@ -284,15 +287,14 @@ public class FontReader extends DefaultHandler { int[] wds = new int[cidWidths.size()]; int j = 0; for (int count = 0; count < cidWidths.size(); count++) { - Integer i = (Integer)cidWidths.get(count); - wds[j++] = i.intValue(); + wds[j++] = cidWidths.get(count).intValue(); } //multiFont.addCIDWidthEntry(cidWidthIndex, wds); multiFont.setWidthArray(wds); } else if ("bfranges".equals(localName)) { - multiFont.setBFEntries((BFEntry[])bfranges.toArray(new BFEntry[0])); + multiFont.setBFEntries(bfranges.toArray(new BFEntry[0])); } text.setLength(0); //Reset text buffer (see characters()) } diff --git a/src/java/org/apache/fop/fonts/FontSetup.java b/src/java/org/apache/fop/fonts/FontSetup.java index 1f49f7bb5..935f695b1 100644 --- a/src/java/org/apache/fop/fonts/FontSetup.java +++ b/src/java/org/apache/fop/fonts/FontSetup.java @@ -72,7 +72,8 @@ public final class FontSetup { * @param embedFontInfoList a list of EmbedFontInfo objects * @param resolver the font resolver */ - public static void setup(FontInfo fontInfo, List embedFontInfoList, FontResolver resolver) { + public static void setup(FontInfo fontInfo, List<EmbedFontInfo> embedFontInfoList, + FontResolver resolver) { final boolean base14Kerning = false; fontInfo.addMetrics("F1", new Helvetica(base14Kerning)); fontInfo.addMetrics("F2", new HelveticaOblique(base14Kerning)); @@ -190,7 +191,7 @@ public final class FontSetup { * @param resolver the font resolver */ private static void addConfiguredFonts(FontInfo fontInfo, - List/*<EmbedFontInfo>*/ embedFontInfoList, int num, FontResolver resolver) { + List<EmbedFontInfo> embedFontInfoList, int num, FontResolver resolver) { if (embedFontInfoList == null) { return; //No fonts to process } @@ -202,18 +203,16 @@ public final class FontSetup { String internalName = null; - for (int i = 0; i < embedFontInfoList.size(); i++) { - EmbedFontInfo embedFontInfo = (EmbedFontInfo)embedFontInfoList.get(i); - + for (EmbedFontInfo embedFontInfo : embedFontInfoList) { internalName = "F" + num; num++; LazyFont font = new LazyFont(embedFontInfo, resolver); fontInfo.addMetrics(internalName, font); - List triplets = embedFontInfo.getFontTriplets(); + List<FontTriplet> triplets = embedFontInfo.getFontTriplets(); for (int tripletIndex = 0; tripletIndex < triplets.size(); tripletIndex++) { - FontTriplet triplet = (FontTriplet) triplets.get(tripletIndex); + FontTriplet triplet = triplets.get(tripletIndex); fontInfo.addFontProperties(internalName, triplet); } } diff --git a/src/java/org/apache/fop/fonts/FontTriplet.java b/src/java/org/apache/fop/fonts/FontTriplet.java index f5cfe442a..c14634460 100644 --- a/src/java/org/apache/fop/fonts/FontTriplet.java +++ b/src/java/org/apache/fop/fonts/FontTriplet.java @@ -25,7 +25,7 @@ import java.io.Serializable; /** * FontTriplet contains information on name, style and weight of one font */ -public class FontTriplet implements Comparable, Serializable { +public class FontTriplet implements Comparable<FontTriplet>, Serializable { /** serial version UID */ private static final long serialVersionUID = 1168991106658033508L; @@ -99,8 +99,8 @@ public class FontTriplet implements Comparable, Serializable { } /** {@inheritDoc} */ - public int compareTo(Object o) { - return getKey().compareTo(((FontTriplet)o).getKey()); + public int compareTo(FontTriplet o) { + return getKey().compareTo(o.getKey()); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/fonts/LazyFont.java b/src/java/org/apache/fop/fonts/LazyFont.java index e5d111d38..a8fd447c4 100644 --- a/src/java/org/apache/fop/fonts/LazyFont.java +++ b/src/java/org/apache/fop/fonts/LazyFont.java @@ -221,7 +221,7 @@ public class LazyFont extends Typeface implements FontDescriptor { } /** {@inheritDoc} */ - public Set getFamilyNames() { + public Set<String> getFamilyNames() { load(true); return realFont.getFamilyNames(); } @@ -293,7 +293,7 @@ public class LazyFont extends Typeface implements FontDescriptor { /** * {@inheritDoc} */ - public Map getKerningInfo() { + public Map<Integer, Map<Integer, Integer>> getKerningInfo() { load(true); return realFont.getKerningInfo(); } diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java index b3b5d8639..afac21c1b 100644 --- a/src/java/org/apache/fop/fonts/MultiByteFont.java +++ b/src/java/org/apache/fop/fonts/MultiByteFont.java @@ -237,7 +237,7 @@ public class MultiByteFont extends CIDFont { * Returns a Map of used Glyphs. * @return Map Map of used Glyphs */ - public Map getUsedGlyphs() { + public Map<Integer, Integer> getUsedGlyphs() { return subset.getSubsetGlyphs(); } diff --git a/src/java/org/apache/fop/fonts/MutableFont.java b/src/java/org/apache/fop/fonts/MutableFont.java index a5acf51b3..bcbcadbdc 100644 --- a/src/java/org/apache/fop/fonts/MutableFont.java +++ b/src/java/org/apache/fop/fonts/MutableFont.java @@ -46,7 +46,7 @@ public interface MutableFont { * Sets the font's family names (Example: "Helvetica"). * @param names the font's family names (a Set of Strings) */ - void setFamilyNames(Set names); + void setFamilyNames(Set<String> names); /** * Sets the path to the embeddable font file. @@ -137,6 +137,6 @@ public interface MutableFont { * @param key Kerning key * @param value Kerning value */ - void putKerningEntry(Integer key, Map value); + void putKerningEntry(Integer key, Map<Integer, Integer> value); } diff --git a/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java b/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java index d55529d58..cec39bfb9 100644 --- a/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java +++ b/src/java/org/apache/fop/fonts/SimpleSingleByteEncoding.java @@ -19,13 +19,14 @@ package org.apache.fop.fonts; +import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.xmlgraphics.fonts.Glyphs; - import org.apache.fop.util.CharUtilities; +import org.apache.xmlgraphics.fonts.Glyphs; /** * A simple implementation of the OneByteEncoding mostly used for encodings that are constructed @@ -33,11 +34,9 @@ import org.apache.fop.util.CharUtilities; */ public class SimpleSingleByteEncoding implements SingleByteEncoding { - private String name; - private List mapping = new java.util.ArrayList(); - //List<NamedCharacter> - private Map charMap = new java.util.HashMap(); - //Map<Character(Unicode), Character(code point)> + private final String name; + private final List<NamedCharacter> mapping = new ArrayList<NamedCharacter>(); + private final Map<Character, Character> charMap = new HashMap<Character, Character>(); /** * Main constructor. @@ -54,7 +53,7 @@ public class SimpleSingleByteEncoding implements SingleByteEncoding { /** {@inheritDoc} */ public char mapChar(char c) { - Character nc = (Character)charMap.get(new Character(c)); + Character nc = charMap.get(new Character(c)); if (nc != null) { return nc.charValue(); } @@ -66,7 +65,7 @@ public class SimpleSingleByteEncoding implements SingleByteEncoding { String[] map = new String[getSize()]; Arrays.fill(map, Glyphs.NOTDEF); for (int i = getFirstChar(); i <= getLastChar(); i++) { - NamedCharacter ch = (NamedCharacter)this.mapping.get(i - 1); + NamedCharacter ch = this.mapping.get(i - 1); map[i] = ch.getName(); } return map; @@ -133,7 +132,7 @@ public class SimpleSingleByteEncoding implements SingleByteEncoding { throw new IllegalArgumentException("codePoint must be between 0 and 255"); } if (codePoint <= getLastChar()) { - return (NamedCharacter)this.mapping.get(codePoint - 1); + return this.mapping.get(codePoint - 1); } else { return null; } @@ -152,6 +151,7 @@ public class SimpleSingleByteEncoding implements SingleByteEncoding { } /** {@inheritDoc} */ + @Override public String toString() { return getName() + " (" + getSize() + " chars)"; } diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java index fb4725bd4..d798db1bb 100644 --- a/src/java/org/apache/fop/fonts/SingleByteFont.java +++ b/src/java/org/apache/fop/fonts/SingleByteFont.java @@ -19,10 +19,12 @@ package org.apache.fop.fonts; -import java.util.Iterator; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,9 +42,8 @@ public class SingleByteFont extends CustomFont { private int[] width = null; - private Map unencodedCharacters; - //Map<Character, UnencodedCharacter> - private List additionalEncodings; + private Map<Character, UnencodedCharacter> unencodedCharacters; + private List<SimpleSingleByteEncoding> additionalEncodings; /** @@ -59,6 +60,7 @@ public class SingleByteFont extends CustomFont { } /** {@inheritDoc} */ + @Override public String getEncodingName() { return this.mapping.getName(); } @@ -84,8 +86,7 @@ public class SingleByteFont extends CustomFont { int codePoint = i % 256; NamedCharacter nc = encoding.getCharacterForIndex(codePoint); UnencodedCharacter uc - = (UnencodedCharacter)this.unencodedCharacters.get( - new Character(nc.getSingleUnicodeValue())); + = this.unencodedCharacters.get(new Character(nc.getSingleUnicodeValue())); return size * uc.getWidth(); } return 0; @@ -99,6 +100,7 @@ public class SingleByteFont extends CustomFont { } /** {@inheritDoc} */ + @Override public char mapChar(char c) { notifyMapOperation(); char d = mapping.mapChar(c); @@ -117,11 +119,10 @@ public class SingleByteFont extends CustomFont { private char mapUnencodedChar(char ch) { if (this.unencodedCharacters != null) { - UnencodedCharacter unencoded - = (UnencodedCharacter)this.unencodedCharacters.get(new Character(ch)); + UnencodedCharacter unencoded = this.unencodedCharacters.get(new Character(ch)); if (unencoded != null) { if (this.additionalEncodings == null) { - this.additionalEncodings = new java.util.ArrayList(); + this.additionalEncodings = new ArrayList<SimpleSingleByteEncoding>(); } SimpleSingleByteEncoding encoding = null; char mappedStart = 0; @@ -150,6 +151,7 @@ public class SingleByteFont extends CustomFont { } /** {@inheritDoc} */ + @Override public boolean hasChar(char c) { char d = mapping.mapChar(c); if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) { @@ -230,7 +232,7 @@ public class SingleByteFont extends CustomFont { */ public void addUnencodedCharacter(NamedCharacter ch, int width) { if (this.unencodedCharacters == null) { - this.unencodedCharacters = new java.util.HashMap(); + this.unencodedCharacters = new HashMap<Character, UnencodedCharacter>(); } if (ch.hasSingleUnicodeValue()) { UnencodedCharacter uc = new UnencodedCharacter(ch, width); @@ -248,10 +250,8 @@ public class SingleByteFont extends CustomFont { */ public void encodeAllUnencodedCharacters() { if (this.unencodedCharacters != null) { - Set sortedKeys = new java.util.TreeSet(this.unencodedCharacters.keySet()); - Iterator iter = sortedKeys.iterator(); - while (iter.hasNext()) { - Character ch = (Character)iter.next(); + Set<Character> sortedKeys = new TreeSet<Character>(this.unencodedCharacters.keySet()); + for (Character ch : sortedKeys) { char mapped = mapChar(ch.charValue()); assert mapped != Typeface.NOT_FOUND; } @@ -287,7 +287,7 @@ public class SingleByteFont extends CustomFont { public SimpleSingleByteEncoding getAdditionalEncoding(int index) throws IndexOutOfBoundsException { if (hasAdditionalEncodings()) { - return (SimpleSingleByteEncoding)this.additionalEncodings.get(index); + return this.additionalEncodings.get(index); } else { throw new IndexOutOfBoundsException("No additional encodings available"); } @@ -303,7 +303,7 @@ public class SingleByteFont extends CustomFont { int[] arr = new int[enc.getLastChar() - enc.getFirstChar() + 1]; for (int i = 0, c = arr.length; i < c; i++) { NamedCharacter nc = enc.getCharacterForIndex(enc.getFirstChar() + i); - UnencodedCharacter uc = (UnencodedCharacter)this.unencodedCharacters.get( + UnencodedCharacter uc = this.unencodedCharacters.get( new Character(nc.getSingleUnicodeValue())); arr[i] = uc.getWidth(); } @@ -312,8 +312,8 @@ public class SingleByteFont extends CustomFont { private static final class UnencodedCharacter { - private NamedCharacter character; - private int width; + private final NamedCharacter character; + private final int width; public UnencodedCharacter(NamedCharacter character, int width) { this.character = character; @@ -329,6 +329,7 @@ public class SingleByteFont extends CustomFont { } /** {@inheritDoc} */ + @Override public String toString() { return getCharacter().toString(); } diff --git a/src/java/org/apache/fop/fonts/Typeface.java b/src/java/org/apache/fop/fonts/Typeface.java index f0419464c..a0c1d99ec 100644 --- a/src/java/org/apache/fop/fonts/Typeface.java +++ b/src/java/org/apache/fop/fonts/Typeface.java @@ -19,6 +19,7 @@ package org.apache.fop.fonts; +import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; @@ -49,7 +50,7 @@ public abstract class Typeface implements FontMetrics { /** An optional event listener that receives events such as missing glyphs etc. */ protected FontEventListener eventListener; - private Set warnedChars; + private Set<Character> warnedChars; /** * Get the encoding of the font. @@ -120,7 +121,7 @@ public abstract class Typeface implements FontMetrics { // Give up, character is not available Character ch = new Character(c); if (warnedChars == null) { - warnedChars = new java.util.HashSet(); + warnedChars = new HashSet<Character>(); } if (warnedChars.size() < 8 && !warnedChars.contains(ch)) { warnedChars.add(ch); diff --git a/src/java/org/apache/fop/fonts/autodetect/FontFinder.java b/src/java/org/apache/fop/fonts/autodetect/FontFinder.java index 0ab71daec..ee0d1e07f 100644 --- a/src/java/org/apache/fop/fonts/autodetect/FontFinder.java +++ b/src/java/org/apache/fop/fonts/autodetect/FontFinder.java @@ -37,6 +37,6 @@ public interface FontFinder { * @throws IOException * In case of an I/O problem */ - List/*<URL>*/ find() throws IOException; + List find() throws IOException; } diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFile.java b/src/java/org/apache/fop/fonts/truetype/TTFFile.java index a049aaf04..11386299e 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFFile.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFFile.java @@ -28,10 +28,8 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.apache.xmlgraphics.fonts.Glyphs; - import org.apache.fop.fonts.FontUtil; +import org.apache.xmlgraphics.fonts.Glyphs; /** * Reads a TrueType file or a TrueType Collection. @@ -48,17 +46,17 @@ public class TTFFile { /** Set to true to get even more debug output than with level DEBUG */ public static final boolean TRACE_ENABLED = false; - private String encoding = "WinAnsiEncoding"; // Default encoding + private final String encoding = "WinAnsiEncoding"; // Default encoding - private short firstChar = 0; + private final short firstChar = 0; private boolean isEmbeddable = true; private boolean hasSerifs = true; /** * Table directory */ protected Map dirTabs; - private Map kerningTab; // for CIDs - private Map ansiKerningTab; // For winAnsiEncoding + private Map<Integer, Map<Integer, Integer>> kerningTab; // for CIDs + private Map<Integer, Map<Integer, Integer>> ansiKerningTab; // For winAnsiEncoding private List cmaps; private List unicodeMapping; @@ -77,12 +75,12 @@ public class TTFFile { * Contains glyph data */ protected TTFMtxEntry[] mtxTab; // Contains glyph data - private int[] mtxEncoded = null; + private final int[] mtxEncoded = null; private String postScriptName = ""; private String fullName = ""; private String notice = ""; - private Set familyNames = new java.util.HashSet(); //Set<String> + private final Set familyNames = new java.util.HashSet(); //Set<String> private String subFamilyName = ""; private long italicAngle = 0; @@ -115,8 +113,8 @@ public class TTFFile { // internal mapping of glyph indexes to unicode indexes // used for quick mappings in this class - private Map glyphToUnicodeMap = new java.util.HashMap(); - private Map unicodeToGlyphMap = new java.util.HashMap(); + private final Map glyphToUnicodeMap = new java.util.HashMap(); + private final Map unicodeToGlyphMap = new java.util.HashMap(); private TTFDirTabEntry currentDirTab; @@ -132,8 +130,8 @@ public class TTFFile { */ class UnicodeMapping { - private int unicodeIndex; - private int glyphIndex; + private final int unicodeIndex; + private final int glyphIndex; UnicodeMapping(int glyphIndex, int unicodeIndex) { this.unicodeIndex = unicodeIndex; @@ -492,7 +490,7 @@ public class TTFFile { ansiIndex = new java.util.HashMap(); for (int i = 32; i < Glyphs.WINANSI_ENCODING.length; i++) { Integer ansi = new Integer(i); - Integer uni = new Integer((int)Glyphs.WINANSI_ENCODING[i]); + Integer uni = new Integer(Glyphs.WINANSI_ENCODING[i]); List v = (List)ansiIndex.get(uni); if (v == null) { @@ -641,7 +639,7 @@ public class TTFFile { * @return int The CapHeight */ public int getCapHeight() { - return (int)convertTTFUnit2PDFUnit(capHeight); + return convertTTFUnit2PDFUnit(capHeight); } /** @@ -649,7 +647,7 @@ public class TTFFile { * @return int The XHeight */ public int getXHeight() { - return (int)convertTTFUnit2PDFUnit(xHeight); + return convertTTFUnit2PDFUnit(xHeight); } /** @@ -708,10 +706,10 @@ public class TTFFile { */ public int[] getFontBBox() { final int[] fbb = new int[4]; - fbb[0] = (int)convertTTFUnit2PDFUnit(fontBBox1); - fbb[1] = (int)convertTTFUnit2PDFUnit(fontBBox2); - fbb[2] = (int)convertTTFUnit2PDFUnit(fontBBox3); - fbb[3] = (int)convertTTFUnit2PDFUnit(fontBBox4); + fbb[0] = convertTTFUnit2PDFUnit(fontBBox1); + fbb[1] = convertTTFUnit2PDFUnit(fontBBox2); + fbb[2] = convertTTFUnit2PDFUnit(fontBBox3); + fbb[3] = convertTTFUnit2PDFUnit(fontBBox4); return fbb; } @@ -721,7 +719,7 @@ public class TTFFile { * @return int The LowerCaseAscent */ public int getLowerCaseAscent() { - return (int)convertTTFUnit2PDFUnit(ascender); + return convertTTFUnit2PDFUnit(ascender); } /** @@ -729,7 +727,7 @@ public class TTFFile { * @return int The LowerCaseDescent */ public int getLowerCaseDescent() { - return (int)convertTTFUnit2PDFUnit(descender); + return convertTTFUnit2PDFUnit(descender); } /** @@ -756,7 +754,7 @@ public class TTFFile { public int[] getWidths() { int[] wx = new int[mtxTab.length]; for (int i = 0; i < wx.length; i++) { - wx[i] = (int)convertTTFUnit2PDFUnit(mtxTab[i].getWx()); + wx[i] = convertTTFUnit2PDFUnit(mtxTab[i].getWx()); } return wx; @@ -768,14 +766,14 @@ public class TTFFile { * @return int Standard width */ public int getCharWidth(int idx) { - return (int)convertTTFUnit2PDFUnit(ansiWidth[idx]); + return convertTTFUnit2PDFUnit(ansiWidth[idx]); } /** * Returns the kerning table. * @return Map The kerning table */ - public Map getKerning() { + public Map<Integer, Map<Integer, Integer>> getKerning() { return kerningTab; } @@ -783,7 +781,7 @@ public class TTFFile { * Returns the ANSI kerning table. * @return Map The ANSI kerning table */ - public Map getAnsiKerning() { + public Map<Integer, Map<Integer, Integer>> getAnsiKerning() { return ansiKerningTab; } @@ -1440,11 +1438,11 @@ public class TTFFile { log.debug("Ignoring kerning pair because Unicode index was" + " found for the second glyph " + i); } else { - Map adjTab = (Map)kerningTab.get(iObj); + Map adjTab = kerningTab.get(iObj); if (adjTab == null) { adjTab = new java.util.HashMap(); } - adjTab.put(u2, new Integer((int)convertTTFUnit2PDFUnit(kpx))); + adjTab.put(u2, new Integer(convertTTFUnit2PDFUnit(kpx))); kerningTab.put(iObj, adjTab); } } @@ -1458,8 +1456,8 @@ public class TTFFile { while (ae.hasNext()) { Integer unicodeKey1 = (Integer)ae.next(); Integer cidKey1 = unicodeToGlyph(unicodeKey1.intValue()); - Map akpx = new java.util.HashMap(); - Map ckpx = (Map)kerningTab.get(unicodeKey1); + Map<Integer, Integer> akpx = new java.util.HashMap(); + Map ckpx = kerningTab.get(unicodeKey1); Iterator aee = ckpx.keySet().iterator(); while (aee.hasNext()) { @@ -1640,8 +1638,8 @@ public class TTFFile { System.out.println("Family name: " + familyNames); System.out.println("Subfamily name: " + subFamilyName); System.out.println("Notice: " + notice); - System.out.println("xHeight: " + (int)convertTTFUnit2PDFUnit(xHeight)); - System.out.println("capheight: " + (int)convertTTFUnit2PDFUnit(capHeight)); + System.out.println("xHeight: " + convertTTFUnit2PDFUnit(xHeight)); + System.out.println("capheight: " + convertTTFUnit2PDFUnit(capHeight)); int italic = (int)(italicAngle >> 16); System.out.println("Italic: " + italic); @@ -1654,10 +1652,10 @@ public class TTFFile { System.out.println(); System.out.println("Ascender: " + convertTTFUnit2PDFUnit(ascender)); System.out.println("Descender: " + convertTTFUnit2PDFUnit(descender)); - System.out.println("FontBBox: [" + (int)convertTTFUnit2PDFUnit(fontBBox1) - + " " + (int)convertTTFUnit2PDFUnit(fontBBox2) + " " - + (int)convertTTFUnit2PDFUnit(fontBBox3) + " " - + (int)convertTTFUnit2PDFUnit(fontBBox4) + "]"); + System.out.println("FontBBox: [" + convertTTFUnit2PDFUnit(fontBBox1) + + " " + convertTTFUnit2PDFUnit(fontBBox2) + " " + + convertTTFUnit2PDFUnit(fontBBox3) + " " + + convertTTFUnit2PDFUnit(fontBBox4) + "]"); } private String formatUnitsForDebug(int units) { diff --git a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java index 405a25f9e..8ee36ec1f 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java @@ -24,11 +24,9 @@ import java.io.InputStream; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.io.IOUtils; - -import org.apache.xmlgraphics.fonts.Glyphs; - import org.apache.fop.fonts.BFEntry; import org.apache.fop.fonts.CIDFontType; import org.apache.fop.fonts.EncodingMode; @@ -38,6 +36,7 @@ import org.apache.fop.fonts.FontType; import org.apache.fop.fonts.MultiByteFont; import org.apache.fop.fonts.NamedCharacter; import org.apache.fop.fonts.SingleByteFont; +import org.apache.xmlgraphics.fonts.Glyphs; /** * Loads a TrueType font into memory directly from the original font file. @@ -46,7 +45,7 @@ public class TTFFontLoader extends FontLoader { private MultiByteFont multiFont; private SingleByteFont singleFont; - private String subFontName; + private final String subFontName; private EncodingMode encodingMode; /** @@ -80,6 +79,7 @@ public class TTFFontLoader extends FontLoader { } /** {@inheritDoc} */ + @Override protected void read() throws IOException { read(this.subFontName); } @@ -205,21 +205,20 @@ public class TTFFontLoader extends FontLoader { private void copyKerning(TTFFile ttf, boolean isCid) { // Get kerning - Iterator iter; + Set<Integer> kerningSet; if (isCid) { - iter = ttf.getKerning().keySet().iterator(); + kerningSet = ttf.getKerning().keySet(); } else { - iter = ttf.getAnsiKerning().keySet().iterator(); + kerningSet = ttf.getAnsiKerning().keySet(); } - while (iter.hasNext()) { - Integer kpx1 = (Integer)iter.next(); + for (Integer kpx1 : kerningSet) { - Map h2; + Map<Integer, Integer> h2; if (isCid) { - h2 = (Map)ttf.getKerning().get(kpx1); + h2 = ttf.getKerning().get(kpx1); } else { - h2 = (Map)ttf.getAnsiKerning().get(kpx1); + h2 = ttf.getAnsiKerning().get(kpx1); } returnFont.putKerningEntry(kpx1, h2); } diff --git a/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java b/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java index 37e24836e..ee89d9303 100644 --- a/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java +++ b/src/java/org/apache/fop/fonts/truetype/TTFSubSetFile.java @@ -645,7 +645,7 @@ public class TTFSubSetFile extends TTFFile { * @throws IOException in case of an I/O problem */ public byte[] readFont(FontFileReader in, String name, - Map glyphs) throws IOException { + Map<Integer, Integer> glyphs) throws IOException { //Check if TrueType collection, and that the name exists in the collection if (!checkTTC(in, name)) { @@ -653,7 +653,7 @@ public class TTFSubSetFile extends TTFFile { } //Copy the Map as we're going to modify it - Map subsetGlyphs = new java.util.HashMap(glyphs); + Map<Integer, Integer> subsetGlyphs = new java.util.HashMap<Integer, Integer>(glyphs); output = new byte[in.getFileSize()]; diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java index e41a8f272..43276b630 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java @@ -27,7 +27,6 @@ import java.util.ListIterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.apache.fop.area.Area; import org.apache.fop.area.LineArea; import org.apache.fop.area.Trait; @@ -94,7 +93,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager */ private static Log log = LogFactory.getLog(LineLayoutManager.class); - private Block fobj; + private final Block fobj; private boolean isFirstInBlock; /** @@ -103,19 +102,19 @@ public class LineLayoutManager extends InlineStackingLayoutManager * inline break positions. */ private static class LineBreakPosition extends LeafPosition { - private int parIndex; // index of the Paragraph this Position refers to - private int startIndex; //index of the first element this Position refers to - private int availableShrink; - private int availableStretch; - private int difference; - private double dAdjust; // Percentage to adjust (stretch or shrink) - private double ipdAdjust; // Percentage to adjust (stretch or shrink) - private int startIndent; - private int lineHeight; - private int lineWidth; - private int spaceBefore; - private int spaceAfter; - private int baseline; + private final int parIndex; // index of the Paragraph this Position refers to + private final int startIndex; //index of the first element this Position refers to + private final int availableShrink; + private final int availableStretch; + private final int difference; + private final double dAdjust; // Percentage to adjust (stretch or shrink) + private final double ipdAdjust; // Percentage to adjust (stretch or shrink) + private final int startIndent; + private final int lineHeight; + private final int lineWidth; + private final int spaceBefore; + private final int spaceAfter; + private final int baseline; LineBreakPosition( // CSOK: ParameterNumber LayoutManager lm, int index, int startIndex, int breakIndex, @@ -151,9 +150,9 @@ public class LineLayoutManager extends InlineStackingLayoutManager private int whiteSpaceTreament; //private LayoutProps layoutProps; - private Length lineHeight; - private int lead; - private int follow; + private final Length lineHeight; + private final int lead; + private final int follow; private AlignmentContext alignmentContext; private List knuthParagraphs; @@ -194,12 +193,12 @@ public class LineLayoutManager extends InlineStackingLayoutManager // space at the end of the last line (in millipoints) private MinOptMax lineFiller; - private int textAlignment; - private int textAlignmentLast; - private int textIndent; - private int lastLineEndIndent; + private final int textAlignment; + private final int textAlignmentLast; + private final int textIndent; + private final int lastLineEndIndent; // the LM which created the paragraph - private LineLayoutManager layoutManager; + private final LineLayoutManager layoutManager; Paragraph(LineLayoutManager llm, int alignment, int alignmentLast, int indent, int endIndent) { @@ -211,6 +210,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager lastLineEndIndent = endIndent; } + @Override public void startSequence() { // set the minimum amount of empty space at the end of the // last line @@ -245,6 +245,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } } + @Override public KnuthSequence endSequence() { if (this.size() > ignoreAtStart) { if (textAlignment == EN_CENTER @@ -294,14 +295,14 @@ public class LineLayoutManager extends InlineStackingLayoutManager } private class LineBreakingAlgorithm extends BreakingAlgorithm { - private LineLayoutManager thisLLM; - private int pageAlignment; + private final LineLayoutManager thisLLM; + private final int pageAlignment; private int activePossibility; private int addedPositions; - private int textIndent; - private int lineHeight; - private int lead; - private int follow; + private final int textIndent; + private final int lineHeight; + private final int lead; + private final int follow; private static final double MAX_DEMERITS = 10e6; public LineBreakingAlgorithm( // CSOK: ParameterNumber @@ -317,6 +318,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager activePossibility = -1; } + @Override public void updateData1(int lineCount, double demerits) { lineLayouts.addPossibility(lineCount, demerits); if (log.isTraceEnabled()) { @@ -324,6 +326,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } } + @Override public void updateData2(KnuthNode bestActiveNode, KnuthSequence par, int total) { @@ -466,6 +469,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } } + @Override protected int filterActiveNodes() { KnuthNode bestActiveNode = null; @@ -537,6 +541,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } /** {@inheritDoc} */ + @Override public void initialize() { textAlignment = fobj.getTextAlign(); textAlignmentLast = fobj.getTextAlignLast(); @@ -560,6 +565,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } /** {@inheritDoc} */ + @Override public List getNextKnuthElements(LayoutContext context, int alignment) { if (alignmentContext == null) { FontInfo fi = fobj.getFOEventHandler().getFontInfo(); @@ -771,7 +777,8 @@ public class LineLayoutManager extends InlineStackingLayoutManager // we only need an entry in lineLayoutsList. llPoss = new LineLayoutPossibilities(); } else { - llPoss = findOptimalBreakingPoints(alignment, (Paragraph) seq, !paragraphsIterator.hasNext()); + llPoss = findOptimalBreakingPoints(alignment, (Paragraph) seq, + !paragraphsIterator.hasNext()); } lineLayoutsList[i] = llPoss; } @@ -789,7 +796,8 @@ public class LineLayoutManager extends InlineStackingLayoutManager * @param isLastPar flag indicating whether currPar is the last paragraph * @return the line layout possibilities for the paragraph */ - private LineLayoutPossibilities findOptimalBreakingPoints(int alignment, Paragraph currPar, boolean isLastPar) { + private LineLayoutPossibilities findOptimalBreakingPoints(int alignment, Paragraph currPar, + boolean isLastPar) { // use the member lineLayouts, which is read by LineBreakingAlgorithm.updateData1 and 2 lineLayouts = new LineLayoutPossibilities(); double maxAdjustment = 1; @@ -855,7 +863,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager // use non-hyphenated breaks, when possible lineLayouts.restorePossibilities(); } - + return lineLayouts; } @@ -1158,6 +1166,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } /** {@inheritDoc} */ + @Override public List getChangedKnuthElements(List oldList, int alignment) { List returnList = new LinkedList(); for (int p = 0; p < knuthParagraphs.size(); p++) { @@ -1340,6 +1349,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager * @param isNotFirst ignored * @return always true */ + @Override protected boolean hasLeadingFence(boolean isNotFirst) { return true; } @@ -1349,6 +1359,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager * @param isNotLast ignored * @return always true */ + @Override protected boolean hasTrailingFence(boolean isNotLast) { return true; } @@ -1396,6 +1407,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager * @param parentIter the iterator of break positions * @param context the context for adding areas */ + @Override public void addAreas(PositionIterator parentIter, LayoutContext context) { while (parentIter.hasNext()) { @@ -1566,6 +1578,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager } /** {@inheritDoc} */ + @Override public void addChildArea(Area childArea) { // Make sure childArea is inline area if (childArea instanceof InlineArea) { @@ -1581,16 +1594,19 @@ public class LineLayoutManager extends InlineStackingLayoutManager // --------- Property Resolution related functions --------- // /** {@inheritDoc} */ + @Override public boolean getGeneratesBlockArea() { return true; } /** {@inheritDoc} */ + @Override public boolean getGeneratesLineArea() { return true; } /** {@inheritDoc} */ + @Override public boolean isRestartable() { return true; } diff --git a/src/java/org/apache/fop/pdf/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java index cbfc9d53a..12eca75e4 100644 --- a/src/java/org/apache/fop/pdf/PDFResources.java +++ b/src/java/org/apache/fop/pdf/PDFResources.java @@ -98,11 +98,9 @@ public class PDFResources extends PDFObject { * @param fontInfo font info object to get font information from */ public void addFonts(PDFDocument doc, FontInfo fontInfo) { - Map usedFonts = fontInfo.getUsedFonts(); - Iterator e = usedFonts.keySet().iterator(); - while (e.hasNext()) { - String f = (String)e.next(); - Typeface font = (Typeface)usedFonts.get(f); + Map<String, Typeface> usedFonts = fontInfo.getUsedFonts(); + for (String f : usedFonts.keySet()) { + Typeface font = usedFonts.get(f); //Check if the font actually had any mapping operations. If not, it is an indication //that it has never actually been used and therefore doesn't have to be embedded. @@ -196,6 +194,7 @@ public class PDFResources extends PDFObject { * @return the PDF * {@inheritDoc} */ + @Override public String toPDFString() { StringBuffer p = new StringBuffer(128); p.append(getObjectID() + "<<\n"); diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java index 6e501c199..be3ace016 100644 --- a/src/java/org/apache/fop/render/PrintRenderer.java +++ b/src/java/org/apache/fop/render/PrintRenderer.java @@ -30,6 +30,7 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.area.Area; import org.apache.fop.area.Trait; import org.apache.fop.fonts.CustomFontCollection; +import org.apache.fop.fonts.EmbedFontInfo; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; @@ -48,13 +49,13 @@ public abstract class PrintRenderer extends AbstractRenderer { protected FontResolver fontResolver = null; /** list of fonts */ - protected List/*<EmbedFontInfo>*/ embedFontInfoList = null; + protected List<EmbedFontInfo> embedFontInfoList = null; /** * Adds a font list to current list of fonts * @param fontList a font info list */ - public void addFontList(List/*<EmbedFontInfo>*/ fontList) { + public void addFontList(List<EmbedFontInfo> fontList) { if (embedFontInfoList == null) { setFontList(fontList); } else { @@ -65,14 +66,14 @@ public abstract class PrintRenderer extends AbstractRenderer { /** * @param embedFontInfoList list of available fonts */ - public void setFontList(List/*<EmbedFontInfo>*/ embedFontInfoList) { + public void setFontList(List<EmbedFontInfo> embedFontInfoList) { this.embedFontInfoList = embedFontInfoList; } /** * @return list of available embedded fonts */ - public List/*<EmbedFontInfo>*/ getFontList() { + public List<EmbedFontInfo> getFontList() { return this.embedFontInfoList; } diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java index 8f94684b2..90305ae03 100644 --- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java +++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java @@ -19,6 +19,7 @@ package org.apache.fop.render; +import java.util.ArrayList; import java.util.List; import org.apache.avalon.framework.configuration.Configuration; @@ -76,7 +77,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator FontEventListener listener = new FontEventAdapter( renderer.getUserAgent().getEventBroadcaster()); - List/*<EmbedFontInfo>*/ embedFontInfoList = buildFontList(cfg, fontResolver, listener); + List<EmbedFontInfo> embedFontInfoList = buildFontList(cfg, fontResolver, listener); printRenderer.addFontList(embedFontInfoList); } @@ -88,7 +89,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator * @return the list of {@link EmbedFontInfo} objects * @throws FOPException if an error occurs while processing the configuration */ - protected List/*<EmbedFontInfo>*/ buildFontList(Configuration cfg, FontResolver fontResolver, + protected List<EmbedFontInfo> buildFontList(Configuration cfg, FontResolver fontResolver, FontEventListener listener) throws FOPException { FopFactory factory = userAgent.getFactory(); FontManager fontManager = factory.getFontManager(); @@ -102,7 +103,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator //Read font configuration FontInfoConfigurator fontInfoConfigurator = new FontInfoConfigurator(cfg, fontManager, fontResolver, listener, strict); - List/*<EmbedFontInfo>*/ fontInfoList = new java.util.ArrayList/*<EmbedFontInfo>*/(); + List<EmbedFontInfo> fontInfoList = new ArrayList<EmbedFontInfo>(); fontInfoConfigurator.configure(fontInfoList); return fontInfoList; } @@ -118,7 +119,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo) throws FOPException { FontManager fontManager = userAgent.getFactory().getFontManager(); - List fontCollections = new java.util.ArrayList(); + List<FontCollection> fontCollections = new ArrayList<FontCollection>(); fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled())); Configuration cfg = super.getRendererConfig(documentHandler.getMimeType()); @@ -126,7 +127,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator FontResolver fontResolver = new DefaultFontResolver(userAgent); FontEventListener listener = new FontEventAdapter( userAgent.getEventBroadcaster()); - List fontList = buildFontList(cfg, fontResolver, listener); + List<EmbedFontInfo> fontList = buildFontList(cfg, fontResolver, listener); fontCollections.add(new CustomFontCollection(fontResolver, fontList)); } diff --git a/src/java/org/apache/fop/render/afp/AFPPainter.java b/src/java/org/apache/fop/render/afp/AFPPainter.java index ed16a923b..28ca6c67f 100644 --- a/src/java/org/apache/fop/render/afp/AFPPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPPainter.java @@ -30,11 +30,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; -import org.w3c.dom.Document; - -import org.apache.xmlgraphics.image.loader.ImageProcessingHints; -import org.apache.xmlgraphics.image.loader.ImageSessionContext; - import org.apache.fop.afp.AFPBorderPainter; import org.apache.fop.afp.AFPPaintingState; import org.apache.fop.afp.AFPUnitConverter; @@ -55,6 +50,7 @@ import org.apache.fop.afp.util.ResourceAccessor; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; +import org.apache.fop.fonts.Typeface; import org.apache.fop.render.RenderingContext; import org.apache.fop.render.intermediate.AbstractIFPainter; import org.apache.fop.render.intermediate.BorderPainter; @@ -64,6 +60,9 @@ import org.apache.fop.render.intermediate.IFState; import org.apache.fop.traits.BorderProps; import org.apache.fop.traits.RuleStyle; import org.apache.fop.util.CharUtilities; +import org.apache.xmlgraphics.image.loader.ImageProcessingHints; +import org.apache.xmlgraphics.image.loader.ImageSessionContext; +import org.w3c.dom.Document; /** * IFPainter implementation that produces AFP (MO:DCA). @@ -76,12 +75,12 @@ public class AFPPainter extends AbstractIFPainter { private static final int X = 0; private static final int Y = 1; - private AFPDocumentHandler documentHandler; + private final AFPDocumentHandler documentHandler; /** the border painter */ - private AFPBorderPainterAdapter borderPainter; + private final AFPBorderPainterAdapter borderPainter; /** the rectangle painter */ - private AbstractAFPPainter rectanglePainter; + private final AbstractAFPPainter rectanglePainter; /** unit converter */ private final AFPUnitConverter unitConv; @@ -101,6 +100,7 @@ public class AFPPainter extends AbstractIFPainter { } /** {@inheritDoc} */ + @Override protected IFContext getContext() { return this.documentHandler.getContext(); } @@ -165,6 +165,7 @@ public class AFPPainter extends AbstractIFPainter { } /** {@inheritDoc} */ + @Override protected Map createDefaultImageProcessingHints(ImageSessionContext sessionContext) { Map hints = super.createDefaultImageProcessingHints(sessionContext); @@ -175,6 +176,7 @@ public class AFPPainter extends AbstractIFPainter { } /** {@inheritDoc} */ + @Override protected RenderingContext createRenderingContext() { AFPRenderingContext psContext = new AFPRenderingContext( getUserAgent(), @@ -256,6 +258,7 @@ public class AFPPainter extends AbstractIFPainter { } /** {@inheritDoc} */ + @Override public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after, BorderProps start, BorderProps end) throws IFException { if (before != null || after != null || start != null || end != null) { @@ -271,32 +274,38 @@ public class AFPPainter extends AbstractIFPainter { //and this one. Not done for now to avoid a lot of re-implementation and code duplication. private static class AFPBorderPainterAdapter extends BorderPainter { - private AFPBorderPainter delegate; + private final AFPBorderPainter delegate; public AFPBorderPainterAdapter(AFPBorderPainter borderPainter) { this.delegate = borderPainter; } + @Override protected void clip() throws IOException { //not supported by AFP } + @Override protected void closePath() throws IOException { //used for clipping only, so not implemented } + @Override protected void moveTo(int x, int y) throws IOException { //used for clipping only, so not implemented } + @Override protected void lineTo(int x, int y) throws IOException { //used for clipping only, so not implemented } + @Override protected void saveGraphicsState() throws IOException { //used for clipping only, so not implemented } + @Override protected void restoreGraphicsState() throws IOException { //used for clipping only, so not implemented } @@ -305,6 +314,7 @@ public class AFPPainter extends AbstractIFPainter { return mpt / 1000f; } + @Override protected void drawBorderLine( // CSOK: ParameterNumber int x1, int y1, int x2, int y2, boolean horz, boolean startOrBefore, int style, Color color) throws IOException { @@ -314,6 +324,7 @@ public class AFPPainter extends AbstractIFPainter { delegate.paint(borderPaintInfo); } + @Override public void drawLine(Point start, Point end, int width, Color color, RuleStyle style) throws IOException { if (start.y != end.y) { @@ -331,6 +342,7 @@ public class AFPPainter extends AbstractIFPainter { } /** {@inheritDoc} */ + @Override public void drawLine(Point start, Point end, int width, Color color, RuleStyle style) throws IFException { try { @@ -357,7 +369,7 @@ public class AFPPainter extends AbstractIFPainter { } // register font as necessary - Map/*<String,FontMetrics>*/ fontMetricMap = documentHandler.getFontInfo().getFonts(); + Map<String, Typeface> fontMetricMap = documentHandler.getFontInfo().getFonts(); final AFPFont afpFont = (AFPFont)fontMetricMap.get(fontKey); final Font font = getFontInfo().getFontInstance(triplet, fontSize); AFPPageFonts pageFonts = getPaintingState().getPageFonts(); diff --git a/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java b/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java index 29570e69f..fb88b8bce 100644 --- a/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java +++ b/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java @@ -95,7 +95,7 @@ public class ConfiguredFontCollection implements FontCollection { fontInfo.addMetrics(internalName, font); - List triplets = configFontInfo.getFontTriplets(); + List<FontTriplet> triplets = configFontInfo.getFontTriplets(); for (int c = 0; c < triplets.size(); c++) { FontTriplet triplet = (FontTriplet) triplets.get(c); diff --git a/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java b/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java index 6394964ac..6540d6e37 100644 --- a/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java +++ b/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java @@ -161,7 +161,7 @@ public class CustomFontMetricsMapper extends Typeface implements FontMetricsMapp } /** {@inheritDoc} */ - public final Set getFamilyNames() { + public final Set<String> getFamilyNames() { return typeface.getFamilyNames(); } diff --git a/src/java/org/apache/fop/render/ps/FontResourceCache.java b/src/java/org/apache/fop/render/ps/FontResourceCache.java index 7d6f076a7..086117536 100644 --- a/src/java/org/apache/fop/render/ps/FontResourceCache.java +++ b/src/java/org/apache/fop/render/ps/FontResourceCache.java @@ -21,18 +21,17 @@ package org.apache.fop.render.ps; import java.util.Map; -import org.apache.xmlgraphics.ps.PSResource; - import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.LazyFont; import org.apache.fop.fonts.Typeface; +import org.apache.xmlgraphics.ps.PSResource; /** * A cache for font resource objects. */ class FontResourceCache { - private FontInfo fontInfo; + private final FontInfo fontInfo; /** This is a map of PSResource instances of all fonts defined (key: font key) */ private Map fontResources = new java.util.HashMap(); @@ -67,8 +66,8 @@ class FontResourceCache { postFix = key.substring(pos); key = key.substring(0, pos); } - Map fonts = fontInfo.getFonts(); - Typeface tf = (Typeface)fonts.get(key); + Map<String, Typeface> fonts = fontInfo.getFonts(); + Typeface tf = fonts.get(key); if (tf instanceof LazyFont) { tf = ((LazyFont)tf).getRealFont(); } diff --git a/src/java/org/apache/fop/render/ps/PSFontUtils.java b/src/java/org/apache/fop/render/ps/PSFontUtils.java index 0d0975045..b8d1b63e8 100644 --- a/src/java/org/apache/fop/render/ps/PSFontUtils.java +++ b/src/java/org/apache/fop/render/ps/PSFontUtils.java @@ -23,7 +23,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; -import java.util.Iterator; import java.util.Map; import javax.xml.transform.Source; @@ -31,13 +30,6 @@ import javax.xml.transform.stream.StreamSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.apache.xmlgraphics.fonts.Glyphs; -import org.apache.xmlgraphics.ps.DSCConstants; -import org.apache.xmlgraphics.ps.PSGenerator; -import org.apache.xmlgraphics.ps.PSResource; -import org.apache.xmlgraphics.ps.dsc.ResourceTracker; - import org.apache.fop.fonts.Base14Font; import org.apache.fop.fonts.CustomFont; import org.apache.fop.fonts.Font; @@ -47,6 +39,11 @@ import org.apache.fop.fonts.LazyFont; import org.apache.fop.fonts.SingleByteEncoding; import org.apache.fop.fonts.SingleByteFont; import org.apache.fop.fonts.Typeface; +import org.apache.xmlgraphics.fonts.Glyphs; +import org.apache.xmlgraphics.ps.DSCConstants; +import org.apache.xmlgraphics.ps.PSGenerator; +import org.apache.xmlgraphics.ps.PSResource; +import org.apache.xmlgraphics.ps.dsc.ResourceTracker; /** * Utility code for font handling in PostScript. @@ -80,7 +77,8 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { * @return a Map of PSResource instances representing all defined fonts (key: font key) * @throws IOException in case of an I/O problem */ - public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts) + public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, + Map<String, Typeface> fonts) throws IOException { return writeFontDict(gen, fontInfo, fonts, false); } @@ -95,14 +93,12 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { * @return a Map of PSResource instances representing all defined fonts (key: font key) * @throws IOException in case of an I/O problem */ - private static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts, - boolean encodeAllCharacters) throws IOException { + private static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, + Map<String, Typeface> fonts, boolean encodeAllCharacters) throws IOException { gen.commentln("%FOPBeginFontDict"); Map fontResources = new java.util.HashMap(); - Iterator iter = fonts.keySet().iterator(); - while (iter.hasNext()) { - String key = (String)iter.next(); + for (String key : fonts.keySet()) { Typeface tf = getTypeFace(fontInfo, fonts, key); PSResource fontRes = new PSResource(PSResource.TYPE_FONT, tf.getFontName()); fontResources.put(key, fontRes); @@ -130,7 +126,8 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { return fontResources; } - private static void reencodeFonts(PSGenerator gen, Map fonts) throws IOException { + private static void reencodeFonts(PSGenerator gen, Map<String, Typeface> fonts) + throws IOException { ResourceTracker tracker = gen.getResourceTracker(); if (!tracker.isResourceSupplied(WINANSI_ENCODING_RESOURCE)) { @@ -140,10 +137,8 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { gen.commentln("%FOPBeginFontReencode"); //Rewrite font encodings - Iterator iter = fonts.keySet().iterator(); - while (iter.hasNext()) { - String key = (String)iter.next(); - Typeface tf = (Typeface)fonts.get(key); + for (String key : fonts.keySet()) { + Typeface tf = fonts.get(key); if (tf instanceof LazyFont) { tf = ((LazyFont)tf).getRealFont(); if (tf == null) { @@ -172,8 +167,9 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { gen.commentln("%FOPEndFontReencode"); } - private static Typeface getTypeFace(FontInfo fontInfo, Map fonts, String key) { - Typeface tf = (Typeface)fonts.get(key); + private static Typeface getTypeFace(FontInfo fontInfo, Map<String, Typeface> fonts, + String key) { + Typeface tf = fonts.get(key); if (tf instanceof LazyFont) { tf = ((LazyFont)tf).getRealFont(); } @@ -181,7 +177,7 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { //This is to avoid an NPE if a malconfigured font is in the configuration but not //used in the document. If it were used, we wouldn't get this far. String fallbackKey = fontInfo.getInternalFontKey(Font.DEFAULT_FONT); - tf = (Typeface)fonts.get(fallbackKey); + tf = fonts.get(fallbackKey); } return tf; } @@ -271,11 +267,9 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils { * @return a Map of PSResource instances representing all defined fonts (key: font key) */ public static Map determineSuppliedFonts(ResourceTracker resTracker, - FontInfo fontInfo, Map fonts) { + FontInfo fontInfo, Map<String, Typeface> fonts) { Map fontResources = new java.util.HashMap(); - Iterator iter = fonts.keySet().iterator(); - while (iter.hasNext()) { - String key = (String)iter.next(); + for (String key : fonts.keySet()) { Typeface tf = getTypeFace(fontInfo, fonts, key); PSResource fontRes = new PSResource("font", tf.getFontName()); fontResources.put(key, fontRes); diff --git a/src/java/org/apache/fop/tools/fontlist/FontSpec.java b/src/java/org/apache/fop/tools/fontlist/FontSpec.java index ce5c7a6c7..953175abc 100644 --- a/src/java/org/apache/fop/tools/fontlist/FontSpec.java +++ b/src/java/org/apache/fop/tools/fontlist/FontSpec.java @@ -22,6 +22,7 @@ package org.apache.fop.tools.fontlist; import java.util.Collection; import java.util.Collections; import java.util.SortedSet; +import java.util.TreeSet; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.fonts.FontTriplet; @@ -33,8 +34,8 @@ public class FontSpec implements Comparable { private String key; private FontMetrics metrics; - private SortedSet familyNames = new java.util.TreeSet(); - private Collection triplets = new java.util.TreeSet(); + private SortedSet<String> familyNames = new TreeSet<String>(); + private Collection triplets = new TreeSet(); /** * Creates a new font spec. @@ -50,7 +51,7 @@ public class FontSpec implements Comparable { * Adds font family names. * @param names the names */ - public void addFamilyNames(Collection names) { + public void addFamilyNames(Collection<String> names) { this.familyNames.addAll(names); } |