From: Jeremias Maerki Date: Fri, 8 Nov 2002 10:25:29 +0000 (+0000) Subject: Configuration now has two static getter methods returning a baseURL and a fontBaseURL... X-Git-Tag: fop-0_20_5rc~77 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c491bf2c336d7dbcf8596c6544780f8129ab5b04;p=xmlgraphics-fop.git Configuration now has two static getter methods returning a baseURL and a fontBaseURL. Those two values can be a filename or a URL. I've changed quite a few places where Strings were used to reference a file to URLs. The whole stuff should now be more consistent and less error prone. It uses the URLBuilder class I've submitted earlier. line ending corrections ArrayList --> List, HashMap --> Map git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195452 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/configuration/Configuration.java b/src/org/apache/fop/configuration/Configuration.java index 40b85bd22..b14cc5e54 100644 --- a/src/org/apache/fop/configuration/Configuration.java +++ b/src/org/apache/fop/configuration/Configuration.java @@ -1,15 +1,17 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ package org.apache.fop.configuration; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Iterator; +import java.io.File; +import java.net.URL; import org.apache.fop.messaging.MessageHandler; /** @@ -31,17 +33,21 @@ public class Configuration { /** * stores the configuration information */ - private static HashMap standardConfiguration = new HashMap(30); - private static HashMap pdfConfiguration = new HashMap(20); - private static HashMap awtConfiguration = new HashMap(20); + private static Map standardConfiguration = new java.util.HashMap(30); + private static Map pdfConfiguration = new java.util.HashMap(20); + private static Map awtConfiguration = new java.util.HashMap(20); /** - * contains a HashMap of existing HashMaps + * contains a Map of existing Maps */ - private static HashMap configuration = new HashMap(3); + private static Map configuration = new java.util.HashMap(3); + + //URL cache + private static URL cachedBaseURL = null; + private static URL cachedFontBaseURL = null; /** - * loads the configuration types into the configuration HashMap + * loads the configuration types into the configuration Map */ static { configuration.put("standard", standardConfiguration); @@ -49,7 +55,7 @@ public class Configuration { configuration.put("awt", awtConfiguration); } - public static HashMap getConfiguration() { + public static Map getConfiguration() { return configuration; } @@ -57,9 +63,9 @@ public class Configuration { * general access method * * @param key a string containing the key value for the configuration value - * role detemines the configuration target + * @param role detemines the configuration target * @return Object containing the value; normally you would use one of the - * convenience methods, which return the correct form. + * convenience methods, which return the correct form, * null if the key is not defined. */ public static Object getValue(String key, int role) { @@ -75,13 +81,12 @@ public class Configuration { } } - ; /** * convenience methods to access strings values in the configuration * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return String a string containing the value + * @param role detemines the configuration target + * @return String a string containing the value, * null if the key is not defined. */ public static String getStringValue(String key, int role) { @@ -93,13 +98,12 @@ public class Configuration { } } - ; /** * convenience methods to access int values in the configuration * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return int a int containing the value + * @param role detemines the configuration target + * @return int a int containing the value, * -1 if the key is not defined. */ public static int getIntValue(String key, int role) { @@ -111,13 +115,12 @@ public class Configuration { } } - ; /** * convenience methods to access boolean values in the configuration * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return Boolean true or false as value + * @param role detemines the configuration target + * @return Boolean true or false as value, * null if the key is not defined. */ public static Boolean getBooleanValue(String key, int role) { @@ -131,44 +134,40 @@ public class Configuration { } } - ; /** * convenience methods to access list values in the configuration * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return ArrayList a ArrayList containing the values + * @param role detemines the configuration target + * @return List a List containing the values, * null if the key is not defined. */ - public static ArrayList getListValue(String key, int role) { + public static List getListValue(String key, int role) { Object obj = Configuration.getValue(key, role); - if (obj instanceof ArrayList) { - return (ArrayList)obj; + if (obj instanceof List) { + return (List)obj; } else { return null; } } - ; /** - * convenience methods to access map/HashMap values in the configuration + * convenience methods to access Map values in the configuration * @param key a string containing the key value for the configuration value - * role detemines the configuration target - * @return HashMap a HashMap containing the values + * @param role detemines the configuration target + * @return Map a Map containing the values * null if the key is not defined. */ - public static HashMap getHashMapValue(String key, int role) { + public static Map getMapValue(String key, int role) { Object obj = Configuration.getValue(key, role); - if (obj instanceof HashMap) { - return (HashMap)obj; + if (obj instanceof Map) { + return (Map)obj; } else { return null; } } - ; - /** * convenience method which retrieves some configuration information @@ -198,7 +197,7 @@ public class Configuration { * convenience methods to access int values in the standard configuration * * @param key a string containing the key value for the configuration value - * @return int a int containing the value + * @return int a int containing the value, * -1 if the key is not defined. */ public static int getIntValue(String key) { @@ -209,7 +208,7 @@ public class Configuration { * convenience methods to access boolean values in the configuration * * @param key a string containing the key value for the configuration value - * @return boolean true or false as value + * @return boolean true or false as value, * null if the key is not defined. */ public static Boolean getBooleanValue(String key) { @@ -220,42 +219,90 @@ public class Configuration { * convenience methods to access list values in the standard configuration * * @param key a string containing the key value for the configuration value - * @return ArrayList a ArrayList containing the values + * @return List a List containing the values, * null if the key is not defined. */ - public static ArrayList getListValue(String key) { + public static List getListValue(String key) { return Configuration.getListValue(key, Configuration.STANDARD); } /** - * convenience methods to access map/HashMap values in the standard configuration + * convenience methods to access Map values in the standard configuration * * @param key a string containing the key value for the configuration value - * @return HashMap a HashMap containing the values + * @return Map a Map containing the values, * null if the key is not defined. */ - public static HashMap getHashMapValue(String key) { - return Configuration.getHashMapValue(key, Configuration.STANDARD); + public static Map getMapValue(String key) { + return Configuration.getMapValue(key, Configuration.STANDARD); } /** - * method to access fonts values in the standard configuration + * Method to access fonts values in the standard configuration * - * @param key a string containing the key value for the configuration value - * @return HashMap a HashMap containing the values + * @return List a List containing the values, * null if the key is not defined. */ - public static ArrayList getFonts() { - return (ArrayList)Configuration.getValue("fonts", + public static List getFonts() { + return (List)Configuration.getValue("fonts", Configuration.STANDARD); } + + private static URL buildBaseURL(String directory) throws java.net.MalformedURLException { + if (directory == null) return null; + File dir = new File(directory); + if (dir.isDirectory()) { + return dir.toURL(); + } else { + URL baseURL = new URL(directory); + return baseURL; + } + } + + public static URL getBaseURL() { + if (cachedBaseURL != null) { + return cachedBaseURL; + } else { + String baseDir = getStringValue("baseDir"); + try { + URL url = buildBaseURL(baseDir);; + cachedBaseURL = url; + return url; + } catch (java.net.MalformedURLException mfue) { + throw new RuntimeException("Invalid baseDir specified: "+baseDir+" ("+mfue.getMessage()+")"); + } + } + } + + + public static URL getFontBaseURL() { + if (cachedFontBaseURL != null) { + return cachedFontBaseURL; + } else { + URL url = null; + String baseDir = getStringValue("fontBaseDir"); + if (baseDir == null) { + url = getBaseURL(); + } else { + try { + url = buildBaseURL(baseDir); + } catch (java.net.MalformedURLException mfue) { + throw new RuntimeException("Invalid fontBaseDir specified: "+baseDir+" ("+mfue.getMessage()+")"); + } + } + cachedFontBaseURL = url; + return url; + } + } + /** - * initializes this configuration + * Initializes this configuration + * @param role detemines the configuration target * @param config contains the configuration information */ - public static void setup(int role, HashMap config) { + public static void setup(int role, Map config) { switch (role) { case Configuration.STANDARD: standardConfiguration = config; @@ -269,14 +316,14 @@ public class Configuration { default: MessageHandler.errorln("Can't setup configuration. Unknown configuration role/target"); } + invalidateURLCache(); } /** - * adds information to the configuration map/HashMap in key,value form + * adds information to the configuration Map in key,value form * @param key a string containing the key value for the configuration value - * value the configuration information - * role detemines the configuration target - * @param value an Object containing the value; can be a String, a ArrayList or a HashMap + * @param value the configuration information; can be a String, a List or a Map + * @param role detemines the configuration target */ public static void put(String key, Object value, int role) { switch (role) { @@ -295,33 +342,37 @@ public class Configuration { + "Putting key:" + key + " - value:" + value + " into standard configuration."); } + invalidateURLCache(); } - ; - /** - * adds information to the standard configuration map/HashMap in key,value form + * adds information to the standard configuration Map in key,value form * @param key a string containing the key value for the configuration value * value the configuration information * role detemines the configuration target - * @param value an Object containing the value; can be a String, a ArrayList or a HashMap + * @param value an Object containing the value; can be a String, a List or a Map */ public static void put(String key, Object value) { Configuration.put(key, value, Configuration.STANDARD); } + private static void invalidateURLCache() { + cachedBaseURL = null; + cachedFontBaseURL = null; + } + /** * debug methods, which writes out all information in this configuration */ public static void dumpConfiguration() { String key; Object value; - ArrayList list; - HashMap map, configuration; + List list; + Map map, configuration; String tmp; System.out.println("Dumping configuration: "); - HashMap[] configs = { + Map[] configs = { standardConfiguration, pdfConfiguration, awtConfiguration }; for (int i = 0; i < configs.length; i++) { @@ -334,15 +385,15 @@ public class Configuration { value = configuration.get(key); if (value instanceof String) { MessageHandler.logln(" value: " + value); - } else if (value instanceof ArrayList) { - list = (ArrayList)value; + } else if (value instanceof List) { + list = (List)value; MessageHandler.log(" values: "); for (int j = 0; j < list.size(); j++) { MessageHandler.log(list.get(j) + " - "); } MessageHandler.logln(""); - } else if (value instanceof HashMap) { - map = (HashMap)value; + } else if (value instanceof Map) { + map = (Map)value; MessageHandler.log(" values: "); Iterator it2 = map.keySet().iterator(); while (it2.hasNext()) { diff --git a/src/org/apache/fop/configuration/ConfigurationParser.java b/src/org/apache/fop/configuration/ConfigurationParser.java index afee679bc..5f1753613 100644 --- a/src/org/apache/fop/configuration/ConfigurationParser.java +++ b/src/org/apache/fop/configuration/ConfigurationParser.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -14,8 +14,8 @@ import org.xml.sax.Attributes; import org.xml.sax.Locator; // java -import java.util.HashMap; -import java.util.ArrayList; +import java.util.Map; +import java.util.List; // fop import org.apache.fop.messaging.MessageHandler; @@ -45,12 +45,12 @@ public class ConfigurationParser extends DefaultHandler { private int datatype = -1; // store the result configuration - private static HashMap configuration; - private static HashMap activeConfiguration; + private static Map configuration; + private static Map activeConfiguration; // stores key for new config entry private String key = ""; - private ArrayList keyStack = new ArrayList(); + private List keyStack = new java.util.ArrayList(); // stores string value private String value = ""; @@ -59,10 +59,10 @@ public class ConfigurationParser extends DefaultHandler { private String subkey = ""; // stores list value - private ArrayList list = new ArrayList(15); + private List list = new java.util.ArrayList(15); - // stores HashMap value - private HashMap map = new HashMap(15); + // stores Map value + private Map map = new java.util.HashMap(15); /** * locator for line number information @@ -75,7 +75,7 @@ public class ConfigurationParser extends DefaultHandler { private String role = "standard"; // stores fonts - private ArrayList fontList = null; + private List fontList = null; // stores information on one font private FontInfo fontInfo = null; @@ -86,7 +86,7 @@ public class ConfigurationParser extends DefaultHandler { // information on a font private String fontName, metricsFile, embedFile, kerningAsString; private boolean kerning; - private ArrayList fontTriplets; + private List fontTriplets; // information on a font triplet private String fontTripletName, weight, style; @@ -125,7 +125,7 @@ public class ConfigurationParser extends DefaultHandler { } } else if (localName.equals("configuration")) {} else if (localName.equals("fonts")) { // list of fonts starts - fontList = new ArrayList(10); + fontList = new java.util.ArrayList(10); } else if (localName.equals("font")) { kerningAsString = attributes.getValue("kerning"); if (kerningAsString.equalsIgnoreCase("yes")) { @@ -136,7 +136,7 @@ public class ConfigurationParser extends DefaultHandler { metricsFile = attributes.getValue("metrics-file"); embedFile = attributes.getValue("embed-file"); fontName = attributes.getValue("name"); - fontTriplets = new ArrayList(5); + fontTriplets = new java.util.ArrayList(5); } else if (localName.equals("font-triplet")) { fontTripletName = attributes.getValue("name"); weight = attributes.getValue("weight"); @@ -241,14 +241,14 @@ public class ConfigurationParser extends DefaultHandler { } // end characters /** - * stores configuration entry into configuration HashMap according to the role + * stores configuration entry into configuration Map according to the role * * @param role a string containing the role / target for this configuration information * @param key a string containing the key value for the configuration * @param value a string containing the value for the configuration */ private void store(String role, String key, Object value) { - activeConfiguration = (HashMap)configuration.get(role); + activeConfiguration = (Map)configuration.get(role); if (activeConfiguration != null) { activeConfiguration.put(key, value); } else { diff --git a/src/org/apache/fop/configuration/FontInfo.java b/src/org/apache/fop/configuration/FontInfo.java index c6923bbdc..2340e15a3 100644 --- a/src/org/apache/fop/configuration/FontInfo.java +++ b/src/org/apache/fop/configuration/FontInfo.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -12,10 +12,11 @@ package org.apache.fop.configuration; import java.io.File; import java.net.URL; import java.net.MalformedURLException; -import java.util.ArrayList; +import java.util.List; // Fop import org.apache.fop.apps.FOPException; +import org.apache.fop.tools.URLBuilder; /** * FontInfo contains meta information on fonts (where is the metrics file etc.) @@ -25,11 +26,10 @@ public class FontInfo { private String metricsFile, embedFile, name; private boolean kerning; - private ArrayList fontTriplets; - private String baseDir; + private List fontTriplets; public FontInfo(String name, String metricsFile, boolean kerning, - ArrayList fontTriplets, String embedFile) { + List fontTriplets, String embedFile) { this.name = name; this.metricsFile = metricsFile; this.embedFile = embedFile; @@ -38,37 +38,26 @@ public class FontInfo { } /** - * @return the (absolute) file name of the metrics file + * @return the URL to the metrics file */ - public String getMetricsFile() throws FOPException { - // check if it's a URL and convert it to a filename + public URL getMetricsFile() throws FOPException { try { - metricsFile = new URL(metricsFile).getFile(); - } catch (MalformedURLException mue) {} - - // check if filename is absolute - if ((new File(metricsFile).isAbsolute())) { - return metricsFile; - } else { - return getBaseDir() + metricsFile; + return URLBuilder.buildURL(Configuration.getFontBaseURL(), metricsFile); + } catch (Exception e) { + throw new FOPException("Invalid font metrics file: "+metricsFile+" ("+e.getMessage()+")"); } } /** - * @return the (absolute) file name of the font + * @return the url to the font */ - public String getEmbedFile() throws FOPException { + public URL getEmbedFile() throws FOPException { // check if it's a URL and convert it to a filename - if (embedFile == null) return null; + if (embedFile == null) return null; try { - embedFile = new URL(embedFile).getFile(); - } catch (MalformedURLException mue) {} - - // check if filename is absolute - if ((new File(embedFile).isAbsolute())) { - return embedFile; - } else { - return getBaseDir() + embedFile; + return URLBuilder.buildURL(Configuration.getFontBaseURL(), embedFile); + } catch (Exception e) { + throw new FOPException("Invalid font file (embedFile): "+metricsFile+" ("+e.getMessage()+")"); } } @@ -76,31 +65,9 @@ public class FontInfo { return kerning; } - public ArrayList getFontTriplets() { + public List getFontTriplets() { return fontTriplets; } - /** - * @return BaseDir (path) - */ - private String getBaseDir() throws FOPException { - baseDir = Configuration.getStringValue("baseDir"); - URL baseURL = null; - try { - baseURL = new URL(baseDir); - } catch (MalformedURLException mue) { - // if the href contains only a path then file is assumed - try { - baseURL = new URL("file:" + baseDir); - } catch (MalformedURLException mue2) { - throw new FOPException("Error with baseDir: " - + mue2.getMessage()); - } - } - baseDir = baseURL.getFile(); - return baseDir; - } - - } diff --git a/src/org/apache/fop/fonts/FontFileReader.java b/src/org/apache/fop/fonts/FontFileReader.java index bcc2074d0..770aecd04 100644 --- a/src/org/apache/fop/fonts/FontFileReader.java +++ b/src/org/apache/fop/fonts/FontFileReader.java @@ -6,8 +6,8 @@ */ package org.apache.fop.fonts; -import java.io.FileInputStream; import java.io.InputStream; +import java.io.OutputStream; import java.io.File; import java.io.IOException; @@ -21,38 +21,29 @@ public class FontFileReader { private byte[] file; /** - * Initialisez class and reads stream. Init does not close stream - * @param stream InputStream to read from - * @param start initial size av array to read to - * @param inc if initial size isn't enough, create + * Initializes class and reads stream. Init does not close stream + * @param in InputStream to read from * new array with size + inc */ - private void init(InputStream stream, int start, - int inc) throws java.io.IOException { - fsize = 0; - current = 0; - - file = new byte[start]; - - int l = stream.read(file, 0, start); - fsize += l; - - if (l == start) { - // More to read - needs to extend - byte[] tmpbuf; - - while (l > 0) { - tmpbuf = new byte[file.length + inc]; - System.arraycopy(file, 0, tmpbuf, 0, file.length); - l = stream.read(tmpbuf, file.length, inc); - fsize += l; - file = tmpbuf; - - if (l < inc) // whole file read. No need to loop again + private void init(InputStream in) throws java.io.IOException { + java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream(); + try { + copyStream(in, bout); + this.file = bout.toByteArray(); + } finally { + bout.close(); + } + } - l = 0; - } + /**@todo Use method from Avalon Excalibur IO or Jakarta Commons IO*/ + private void copyStream(InputStream in, OutputStream out) throws IOException { + final int bufferSize = 2048; + final byte[] buffer = new byte[bufferSize]; + byte[] buf = new byte[bufferSize]; + int bytesRead; + while ((bytesRead = in.read(buf)) != -1) { + out.write(buf, 0, bytesRead); } } @@ -61,12 +52,22 @@ public class FontFileReader { * @param fileName filename to read */ public FontFileReader(String fileName) throws java.io.IOException { - - // Get estimates for file size and increment File f = new File(fileName); - FileInputStream ins = new FileInputStream(fileName); - init(ins, (int)(f.length() + 1), (int)(f.length() / 10)); - ins.close(); + InputStream in = new java.io.FileInputStream(fileName); + try { + init(in); + } finally { + in.close(); + } + } + + + /** + * Constructor + * @param in InputStream to read from + */ + public FontFileReader(InputStream in) throws java.io.IOException { + init(in); } diff --git a/src/org/apache/fop/fonts/TTFSubSetFile.java b/src/org/apache/fop/fonts/TTFSubSetFile.java index 20ed519e3..020510c0b 100644 --- a/src/org/apache/fop/fonts/TTFSubSetFile.java +++ b/src/org/apache/fop/fonts/TTFSubSetFile.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -9,10 +9,10 @@ package org.apache.fop.fonts; import org.apache.fop.messaging.MessageHandler; -import java.io.*; +import java.io.IOException; import java.util.Iterator; -import java.util.HashMap; -import java.util.ArrayList; +import java.util.Map; +import java.util.List; /** * Reads a TrueType file and generates a subset @@ -302,7 +302,7 @@ public class TTFSubSetFile extends TTFFile { * Create the glyf table and fill in loca table */ private void createGlyf(FontFileReader in, - HashMap glyphs) throws IOException { + Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf"); int size = 0; int start = 0; @@ -364,12 +364,12 @@ public class TTFSubSetFile extends TTFFile { /** * Create the hmtx table by copying metrics from original - * font to subset font. The glyphs HashMap contains an + * font to subset font. The glyphs Map contains an * Integer key and Integer value that maps the original * metric (key) to the subset metric (value) */ private void createHmtx(FontFileReader in, - HashMap glyphs) throws IOException { + Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("hmtx"); int longHorMetricSize = glyphs.size() * 2; @@ -401,12 +401,12 @@ public class TTFSubSetFile extends TTFFile { } /** - * Returns a ArrayList containing the glyph itself plus all glyphs + * Returns a List containing the glyph itself plus all glyphs * that this composite glyph uses */ - private ArrayList getIncludedGlyphs(FontFileReader in, int glyphOffset, + private List getIncludedGlyphs(FontFileReader in, int glyphOffset, Integer glyphIdx) throws IOException { - ArrayList ret = new ArrayList(); + List ret = new java.util.ArrayList(); ret.add(glyphIdx); int offset = glyphOffset + (int)mtx_tab[glyphIdx.intValue()].offset + 10; @@ -447,7 +447,7 @@ public class TTFSubSetFile extends TTFFile { * Rewrite all compositepointers in glyphindex glyphIdx * */ - private void remapComposite(FontFileReader in, HashMap glyphs, + private void remapComposite(FontFileReader in, Map glyphs, int glyphOffset, Integer glyphIdx) throws IOException { int offset = glyphOffset + (int)mtx_tab[glyphIdx.intValue()].offset @@ -505,17 +505,17 @@ public class TTFSubSetFile extends TTFFile { * mapping */ private void scanGlyphs(FontFileReader in, - HashMap glyphs) throws IOException { + Map glyphs) throws IOException { TTFDirTabEntry entry = (TTFDirTabEntry)dirTabs.get("glyf"); - HashMap newComposites = null; - HashMap allComposites = new HashMap(); + Map newComposites = null; + Map allComposites = new java.util.HashMap(); int newIndex = glyphs.size(); if (entry != null) { while (newComposites == null || newComposites.size() > 0) { // Inefficient to iterate through all glyphs - newComposites = new HashMap(); + newComposites = new java.util.HashMap(); for (Iterator e = glyphs.keySet().iterator(); e.hasNext(); ) { Integer origIndex = (Integer)e.next(); @@ -524,7 +524,7 @@ public class TTFSubSetFile extends TTFFile { + mtx_tab[origIndex.intValue()].offset) < 0) { // origIndex is a composite glyph allComposites.put(origIndex, glyphs.get(origIndex)); - ArrayList composites = + List composites = getIncludedGlyphs(in, (int)entry.offset, origIndex); @@ -570,7 +570,7 @@ public class TTFSubSetFile extends TTFFile { */ public byte[] readFont(FontFileReader in, String name, - HashMap glyphs) throws IOException { + Map glyphs) throws IOException { /* * Check if TrueType collection, and that the name diff --git a/src/org/apache/fop/layout/FontDescriptor.java b/src/org/apache/fop/layout/FontDescriptor.java index fb818631b..786ccc13f 100644 --- a/src/org/apache/fop/layout/FontDescriptor.java +++ b/src/org/apache/fop/layout/FontDescriptor.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -20,7 +20,7 @@ public interface FontDescriptor { public int getStemV(); public boolean hasKerningInfo(); - public java.util.HashMap getKerningInfo(); + public java.util.Map getKerningInfo(); public boolean isEmbeddable(); public byte getSubType(); public org.apache.fop.pdf.PDFStream getFontFile(int objNum); diff --git a/src/org/apache/fop/layout/FontState.java b/src/org/apache/fop/layout/FontState.java index 1c8305890..1b45ca118 100644 --- a/src/org/apache/fop/layout/FontState.java +++ b/src/org/apache/fop/layout/FontState.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -11,7 +11,7 @@ import org.apache.fop.apps.FOPException; import org.apache.fop.fo.properties.FontVariant; import org.apache.fop.render.pdf.CodePointMapping; -import java.util.HashMap; +import java.util.Map; import java.util.StringTokenizer; public class FontState { @@ -27,7 +27,7 @@ public class FontState { private FontMetric _metric; private int _letterSpacing; - private static HashMap EMPTY_HASHMAP = new HashMap(); + private static Map EMPTY_MAP = new java.util.HashMap(); public FontState(FontInfo fontInfo, String fontFamily, String fontStyle, @@ -146,13 +146,13 @@ public class FontState { return _metric.getXHeight(_fontSize) / 1000; } - public HashMap getKerning() { + public Map getKerning() { if (_metric instanceof FontDescriptor) { - HashMap ret = ((FontDescriptor)_metric).getKerningInfo(); + Map ret = ((FontDescriptor)_metric).getKerningInfo(); if (ret != null) return ret; } - return EMPTY_HASHMAP; + return EMPTY_MAP; } public int width(int charnum) { @@ -173,12 +173,12 @@ public class FontState { } // Use default CodePointMapping - char d = CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c); - if (d != 0) { - c = d; - } else { - c = '#'; - } + char d = CodePointMapping.getMapping("WinAnsiEncoding").mapChar(c); + if (d != 0) { + c = d; + } else { + c = '#'; + } return c; } diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index c3a97095c..0bc1daafe 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -28,8 +28,8 @@ import org.apache.fop.layout.FontDescriptor; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.awt.Rectangle; /** @@ -71,10 +71,10 @@ public class PDFDocument { /** * the character position of each object */ - protected ArrayList location = new ArrayList(); + protected List location = new java.util.ArrayList(); /** List of objects to write in the trailer */ - private ArrayList trailerObjects = new ArrayList(); + private List trailerObjects = new java.util.ArrayList(); /** * the counter for object numbering @@ -84,7 +84,7 @@ public class PDFDocument { /** * the objects themselves */ - protected ArrayList objects = new ArrayList(); + protected List objects = new java.util.ArrayList(); /** * character position of xref table @@ -141,18 +141,18 @@ public class PDFDocument { /** * the XObjects */ - protected ArrayList xObjects = new ArrayList(); + protected List xObjects = new java.util.ArrayList(); /** * the XObjects Map. * Should be modified (works only for image subtype) */ - protected HashMap xObjectsMap = new HashMap(); + protected Map xObjectsMap = new java.util.HashMap(); /** * the objects themselves */ - protected ArrayList pendingLinks = null; + protected List pendingLinks = null; /** * Encoding of the PDF @@ -250,13 +250,13 @@ public class PDFDocument { /** * Make a Type 0 sampled function * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theSize A ArrayList object of Integer objects. + * @param theSize A List object of Integer objects. * This is the number of samples in each input dimension. * I can't imagine there being more or less than two input dimensions, * so maybe this should be an array of length 2. @@ -271,14 +271,14 @@ public class PDFDocument { * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theDecode ArrayList objects of Double objects. + * @param theDecode List objects of Double objects. * This is a linear mapping of sample values into the range. * The default is just the range. * @@ -289,7 +289,7 @@ public class PDFDocument { * This is optional, but is almost always used. * * Page 265 of the PDF 1.3 spec has more. - * @param theFilter This is a ArrayList of String objects which are the various filters that + * @param theFilter This is a List of String objects which are the various filters that * have are to be applied to the stream to make sense of it. Order matters, * so watch out. * @@ -300,12 +300,12 @@ public class PDFDocument { * @param theFunctionType This is the type of function (0,2,3, or 4). * It should be 0 as this is the constructor for sampled functions. */ - public PDFFunction makeFunction(int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theSize, + public PDFFunction makeFunction(int theFunctionType, List theDomain, + List theRange, List theSize, int theBitsPerSample, int theOrder, - ArrayList theEncode, ArrayList theDecode, + List theEncode, List theDecode, StringBuffer theFunctionDataStream, - ArrayList theFilter) { // Type 0 function + List theFilter) { // Type 0 function PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, theRange, theSize, @@ -322,17 +322,17 @@ public class PDFDocument { * make a type Exponential interpolation function * (for shading usually) * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList of Doubles that is the Range of the function. + * @param theRange List of Doubles that is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theCZero This is a ArrayList of Double objects which defines the function result + * @param theCZero This is a List of Double objects which defines the function result * when x=0. * * This attribute is optional. * It's described on page 268 of the PDF 1.3 spec. - * @param theCOne This is a ArrayList of Double objects which defines the function result + * @param theCOne This is a List of Double objects which defines the function result * when x=1. * * This attribute is optional. @@ -343,9 +343,9 @@ public class PDFDocument { * PDF Spec page 268 * @param theFunctionType The type of the function, which should be 2. */ - public PDFFunction makeFunction(int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theCZero, - ArrayList theCOne, + public PDFFunction makeFunction(int theFunctionType, List theDomain, + List theRange, List theCZero, + List theCOne, double theInterpolationExponentN) { // type 2 PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, @@ -359,17 +359,17 @@ public class PDFDocument { /** * Make a Type 3 Stitching function * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theFunctions A ArrayList of the PDFFunction objects that the stitching function stitches. + * @param theFunctions A List of the PDFFunction objects that the stitching function stitches. * * This attributed is required. * It is described on page 269 of the PDF spec. - * @param theBounds This is a ArrayList of Doubles representing the numbers that, + * @param theBounds This is a List of Doubles representing the numbers that, * in conjunction with Domain define the intervals to which each function from * the 'functions' object applies. It must be in order of increasing magnitude, * and each must be within Domain. @@ -378,7 +378,7 @@ public class PDFDocument { * * This attributed is required. * It's described on page 269 of the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. @@ -388,10 +388,10 @@ public class PDFDocument { * @param theFunctionType This is the function type. It should be 3, * for a stitching function. */ - public PDFFunction makeFunction(int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theFunctions, - ArrayList theBounds, - ArrayList theEncode) { // Type 3 + public PDFFunction makeFunction(int theFunctionType, List theDomain, + List theRange, List theFunctions, + List theBounds, + List theEncode) { // Type 3 PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, @@ -412,7 +412,7 @@ public class PDFDocument { * @param theFunctionDataStream */ public PDFFunction makeFunction(int theNumber, int theFunctionType, - ArrayList theDomain, ArrayList theRange, + List theDomain, List theRange, StringBuffer theFunctionDataStream) { // Type 4 PDFFunction function = new PDFFunction(++this.objectcount, theFunctionType, theDomain, @@ -433,13 +433,13 @@ public class PDFDocument { * @param theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Whether or not to anti-alias. - * @param theDomain Optional ArrayList of Doubles specifying the domain. - * @param theMatrix ArrayList of Doubles specifying the matrix. + * @param theDomain Optional List of Doubles specifying the domain. + * @param theMatrix List of Doubles specifying the matrix. * If it's a pattern, then the matrix maps it to pattern space. * If it's a shading, then it maps it to current user space. * It's optional, the default is the identity matrix @@ -447,9 +447,9 @@ public class PDFDocument { */ public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theDomain, - ArrayList theMatrix, + List theBackground, List theBBox, + boolean theAntiAlias, List theDomain, + List theMatrix, PDFFunction theFunction) { // make Shading of Type 1 String theShadingName = new String("Sh" + (++this.shadingCount)); @@ -474,23 +474,23 @@ public class PDFDocument { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false - * @param theCoords ArrayList of four (type 2) or 6 (type 3) Double - * @param theDomain ArrayList of Doubles specifying the domain + * @param theCoords List of four (type 2) or 6 (type 3) Double + * @param theDomain List of Doubles specifying the domain * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function - * @param theExtend ArrayList of Booleans of whether to extend teh start and end colors past the start and end points + * @param theExtend List of Booleans of whether to extend teh start and end colors past the start and end points * The default is [false, false] */ public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theCoords, - ArrayList theDomain, PDFFunction theFunction, - ArrayList theExtend) { // make Shading of Type 2 or 3 + List theBackground, List theBBox, + boolean theAntiAlias, List theCoords, + List theDomain, PDFFunction theFunction, + List theExtend) { // make Shading of Type 2 or 3 String theShadingName = new String("Sh" + (++this.shadingCount)); PDFShading shading = new PDFShading(++this.objectcount, @@ -517,7 +517,7 @@ public class PDFDocument { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. @@ -525,16 +525,16 @@ public class PDFDocument { * @param theBitsPerCoordinate 1,2,4,8,12,16,24 or 32. * @param theBitsPerComponent 1,2,4,8,12, and 16 * @param theBitsPerFlag 2,4,8. - * @param theDecode ArrayList of Doubles see PDF 1.3 spec pages 303 to 312. + * @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312. * @param theFunction the PDFFunction */ public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, - int theBitsPerFlag, ArrayList theDecode, + int theBitsPerFlag, List theDecode, PDFFunction theFunction) { // make Shading of type 4,6 or 7 String theShadingName = new String("Sh" + (++this.shadingCount)); @@ -562,23 +562,23 @@ public class PDFDocument { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false * @param theBitsPerCoordinate 1,2,4,8,12,16, 24, or 32 * @param theBitsPerComponent 1,2,4,8,12,24,32 - * @param theDecode ArrayList of Doubles. See page 305 in PDF 1.3 spec. + * @param theDecode List of Doubles. See page 305 in PDF 1.3 spec. * @param theVerticesPerRow number of vertices in each "row" of the lattice. * @param theFunction The PDFFunction that's mapped on to this shape */ public PDFShading makeShading(int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, - int theBitsPerComponent, ArrayList theDecode, + int theBitsPerComponent, List theDecode, int theVerticesPerRow, PDFFunction theFunction) { // make shading of Type 5 String theShadingName = new String("Sh" + (++this.shadingCount)); @@ -605,17 +605,17 @@ public class PDFDocument { * @param theResources the resources associated with this pattern * @param thePaintType 1 or 2, colored or uncolored. * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or faster tiling - * @param theBBox ArrayList of Doubles: The pattern cell bounding box + * @param theBBox List of Doubles: The pattern cell bounding box * @param theXStep horizontal spacing * @param theYStep vertical spacing - * @param theMatrix Optional ArrayList of Doubles transformation matrix - * @param theXUID Optional ArrayList of Integers that uniquely identify the pattern + * @param theMatrix Optional List of Doubles transformation matrix + * @param theXUID Optional List of Integers that uniquely identify the pattern * @param thePatternDataStream The stream of pattern data to be tiled. */ public PDFPattern makePattern(int thePatternType, // 1 PDFResources theResources, int thePaintType, int theTilingType, - ArrayList theBBox, double theXStep, double theYStep, ArrayList theMatrix, - ArrayList theXUID, StringBuffer thePatternDataStream) { + List theBBox, double theXStep, double theYStep, List theMatrix, + List theXUID, StringBuffer thePatternDataStream) { String thePatternName = new String("Pa" + (++this.patternCount)); // int theNumber, String thePatternName, // PDFResources theResources @@ -639,11 +639,11 @@ public class PDFDocument { * @param theShading the PDF Shading object that comprises this pattern * @param theXUID optional:the extended unique Identifier if used. * @param theExtGState optional: the extended graphics state, if used. - * @param theMatrix Optional:ArrayList of Doubles that specify the matrix. + * @param theMatrix Optional:List of Doubles that specify the matrix. */ public PDFPattern makePattern(int thePatternType, PDFShading theShading, - ArrayList theXUID, StringBuffer theExtGState, - ArrayList theMatrix) { + List theXUID, StringBuffer theExtGState, + List theMatrix) { String thePatternName = new String("Pa" + (++this.patternCount)); PDFPattern pattern = new PDFPattern(++this.objectcount, @@ -667,17 +667,17 @@ public class PDFDocument { public PDFPattern createGradient(boolean radial, ColorSpace theColorspace, - ArrayList theColors, ArrayList theBounds, - ArrayList theCoords) { + List theColors, List theBounds, + List theCoords) { PDFShading myShad; PDFFunction myfunky; PDFFunction myfunc; - ArrayList theCzero; - ArrayList theCone; + List theCzero; + List theCone; PDFPattern myPattern; ColorSpace theColorSpace; double interpolation = (double)1.000; - ArrayList theFunctions = new ArrayList(); + List theFunctions = new java.util.ArrayList(); int currentPosition; int lastPosition = theColors.size() - 1; @@ -722,7 +722,7 @@ public class PDFDocument { } else { // if the center x, center y, and radius specifiy // the gradient, then assume the same center x, center y, // and radius of zero for the other necessary component - ArrayList newCoords = new ArrayList(); + List newCoords = new java.util.ArrayList(); newCoords.add(theCoords.get(0)); newCoords.add(theCoords.get(1)); newCoords.add(theCoords.get(2)); @@ -1068,7 +1068,7 @@ public class PDFDocument { pl.link = link; pl.dest = dest; if(pendingLinks == null) { - pendingLinks = new ArrayList(); + pendingLinks = new java.util.ArrayList(); } pendingLinks.add(pl); @@ -1226,7 +1226,7 @@ public class PDFDocument { pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { pdf = ("%PDF-" + this.pdfVersion + "\n").getBytes(); - } + } stream.write(pdf); this.position += pdf.length; @@ -1276,7 +1276,7 @@ public class PDFDocument { trailer = pdf.getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { trailer = pdf.getBytes(); - } + } stream.write(trailer); } @@ -1313,7 +1313,7 @@ public class PDFDocument { pdfBytes = pdf.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { pdfBytes = pdf.toString().getBytes(); - } + } stream.write(pdfBytes); return pdfBytes.length; } diff --git a/src/org/apache/fop/pdf/PDFFunction.java b/src/org/apache/fop/pdf/PDFFunction.java index 3f495575d..541b51482 100644 --- a/src/org/apache/fop/pdf/PDFFunction.java +++ b/src/org/apache/fop/pdf/PDFFunction.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -8,7 +8,7 @@ package org.apache.fop.pdf; // Java... -import java.util.ArrayList; +import java.util.List; import java.io.UnsupportedEncodingException; /** @@ -32,12 +32,12 @@ public class PDFFunction extends PDFObject { /** * Required: 2 * m Array of Double numbers which are possible inputs to the function */ - protected ArrayList domain = null; + protected List domain = null; /** * Required: 2 * n Array of Double numbers which are possible outputs to the function */ - protected ArrayList range = null; + protected List range = null; /* ********************TYPE 0***************************** */ // FunctionType 0 specific function guts @@ -47,7 +47,7 @@ public class PDFFunction extends PDFObject { * Note: This is really more like two seperate integers, sizeDomain, and sizeRange, * but since they're expressed as an array in PDF, my implementation reflects that. */ - protected ArrayList size = null; + protected List size = null; /** * Required for Type 0: Number of Bits used to represent each sample value. Limited to 1,2,4,8,12,16,24, or 32 @@ -65,12 +65,12 @@ public class PDFFunction extends PDFObject { * Required for Type 3: A 2 * k array of Doubles that, taken in pairs, map each subset of the domain defined by Domain and the Bounds array to the domain of the corresponding function. * Should be two values per function, usually (0,1), as in [0 1 0 1] for 2 functions. */ - protected ArrayList encode = null; + protected List encode = null; /** * Optinoal for Type 0: A 2 * n array of Doubles which provides a linear mapping of sample values to the range. Defaults to Range. */ - protected ArrayList decode = null; + protected List decode = null; /** * Optional For Type 0: A stream of sample values @@ -82,21 +82,21 @@ public class PDFFunction extends PDFObject { protected StringBuffer functionDataStream = null; /** - * Required (?) For Type 0: A ArrayList of Strings for the various filters to be used to decode the stream. + * Required (?) For Type 0: A List of Strings for the various filters to be used to decode the stream. * These are how the string is compressed. Flate, LZW, etc. */ - protected ArrayList filter = null; + protected List filter = null; /* *************************TYPE 2************************** */ /** * Required For Type 2: An Array of n Doubles defining the function result when x=0. Default is [0]. */ - protected ArrayList cZero = null; + protected List cZero = null; /** * Required For Type 2: An Array of n Doubles defining the function result when x=1. Default is [1]. */ - protected ArrayList cOne = null; + protected List cOne = null; /** * Required for Type 2: The interpolation exponent. @@ -108,9 +108,9 @@ public class PDFFunction extends PDFObject { /* *************************TYPE 3************************** */ /** - * Required for Type 3: An ArrayList of PDFFunctions which form an array of k single input functions making up the stitching function. + * Required for Type 3: A List of PDFFunctions which form an array of k single input functions making up the stitching function. */ - protected ArrayList functions = null; + protected List functions = null; /** * Optional for Type 3: An array of (k-1) Doubles that, in combination with Domain, define the intervals to which each function from the Functions array apply. Bounds elements must be in order of increasing magnitude, and each value must be within the value of Domain. @@ -119,7 +119,7 @@ public class PDFFunction extends PDFObject { * This makes each function responsible for an equal amount of the stitching function. * It makes the gradient even. */ - protected ArrayList bounds = null; + protected List bounds = null; // See encode above, as it's also part of Type 3 Functions. /* *************************TYPE 4************************** */ @@ -131,13 +131,13 @@ public class PDFFunction extends PDFObject { * Use null for an optional object parameter if you choose not to use it. * For optional int parameters, pass the default. * - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theSize A ArrayList object of Integer objects. + * @param theSize A List object of Integer objects. * This is the number of samples in each input dimension. * I can't imagine there being more or less than two input dimensions, * so maybe this should be an array of length 2. @@ -152,14 +152,14 @@ public class PDFFunction extends PDFObject { * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. * This attribute is optional. * * See page 265 in the PDF 1.3 spec. - * @param theDecode ArrayList objects of Double objects. + * @param theDecode List objects of Double objects. * This is a linear mapping of sample values into the range. * The default is just the range. * @@ -170,7 +170,7 @@ public class PDFFunction extends PDFObject { * This is optional, but is almost always used. * * Page 265 of the PDF 1.3 spec has more. - * @param theFilter This is a ArrayList of String objects which are the various filters that + * @param theFilter This is a List of String objects which are the various filters that * have are to be applied to the stream to make sense of it. Order matters, * so watch out. * @@ -181,20 +181,20 @@ public class PDFFunction extends PDFObject { * @param theFunctionType This is the type of function (0,2,3, or 4). * It should be 0 as this is the constructor for sampled functions. */ - public PDFFunction(int theNumber, int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theSize, int theBitsPerSample, - int theOrder, ArrayList theEncode, ArrayList theDecode, - StringBuffer theFunctionDataStream, ArrayList theFilter) { + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, List theSize, int theBitsPerSample, + int theOrder, List theEncode, List theDecode, + StringBuffer theFunctionDataStream, List theFilter) { super(theNumber); this.functionType = 0; // dang well better be 0; this.size = theSize; this.bitsPerSample = theBitsPerSample; this.order = theOrder; // int - this.encode = theEncode; // ArrayList of int - this.decode = theDecode; // ArrayList of int + this.encode = theEncode; // List of int + this.decode = theDecode; // List of int this.functionDataStream = theFunctionDataStream; - this.filter = theFilter; // ArrayList of Strings + this.filter = theFilter; // List of Strings // the domain and range are actually two dimensional arrays. // so if there's not an even number of items, bad stuff @@ -210,17 +210,17 @@ public class PDFFunction extends PDFObject { * For optional int parameters, pass the default. * * @param theNumber the object's number - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList of Doubles that is the Range of the function. + * @param theRange List of Doubles that is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theCZero This is a ArrayList of Double objects which defines the function result + * @param theCZero This is a List of Double objects which defines the function result * when x=0. * * This attribute is optional. * It's described on page 268 of the PDF 1.3 spec. - * @param theCOne This is a ArrayList of Double objects which defines the function result + * @param theCOne This is a List of Double objects which defines the function result * when x=1. * * This attribute is optional. @@ -231,8 +231,8 @@ public class PDFFunction extends PDFObject { * PDF Spec page 268 * @param theFunctionType The type of the function, which should be 2. */ - public PDFFunction(int theNumber, int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theCZero, ArrayList theCOne, + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, List theCZero, List theCOne, double theInterpolationExponentN) { super(theNumber); @@ -255,17 +255,17 @@ public class PDFFunction extends PDFObject { * For optional int parameters, pass the default. * * @param theNumber the object's number - * @param theDomain ArrayList objects of Double objects. + * @param theDomain List objects of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList objects of Double objects. + * @param theRange List objects of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. - * @param theFunctions A ArrayList of the PDFFunction objects that the stitching function stitches. + * @param theFunctions A List of the PDFFunction objects that the stitching function stitches. * * This attributed is required. * It is described on page 269 of the PDF spec. - * @param theBounds This is a ArrayList of Doubles representing the numbers that, + * @param theBounds This is a List of Doubles representing the numbers that, * in conjunction with Domain define the intervals to which each function from * the 'functions' object applies. It must be in order of increasing magnitude, * and each must be within Domain. @@ -274,7 +274,7 @@ public class PDFFunction extends PDFObject { * * This attributed is required. * It's described on page 269 of the PDF 1.3 spec. - * @param theEncode ArrayList objects of Double objects. + * @param theEncode List objects of Double objects. * This is the linear mapping of input values intop the domain * of the function's sample table. Default is hard to represent in * ascii, but basically [0 (Size0 1) 0 (Size1 1)...]. @@ -284,9 +284,9 @@ public class PDFFunction extends PDFObject { * @param theFunctionType This is the function type. It should be 3, * for a stitching function. */ - public PDFFunction(int theNumber, int theFunctionType, ArrayList theDomain, - ArrayList theRange, ArrayList theFunctions, - ArrayList theBounds, ArrayList theEncode) { + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, List theFunctions, + List theBounds, List theEncode) { super(theNumber); this.functionType = 3; // dang well better be 3; @@ -305,10 +305,10 @@ public class PDFFunction extends PDFObject { * Use null for an optional object parameter if you choose not to use it. * For optional int parameters, pass the default. * - * @param theDomain ArrayList object of Double objects. + * @param theDomain List object of Double objects. * This is the domain of the function. * See page 264 of the PDF 1.3 Spec. - * @param theRange ArrayList object of Double objects. + * @param theRange List object of Double objects. * This is the Range of the function. * See page 264 of the PDF 1.3 Spec. * @param theFunctionDataStream This is a stream of arithmetic, boolean, and stack operators and boolean constants. @@ -321,8 +321,8 @@ public class PDFFunction extends PDFObject { * @param theFunctionType The type of function which should be 4, as this is * a Postscript calculator function */ - public PDFFunction(int theNumber, int theFunctionType, ArrayList theDomain, - ArrayList theRange, StringBuffer theFunctionDataStream) { + public PDFFunction(int theNumber, int theFunctionType, List theDomain, + List theRange, StringBuffer theFunctionDataStream) { super(theNumber); this.functionType = 4; // dang well better be 4; @@ -668,7 +668,7 @@ public class PDFFunction extends PDFObject { return p.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { return p.toString().getBytes(); - } + } } } diff --git a/src/org/apache/fop/pdf/PDFPattern.java b/src/org/apache/fop/pdf/PDFPattern.java index 6e7efd16c..e6390b32f 100644 --- a/src/org/apache/fop/pdf/PDFPattern.java +++ b/src/org/apache/fop/pdf/PDFPattern.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -12,7 +12,7 @@ import org.apache.fop.datatypes.ColorSpace; // Java... import java.io.UnsupportedEncodingException; -import java.util.ArrayList; +import java.util.List; /** * class representing a PDF Function. @@ -36,7 +36,7 @@ public class PDFPattern extends PDFPathPaint { /** * Either one (1) for tiling, or two (2) for shading. */ - protected int patternType = 2; // Default + protected int patternType = 2; // Default /** * The name of the pattern such as "Pa1" or "Pattern1" @@ -54,9 +54,9 @@ public class PDFPattern extends PDFPathPaint { protected int tilingType = 1; /** - * ArrayList of Doubles representing the Bounding box rectangle + * List of Doubles representing the Bounding box rectangle */ - protected ArrayList bBox = null; + protected List bBox = null; /** * Horizontal spacing @@ -74,21 +74,21 @@ public class PDFPattern extends PDFPathPaint { protected PDFShading shading = null; /** - * ArrayList of Integers represetning the Extended unique Identifier + * List of Integers represetning the Extended unique Identifier */ - protected ArrayList xUID = null; + protected List xUID = null; /** * String representing the extended Graphics state. * Probably will never be used like this. */ protected StringBuffer extGState = - null; // eventually, need a PDFExtGSState object... but not now. + null; // eventually, need a PDFExtGSState object... but not now. /** - * ArrayList of Doubles representing the Transformation matrix. + * List of Doubles representing the Transformation matrix. */ - protected ArrayList matrix = null; + protected List matrix = null; /** * The stream of a pattern @@ -105,18 +105,19 @@ public class PDFPattern extends PDFPathPaint { * @param thePatternType the type of pattern, which is 1 for tiling. * @param thePaintType 1 or 2, colored or uncolored. * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or faster tiling - * @param theBBox ArrayList of Doubles: The pattern cell bounding box + * @param theBBox List of Doubles: The pattern cell bounding box * @param theXStep horizontal spacing * @param theYStep vertical spacing - * @param theMatrix Optional ArrayList of Doubles transformation matrix - * @param theXUID Optional ArrayList of Integers that uniquely identify the pattern + * @param theMatrix Optional List of Doubles transformation matrix + * @param theXUID Optional List of Integers that uniquely identify the pattern * @param thePatternDataStream The stream of pattern data to be tiled. */ public PDFPattern(int theNumber, String thePatternName, PDFResources theResources, int thePatternType, // 1 - int thePaintType, int theTilingType, ArrayList theBBox, double theXStep, - double theYStep, ArrayList theMatrix, ArrayList theXUID, - StringBuffer thePatternDataStream) { + int thePaintType, int theTilingType, List theBBox, + double theXStep, double theYStep, + List theMatrix, List theXUID, + StringBuffer thePatternDataStream) { super(theNumber); this.patternName = thePatternName; @@ -144,12 +145,12 @@ public class PDFPattern extends PDFPathPaint { * @param theShading the PDF Shading object that comprises this pattern * @param theXUID optional:the extended unique Identifier if used. * @param theExtGState optional: the extended graphics state, if used. - * @param theMatrix Optional:ArrayList of Doubles that specify the matrix. + * @param theMatrix Optional:List of Doubles that specify the matrix. */ public PDFPattern(int theNumber, String thePatternName, int thePatternType, PDFShading theShading, - ArrayList theXUID, StringBuffer theExtGState, - ArrayList theMatrix) { + List theXUID, StringBuffer theExtGState, + List theMatrix) { super(theNumber); this.patternName = thePatternName; @@ -293,7 +294,7 @@ public class PDFPattern extends PDFPathPaint { return p.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { return p.toString().getBytes(); - } + } } } diff --git a/src/org/apache/fop/pdf/PDFResources.java b/src/org/apache/fop/pdf/PDFResources.java index f08174397..f8a0ce61c 100644 --- a/src/org/apache/fop/pdf/PDFResources.java +++ b/src/org/apache/fop/pdf/PDFResources.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -11,8 +11,8 @@ package org.apache.fop.pdf; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.Iterator; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * class representing a /Resources object. @@ -25,11 +25,11 @@ public class PDFResources extends PDFObject { /** * /Font objects keyed by their internal name */ - protected HashMap fonts = new HashMap(); + protected Map fonts = new java.util.HashMap(); - protected ArrayList xObjects = null; - protected ArrayList patterns = new ArrayList(); - protected ArrayList shadings = new ArrayList(); + protected List xObjects = null; + protected List patterns = new java.util.ArrayList(); + protected List shadings = new java.util.ArrayList(); /** * create a /Resources object. @@ -60,7 +60,7 @@ public class PDFResources extends PDFObject { this.patterns.add(thePattern); } - public void setXObjects(ArrayList xObjects) { + public void setXObjects(List xObjects) { this.xObjects = xObjects; } @@ -143,7 +143,7 @@ public class PDFResources extends PDFObject { return p.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { return p.toString().getBytes(); - } + } } } diff --git a/src/org/apache/fop/pdf/PDFShading.java b/src/org/apache/fop/pdf/PDFShading.java index 278411e3d..1e7ef7b7f 100644 --- a/src/org/apache/fop/pdf/PDFShading.java +++ b/src/org/apache/fop/pdf/PDFShading.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -9,7 +9,7 @@ package org.apache.fop.pdf; // Java... import java.io.UnsupportedEncodingException; -import java.util.ArrayList; +import java.util.List; // FOP import org.apache.fop.datatypes.ColorSpace; @@ -47,12 +47,12 @@ public class PDFShading extends PDFObject { * The background color. Since shading is opaque, * this is very rarely used. */ - protected ArrayList background = null; + protected List background = null; /** - * Optional: A ArrayList specifying the clipping rectangle + * Optional: A List specifying the clipping rectangle */ - protected ArrayList bBox = null; + protected List bBox = null; /** * Optional: A flag whether or not to filter the shading function @@ -66,12 +66,12 @@ public class PDFShading extends PDFObject { * Optional for Type 3: An array of two numbers between which the blend varies between start and end points. Default is 0, 1. */ - protected ArrayList domain = null; + protected List domain = null; /** * Optional for Type 1: A transformation matrix */ - protected ArrayList matrix = null; + protected List matrix = null; /** * Required for Type 1, 2, and 3: @@ -85,14 +85,14 @@ public class PDFShading extends PDFObject { * Required for Type 3: An Array of six numbers [x0,y0,r0,x1,y1,r1] specifying the centers and radii of * the starting and ending circles. */ - protected ArrayList coords = null; + protected List coords = null; /** * Required for Type 2+3: An Array of two boolean values specifying whether to extend the * start and end colors past the start and end points, * respectively. Default is false, false. */ - protected ArrayList extend = null; + protected List extend = null; /** * Required for Type 4,5,6, and 7: Specifies the number of bits used to represent each vertex coordinate. @@ -111,7 +111,7 @@ public class PDFShading extends PDFObject { * Each type has a differing number of decode array members, so check the spec. * Page 303 in PDF Spec 1.3 */ - protected ArrayList decode = null; + protected List decode = null; /** * Required for Type 4,5,6, and 7: Specifies the number of bits used to represent each color coordinate. @@ -136,13 +136,13 @@ public class PDFShading extends PDFObject { * @param theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Whether or not to anti-alias. - * @param theDomain Optional ArrayList of Doubles specifying the domain. - * @param theMatrix ArrayList of Doubles specifying the matrix. + * @param theDomain Optional List of Doubles specifying the domain. + * @param theMatrix List of Doubles specifying the matrix. * If it's a pattern, then the matrix maps it to pattern space. * If it's a shading, then it maps it to current user space. * It's optional, the default is the identity matrix @@ -150,9 +150,9 @@ public class PDFShading extends PDFObject { */ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theDomain, - ArrayList theMatrix, PDFFunction theFunction) { + List theBackground, List theBBox, + boolean theAntiAlias, List theDomain, + List theMatrix, PDFFunction theFunction) { super(theNumber); this.shadingName = theShadingName; this.shadingType = theShadingType; // 1 @@ -178,23 +178,23 @@ public class PDFShading extends PDFObject { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false - * @param theCoords ArrayList of four (type 2) or 6 (type 3) Double - * @param theDomain ArrayList of Doubles specifying the domain + * @param theCoords List of four (type 2) or 6 (type 3) Double + * @param theDomain List of Doubles specifying the domain * @param theFunction the Stitching (PDFfunction type 3) function, even if it's stitching a single function - * @param theExtend ArrayList of Booleans of whether to extend teh start and end colors past the start and end points + * @param theExtend List of Booleans of whether to extend teh start and end colors past the start and end points * The default is [false, false] */ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, - boolean theAntiAlias, ArrayList theCoords, - ArrayList theDomain, PDFFunction theFunction, - ArrayList theExtend) { + List theBackground, List theBBox, + boolean theAntiAlias, List theCoords, + List theDomain, PDFFunction theFunction, + List theExtend) { super(theNumber); this.shadingName = theShadingName; this.shadingType = theShadingType; // 2 or 3 @@ -223,7 +223,7 @@ public class PDFShading extends PDFObject { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. @@ -231,15 +231,15 @@ public class PDFShading extends PDFObject { * @param theBitsPerCoordinate 1,2,4,8,12,16,24 or 32. * @param theBitsPerComponent 1,2,4,8,12, and 16 * @param theBitsPerFlag 2,4,8. - * @param theDecode ArrayList of Doubles see PDF 1.3 spec pages 303 to 312. + * @param theDecode List of Doubles see PDF 1.3 spec pages 303 to 312. * @param theFunction the PDFFunction */ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, int theBitsPerComponent, int theBitsPerFlag, - ArrayList theDecode, PDFFunction theFunction) { + List theDecode, PDFFunction theFunction) { super(theNumber); this.shadingType = theShadingType; // 4,6 or 7 @@ -265,23 +265,23 @@ public class PDFShading extends PDFObject { * @param theBackground theBackground An array of color components appropriate to the * colorspace key specifying a single color value. * This key is used by the f operator buy ignored by the sh operator. - * @param theBBox ArrayList of double's representing a rectangle + * @param theBBox List of double's representing a rectangle * in the coordinate space that is current at the * time of shading is imaged. Temporary clipping * boundary. * @param theAntiAlias Default is false * @param theBitsPerCoordinate 1,2,4,8,12,16, 24, or 32 * @param theBitsPerComponent 1,2,4,8,12,24,32 - * @param theDecode ArrayList of Doubles. See page 305 in PDF 1.3 spec. + * @param theDecode List of Doubles. See page 305 in PDF 1.3 spec. * @param theVerticesPerRow number of vertices in each "row" of the lattice. * @param theFunction The PDFFunction that's mapped on to this shape * @param theNumber the object number of this PDF object. */ public PDFShading(int theNumber, String theShadingName, int theShadingType, ColorSpace theColorSpace, - ArrayList theBackground, ArrayList theBBox, + List theBackground, List theBBox, boolean theAntiAlias, int theBitsPerCoordinate, - int theBitsPerComponent, ArrayList theDecode, + int theBitsPerComponent, List theDecode, int theVerticesPerRow, PDFFunction theFunction) { super(theNumber); this.shadingName = theShadingName; @@ -510,7 +510,7 @@ public class PDFShading extends PDFObject { return p.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { return p.toString().getBytes(); - } + } } } diff --git a/src/org/apache/fop/pdf/PDFStream.java b/src/org/apache/fop/pdf/PDFStream.java index 297d8ccc9..c2821165d 100644 --- a/src/org/apache/fop/pdf/PDFStream.java +++ b/src/org/apache/fop/pdf/PDFStream.java @@ -16,7 +16,7 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; +import java.util.List; /** * class representing a PDF stream. @@ -36,7 +36,7 @@ public class PDFStream extends PDFObject { /** * the filters that should be applied */ - private ArrayList _filters; + private List _filters; /** * create an empty stream object @@ -46,7 +46,7 @@ public class PDFStream extends PDFObject { public PDFStream(int number) { super(number); _data = new ByteArrayOutputStream(); - _filters = new ArrayList(); + _filters = new java.util.ArrayList(); } /** @@ -101,7 +101,7 @@ public class PDFStream extends PDFObject { protected void addDefaultFilters() { - ArrayList filters = Configuration.getListValue("stream-filter-list", + List filters = Configuration.getListValue("stream-filter-list", Configuration.PDF); if (filters == null) { // try getting it as a String @@ -277,8 +277,8 @@ public class PDFStream extends PDFObject { */ protected String applyFilters() throws IOException { if (_filters.size() > 0) { - ArrayList names = new ArrayList(); - ArrayList parms = new ArrayList(); + List names = new java.util.ArrayList(); + List parms = new java.util.ArrayList(); // run the filters for (int i = 0; i < _filters.size(); i++) { @@ -290,7 +290,7 @@ public class PDFStream extends PDFObject { _data.write(tmp); filter.setApplied(true); } - // place the names in our local ArrayList in reverse order + // place the names in our local List in reverse order names.add(0, filter.getName()); parms.add(0, filter.getDecodeParms()); } @@ -302,7 +302,7 @@ public class PDFStream extends PDFObject { } - private String buildFilterEntries(ArrayList names) { + private String buildFilterEntries(List names) { StringBuffer sb = new StringBuffer(); sb.append("/Filter "); if (names.size() > 1) { @@ -319,7 +319,7 @@ public class PDFStream extends PDFObject { return sb.toString(); } - private String buildDecodeParms(ArrayList parms) { + private String buildDecodeParms(List parms) { StringBuffer sb = new StringBuffer(); boolean needParmsEntry = false; sb.append("/DecodeParms "); diff --git a/src/org/apache/fop/pdf/PDFXObject.java b/src/org/apache/fop/pdf/PDFXObject.java index db2ec8cb4..f16e50fe3 100644 --- a/src/org/apache/fop/pdf/PDFXObject.java +++ b/src/org/apache/fop/pdf/PDFXObject.java @@ -125,13 +125,13 @@ public class PDFXObject extends PDFObject { preBytes = preamble.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { preBytes = preamble.toString().getBytes(); - } + } byte[] postBytes; try { postBytes = post.toString().getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { postBytes = post.toString().getBytes(); - } + } byte[] imgData = new byte[preBytes.length + postBytes.length + fopimage.getBitmaps().length]; System.arraycopy (preBytes, 0, imgData, 0, preBytes.length); @@ -151,7 +151,8 @@ public class PDFXObject extends PDFObject { p = p + "/Length " + imgStream.getDataLength(); // don't know if it's the good place (other objects can have references to it) - fopimage.close(); + //fopimage.close(); //Not really necessary, is it? Only leads to image reloading. + p = p + dictEntries; p = p + ">>\n"; @@ -161,7 +162,7 @@ public class PDFXObject extends PDFObject { pdfBytes = p.getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { pdfBytes = p.getBytes(); - } + } stream.write(pdfBytes); length += pdfBytes.length; // push all the image data on the writer and takes care of length for trailer @@ -171,7 +172,7 @@ public class PDFXObject extends PDFObject { pdfBytes = ("endobj\n").getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { pdfBytes = ("endobj\n").getBytes(); - } + } stream.write(pdfBytes); length += pdfBytes.length; @@ -227,7 +228,7 @@ public class PDFXObject extends PDFObject { p = p + ">>\n"; // don't know if it's the good place (other objects can have references to it) - fopimage.close(); + //fopimage.close(); //Not really necessary, is it? Only leads to image reloading. // push the pdf dictionary on the writer byte[] pdfBytes; @@ -235,7 +236,7 @@ public class PDFXObject extends PDFObject { pdfBytes = p.getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { pdfBytes = p.getBytes(); - } + } stream.write(pdfBytes); length += pdfBytes.length; // push all the image data on the writer and takes care of length for trailer @@ -245,7 +246,7 @@ public class PDFXObject extends PDFObject { pdfBytes = ("endobj\n").getBytes(PDFDocument.ENCODING); } catch (UnsupportedEncodingException ue) { pdfBytes = ("endobj\n").getBytes(); - } + } stream.write(pdfBytes); length += pdfBytes.length; } diff --git a/src/org/apache/fop/render/AbstractRenderer.java b/src/org/apache/fop/render/AbstractRenderer.java index 9199b00ce..430ea0330 100644 --- a/src/org/apache/fop/render/AbstractRenderer.java +++ b/src/org/apache/fop/render/AbstractRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -16,7 +16,6 @@ import org.apache.fop.fo.properties.*; import org.apache.fop.layout.*; import org.apache.fop.layout.inline.*; import org.apache.fop.datatypes.*; -import org.apache.fop.render.pdf.FontSetup; // Avalon import org.apache.avalon.framework.logger.Logger; @@ -24,10 +23,10 @@ import org.apache.avalon.framework.logger.Logger; // Java import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; +import java.util.List; /** * Abstract base class for all renderers. - * + * */ public abstract class AbstractRenderer implements Renderer { protected Logger log; @@ -52,7 +51,7 @@ public abstract class AbstractRenderer implements Renderer { } public void renderSpanArea(SpanArea area) { - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); // column areas @@ -70,119 +69,119 @@ public abstract class AbstractRenderer implements Renderer { * @param h the height in millipoints */ protected void doBackground(Area area, int x, int y, int w, int h) { - if (h == 0 || w == 0) - return; - - BackgroundProps props = area.getBackground(); - if (props == null) - return; - - if (props.backColor.alpha() == 0) { - this.addFilledRect(x, y, w, -h, props.backColor); - } - - // XXX: I'm ignoring area rotation here 8( - // is this taken care of for me elsewhere in the codebase? - if (props.backImage != null) { - int imgW; - int imgH; - try { - // XXX: do correct unit conversion here - imgW = props.backImage.getWidth() * 1000; - imgH = props.backImage.getHeight() * 1000; - } - catch (FopImageException fie) { - log.error("Error obtaining bg image width and height", fie); - return; - } - - int dx = x; - int dy = y; - int endX = x + w; - int endY = y - h; - int clipW = w % imgW; - int clipH = h % imgH; - - boolean repeatX = true; - boolean repeatY = true; - switch (props.backRepeat) { - case BackgroundRepeat.REPEAT: - break; - - case BackgroundRepeat.REPEAT_X: - repeatY = false; - break; - - case BackgroundRepeat.REPEAT_Y: - repeatX = false; - break; - - case BackgroundRepeat.NO_REPEAT: - repeatX = false; - repeatY = false; - break; - - case BackgroundRepeat.INHERIT: - // XXX: what to do here? - break; - - default: - log.error("Ignoring invalid background-repeat property"); - } - - FontState fs = area.getFontState(); - - while (dy > endY) { // looping through rows - while (dx < endX) { // looping through cols - if (dx + imgW <= endX) { - // no x clipping - if (dy - imgH >= endY) { - // no x clipping, no y clipping - drawImageScaled(dx, dy, imgW, imgH, - props.backImage, fs); - } - else { - // no x clipping, y clipping - drawImageClipped(dx, dy, - 0, 0, imgW, clipH, - props.backImage, fs); - } - } - else { - // x clipping - if (dy - imgH >= endY) { - // x clipping, no y clipping - drawImageClipped(dx, dy, - 0, 0, clipW, imgH, - props.backImage, fs); - } - - else { - // x clipping, y clipping - drawImageClipped(dx, dy, - 0, 0, clipW, clipH, - props.backImage, fs); - } - } - - if (repeatX) { - dx += imgW; - } - else { - break; - } - } // end looping through cols - - dx = x; - - if (repeatY) { - dy -= imgH; - } - else { - break; - } - } // end looping through rows - } + if (h == 0 || w == 0) + return; + + BackgroundProps props = area.getBackground(); + if (props == null) + return; + + if (props.backColor.alpha() == 0) { + this.addFilledRect(x, y, w, -h, props.backColor); + } + + // XXX: I'm ignoring area rotation here 8( + // is this taken care of for me elsewhere in the codebase? + if (props.backImage != null) { + int imgW; + int imgH; + try { + // XXX: do correct unit conversion here + imgW = props.backImage.getWidth() * 1000; + imgH = props.backImage.getHeight() * 1000; + } + catch (FopImageException fie) { + log.error("Error obtaining bg image width and height", fie); + return; + } + + int dx = x; + int dy = y; + int endX = x + w; + int endY = y - h; + int clipW = w % imgW; + int clipH = h % imgH; + + boolean repeatX = true; + boolean repeatY = true; + switch (props.backRepeat) { + case BackgroundRepeat.REPEAT: + break; + + case BackgroundRepeat.REPEAT_X: + repeatY = false; + break; + + case BackgroundRepeat.REPEAT_Y: + repeatX = false; + break; + + case BackgroundRepeat.NO_REPEAT: + repeatX = false; + repeatY = false; + break; + + case BackgroundRepeat.INHERIT: + // XXX: what to do here? + break; + + default: + log.error("Ignoring invalid background-repeat property"); + } + + FontState fs = area.getFontState(); + + while (dy > endY) { // looping through rows + while (dx < endX) { // looping through cols + if (dx + imgW <= endX) { + // no x clipping + if (dy - imgH >= endY) { + // no x clipping, no y clipping + drawImageScaled(dx, dy, imgW, imgH, + props.backImage, fs); + } + else { + // no x clipping, y clipping + drawImageClipped(dx, dy, + 0, 0, imgW, clipH, + props.backImage, fs); + } + } + else { + // x clipping + if (dy - imgH >= endY) { + // x clipping, no y clipping + drawImageClipped(dx, dy, + 0, 0, clipW, imgH, + props.backImage, fs); + } + + else { + // x clipping, y clipping + drawImageClipped(dx, dy, + 0, 0, clipW, clipH, + props.backImage, fs); + } + } + + if (repeatX) { + dx += imgW; + } + else { + break; + } + } // end looping through cols + + dx = x; + + if (repeatY) { + dy -= imgH; + } + else { + break; + } + } // end looping through rows + } } /** @@ -204,7 +203,7 @@ public abstract class AbstractRenderer implements Renderer { * This by default calls drawImageScaled() with the image's * intrinsic width and height, but implementations may * override this method if it can provide a more efficient solution. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param image the image to be rendered @@ -212,25 +211,25 @@ public abstract class AbstractRenderer implements Renderer { * in non-bitmapped images. */ protected void drawImage(int x, int y, FopImage image, FontState fs) { - int w; - int h; - try { - // XXX: convert these units correctly - w = image.getWidth() * 1000; - h = image.getHeight() * 1000; - } - catch (FopImageException e) { - log.error("Failed to obtain the image width and height", e); - return; - } - drawImageScaled(x, y, w, h, image, fs); + int w; + int h; + try { + // XXX: convert these units correctly + w = image.getWidth() * 1000; + h = image.getHeight() * 1000; + } + catch (FopImageException e) { + log.error("Failed to obtain the image width and height", e); + return; + } + drawImageScaled(x, y, w, h, image, fs); } /** * Renders an image, scaling it to the given width and height. * If the scaled width and height is the same intrinsic size * of the image, the image is not scaled. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param w the width in millipoints @@ -240,12 +239,12 @@ public abstract class AbstractRenderer implements Renderer { * in non-bitmapped images. */ protected abstract void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs); + FopImage image, + FontState fs); /** - * Renders an image, clipping it as specified. - * + * Renders an image, clipping it as specified. + * * @param x the x position of left edge in millipoints. * @param y the y position of top edge in millipoints. * @param clipX the left edge of the clip in millipoints @@ -257,10 +256,10 @@ public abstract class AbstractRenderer implements Renderer { * in non-bitmapped images. */ protected abstract void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs); + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs); /** * Render an image area. @@ -279,11 +278,10 @@ public abstract class AbstractRenderer implements Renderer { FopImage img = area.getImage(); if (img == null) { - log.error("Error while loading image : area.getImage() is null"); - } - else { - drawImageScaled(x, y, w, h, img, area.getFontState()); - } + log.error("Error while loading image: area.getImage() is null"); + } else { + drawImageScaled(x, y, w, h, img, area.getFontState()); + } this.currentXPosition += w; } @@ -304,24 +302,24 @@ public abstract class AbstractRenderer implements Renderer { this.currentXPosition = this.currentAreaContainerXPosition; int rx = this.currentAreaContainerXPosition; int ry = this.currentYPosition; - // XXX: (mjg@recaldesign.com) I had to use getAllocationWidth() - // and getMaxHeight() as the content width and height are - // always 0. Is this supposed to be the case? - // IMHO, the bg should cover the entire area anyway, not - // just the parts with content, which makes this correct. - // Probably want to check this for the other region - // areas as well. - int w = area.getAllocationWidth(); - int h = area.getMaxHeight(); + // XXX: (mjg@recaldesign.com) I had to use getAllocationWidth() + // and getMaxHeight() as the content width and height are + // always 0. Is this supposed to be the case? + // IMHO, the bg should cover the entire area anyway, not + // just the parts with content, which makes this correct. + // Probably want to check this for the other region + // areas as well. + int w = area.getAllocationWidth(); + int h = area.getMaxHeight(); - doBackground(area, rx, ry, w, h); + doBackground(area, rx, ry, w, h); // floats & footnotes stuff renderAreaContainer(area.getBeforeFloatReferenceArea()); renderAreaContainer(area.getFootnoteReferenceArea()); // main reference area - ArrayList children = area.getMainReferenceArea().getChildren(); + List children = area.getMainReferenceArea().getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); // span areas @@ -333,7 +331,6 @@ public abstract class AbstractRenderer implements Renderer { } else { this.currentYPosition -= area.getHeight(); } - } /** @@ -362,7 +359,7 @@ public abstract class AbstractRenderer implements Renderer { doBackground(area, rx, ry, w, h); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); // span areas @@ -371,8 +368,9 @@ public abstract class AbstractRenderer implements Renderer { if (area.getPosition() != Position.STATIC) { this.currentYPosition = saveY; this.currentAreaContainerXPosition = saveX; - } else + } else { this.currentYPosition -= area.getHeight(); + } } /** @@ -404,7 +402,7 @@ public abstract class AbstractRenderer implements Renderer { this.currentXPosition = this.currentAreaContainerXPosition; doFrame(area); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -438,7 +436,7 @@ public abstract class AbstractRenderer implements Renderer { this.currentYPosition -= (area.getPaddingTop() + area.getBorderTopWidth()); doFrame(area); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -463,7 +461,7 @@ public abstract class AbstractRenderer implements Renderer { int bl = this.currentYPosition; - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); if (b instanceof InlineArea) { diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index b12fa7bc6..bb1f6750b 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -22,7 +22,7 @@ import java.io.IOException; /** * interface implement by all renderers. - * + * * a Renderer implementation takes areas/spaces and produces output in * some format. */ @@ -41,7 +41,7 @@ public interface Renderer { /** * set up renderer options */ - public void setOptions(java.util.HashMap options); + public void setOptions(java.util.Map options); /** * set the producer of the rendering @@ -53,7 +53,7 @@ public interface Renderer { */ //public void render(AreaTree areaTree, OutputStream stream) throws IOException, FOPException; public void render(Page page, OutputStream stream) - throws IOException, FOPException; + throws IOException, FOPException; /** * render the given area container @@ -126,9 +126,9 @@ public interface Renderer { public void renderLeaderArea(LeaderArea area); public void startRenderer(OutputStream outputStream) - throws IOException; + throws IOException; public void stopRenderer(OutputStream outputStream) - throws IOException; + throws IOException; } diff --git a/src/org/apache/fop/render/awt/AWTFontMetrics.java b/src/org/apache/fop/render/awt/AWTFontMetrics.java index 8ad69b2ce..4c787f535 100644 --- a/src/org/apache/fop/render/awt/AWTFontMetrics.java +++ b/src/org/apache/fop/render/awt/AWTFontMetrics.java @@ -14,7 +14,8 @@ import org.apache.fop.layout.FontDescriptor; import org.apache.fop.layout.FontState; // Java -import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URL; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; @@ -23,7 +24,7 @@ import java.awt.geom.Rectangle2D; import java.awt.FontMetrics; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; -import java.util.HashMap; +import java.util.Map; /** * This is a FontMetrics to be used for AWT rendering. @@ -96,12 +97,12 @@ public class AWTFontMetrics { /** * Embed Font List. */ - private HashMap embedFontList = null; + private Map embedFontList = null; /** - * Physical Font Cash. + * Physical Font Cache. */ - private HashMap fontCash = null; + private Map fontCache = null; /** * Constructs a new Font-metrics. @@ -251,12 +252,12 @@ public class AWTFontMetrics { * set embed font. * @param family font-family name * @param style font style - * @param fontPath path to phsical font + * @param fontURL URL to physical font */ - public void setEmbedFont(String family,int style,String fontPath) { + public void setEmbedFont(String family, int style, URL fontURL) { if (embedFontList == null) - embedFontList = new HashMap(); - embedFontList.put(family+style,fontPath); + embedFontList = new java.util.HashMap(); + embedFontList.put(family+style, fontURL); } /** @@ -266,37 +267,37 @@ public class AWTFontMetrics { * @param size font size */ public java.awt.Font createFont(String family, int style, int size) { - String fontPath = null; + URL fontURL = null; if (embedFontList != null) - fontPath = (String)embedFontList.get(family+style); - if (fontPath == null) + fontURL = (URL)embedFontList.get(family+style); + if (fontURL == null) return new Font(family, style, size); - // lazy instanciation for fontCash. - if (fontCash == null) - fontCash = new HashMap(); - Font cashedFont = (Font)fontCash.get(fontPath); - if (cashedFont == null) { + // lazy instanciation for fontCache. + if (fontCache == null) + fontCache = new java.util.HashMap(); + Font cachedFont = (Font)fontCache.get(fontURL.toExternalForm()); + if (cachedFont == null) { // Create specified TrueType Font. - FileInputStream fontStream = null; + InputStream fontStream = null; try { - MessageHandler.logln("create embedFont "+fontPath); - fontStream = new FileInputStream(fontPath); + MessageHandler.logln("Create embedded AWT font from stream "+fontURL.toExternalForm()); + fontStream = fontURL.openStream(); // createFont methods supports higer than JDK1.3 // Currently supports only TrueType font. - cashedFont = Font.createFont(Font.TRUETYPE_FONT,fontStream); + cachedFont = Font.createFont(Font.TRUETYPE_FONT, fontStream); } catch(Throwable th) { - MessageHandler.error("Failed to create embedFont "+ - fontPath + " : " + th.toString()); + MessageHandler.error("Failed to create embedded AWT font "+ + fontURL.toExternalForm() + ": " + th.toString()); // if failed create font, use system "Dialog" logical font // name for each Locale. - cashedFont = new Font("Dialog", style, size); + cachedFont = new Font("Dialog", style, size); } finally { if (fontStream != null) try { fontStream.close(); } catch(Exception ex) {} } - fontCash.put(fontPath,cashedFont); + fontCache.put(fontURL.toExternalForm(), cachedFont); } - Font font = cashedFont.deriveFont(style, (float)size); + Font font = cachedFont.deriveFont(style, (float)size); return font; } diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index 9fb088c63..72f0b831f 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -68,8 +68,8 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable protected ProgressListener progressListener = null; protected Translator res = null; - protected HashMap fontNames = new HashMap(); - protected HashMap fontStyles = new HashMap(); + protected Map fontNames = new java.util.HashMap(); + protected Map fontStyles = new java.util.HashMap(); protected Color saveColor = null; protected IDReferences idReferences = null; @@ -115,12 +115,12 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable /** * options */ - protected java.util.HashMap options; + protected java.util.Map options; /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -410,7 +410,7 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable w = w + area.getPaddingLeft() + area.getPaddingRight(); h = h + area.getPaddingTop() + area.getPaddingBottom(); - doBackground(area, rx, ry, w, h); + doBackground(area, rx, ry, w, h); rx = rx - area.getBorderLeftWidth(); ry = ry + area.getBorderTopWidth(); @@ -487,9 +487,9 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable * in non-bitmapped images. */ protected void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs) { - // XXX: implement this + FopImage image, + FontState fs) { + // XXX: implement this } /** @@ -506,11 +506,11 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable * in non-bitmapped images. */ protected void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs) { - // XXX: implement this + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs) { + // XXX: implement this } // correct integer roundoff (aml/rlc) diff --git a/src/org/apache/fop/render/awt/FontMetricsMapper.java b/src/org/apache/fop/render/awt/FontMetricsMapper.java index 5db5dea71..4d3d3bb4c 100644 --- a/src/org/apache/fop/render/awt/FontMetricsMapper.java +++ b/src/org/apache/fop/render/awt/FontMetricsMapper.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -14,6 +14,7 @@ import org.apache.fop.layout.FontDescriptor; import org.apache.fop.layout.FontState; // Java +import java.net.URL; import java.awt.Graphics2D; import java.awt.Font; @@ -69,10 +70,10 @@ public class FontMetricsMapper implements org.apache.fop.layout.FontMetric { /** * Create Original Font. - * @param fontPath path to truetype font + * @param fontURL URL to truetype font */ - public void setEmbedFont(String fontPath) { - metric.setEmbedFont(family,style,fontPath); + public void setEmbedFont(URL fontURL) { + metric.setEmbedFont(family, style, fontURL); } /** diff --git a/src/org/apache/fop/render/awt/FontSetup.java b/src/org/apache/fop/render/awt/FontSetup.java index 4fe1c1794..cbecb2000 100644 --- a/src/org/apache/fop/render/awt/FontSetup.java +++ b/src/org/apache/fop/render/awt/FontSetup.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -19,7 +19,8 @@ import org.apache.fop.apps.FOPException; // Java import java.awt.Font; import java.awt.Graphics2D; -import java.util.ArrayList; +import java.util.List; +import java.net.URL; /** * sets up the AWT fonts. It is similar to @@ -45,8 +46,8 @@ public class FontSetup { * triplets for lookup * * @param fontInfo the font info object to set up - * @param parent needed, since a live AWT component is needed - * to get a valid java.awt.FontMetrics object + * @param graphics Graphics2D to work on + * @throws FOPException in case of an error during font setup */ public static void setup(FontInfo fontInfo, Graphics2D graphics) throws FOPException { @@ -188,6 +189,10 @@ public class FontSetup { /** * Add fonts from configuration file starting with * internalnames F + * @param fontInfo FontInfo from Configuration + * @param num starting index + * @param graphics Graphics2D to work on + * @throws FOPException in case of an error during font setup */ public static void addConfiguredFonts( FontInfo fontInfo, int num, Graphics2D graphics) @@ -195,7 +200,7 @@ public class FontSetup { FontMetricsMapper metric; String internalName = null; - ArrayList fontInfos = Configuration.getFonts(); + List fontInfos = Configuration.getFonts(); if (fontInfos == null) return; @@ -204,12 +209,12 @@ public class FontSetup { (org.apache.fop.configuration.FontInfo)fontInfos.get(i); try { - String metricsFile = configFontInfo.getMetricsFile(); + URL metricsFile = configFontInfo.getMetricsFile(); if (metricsFile != null) { internalName = "F" + num; num++; - - ArrayList triplets = configFontInfo.getFontTriplets(); + + List triplets = configFontInfo.getFontTriplets(); for (int j = 0; j < triplets.size(); j++) { FontTriplet triplet = (FontTriplet)triplets.get(j); boolean embed = configFontInfo.getEmbedFile() != null; @@ -229,15 +234,17 @@ public class FontSetup { } } } catch (Exception ex) { - MessageHandler.error("Failed to read font metrics file " - + configFontInfo.getMetricsFile() - + " : " + ex.getMessage()); + MessageHandler.error("Failed to read font metrics file: " + + ex.getMessage()); } } } /** * Return configured font metrics value. + * + * @param triplet FontTriplet to analyze + * @return value indicating font style */ private static int getFontMetrics(FontTriplet triplet) { boolean isBold = ("bold".equalsIgnoreCase(triplet.getWeight())); diff --git a/src/org/apache/fop/render/mif/MIFRenderer.java b/src/org/apache/fop/render/mif/MIFRenderer.java index 989490510..d024f9973 100644 --- a/src/org/apache/fop/render/mif/MIFRenderer.java +++ b/src/org/apache/fop/render/mif/MIFRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -73,7 +73,7 @@ public class MIFRenderer extends AbstractRenderer { /** * options */ - protected java.util.HashMap options; + protected java.util.Map options; /** * create the MIF renderer @@ -85,7 +85,7 @@ public class MIFRenderer extends AbstractRenderer { /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -163,7 +163,7 @@ public class MIFRenderer extends AbstractRenderer { w = w + area.getPaddingLeft() + area.getPaddingRight(); h = h + area.getPaddingTop() + area.getPaddingBottom(); - doBackground(area, rx, ry, w, h); + doBackground(area, rx, ry, w, h); rx = rx - area.getBorderLeftWidth(); ry = ry + area.getBorderTopWidth(); @@ -236,7 +236,7 @@ public class MIFRenderer extends AbstractRenderer { * Renders an image, scaling it to the given width and height. * If the scaled width and height is the same intrinsic size * of the image, the image is not scaled. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param w the width in millipoints @@ -246,14 +246,14 @@ public class MIFRenderer extends AbstractRenderer { * in non-bitmapped images. */ protected void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs) { - // XXX: implement this + FopImage image, + FontState fs) { + // XXX: implement this } - + /** - * Renders an image, clipping it as specified. - * + * Renders an image, clipping it as specified. + * * @param x the x position of left edge in millipoints. * @param y the y position of top edge in millipoints. * @param clipX the left edge of the clip in millipoints @@ -265,11 +265,11 @@ public class MIFRenderer extends AbstractRenderer { * in non-bitmapped images. */ protected void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs) { - // XXX: implement this + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs) { + // XXX: implement this } /** diff --git a/src/org/apache/fop/render/pcl/PCLRenderer.java b/src/org/apache/fop/render/pcl/PCLRenderer.java index 0a8e33cea..ba52bfee1 100755 --- a/src/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/org/apache/fop/render/pcl/PCLRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -58,7 +58,7 @@ public class PCLRenderer extends PrintRenderer { private int xoffset = -180; // X Offset to allow for PCL implicit 1/4" left margin. - private java.util.HashMap options; + private java.util.Map options; /** * Create the PCL renderer @@ -68,7 +68,7 @@ public class PCLRenderer extends PrintRenderer { /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -248,7 +248,7 @@ public class PCLRenderer extends PrintRenderer { * Renders an image, scaling it to the given width and height. * If the scaled width and height is the same intrinsic size * of the image, the image is not scaled. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param w the width in millipoints @@ -258,14 +258,14 @@ public class PCLRenderer extends PrintRenderer { * in non-bitmapped images. */ protected void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs) { - // XXX: implement this + FopImage image, + FontState fs) { + // XXX: implement this } - + /** - * Renders an image, clipping it as specified. - * + * Renders an image, clipping it as specified. + * * @param x the x position of left edge in millipoints. * @param y the y position of top edge in millipoints. * @param clipX the left edge of the clip in millipoints @@ -277,11 +277,11 @@ public class PCLRenderer extends PrintRenderer { * in non-bitmapped images. */ protected void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs) { - // XXX: implement this + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs) { + // XXX: implement this } boolean printBMP(FopImage img, int x, int y, int w, diff --git a/src/org/apache/fop/render/pdf/FontReader.java b/src/org/apache/fop/render/pdf/FontReader.java index 8ed04813d..4e926977d 100644 --- a/src/org/apache/fop/render/pdf/FontReader.java +++ b/src/org/apache/fop/render/pdf/FontReader.java @@ -1,25 +1,31 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ package org.apache.fop.render.pdf; + +import java.util.List; +import java.util.Map; +import java.io.IOException; +import java.net.URL; + import org.apache.fop.render.pdf.fonts.*; +import org.apache.fop.pdf.PDFWArray; +import org.apache.fop.pdf.PDFCIDFont; +import org.apache.fop.configuration.ConfigurationReader; +import org.apache.fop.configuration.Configuration; +import org.apache.fop.apps.FOPException; +import org.apache.fop.tools.URLBuilder; + import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.XMLReader; import org.xml.sax.SAXException; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.Attributes; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import org.apache.fop.pdf.PDFWArray; -import org.apache.fop.pdf.PDFCIDFont; -import org.apache.fop.configuration.ConfigurationReader; -import org.apache.fop.apps.FOPException; /** * Class for reading a metric.xml file and creating a font object. @@ -40,14 +46,14 @@ public class FontReader extends DefaultHandler { // private SingleByteFont singleFont = null; private String text = null; - private ArrayList cidWidths = null; + private List cidWidths = null; private int cidWidthIndex = 0; - private HashMap currentKerning = null; + private Map currentKerning = null; - private ArrayList bfranges = null; + private List bfranges = null; - private void createFont(String path) throws FOPException { + private void createFont(URL url) throws FOPException { XMLReader parser = ConfigurationReader.createParser(); if (parser == null) throw new FOPException("Unable to create SAX parser"); @@ -63,7 +69,7 @@ public class FontReader extends DefaultHandler { parser.setContentHandler(this); try { - parser.parse(path); + parser.parse(new InputSource(url.openStream())); } catch (SAXException e) { throw new FOPException(e); } catch (IOException e) { @@ -75,7 +81,7 @@ public class FontReader extends DefaultHandler { /** * Sets the path to embed a font. a null value disables font embedding */ - public void setFontEmbedPath(String path) { + public void setFontEmbedPath(URL path) { if (isCID) multiFont.embedFileName = path; else @@ -104,7 +110,7 @@ public class FontReader extends DefaultHandler { * Construct a FontReader object from a path to a metric.xml file * and read metric data */ - public FontReader(String path) throws FOPException { + public FontReader(URL path) throws FOPException { createFont(path); } @@ -115,7 +121,7 @@ public class FontReader extends DefaultHandler { } public void startElement(String uri, String localName, String qName, - Attributes attributes) { + Attributes attributes) throws SAXException { if (localName.equals("font-metrics")) { if ("TYPE0".equals(attributes.getValue("type"))) { multiFont = new MultiByteFont(); @@ -134,19 +140,35 @@ public class FontReader extends DefaultHandler { } } else if ("embed".equals(localName)) { if (isCID) { - // This *is* annoying... should create a common - // interface for sing/multibytefonts... - multiFont.embedFileName = attributes.getValue("file"); + /**@todo This *is* annoying... should create a common + interface for sing/multibytefonts...*/ + String filename = attributes.getValue("file"); + if (filename != null) { + try { + multiFont.embedFileName = URLBuilder.buildURL( + Configuration.getFontBaseURL(), filename); + } catch (java.net.MalformedURLException mfue) { + throw new SAXException(mfue); + } + } multiFont.embedResourceName = attributes.getValue("class"); } else { - singleFont.embedFileName = attributes.getValue("file"); + String filename = attributes.getValue("file"); + if (filename != null) { + try { + singleFont.embedFileName = URLBuilder.buildURL( + Configuration.getFontBaseURL(), filename); + } catch (java.net.MalformedURLException mfue) { + throw new SAXException(mfue); + } + } singleFont.embedResourceName = attributes.getValue("class"); } } else if ("cid-widths".equals(localName)) { cidWidthIndex = getInt(attributes.getValue("start-index")); - cidWidths = new ArrayList(); + cidWidths = new java.util.ArrayList(); } else if ("kerning".equals(localName)) { - currentKerning = new HashMap(); + currentKerning = new java.util.HashMap(); if (isCID) multiFont.kerning.put(new Integer(attributes.getValue("kpx1")), currentKerning); @@ -154,7 +176,7 @@ public class FontReader extends DefaultHandler { singleFont.kerning.put(new Integer(attributes.getValue("kpx1")), currentKerning); } else if ("bfranges".equals(localName)) { - bfranges = new ArrayList(); + bfranges = new java.util.ArrayList(); } else if ("bf".equals(localName)) { BFEntry entry = new BFEntry(); entry.unicodeStart = getInt(attributes.getValue("us")); diff --git a/src/org/apache/fop/render/pdf/FontSetup.java b/src/org/apache/fop/render/pdf/FontSetup.java index 5f4df68c0..de8c2a280 100644 --- a/src/org/apache/fop/render/pdf/FontSetup.java +++ b/src/org/apache/fop/render/pdf/FontSetup.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -20,8 +20,9 @@ import org.apache.fop.apps.FOPException; // Java import java.util.Iterator; -import java.util.HashMap; -import java.util.ArrayList; +import java.util.Map; +import java.util.List; +import java.net.URL; /** * sets up the PDF fonts. @@ -145,7 +146,7 @@ public class FontSetup { String internalName = null; FontReader reader = null; - ArrayList fontInfos = Configuration.getFonts(); + List fontInfos = Configuration.getFonts(); if (fontInfos == null) return; @@ -154,7 +155,7 @@ public class FontSetup { (org.apache.fop.configuration.FontInfo)fontInfos.get(i); try { - String metricsFile = configFontInfo.getMetricsFile(); + URL metricsFile = configFontInfo.getMetricsFile(); if (metricsFile != null) { internalName = "F" + num; num++; @@ -168,8 +169,8 @@ public class FontSetup { metricsFile, configFontInfo.getKerning()); fontInfo.addMetrics(internalName, font); - - ArrayList triplets = configFontInfo.getFontTriplets(); + + List triplets = configFontInfo.getFontTriplets(); for (int j = 0; j < triplets.size(); j++) { FontTriplet triplet = (FontTriplet)triplets.get(j); @@ -180,9 +181,8 @@ public class FontSetup { } } } catch (Exception ex) { - MessageHandler.error("Failed to read font metrics file " - + configFontInfo.getMetricsFile() - + " : " + ex.getMessage()); + MessageHandler.error("Failed to read a font metrics file: " + + ex.getMessage()); } } } @@ -194,7 +194,7 @@ public class FontSetup { * @param fontInfo font info object to get font information from */ public static void addToResources(PDFDocument doc, FontInfo fontInfo) { - HashMap fonts = fontInfo.getUsedFonts(); + Map fonts = fontInfo.getUsedFonts(); Iterator e = fonts.keySet().iterator(); PDFResources resources = doc.getResources(); while (e.hasNext()) { diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index eaab64a22..ddae066c9 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -38,8 +38,8 @@ import org.w3c.dom.svg.SVGLength; // Java import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; import java.awt.Point; @@ -120,9 +120,9 @@ public class PDFRenderer extends PrintRenderer { /** * options */ - protected java.util.HashMap options; + protected java.util.Map options; - protected ArrayList extensions = null; + protected List extensions = null; /** * create the PDF renderer @@ -136,7 +136,7 @@ public class PDFRenderer extends PrintRenderer { * * @param options Options for the renderer */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -589,7 +589,7 @@ public class PDFRenderer extends PrintRenderer { StringBuffer pdf = _wordAreaPDF; pdf.setLength(0); - HashMap kerning = null; + Map kerning = null; boolean kerningAvailable = false; kerning = area.getFontState().getKerning(); @@ -782,9 +782,9 @@ public class PDFRenderer extends PrintRenderer { } private void addKerning(StringBuffer buf, Integer ch1, Integer ch2, - HashMap kerning, String startText, + Map kerning, String startText, String endText) { - HashMap kernPair = (HashMap) kerning.get(ch1); + Map kernPair = (Map) kerning.get(ch1); if (kernPair != null) { Integer width = (Integer) kernPair.get(ch2); @@ -812,7 +812,7 @@ public class PDFRenderer extends PrintRenderer { this.pdfDoc.setIDReferences(idReferences); this.renderPage(page); - ArrayList exts = page.getExtensions(); + List exts = page.getExtensions(); if (exts != null) { extensions = exts; } @@ -852,14 +852,14 @@ public class PDFRenderer extends PrintRenderer { } currentPage.setAnnotList(currentAnnotList); - ArrayList linkSets = page.getLinkSets(); + List linkSets = page.getLinkSets(); for (int i = 0; i < linkSets.size(); i++) { LinkSet linkSet = (LinkSet)linkSets.get(i); linkSet.align(); String dest = linkSet.getDest(); int linkType = linkSet.getLinkType(); - ArrayList linkRects = linkSet.getRects(); + List linkRects = linkSet.getRects(); for (int j = 0; j < linkRects.size(); j++) { LinkedRectangle lrect = (LinkedRectangle)linkRects.get(j); currentAnnotList.addLink( @@ -909,7 +909,7 @@ public class PDFRenderer extends PrintRenderer { * * @param exts the list of root extensions to process */ - protected void renderRootExtensions(ArrayList extensions) { + protected void renderRootExtensions(List extensions) { if (extensions != null) { for (int i = 0; i < extensions.size(); i++) { ExtensionObj ext = (ExtensionObj) extensions.get(i); @@ -945,7 +945,7 @@ public class PDFRenderer extends PrintRenderer { outline.setRendererObject(pdfOutline); // handle sub outlines - ArrayList v = outline.getOutlines(); + List v = outline.getOutlines(); for (int i = 0; i < v.size(); i++) { renderOutline((Outline) v.get(i)); } diff --git a/src/org/apache/fop/render/pdf/fonts/LazyFont.java b/src/org/apache/fop/render/pdf/fonts/LazyFont.java index 062d03f83..4d42051f8 100644 --- a/src/org/apache/fop/render/pdf/fonts/LazyFont.java +++ b/src/org/apache/fop/render/pdf/fonts/LazyFont.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -11,31 +11,33 @@ import org.apache.fop.render.pdf.Font; import org.apache.fop.layout.FontDescriptor; import org.apache.fop.pdf.PDFStream; import org.apache.fop.messaging.MessageHandler; -import java.util.HashMap; + +import java.util.Map; +import java.net.URL; import org.apache.fop.render.pdf.FontReader; public class LazyFont extends Font implements FontDescriptor { - - private String metricsFileName = null; - private String fontEmbedPath = null; + + private URL metricsFile = null; + private URL fontEmbedPath = null; private boolean useKerning = false; - + private boolean isMetricsLoaded = false; private Font realFont = null; private FontDescriptor realFontDescriptor = null; - - public LazyFont(String fontEmbedPath, String metricsFileName, boolean useKerning){ - this.metricsFileName = metricsFileName; + + public LazyFont(URL fontEmbedPath, URL metricsFile, boolean useKerning){ + this.metricsFile = metricsFile; this.fontEmbedPath = fontEmbedPath; this.useKerning = useKerning; } - + private void load(){ - if(! isMetricsLoaded){ + if (!isMetricsLoaded) { isMetricsLoaded = true; try{ - FontReader reader = new FontReader(metricsFileName); + FontReader reader = new FontReader(metricsFile); reader.useKerning(useKerning); reader.setFontEmbedPath(fontEmbedPath); realFont = reader.getFont(); @@ -45,129 +47,129 @@ public class LazyFont extends Font implements FontDescriptor { // System.out.println("Metrics " + metricsFileName + " loaded."); } catch (Exception ex) { MessageHandler.error("Failed to read font metrics file " - + metricsFileName - + " : " + ex.getMessage()); + + metricsFile.toExternalForm() + + ": " + ex.getMessage()); } } } - + public Font getRealFont(){ return realFont; } - + // Font public String encoding(){ load(); return realFont.encoding(); } - + public String fontName(){ load(); return realFont.fontName(); } - + public byte getSubType(){ load(); return realFont.getSubType(); } - + public char mapChar(char c){ load(); return realFont.mapChar(c); } - + // FontMetrics public int getAscender(int size){ load(); return realFont.getAscender(size); } - + public int getCapHeight(int size){ load(); return realFont.getCapHeight(size); } - + public int getDescender(int size){ load(); return realFont.getDescender(size); } - + public int getXHeight(int size){ load(); return realFont.getXHeight(size); } - + public int getFirstChar(){ load(); return realFont.getFirstChar(); } - + public int getLastChar(){ load(); return realFont.getLastChar(); } - + public int width(int i, int size){ load(); return realFont.width(i, size); } - + public int[] getWidths(int size){ load(); return realFont.getWidths(size); } - + // FontDescriptor public int getCapHeight(){ load(); return realFontDescriptor.getCapHeight(); } - + public int getDescender(){ load(); return realFontDescriptor.getDescender(); } - + public int getAscender(){ load(); return realFontDescriptor.getAscender(); } - + public int getFlags(){ load(); return realFontDescriptor.getFlags(); } - + public int[] getFontBBox(){ load(); return realFontDescriptor.getFontBBox(); } - + public int getItalicAngle(){ load(); return realFontDescriptor.getItalicAngle(); } - + public int getStemV(){ load(); return realFontDescriptor.getStemV(); } - + public boolean hasKerningInfo(){ load(); return realFontDescriptor.hasKerningInfo(); } - - public HashMap getKerningInfo(){ + + public Map getKerningInfo(){ load(); return realFontDescriptor.getKerningInfo(); } - + public boolean isEmbeddable(){ load(); return realFontDescriptor.isEmbeddable(); } - + public PDFStream getFontFile(int objNum){ load(); return realFontDescriptor.getFontFile(objNum); diff --git a/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java b/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java index 9f6d27c70..6d8d64efb 100644 --- a/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java +++ b/src/org/apache/fop/render/pdf/fonts/MultiByteFont.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -25,7 +25,8 @@ import java.io.IOException; import java.io.FileInputStream; import java.io.File; import java.io.BufferedInputStream; -import java.util.HashMap; +import java.util.Map; +import java.net.URL; /** * Generic MultiByte (CID) font @@ -43,7 +44,7 @@ public class MultiByteFont extends CIDFont implements FontDescriptor { 0, 0, 0, 0 }; - public String embedFileName = null; + public URL embedFileName = null; public String embedResourceName = null; public PDFTTFStream embeddedFont = null; @@ -54,7 +55,7 @@ public class MultiByteFont extends CIDFont implements FontDescriptor { public int defaultWidth = 0; public byte cidType = PDFCIDFont.CID_TYPE2; - public HashMap kerning = new HashMap(); + public Map kerning = new java.util.HashMap(); public boolean useKerning = true; private String namePrefix = null; // Quasi unique prefix private static int uniqueCounter = 1; @@ -67,12 +68,12 @@ public class MultiByteFont extends CIDFont implements FontDescriptor { /** * usedGlyphs contains orginal, new glyph index */ - private HashMap usedGlyphs = new HashMap(); + private Map usedGlyphs = new java.util.HashMap(); /** * usedGlyphsIndex contains new glyph, original index */ - private HashMap usedGlyphsIndex = new HashMap(); + private Map usedGlyphsIndex = new java.util.HashMap(); int usedGlyphsCount = 0; public MultiByteFont() { @@ -100,11 +101,11 @@ public class MultiByteFont extends CIDFont implements FontDescriptor { return (useKerning & kerning.isEmpty()); } - public final java.util.HashMap getKerningInfo() { + public final Map getKerningInfo() { if (useKerning) return kerning; else - return new HashMap(); + return new java.util.HashMap(); } public byte getSubType() { @@ -195,7 +196,9 @@ public class MultiByteFont extends CIDFont implements FontDescriptor { public PDFStream getFontFile(int i) { try { - FontFileReader reader = new FontFileReader(embedFileName); + InputStream in = embedFileName.openStream(); + FontFileReader reader = new FontFileReader(in); + in.close(); TTFSubSetFile subset = new TTFSubSetFile(); byte[] subsetFont = subset.readFont(reader, ttcName, usedGlyphs); diff --git a/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java b/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java index f049d6c7c..232098fe4 100644 --- a/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java +++ b/src/org/apache/fop/render/pdf/fonts/SingleByteFont.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -18,7 +18,8 @@ import org.apache.fop.render.pdf.Font; import java.io.FileInputStream; import java.io.InputStream; import java.io.BufferedInputStream; -import java.util.HashMap; +import java.util.Map; +import java.net.URL; /** * Generic SingleByte font @@ -37,7 +38,7 @@ public class SingleByteFont extends Font implements FontDescriptor { 0, 0, 0, 0 }; - public String embedFileName = null; + public URL embedFileName = null; public String embedResourceName = null; public PDFStream embeddedFont = null; @@ -48,7 +49,7 @@ public class SingleByteFont extends Font implements FontDescriptor { public int italicAngle = 0; public int missingWidth = 0; - public HashMap kerning = new HashMap(); + public Map kerning = new java.util.HashMap(); public boolean useKerning = true; public int width[] = null; @@ -58,11 +59,11 @@ public class SingleByteFont extends Font implements FontDescriptor { return (useKerning & kerning.isEmpty()); } - public final java.util.HashMap getKerningInfo() { + public final Map getKerningInfo() { if (useKerning) return kerning; else - return new HashMap(); + return new java.util.HashMap(); } public byte getSubType() { @@ -109,7 +110,7 @@ public class SingleByteFont extends Font implements FontDescriptor { // Get file first if (embedFileName != null) try { - instream = new FileInputStream(embedFileName); + instream = embedFileName.openStream(); } catch (Exception e) { System.out.println("Failed to embed fontfile: " + embedFileName); @@ -243,10 +244,10 @@ public class SingleByteFont extends Font implements FontDescriptor { public char mapChar(char c) { char d = mapping.mapChar(c); - if(d != 0) + if(d != 0) return d; else - return '#'; + return '#'; } } diff --git a/src/org/apache/fop/render/ps/PSRenderer.java b/src/org/apache/fop/render/ps/PSRenderer.java index 4499a3114..ba60533cd 100644 --- a/src/org/apache/fop/render/ps/PSRenderer.java +++ b/src/org/apache/fop/render/ps/PSRenderer.java @@ -43,8 +43,8 @@ import java.util.*; import java.io.IOException; import java.io.OutputStream; import java.util.Iterator; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; import java.awt.Point; @@ -122,7 +122,7 @@ public class PSRenderer extends AbstractRenderer { protected IDReferences idReferences; - protected java.util.HashMap options; + protected java.util.Map options; /** @@ -138,7 +138,7 @@ public class PSRenderer extends AbstractRenderer { /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -264,7 +264,7 @@ public class PSRenderer extends AbstractRenderer { write("/FOPFonts 100 dict dup begin"); // write("/gfF1{/Helvetica findfont} bd"); // write("/gfF3{/Helvetica-Bold findfont} bd"); - HashMap fonts = fontInfo.getFonts(); + Map fonts = fontInfo.getFonts(); Iterator enum = fonts.keySet().iterator(); while (enum.hasNext()) { String key = (String)enum.next(); @@ -804,7 +804,7 @@ public class PSRenderer extends AbstractRenderer { String fontWeight = area.getFontState().getFontWeight(); //comment("% --- LineArea begin font-weight="+fontWeight); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); this.currentYPosition = ry - area.getPlacementOffset(); diff --git a/src/org/apache/fop/render/svg/SVGRenderer.java b/src/org/apache/fop/render/svg/SVGRenderer.java index c2e930a81..145330c10 100644 --- a/src/org/apache/fop/render/svg/SVGRenderer.java +++ b/src/org/apache/fop/render/svg/SVGRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -36,7 +36,7 @@ import java.awt.Color; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; -import java.util.HashMap; +import java.util.Map; import java.net.URL; import java.net.MalformedURLException; import java.io.OutputStream; @@ -60,8 +60,8 @@ public class SVGRenderer extends AbstractRenderer { protected int pageHeight = 0; protected int pageNumber = 0; - protected HashMap fontNames = new HashMap(); - protected HashMap fontStyles = new HashMap(); + protected Map fontNames = new java.util.HashMap(); + protected Map fontStyles = new java.util.HashMap(); protected Color saveColor = null; protected IDReferences idReferences = null; @@ -86,12 +86,12 @@ public class SVGRenderer extends AbstractRenderer { /** * options */ - protected java.util.HashMap options; + protected java.util.Map options; /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -285,7 +285,7 @@ public class SVGRenderer extends AbstractRenderer { w = w + area.getPaddingLeft() + area.getPaddingRight(); h = h + area.getPaddingTop() + area.getPaddingBottom(); - doBackground(area, rx, ry, w, h); + doBackground(area, rx, ry, w, h); rx = rx - area.getBorderLeftWidth(); ry = ry + area.getBorderTopWidth(); @@ -347,7 +347,7 @@ public class SVGRenderer extends AbstractRenderer { * Renders an image, scaling it to the given width and height. * If the scaled width and height is the same intrinsic size * of the image, the image is not scaled. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param w the width in millipoints @@ -357,14 +357,14 @@ public class SVGRenderer extends AbstractRenderer { * in non-bitmapped images. */ protected void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs) { - // XXX: implement this + FopImage image, + FontState fs) { + // XXX: implement this } - + /** - * Renders an image, clipping it as specified. - * + * Renders an image, clipping it as specified. + * * @param x the x position of left edge in millipoints. * @param y the y position of top edge in millipoints. * @param clipX the left edge of the clip in millipoints @@ -376,11 +376,11 @@ public class SVGRenderer extends AbstractRenderer { * in non-bitmapped images. */ protected void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs) { - // XXX: implement this + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs) { + // XXX: implement this } public void renderImageArea(ImageArea area) { @@ -606,13 +606,13 @@ public class SVGRenderer extends AbstractRenderer { throws IOException { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); svgDocument = impl.createDocument(svgNS, "svg", null); - ProcessingInstruction pi = + ProcessingInstruction pi = svgDocument.createProcessingInstruction( "xml", " version=\"1.0\" encoding=\"ISO-8859-1\""); - svgRoot = svgDocument.getDocumentElement(); + svgRoot = svgDocument.getDocumentElement(); svgDocument.insertBefore(pi, svgRoot); - } + } public void stopRenderer(OutputStream outputStream) throws IOException { diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java index 135ace970..12fb17d6b 100755 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/org/apache/fop/render/txt/TXTRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -30,7 +30,7 @@ import org.w3c.dom.svg.SVGDocument; // Java import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; +import java.util.List; /** * Renderer that renders areas to plain text. @@ -79,14 +79,14 @@ public class TXTRenderer extends PrintRenderer { /** * options */ - protected java.util.HashMap options; + protected java.util.Map options; public TXTRenderer() {} /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; } @@ -295,7 +295,7 @@ public class TXTRenderer extends PrintRenderer { */ } - private void xferLineBytes(int startpos, int bitcount, ArrayList save, + private void xferLineBytes(int startpos, int bitcount, List save, int start2) { /* * Not yet implemented @@ -661,7 +661,7 @@ public class TXTRenderer extends PrintRenderer { * long dx = 0; * long dy = TwoAsquared * b; * int rectlen = iw - 2 * irx; - * ArrayList bottomlines = new ArrayList(); + * List bottomlines = new java.util.ArrayList(); * int x0 = tx; * // Set Transparency modes and select shading. * currentStream.add("\033*v0n1O\033*c" + (int)(100 - ((0.3f * thecolor.red() + 0.59f * thecolor.green() + 0.11f * thecolor.blue()) * 100f)) + "G\033*v2T"); @@ -732,7 +732,7 @@ public class TXTRenderer extends PrintRenderer { } // Add a polyline or polygon. Does not support fills yet!!! - protected void addPolyline(ArrayList points, int posx, int posy, + protected void addPolyline(List points, int posx, int posy, PDFColor fc, PDFColor sc, float sw, boolean close) {} @@ -740,7 +740,7 @@ public class TXTRenderer extends PrintRenderer { * Renders an image, scaling it to the given width and height. * If the scaled width and height is the same intrinsic size * of the image, the image is not scaled. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param w the width in millipoints @@ -750,14 +750,14 @@ public class TXTRenderer extends PrintRenderer { * in non-bitmapped images. */ protected void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs) { - // XXX: implement this + FopImage image, + FontState fs) { + // XXX: implement this } - + /** - * Renders an image, clipping it as specified. - * + * Renders an image, clipping it as specified. + * * @param x the x position of left edge in millipoints. * @param y the y position of top edge in millipoints. * @param clipX the left edge of the clip in millipoints @@ -769,11 +769,11 @@ public class TXTRenderer extends PrintRenderer { * in non-bitmapped images. */ protected void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs) { - // XXX: implement this + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs) { + // XXX: implement this } boolean printBMP(FopImage img, int x, int y, int w, @@ -1264,7 +1264,7 @@ public class TXTRenderer extends PrintRenderer { * float ty = tg.y; * float currentX = x + tx; * float currentY = y + ty; - * ArrayList list = tg.textList; + * List list = tg.textList; * for ( Enumeration e = list.elements() ; e.hasMoreElements() ; ) * { * Object o = e.nextElement(); diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index 42cdb5e69..b4d98daf3 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -26,7 +26,7 @@ import org.apache.avalon.framework.logger.Logger; import java.io.IOException; import java.io.PrintWriter; import java.io.OutputStream; -import java.util.ArrayList; +import java.util.List; /** * Renderer that renders areas to XML for debugging purposes. @@ -60,7 +60,7 @@ public class XMLRenderer implements Renderer { /** * options */ - protected java.util.HashMap options; + protected java.util.Map options; private boolean consistentOutput = false; public XMLRenderer() {} @@ -68,7 +68,7 @@ public class XMLRenderer implements Renderer { /** * set up renderer options */ - public void setOptions(java.util.HashMap options) { + public void setOptions(java.util.Map options) { this.options = options; Boolean con = (Boolean)options.get("consistentOutput"); if(con != null) { @@ -159,7 +159,7 @@ public class XMLRenderer implements Renderer { * Renders an image, scaling it to the given width and height. * If the scaled width and height is the same intrinsic size * of the image, the image is not scaled. - * + * * @param x the x position of left edge in millipoints * @param y the y position of top edge in millipoints * @param w the width in millipoints @@ -169,14 +169,14 @@ public class XMLRenderer implements Renderer { * in non-bitmapped images. */ protected void drawImageScaled(int x, int y, int w, int h, - FopImage image, - FontState fs) { - // XXX: implement this + FopImage image, + FontState fs) { + // XXX: implement this } - + /** - * Renders an image, clipping it as specified. - * + * Renders an image, clipping it as specified. + * * @param x the x position of left edge in millipoints. * @param y the y position of top edge in millipoints. * @param clipX the left edge of the clip in millipoints @@ -188,11 +188,11 @@ public class XMLRenderer implements Renderer { * in non-bitmapped images. */ protected void drawImageClipped(int x, int y, - int clipX, int clipY, - int clipW, int clipH, - FopImage image, - FontState fs) { - // XXX: implement this + int clipX, int clipY, + int clipW, int clipH, + FopImage image, + FontState fs) { + // XXX: implement this } /** @@ -202,7 +202,7 @@ public class XMLRenderer implements Renderer { */ public void renderAreaContainer(AreaContainer area) { writeStartTag(""); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -217,7 +217,7 @@ public class XMLRenderer implements Renderer { */ public void renderBodyAreaContainer(BodyAreaContainer area) { writeStartTag(""); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -241,7 +241,7 @@ public class XMLRenderer implements Renderer { */ public void renderSpanArea(SpanArea area) { writeStartTag(""); - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -273,7 +273,7 @@ public class XMLRenderer implements Renderer { writeStartTag(baText.toString()); // write out marker info - ArrayList markers = area.getMarkers(); + List markers = area.getMarkers(); if (!markers.isEmpty()) { writeStartTag(""); for (int i = 0; i < markers.size(); i++) { @@ -290,7 +290,7 @@ public class XMLRenderer implements Renderer { writeEndTag(""); } - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -311,7 +311,7 @@ public class XMLRenderer implements Renderer { writeStartTag(iaText.toString()); // write out marker info - ArrayList markers = area.getMarkers(); + List markers = area.getMarkers(); if (!markers.isEmpty()) { writeStartTag(""); for (int i = 0; i < markers.size(); i++) { @@ -328,7 +328,7 @@ public class XMLRenderer implements Renderer { writeEndTag(""); } - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); @@ -424,7 +424,7 @@ public class XMLRenderer implements Renderer { String fontWeight = area.getFontState().getFontWeight(); writeStartTag(""); } - ArrayList children = area.getChildren(); + List children = area.getChildren(); for (int i = 0; i < children.size(); i++) { Box b = (Box)children.get(i); b.render(this); diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 8fdfd0252..8083f6ec2 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -1,6 +1,6 @@ /* * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. */ @@ -30,8 +30,7 @@ import java.awt.image.renderable.*; import java.io.*; import java.text.AttributedCharacterIterator; import java.text.CharacterIterator; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -93,13 +92,14 @@ public class PDFGraphics2D extends AbstractGraphics2D { PDFColor currentColour = new PDFColor(0, 0, 0); /** - * A registry of images that have already been drawn. They are mapped to + * A registry of images that have already been drawn. They are mapped to * a structure with the PDF xObjectNum, width and height. This * prevents multiple copies from being stored, which can greatly * reduce the size of a PDF graphic that uses the same image over and over * (e.g. graphic bullets, map icons, etc.). */ - private HashMap imageInfos = new HashMap(); + private Map imageInfos = new java.util.HashMap(); + private static class ImageInfo { public int width; public int height; @@ -233,7 +233,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { ImageObserver observer) { // System.err.println("drawImage:x, y"); - // first we look to see if we've already added this image to + // first we look to see if we've already added this image to // the pdf document. If so, we just reuse the reference; // otherwise we have to build a FopImage and add it to the pdf // document @@ -243,32 +243,32 @@ public class PDFGraphics2D extends AbstractGraphics2D { imageInfo = new ImageInfo(); imageInfo.width = img.getWidth(observer); imageInfo.height = img.getHeight(observer); - + if (imageInfo.width == -1 || imageInfo.height == -1) { return false; } - + Dimension size = new Dimension(imageInfo.width * 3, imageInfo.height * 3); BufferedImage buf = buildBufferedImage(size); - + java.awt.Graphics2D g = buf.createGraphics(); g.setComposite(AlphaComposite.SrcOver); g.setBackground(new Color(1, 1, 1, 0)); g.setPaint(new Color(1, 1, 1, 0)); g.fillRect(0, 0, imageInfo.width * 3, imageInfo.height * 3); g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); - + if (!g.drawImage(img, 0, 0, buf.getWidth(), buf.getHeight(), observer)) { return false; } g.dispose(); - + final byte[] result = new byte[buf.getWidth() * buf.getHeight() * 3]; final byte[] mask = new byte[buf.getWidth() * buf.getHeight()]; - + Raster raster = buf.getData(); DataBuffer bd = raster.getDataBuffer(); - + int count = 0; int maskpos = 0; int[] iarray; @@ -308,7 +308,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { // error break; } - + try { FopImage fopimg = new TempImage("TempImage:" + img.toString(), buf.getWidth(), buf.getHeight(), result, mask); imageInfo.xObjectNum = this.pdfDoc.addImage(fopimg); @@ -679,33 +679,33 @@ public class PDFGraphics2D extends AbstractGraphics2D { Point2D p2 = gp.getPoint2(); boolean cyclic = gp.isCyclic(); - ArrayList theCoords = new ArrayList(); + List theCoords = new java.util.ArrayList(); theCoords.add(new Double(p1.getX())); theCoords.add(new Double(p1.getY())); theCoords.add(new Double(p2.getX())); theCoords.add(new Double(p2.getY())); - ArrayList theExtend = new ArrayList(); + List theExtend = new java.util.ArrayList(); theExtend.add(new Boolean(true)); theExtend.add(new Boolean(true)); - ArrayList theDomain = new ArrayList(); + List theDomain = new java.util.ArrayList(); theDomain.add(new Double(0)); theDomain.add(new Double(1)); - ArrayList theEncode = new ArrayList(); + List theEncode = new java.util.ArrayList(); theEncode.add(new Double(0)); theEncode.add(new Double(1)); theEncode.add(new Double(0)); theEncode.add(new Double(1)); - ArrayList theBounds = new ArrayList(); + List theBounds = new java.util.ArrayList(); theBounds.add(new Double(0)); theBounds.add(new Double(1)); - ArrayList theFunctions = new ArrayList(); + List theFunctions = new java.util.ArrayList(); - ArrayList someColors = new ArrayList(); + List someColors = new java.util.ArrayList(); PDFColor color1 = new PDFColor(c1.getRed(), c1.getGreen(), c1.getBlue()); @@ -884,15 +884,15 @@ public class PDFGraphics2D extends AbstractGraphics2D { } else { fontState = ovFontState; ovFontState = null; - } + } String name; int size; name = fontState.getFontName(); size = fontState.getFontSize() / 1000; - + if ((!name.equals(this.currentFontName)) || (size != this.currentFontSize)) { - this.currentFontName = name; + this.currentFontName = name; this.currentFontSize = size; currentStream.write("/" + name + " " + size + " Tf\n"); @@ -909,7 +909,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { currentStream.write("BT\n"); - HashMap kerning = null; + Map kerning = null; boolean kerningAvailable = false; kerning = fontState.getKerning(); @@ -986,9 +986,9 @@ public class PDFGraphics2D extends AbstractGraphics2D { } private void addKerning(StringWriter buf, Integer ch1, Integer ch2, - HashMap kerning, String startText, + Map kerning, String startText, String endText) { - HashMap kernPair = (HashMap)kerning.get(ch1); + Map kernPair = (Map)kerning.get(ch1); if (kernPair != null) { Integer width = (Integer)kernPair.get(ch2);