You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2006/06/01 09:34:31 UTC
svn commit: r410779 -
/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/PFMFile.java
Author: jeremias
Date: Thu Jun 1 00:34:29 2006
New Revision: 410779
URL: http://svn.apache.org/viewvc?rev=410779&view=rev
Log:
Added detection code for AFM and PFB files. Sadly, for PFM there does not seem to be a reliable method of detecting the file type. For example, I remember is PFM file that did not contain the right file size (file size is in the header).
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/PFMFile.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/PFMFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/PFMFile.java?rev=410779&r1=410778&r2=410779&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/PFMFile.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/type1/PFMFile.java Thu Jun 1 00:34:29 2006
@@ -19,11 +19,11 @@
package org.apache.fop.fonts.type1;
// Java
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -75,14 +75,35 @@
* @throws IOException In case of an I/O problem
*/
public void load(InputStream inStream) throws IOException {
- final byte[] buf = IOUtils.toByteArray(inStream);
- final InputStream bufin = new java.io.ByteArrayInputStream(buf);
+ InputStream bufin = inStream;
+ if (!bufin.markSupported()) {
+ bufin = new BufferedInputStream(bufin);
+ }
PFMInputStream in = new PFMInputStream(bufin);
- /*final int version =*/ in.readShort();
- final long filesize = in.readInt();
- if (filesize != buf.length) {
- log.warn("Effective file size is not the same as indicated in the header.");
+ bufin.mark(16);
+ short sh1 = in.readByte();
+ short sh2 = in.readByte();
+ if (sh1 == 128 && sh2 == 1) {
+ //Found the first section header of a PFB file!
+ throw new IOException("Cannot parse PFM file. You probably specified the PFB file"
+ + " of a Type 1 font as parameter instead of the PFM.");
+ }
+ bufin.reset();
+ byte[] b = new byte[16];
+ bufin.read(b);
+ if (new String(b, "US-ASCII").equalsIgnoreCase("StartFontMetrics")) {
+ //Found the header of a AFM file!
+ throw new IOException("Cannot parse PFM file. You probably specified the AFM file"
+ + " of a Type 1 font as parameter instead of the PFM.");
+ }
+ bufin.reset();
+ final int version = in.readShort();
+ if (version != 256) {
+ log.warn("PFM version expected to be '256' but got '" + version + "'."
+ + " Please make sure you specify the PFM as parameter"
+ + " and not the PFB or the AFM.");
}
+ //final long filesize = in.readInt();
bufin.reset();
loadHeader(in);
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org