diff options
author | Jeremias Maerki <jeremias@apache.org> | 2002-11-29 08:40:54 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2002-11-29 08:40:54 +0000 |
commit | 10a21e34c0c892d8c688a0024fd289fc04124670 (patch) | |
tree | a4632000a121a5e766841f0d6c7270b0ba8049ed /src | |
parent | f7d45457fccc120ddb3ba92c8e367f7238fd3f80 (diff) | |
download | xmlgraphics-fop-10a21e34c0c892d8c688a0024fd289fc04124670.tar.gz xmlgraphics-fop-10a21e34c0c892d8c688a0024fd289fc04124670.zip |
Moved PFM classes to type1 subpackage.
Use of org.apache.fop.tools.IOUtil instead of rewriting the same functionality every time.
Added a parser and memory representation class for Adobe Type 1 PFB files (Full support for raw and PC format as described in the "Download Fonts" spec from Adobe).
Adjusted the PFMReader for the package move.
Added Avalon logging to the PFMReader (adds a dependency to avalon-framework.jar, I will document that)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195649 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/org/apache/fop/fonts/FontFileReader.java | 20 | ||||
-rw-r--r-- | src/org/apache/fop/fonts/apps/PFMReader.java | 189 | ||||
-rw-r--r-- | src/org/apache/fop/fonts/type1/PFBData.java | 142 | ||||
-rw-r--r-- | src/org/apache/fop/fonts/type1/PFBParser.java | 210 | ||||
-rw-r--r-- | src/org/apache/fop/fonts/type1/PFMFile.java (renamed from src/org/apache/fop/fonts/PFMFile.java) | 49 | ||||
-rw-r--r-- | src/org/apache/fop/fonts/type1/PFMInputStream.java (renamed from src/org/apache/fop/fonts/PFMInputStream.java) | 11 | ||||
-rw-r--r-- | src/org/apache/fop/fonts/type1/package.html | 6 |
7 files changed, 487 insertions, 140 deletions
diff --git a/src/org/apache/fop/fonts/FontFileReader.java b/src/org/apache/fop/fonts/FontFileReader.java index 89b70f9c3..901f837d4 100644 --- a/src/org/apache/fop/fonts/FontFileReader.java +++ b/src/org/apache/fop/fonts/FontFileReader.java @@ -6,11 +6,13 @@ */ package org.apache.fop.fonts; + import java.io.InputStream; -import java.io.OutputStream; import java.io.File; import java.io.IOException; +import org.apache.fop.tools.IOUtil; + /** * Reads a file into an array and * provides file like functions for array access. @@ -28,8 +30,7 @@ public class FontFileReader { 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(); + this.file = IOUtil.toByteArray(in, 50000); this.fsize = this.file.length; this.current = 0; } finally { @@ -38,24 +39,13 @@ public class FontFileReader { } - /**@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); - } - } - /** * Constructor * @param fileName filename to read */ public FontFileReader(String fileName) throws java.io.IOException { File f = new File(fileName); - InputStream in = new java.io.FileInputStream(fileName); + InputStream in = new java.io.FileInputStream(f); try { init(in); } finally { diff --git a/src/org/apache/fop/fonts/apps/PFMReader.java b/src/org/apache/fop/fonts/apps/PFMReader.java index 1e3197b7e..5851b667c 100644 --- a/src/org/apache/fop/fonts/apps/PFMReader.java +++ b/src/org/apache/fop/fonts/apps/PFMReader.java @@ -1,28 +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.fonts.apps; -import java.io.*; -import org.w3c.dom.*; -import org.apache.fop.fonts.*; -import java.util.HashMap; -import java.util.ArrayList; +import java.io.File; +import java.io.InputStream; +import java.util.Map; +import java.util.List; import java.util.Iterator; +import org.w3c.dom.*; + +import org.apache.fop.fonts.type1.PFMFile; +import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.framework.logger.ConsoleLogger; +import org.apache.avalon.framework.logger.Logger; + /** * A tool which reads PFM files from Adobe Type 1 fonts and creates * XML font metrics file for use in FOP. - * - * @author jeremias.maerki@outline.ch */ -public class PFMReader { - private boolean invokedStandalone = false; - - public PFMReader() {} +public class PFMReader extends AbstractLogEnabled { + + //private boolean invokedStandalone = false; /** @@ -32,8 +35,8 @@ public class PFMReader { * returns a String[] with the per.ttf and Perpetua.xml. The hash * will have the (key, value) pairs: (-fn, Perpetua) and (-cn, PerpetuaBold) */ - private static String[] parseArguments(HashMap options, String[] args) { - ArrayList arguments = new ArrayList(); + private static String[] parseArguments(Map options, String[] args) { + List arguments = new java.util.ArrayList(); for (int i = 0; i < args.length; i++) { if (args[i].startsWith("-")) { if ((i + 1) < args.length &&!args[i + 1].startsWith("-")) { @@ -52,14 +55,14 @@ public class PFMReader { return argStrings; } - private final static void displayUsage() { - System.out.println(" java org.apache.fop.fonts.apps.PFMReader [options] metricfile.pfm xmlfile.xml\n"); - System.out.println(" where options can be:\n"); - System.out.println(" -fn <fontname>\n"); - System.out.println(" default is to use the fontname in the .ttf file, but\n" - + " you can override that name to make sure that the\n"); - System.out.println(" embedded font is used (if you're embedding fonts)\n"); - System.out.println(" instead of installed fonts when viewing documents with Acrobat Reader.\n"); + private void displayUsage() { + getLogger().info(" java org.apache.fop.fonts.apps.PFMReader [options] metricfile.pfm xmlfile.xml"); + getLogger().info(" where options can be:"); + getLogger().info(" -fn <fontname>"); + getLogger().info(" default is to use the fontname in the .pfm file, but"); + getLogger().info(" you can override that name to make sure that the"); + getLogger().info(" embedded font is used (if you're embedding fonts)"); + getLogger().info(" instead of installed fonts when viewing documents with Acrobat Reader."); } @@ -88,31 +91,43 @@ public class PFMReader { String className = null; String fontName = null; - HashMap options = new HashMap(); + Map options = new java.util.HashMap(); String[] arguments = parseArguments(options, args); PFMReader app = new PFMReader(); - app.invokedStandalone = true; + Logger log; + if (options.get("-d") != null) { + log = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG); + } else { + log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); + } + app.enableLogging(log); + + //app.invokedStandalone = true; - System.out.println("PFM Reader v1.1"); - System.out.println(); + log.info("PFM Reader v1.1"); + log.info(""); - if (options.get("-ef") != null) + if (options.get("-ef") != null) { embFile = (String)options.get("-ef"); + } - if (options.get("-er") != null) + if (options.get("-er") != null) { embResource = (String)options.get("-er"); + } - if (options.get("-fn") != null) + if (options.get("-fn") != null) { fontName = (String)options.get("-fn"); + } - if (options.get("-cn") != null) + if (options.get("-cn") != null) { className = (String)options.get("-cn"); + } if (arguments.length != 2 || options.get("-h") != null - || options.get("-help") != null || options.get("--help") != null) - displayUsage(); - else { + || options.get("-help") != null || options.get("--help") != null) { + app.displayUsage(); + } else { PFMFile pfm = app.loadPFM(arguments[0]); if (pfm != null) { app.preview(pfm); @@ -134,12 +149,17 @@ public class PFMReader { */ public PFMFile loadPFM(String filename) { try { - System.out.println("Reading " + filename + "..."); - System.out.println(); - FileInputStream in = new FileInputStream(filename); - PFMFile pfm = new PFMFile(); - pfm.load(in); - return pfm; + getLogger().info("Reading " + filename + "..."); + getLogger().info(""); + InputStream in = new java.io.FileInputStream(filename); + try { + PFMFile pfm = new PFMFile(); + setupLogger(pfm); + pfm.load(in); + return pfm; + } finally { + in.close(); + } } catch (Exception e) { e.printStackTrace(); return null; @@ -152,34 +172,19 @@ public class PFMReader { * @param pfm The PFM file to preview. */ public void preview(PFMFile pfm) { - PrintStream out = System.out; - - out.print("Font: "); - out.println(pfm.getWindowsName()); - out.print("Name: "); - out.println(pfm.getPostscriptName()); - out.print("CharSet: "); - out.println(pfm.getCharSetName()); - out.print("CapHeight: "); - out.println(pfm.getCapHeight()); - out.print("XHeight: "); - out.println(pfm.getXHeight()); - out.print("LowerCaseAscent: "); - out.println(pfm.getLowerCaseAscent()); - out.print("LowerCaseDescent: "); - out.println(pfm.getLowerCaseDescent()); - out.print("Having widths for "); - out.print(pfm.getLastChar() - pfm.getFirstChar()); - out.print(" characters ("); - out.print(pfm.getFirstChar()); - out.print("-"); - out.print(pfm.getLastChar()); - out.println(")."); - out.print("for example: Char "); - out.print(pfm.getFirstChar()); - out.print(" has a width of "); - out.println(pfm.getCharWidth(pfm.getFirstChar())); - out.println(); + getLogger().info("Font: " + pfm.getWindowsName()); + getLogger().info("Name: " + pfm.getPostscriptName()); + getLogger().info("CharSet: " + pfm.getCharSetName()); + getLogger().info("CapHeight: " + pfm.getCapHeight()); + getLogger().info("XHeight: " + pfm.getXHeight()); + getLogger().info("LowerCaseAscent: " + pfm.getLowerCaseAscent()); + getLogger().info("LowerCaseDescent: " + pfm.getLowerCaseDescent()); + getLogger().info("Having widths for " + (pfm.getLastChar() - pfm.getFirstChar()) + +" characters (" + pfm.getFirstChar() + + "-" + pfm.getLastChar() + ")."); + getLogger().info("for example: Char " + pfm.getFirstChar() + + " has a width of " + pfm.getCharWidth(pfm.getFirstChar())); + getLogger().info(""); } /** @@ -189,23 +194,14 @@ public class PFMReader { * @param target The target filename for the XML file. */ public void writeFontXML(org.w3c.dom.Document doc, String target) { - System.out.println("Writing xml font file " + target + "..."); - System.out.println(); + getLogger().info("Writing xml font file " + target + "..."); + getLogger().info(""); try { - javax.xml.transform.TransformerFactory.newInstance() - .newTransformer().transform( - new javax.xml.transform.dom.DOMSource(doc), - new javax.xml.transform.stream.StreamResult(new File(target))); -/* - OutputFormat format = new OutputFormat(doc); // Serialize DOM - FileWriter out = new FileWriter(target); // Writer will be a String - XMLSerializer serial = new XMLSerializer(out, format); - serial.asDOMSerializer(); // As a DOM Serializer - - serial.serialize(doc.getDocumentElement()); - out.close(); -*/ + javax.xml.transform.TransformerFactory.newInstance() + .newTransformer().transform( + new javax.xml.transform.dom.DOMSource(doc), + new javax.xml.transform.stream.StreamResult(new File(target))); } catch (Exception e) { e.printStackTrace(); } @@ -219,17 +215,17 @@ public class PFMReader { */ public org.w3c.dom.Document constructFontXML(PFMFile pfm, String fontName, String className, String resource, String file) { - System.out.println("Creating xml font file..."); - System.out.println(); + getLogger().info("Creating xml font file..."); + getLogger().info(""); // Document doc = new DocumentImpl(); Document doc; try { - doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (javax.xml.parsers.ParserConfigurationException e) { - System.out.println("Can't create DOM implementation "+e.getMessage()); - return null; + System.out.println("Can't create DOM implementation "+e.getMessage()); + return null; } Element root = doc.createElement("font-metrics"); doc.appendChild(root); @@ -250,10 +246,12 @@ public class PFMReader { el = doc.createElement("embed"); root.appendChild(el); - if (file != null) + if (file != null) { el.setAttribute("file", file); - if (resource != null) + } + if (resource != null) { el.setAttribute("class", resource); + } el = doc.createElement("encoding"); root.appendChild(el); @@ -282,10 +280,8 @@ public class PFMReader { Element bbox = doc.createElement("bbox"); root.appendChild(bbox); int[] bb = pfm.getFontBBox(); - String[] names = { - "left", "bottom", "right", "top" - }; - for (int i = 0; i < 4; i++) { + final String[] names = {"left", "bottom", "right", "top"}; + for (int i = 0; i < names.length; i++) { el = doc.createElement(names[i]); bbox.appendChild(el); value = new Integer(bb[i]); @@ -337,7 +333,7 @@ public class PFMReader { root.appendChild(el); Element el2 = null; - HashMap h2 = (HashMap)pfm.getKerning().get(kpx1); + Map h2 = (Map)pfm.getKerning().get(kpx1); for (Iterator enum2 = h2.keySet().iterator(); enum2.hasNext(); ) { Integer kpx2 = (Integer)enum2.next(); el2 = doc.createElement("pair"); @@ -355,10 +351,11 @@ public class PFMReader { StringBuffer esc = new StringBuffer(); for (int i = 0; i < str.length(); i++) { - if (str.charAt(i) == '\\') + if (str.charAt(i) == '\\') { esc.append("\\\\"); - else + } else { esc.append(str.charAt(i)); + } } return esc.toString(); diff --git a/src/org/apache/fop/fonts/type1/PFBData.java b/src/org/apache/fop/fonts/type1/PFBData.java new file mode 100644 index 000000000..8e66badc0 --- /dev/null +++ b/src/org/apache/fop/fonts/type1/PFBData.java @@ -0,0 +1,142 @@ +package org.apache.fop.fonts.type1; + +import java.io.OutputStream; +import java.io.IOException; + +/** + * Class that represents the contents of a PFB file. + * + * @see PFBParser + */ +public class PFBData { + + /** + * Raw format, no special file structure + */ + public static final int PFB_RAW = 0; + + /** + * PC format + */ + public static final int PFB_PC = 1; + + /** + * MAC Format (unsupported, yet) + */ + public static final int PFB_MAC = 2; + + private int pfbFormat; //One of the PFB_* constants + private byte[] headerSegment; + private byte[] encryptedSegment; + private byte[] trailerSegment; + + + /** + * Sets the PFB format the font was loaded with. + * @param format one of the PFB_* constants + */ + public void setPFBFormat(int format) { + switch (format) { + case PFB_RAW: + case PFB_PC: + this.pfbFormat = format; + break; + case PFB_MAC: + throw new UnsupportedOperationException("Mac format is not yet implemented"); + default: + throw new IllegalArgumentException("Invalid value for PFB format: "+format); + } + } + + + /** + * Returns the format the font was loaded with. + * @return int one of the PFB_* constants + */ + public int getPFBFormat() { + return this.pfbFormat; + } + + /** + * Sets the header segment of the font file. + * @param headerSeg the header segment + */ + public void setHeaderSegment(byte[] headerSeg) { + this.headerSegment = headerSeg; + } + + /** + * Sets the encrypted segment of the font file. + * @param encryptedSeg the encrypted segment + */ + public void setEncryptedSegment(byte[] encryptedSeg) { + this.encryptedSegment = encryptedSeg; + } + + /** + * Sets the trailer segment of the font file. + * @param trailerSeg the trailer segment + */ + public void setTrailerSegment(byte[] trailerSeg) { + this.trailerSegment = trailerSeg; + } + + /** + * Returns the full length of the raw font file. + * @return int the raw file length + */ + public int getLength() { + return getLength1() + getLength2() + getLength3(); + } + + + /** + * Returns the Length1 (length of the header segment). + * @return int Length1 + */ + public int getLength1() { + return this.headerSegment.length; + } + + + /** + * Returns the Length2 (length of the encrypted segment). + * @return int Length2 + */ + public int getLength2() { + return this.encryptedSegment.length; + } + + + /** + * Returns the Length3 (length of the trailer segment). + * @return int Length3 + */ + public int getLength3() { + return this.trailerSegment.length; + } + + + /** + * Writes the PFB file in raw format to an OutputStream. + * @param out the OutputStream to write to + * @throws IOException In case of an I/O problem + */ + public void outputAllParts(OutputStream out) throws IOException { + out.write(this.headerSegment); + out.write(this.encryptedSegment); + out.write(this.trailerSegment); + } + + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + return "PFB: format=" + getPFBFormat() + + " len1=" + getLength1() + + " len2=" + getLength2() + + " len3=" + getLength3(); + } + +}
\ No newline at end of file diff --git a/src/org/apache/fop/fonts/type1/PFBParser.java b/src/org/apache/fop/fonts/type1/PFBParser.java new file mode 100644 index 000000000..ac320050f --- /dev/null +++ b/src/org/apache/fop/fonts/type1/PFBParser.java @@ -0,0 +1,210 @@ +package org.apache.fop.fonts.type1; + +import java.io.IOException; +import java.io.InputStream; +import java.io.DataInputStream; +import java.io.BufferedInputStream; + +//FOP +import org.apache.fop.tools.IOUtil; + +/** + * This class represents a parser for Adobe Type 1 PFB files. + * + * @see PFBData + */ +public class PFBParser { + + private static final byte[] CURRENTFILE_EEXEC; + private static final byte[] CLEARTOMARK; + + static { + try { + CURRENTFILE_EEXEC = "currentfile eexec".getBytes("US-ASCII"); + CLEARTOMARK = "cleartomark".getBytes("US-ASCII"); + } catch (java.io.UnsupportedEncodingException e) { + throw new RuntimeException("Incompatible VM. It doesn't support the US-ASCII encoding"); + } + } + + + /** + * Parses a PFB file into a PFBData object. + * @param url URL to load the PFB file from + * @return PFBData memory representation of the font + * @throws IOException In case of an I/O problem + */ + public PFBData parsePFB(java.net.URL url) throws IOException { + InputStream in = url.openStream(); + try { + return parsePFB(in); + } finally { + in.close(); + } + } + + + /** + * Parses a PFB file into a PFBData object. + * @param pfbFile File to load the PFB file from + * @return PFBData memory representation of the font + * @throws IOException In case of an I/O problem + */ + public PFBData parsePFB(java.io.File pfbFile) throws IOException { + InputStream in = new java.io.FileInputStream(pfbFile); + try { + return parsePFB(in); + } finally { + in.close(); + } + } + + + /** + * Parses a PFB file into a PFBData object. + * @param in InputStream to load the PFB file from + * @return PFBData memory representation of the font + * @throws IOException In case of an I/O problem + */ + public PFBData parsePFB(InputStream in) throws IOException { + PFBData pfb = new PFBData(); + BufferedInputStream bin = new BufferedInputStream(in); + DataInputStream din = new DataInputStream(bin); + din.mark(32); + int firstByte = din.readUnsignedByte(); + din.reset(); + if (firstByte == 128) { + pfb.setPFBFormat(PFBData.PFB_PC); + parsePCFormat(pfb, din); + } else { + pfb.setPFBFormat(PFBData.PFB_RAW); + parseRAWFormat(pfb, bin); + } + return pfb; + } + + + private static int swapInteger(final int value) { + return + (((value >> 0) & 0xff ) << 24) + + (((value >> 8) & 0xff ) << 16) + + (((value >> 16) & 0xff ) << 8) + + (((value >> 24) & 0xff ) << 0); + } + + + private void parsePCFormat(PFBData pfb, DataInputStream din) throws IOException { + int segmentHead; + int segmentType; + int bytesRead; + + //Read first segment + segmentHead = din.readUnsignedByte(); + if (segmentHead != 128) throw new IOException("Invalid file format. Expected ASCII 80hex"); + segmentType = din.readUnsignedByte(); //Read + int len1 = swapInteger(din.readInt()); + byte[] headerSegment = new byte[len1]; + bytesRead = din.read(headerSegment); + if (bytesRead != len1) throw new IOException("Could not load the whole segment"); + pfb.setHeaderSegment(headerSegment); + + //Read second segment + segmentHead = din.readUnsignedByte(); + if (segmentHead != 128) throw new IOException("Invalid file format. Expected ASCII 80hex"); + segmentType = din.readUnsignedByte(); + int len2 = swapInteger(din.readInt()); + byte[] encryptedSegment = new byte[len2]; + bytesRead = din.read(encryptedSegment); + if (bytesRead != len2) throw new IOException("Could not load the whole segment"); + pfb.setEncryptedSegment(encryptedSegment); + + //Read third segment + segmentHead = din.readUnsignedByte(); + if (segmentHead != 128) throw new IOException("Invalid file format. Expected ASCII 80hex"); + segmentType = din.readUnsignedByte(); + int len3 = swapInteger(din.readInt()); + byte[] trailerSegment = new byte[len3]; + bytesRead = din.read(trailerSegment); + if (bytesRead != len3) throw new IOException("Could not load the whole segment"); + pfb.setTrailerSegment(trailerSegment); + + //Read EOF indicator + segmentHead = din.readUnsignedByte(); + if (segmentHead != 128) throw new IOException("Invalid file format. Expected ASCII 80hex"); + segmentType = din.readUnsignedByte(); + if (segmentType != 3) throw new IOException("Expected segment type 3, but found: "+segmentType); + } + + + private final static boolean byteCmp(byte[] src, int srcOffset, byte[] cmp) { + for (int i = 0; i < cmp.length; i++) { + // System.out.println("Compare: "+src[srcOffset+i]+" "+cmp[i]); + if (src[srcOffset + i] != cmp[i]) { + return false; + } + } + return true; + } + + private void calcLengths(PFBData pfb, byte[] originalData) { + // Calculate length 1 and 3 + // System.out.println ("Checking font, size = "+originalData.length); + + // Length1 is the size of the initial ascii portion + // search for "currentfile eexec" + // Get the first binary number and search backwards for "eexec" + int len1 = 30; + + // System.out.println("Length1="+len1); + while (!byteCmp(originalData, len1 - CURRENTFILE_EEXEC.length, CURRENTFILE_EEXEC)) { + len1++; + } + + // Skip newline + len1++; + + // Length3 is length of the last portion of the file + int len3 = 0; + len3 -= CLEARTOMARK.length; + while (!byteCmp(originalData, originalData.length + len3, CLEARTOMARK)) { + len3--; + // System.out.println("Len3="+len3); + } + len3 = -len3; + len3++; + // Eat 512 zeroes + int numZeroes = 0; + byte[] ws1 = new byte[]{0x0D}; //CR + byte[] ws2 = new byte[]{0x0A}; //LF + byte[] ws3 = new byte[]{0x30}; //"0" + while ((originalData[originalData.length - len3] == ws1[0] + || originalData[originalData.length - len3] == ws2[0] + || originalData[originalData.length - len3] == ws3[0]) + && numZeroes < 512) { + len3++; + if (originalData[originalData.length - len3] == ws3[0]) { + numZeroes++; + } + } + // System.out.println("Length3="+len3); + + //Create the 3 segments + byte[] buffer = new byte[len1]; + System.arraycopy(originalData, 0, buffer, 0, len1); + pfb.setHeaderSegment(buffer); + + int len2 = originalData.length - len3 - len1; + buffer = new byte[len2]; + System.arraycopy(originalData, len1, buffer, 0, len2); + pfb.setEncryptedSegment(buffer); + + buffer = new byte[len3]; + System.arraycopy(originalData, len1+len2, buffer, 0, len3); + pfb.setTrailerSegment(buffer); + } + + private void parseRAWFormat(PFBData pfb, BufferedInputStream bin) throws IOException { + calcLengths(pfb, IOUtil.toByteArray(bin, 32768)); + } + +}
\ No newline at end of file diff --git a/src/org/apache/fop/fonts/PFMFile.java b/src/org/apache/fop/fonts/type1/PFMFile.java index 4e438cb54..57f9461c9 100644 --- a/src/org/apache/fop/fonts/PFMFile.java +++ b/src/org/apache/fop/fonts/type1/PFMFile.java @@ -1,21 +1,23 @@ /* * $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.fonts; +package org.apache.fop.fonts.type1; import java.io.*; -import java.util.HashMap; +import java.util.Map; + +import org.apache.avalon.framework.logger.AbstractLogEnabled; + +import org.apache.fop.fonts.Glyphs; /** * This class represents a PFM file (or parts of it) as a Java object. - * - * @author jeremias.maerki@outline.ch */ -public class PFMFile { +public class PFMFile extends AbstractLogEnabled { // Header stuff private String windowsName; @@ -42,11 +44,8 @@ public class PFMFile { // Extent table private int[] extentTable; - private HashMap kerningTab; - public PFMFile() { - kerningTab = new HashMap(); - } - + private Map kerningTab = new java.util.HashMap();; + /** * Parses a PFM file * @@ -142,27 +141,29 @@ public class PFMFile { private void loadKernPairs(PFMInputStream inStream) throws IOException { int i = inStream.readShort(); - - System.out.println(i + " kerning pairs"); + getLogger().info(i + " kerning pairs"); while (i > 0) { int g1 = (int)inStream.readByte(); i--; - // System.out.print ("Char no: ("+g1+", "); - int g2 = (int)inStream.readByte(); - // System.out.print (g2+") kern"); + getLogger().debug("Char no: (" + g1 + ", " + g2 + ") kern"); int adj = inStream.readShort(); - if (adj > 0x8000) + if (adj > 0x8000) { adj = -(0x10000 - adj); - // System.out.println (": " + adj); + getLogger().debug("adjust: " + adj); + } - String glyph1 = Glyphs.tex8r[g1]; - String glyph2 = Glyphs.tex8r[g2]; + if (getLogger().isDebugEnabled()) { + String glyph1 = Glyphs.tex8r[g1]; + String glyph2 = Glyphs.tex8r[g2]; + getLogger().debug("glyphs: " + glyph1 + ", " + glyph2); + } - HashMap adjTab = (HashMap)kerningTab.get(new Integer(g1)); - if (adjTab == null) - adjTab = new HashMap(); + Map adjTab = (Map)kerningTab.get(new Integer(g1)); + if (adjTab == null) { + adjTab = new java.util.HashMap(); + } adjTab.put(new Integer(g2), new Integer(adj)); kerningTab.put(new Integer(g1), adjTab); } @@ -212,7 +213,7 @@ public class PFMFile { * strings with glyphnames as keys, containing hashmaps as value. * The value hashmaps contain a glyph name string key and an Integer value */ - public HashMap getKerning() { + public Map getKerning() { return kerningTab; } diff --git a/src/org/apache/fop/fonts/PFMInputStream.java b/src/org/apache/fop/fonts/type1/PFMInputStream.java index e956070ed..077d9d7af 100644 --- a/src/org/apache/fop/fonts/PFMInputStream.java +++ b/src/org/apache/fop/fonts/type1/PFMInputStream.java @@ -1,19 +1,20 @@ /* * $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.fonts; +package org.apache.fop.fonts.type1; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.DataInputStream; /** * This is a helper class for reading PFM files. It defines functions for * extracting specific values out of the stream. - * - * @author jeremias.maerki@outline.ch */ public class PFMInputStream extends java.io.FilterInputStream { diff --git a/src/org/apache/fop/fonts/type1/package.html b/src/org/apache/fop/fonts/type1/package.html new file mode 100644 index 000000000..0c492fc4d --- /dev/null +++ b/src/org/apache/fop/fonts/type1/package.html @@ -0,0 +1,6 @@ +<HTML> +<TITLE>org.apache.fop.fonts.type1 Package</TITLE> +<BODY> +<P>Classes for Adobe Type 1 fonts.</P> +</BODY> +</HTML>
\ No newline at end of file |