aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/render/ps
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache/fop/render/ps')
-rw-r--r--src/org/apache/fop/render/ps/ASCII85OutputStream.java37
-rw-r--r--src/org/apache/fop/render/ps/ASCIIHexOutputStream.java19
-rw-r--r--src/org/apache/fop/render/ps/Finalizable.java2
-rw-r--r--src/org/apache/fop/render/ps/FlateEncodeOutputStream.java6
-rw-r--r--src/org/apache/fop/render/ps/PSStream.java33
-rw-r--r--src/org/apache/fop/render/ps/RunLengthEncodeOutputStream.java58
6 files changed, 82 insertions, 73 deletions
diff --git a/src/org/apache/fop/render/ps/ASCII85OutputStream.java b/src/org/apache/fop/render/ps/ASCII85OutputStream.java
index 80adf8dab..1b4473539 100644
--- a/src/org/apache/fop/render/ps/ASCII85OutputStream.java
+++ b/src/org/apache/fop/render/ps/ASCII85OutputStream.java
@@ -25,10 +25,10 @@ public class ASCII85OutputStream extends FilterOutputStream
private static final int EOL = 0x0A; //"\n"
private static final byte[] EOD = {0x7E, 0x3E}; //"~>"
- private static final long base85_4 = 85;
- private static final long base85_3 = base85_4 * base85_4;
- private static final long base85_2 = base85_3 * base85_4;
- private static final long base85_1 = base85_2 * base85_4;
+ private static final long BASE85_4 = 85;
+ private static final long BASE85_3 = BASE85_4 * BASE85_4;
+ private static final long BASE85_2 = BASE85_3 * BASE85_4;
+ private static final long BASE85_1 = BASE85_2 * BASE85_4;
private static final boolean DEBUG = false;
@@ -38,11 +38,13 @@ public class ASCII85OutputStream extends FilterOutputStream
private int bw = 0;
+ /** @see java.io.FilterOutputStream **/
public ASCII85OutputStream(OutputStream out) {
super(out);
}
+ /** @see java.io.FilterOutputStream **/
public void write(int b) throws IOException {
if (pos == 0) {
buffer += (b << 24) & 0xff000000L;
@@ -82,10 +84,14 @@ public class ASCII85OutputStream extends FilterOutputStream
private void checkedWrite(byte[] buf , int len) throws IOException {
if (posinline + len > 80) {
int firstpart = len - (posinline + len - 80);
- if (firstpart > 0) out.write(buf, 0, firstpart);
+ if (firstpart > 0) {
+ out.write(buf, 0, firstpart);
+ }
out.write(EOL); bw++;
int rest = len - firstpart;
- if (rest > 0) out.write(buf, firstpart, rest);
+ if (rest > 0) {
+ out.write(buf, firstpart, rest);
+ }
posinline = rest;
} else {
out.write(buf, 0, len);
@@ -113,17 +119,18 @@ public class ASCII85OutputStream extends FilterOutputStream
if (word < 0) {
word = -word;
}
- byte c1 = (byte)((word / base85_1) & 0xFF);
- byte c2 = (byte)(((word - (c1 * base85_1)) / base85_2) & 0xFF);
+ byte c1 = (byte)((word / BASE85_1) & 0xFF);
+ byte c2 = (byte)(((word - (c1 * BASE85_1)) / BASE85_2) & 0xFF);
byte c3 =
- (byte)(((word - (c1 * base85_1) - (c2 * base85_2)) / base85_3)
- & 0xFF);
+ (byte)(((word - (c1 * BASE85_1) - (c2 * BASE85_2))
+ / BASE85_3) & 0xFF);
byte c4 =
- (byte)(((word - (c1 * base85_1) - (c2 * base85_2) - (c3 * base85_3)) / base85_4)
- & 0xFF);
+ (byte)(((word - (c1 * BASE85_1) - (c2 * BASE85_2) - (c3 * BASE85_3))
+ / BASE85_4) & 0xFF);
byte c5 =
- (byte)(((word - (c1 * base85_1) - (c2 * base85_2) - (c3 * base85_3) - (c4 * base85_4)))
- & 0xFF);
+ (byte)(((word - (c1 * BASE85_1) - (c2 * BASE85_2) - (c3 * BASE85_3)
+ - (c4 * BASE85_4)))
+ & 0xFF);
byte[] ret = {
(byte)(c1 + START), (byte)(c2 + START),
@@ -144,6 +151,7 @@ public class ASCII85OutputStream extends FilterOutputStream
}
+ /** @see org.apache.fop.render.ps.Finalizable **/
public void finalizeStream() throws IOException {
// now take care of the trailing few bytes.
// with n leftover bytes, we append 0 bytes to make a full group of 4
@@ -191,6 +199,7 @@ public class ASCII85OutputStream extends FilterOutputStream
}
+ /** @see java.io.FilterOutputStream **/
public void close() throws IOException {
finalizeStream();
super.close();
diff --git a/src/org/apache/fop/render/ps/ASCIIHexOutputStream.java b/src/org/apache/fop/render/ps/ASCIIHexOutputStream.java
index af37a73b4..34b2c5192 100644
--- a/src/org/apache/fop/render/ps/ASCIIHexOutputStream.java
+++ b/src/org/apache/fop/render/ps/ASCIIHexOutputStream.java
@@ -16,32 +16,39 @@ import java.io.IOException;
* @author <a href="mailto:jeremias.maerki@outline.ch">Jeremias Maerki</a>
* @version $Id$
*/
-public class ASCIIHexOutputStream extends FilterOutputStream {
+public class ASCIIHexOutputStream extends FilterOutputStream
+ implements Finalizable {
private static final int EOL = 0x0A; //"\n"
private static final int EOD = 0x3E; //">"
private static final int ZERO = 0x30; //"0"
private static final int NINE = 0x39; //"9"
private static final int A = 0x41; //"A"
- private static final int ADIFF = A - NINE -1;
+ private static final int ADIFF = A - NINE - 1;
private int posinline = 0;
+ /** @see java.io.FilterOutputStream **/
public ASCIIHexOutputStream(OutputStream out) {
super(out);
}
+ /** @see java.io.FilterOutputStream **/
public void write(int b) throws IOException {
b &= 0xFF;
int digit1 = ((b & 0xF0) >> 4) + ZERO;
- if (digit1 > NINE) digit1 += ADIFF;
+ if (digit1 > NINE) {
+ digit1 += ADIFF;
+ }
out.write(digit1);
int digit2 = (b & 0x0F) + ZERO;
- if (digit2 > NINE) digit2 += ADIFF;
+ if (digit2 > NINE) {
+ digit2 += ADIFF;
+ }
out.write(digit2);
posinline++;
@@ -58,6 +65,7 @@ public class ASCIIHexOutputStream extends FilterOutputStream {
}
+ /** @see org.apache.fop.render.ps.Finalizable **/
public void finalizeStream() throws IOException {
checkLineWrap();
//Write closing character ">"
@@ -65,11 +73,12 @@ public class ASCIIHexOutputStream extends FilterOutputStream {
flush();
if (out instanceof Finalizable) {
- ((Finalizable)out).finalizeStream();
+ ((Finalizable) out).finalizeStream();
}
}
+ /** @see java.io.FilterOutputStream **/
public void close() throws IOException {
finalizeStream();
super.close();
diff --git a/src/org/apache/fop/render/ps/Finalizable.java b/src/org/apache/fop/render/ps/Finalizable.java
index d7c77d668..83b80b810 100644
--- a/src/org/apache/fop/render/ps/Finalizable.java
+++ b/src/org/apache/fop/render/ps/Finalizable.java
@@ -24,7 +24,7 @@ public interface Finalizable {
*
* @exception java.io.IOException In case of an IO problem
*/
- public void finalizeStream()
+ void finalizeStream()
throws java.io.IOException;
}
diff --git a/src/org/apache/fop/render/ps/FlateEncodeOutputStream.java b/src/org/apache/fop/render/ps/FlateEncodeOutputStream.java
index e6d96b8e9..ca65a778a 100644
--- a/src/org/apache/fop/render/ps/FlateEncodeOutputStream.java
+++ b/src/org/apache/fop/render/ps/FlateEncodeOutputStream.java
@@ -7,12 +7,12 @@
package org.apache.fop.render.ps;
import java.io.OutputStream;
-import java.io.FilterOutputStream;
import java.io.IOException;
/**
* This class applies a FlateEncode filter to the stream. It is basically the
- * normal DeflaterOutputStream except now conformi
+ * normal DeflaterOutputStream except now also implementing the Finalizable
+ * interface.
*
* @author <a href="mailto:jeremias.maerki@outline.ch">Jeremias Maerki</a>
* @version $Id$
@@ -21,11 +21,13 @@ public class FlateEncodeOutputStream extends java.util.zip.DeflaterOutputStream
implements Finalizable {
+ /** @see java.util.zip.DeflaterOutputStream **/
public FlateEncodeOutputStream(OutputStream out) {
super(out);
}
+ /** @see org.apache.fop.render.ps.Finalizable **/
public void finalizeStream() throws IOException {
finish();
flush();
diff --git a/src/org/apache/fop/render/ps/PSStream.java b/src/org/apache/fop/render/ps/PSStream.java
index 2643a6c5a..2e1c624ab 100644
--- a/src/org/apache/fop/render/ps/PSStream.java
+++ b/src/org/apache/fop/render/ps/PSStream.java
@@ -1,29 +1,50 @@
/*
* $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.ps;
-import java.io.*;
+import java.io.OutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+/**
+ * PSStream is used to to output PostScript code from the PostScript renderer.
+ */
public class PSStream extends FilterOutputStream {
+ /** @see java.io.FilterOutputStream **/
public PSStream(OutputStream out) {
super(out);
}
-
+
+
+ /**
+ * Writes a PostScript command to the stream.
+ *
+ * @param cmd The PostScript code to be written.
+ * @exception IOException In case of an I/O problem
+ */
public void write(String cmd) throws IOException {
- if (cmd.length() > 255)
+ if (cmd.length() > 255) {
throw new RuntimeException("PostScript command exceeded limit of 255 characters");
+ }
write(cmd.getBytes("US-ASCII"));
write('\n');
}
-
+
+
+ /**
+ * Writes encoded data to the PostScript stream.
+ *
+ * @param cmd The encoded PostScript code to be written.
+ * @exception IOException In case of an I/O problem
+ */
public void writeByteArr(byte[] cmd) throws IOException {
write(cmd);
write('\n');
}
+
}
diff --git a/src/org/apache/fop/render/ps/RunLengthEncodeOutputStream.java b/src/org/apache/fop/render/ps/RunLengthEncodeOutputStream.java
index a006bc5b6..64778a3f2 100644
--- a/src/org/apache/fop/render/ps/RunLengthEncodeOutputStream.java
+++ b/src/org/apache/fop/render/ps/RunLengthEncodeOutputStream.java
@@ -16,41 +16,30 @@ import java.io.IOException;
* @author <a href="mailto:smwolke@geistig.com">Stephen Wolke</a>
* @version $Id$
*/
-
public class RunLengthEncodeOutputStream extends FilterOutputStream
implements Finalizable {
- private final static int MAX_SEQUENCE_COUNT = 127;
- private final static int END_OF_DATA = 128;
- private final static int BYTE_MAX = 256;
+ private static final int MAX_SEQUENCE_COUNT = 127;
+ private static final int END_OF_DATA = 128;
+ private static final int BYTE_MAX = 256;
- private final static int NOT_IDENTIFY_SEQUENCE = 0;
- private final static int START_SEQUENCE = 1;
- private final static int IN_SEQUENCE = 2;
- private final static int NOT_IN_SEQUENCE = 3;
+ private static final int NOT_IDENTIFY_SEQUENCE = 0;
+ private static final int START_SEQUENCE = 1;
+ private static final int IN_SEQUENCE = 2;
+ private static final int NOT_IN_SEQUENCE = 3;
private int runCount = 0;
private int isSequence = NOT_IDENTIFY_SEQUENCE;
private byte[] runBuffer = new byte[MAX_SEQUENCE_COUNT + 1];
- /**
- * Constructor for the RunLengthEncode Filter.
- *
- * @param out The OutputStream to write to
- */
+ /** @see java.io.FilterOutputStream **/
public RunLengthEncodeOutputStream(OutputStream out) {
super(out);
}
- /**
- * @see java.io.OutputStream#write(int)
- * @param b the <code>byte</code>.
- * @exception IOException if an I/O error occurs. In particular,
- * an <code>IOException</code> may be thrown if the
- * output stream has been closed.
- */
+ /** @see java.io.FilterOutputStream **/
public void write(byte b)
throws java.io.IOException {
runBuffer[runCount] = b;
@@ -131,11 +120,7 @@ public class RunLengthEncodeOutputStream extends FilterOutputStream
}
- /**
- * @see java.io.OutputStream#write(byte[])
- * @param b the data.
- * @exception IOException if an I/O error occurs.
- */
+ /** @see java.io.FilterOutputStream **/
public void write(byte[] b)
throws IOException {
@@ -145,15 +130,7 @@ public class RunLengthEncodeOutputStream extends FilterOutputStream
}
- /**
- * @see java.io.OutputStream#write(byte[], int, int)
- * @param b the data.
- * @param off the start offset in the data.
- * @param len the number of bytes to write.
- * @exception IOException if an I/O error occurs. In particular,
- * an <code>IOException</code> is thrown if the output
- * stream is closed.
- */
+ /** @see java.io.FilterOutputStream **/
public void write(byte[] b, int off, int len)
throws IOException {
@@ -163,12 +140,7 @@ public class RunLengthEncodeOutputStream extends FilterOutputStream
}
- /**
- * Flushes the the stream and writes out the trailer, but, unlike close(),
- * without closing the stream.
- *
- * @exception IOException if an I/O error occurs.
- */
+ /** @see org.apache.fop.render.ps.Finalizable **/
public void finalizeStream()
throws IOException {
switch (isSequence) {
@@ -190,11 +162,7 @@ public class RunLengthEncodeOutputStream extends FilterOutputStream
}
- /**
- * Closes the stream.
- *
- * @exception IOException if an I/O error occurs.
- */
+ /** @see java.io.FilterOutputStream **/
public void close()
throws IOException {
finalizeStream();