aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-07-18 14:16:49 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-07-18 14:16:49 +0000
commit91fbf6ec462003a68f0470f511d98fcabfdaba3d (patch)
tree830a8ec13189fe9867230267a0a4f9aa40a91569
parentd6c3b958f2bdf839a99ac83cfbd5149c661a9e75 (diff)
downloadxmlgraphics-fop-91fbf6ec462003a68f0470f511d98fcabfdaba3d.tar.gz
xmlgraphics-fop-91fbf6ec462003a68f0470f511d98fcabfdaba3d.zip
* Added PresentationSpaceMixingRulesTriplet, DescriptorPositionTriplet and PresentationSpaceResetMixingTriplet.
* Removed some hardcoded triplets from ObjectAreaDescriptor. * Provided toString() for Record class in DataObjectCache. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@677913 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/render/afp/DataObjectCache.java10
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java2
-rw-r--r--src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java16
-rw-r--r--src/java/org/apache/fop/render/afp/modca/ImageObject.java19
-rw-r--r--src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java81
-rw-r--r--src/java/org/apache/fop/render/afp/modca/PageDescriptor.java4
-rw-r--r--src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java4
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/DescriptorPositionTriplet.java34
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java16
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java62
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java48
-rw-r--r--src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java19
12 files changed, 228 insertions, 87 deletions
diff --git a/src/java/org/apache/fop/render/afp/DataObjectCache.java b/src/java/org/apache/fop/render/afp/DataObjectCache.java
index bd87cbb09..aeec9cd78 100644
--- a/src/java/org/apache/fop/render/afp/DataObjectCache.java
+++ b/src/java/org/apache/fop/render/afp/DataObjectCache.java
@@ -137,7 +137,8 @@ public final class DataObjectCache {
record.size = os.size();
MappedByteBuffer byteBuffer
= channel.map(FileChannel.MapMode.READ_WRITE, record.position, record.size);
- byteBuffer.put(os.toByteArray());
+ byte[] data = os.toByteArray();
+ byteBuffer.put(data);
channel.write(byteBuffer);
nextPos += record.size + 1;
} catch (IOException e) {
@@ -192,5 +193,12 @@ public final class DataObjectCache {
protected long position;
protected int size;
protected String objectName;
+
+ public String toString() {
+ return "Record{name=" + objectName
+ + ", pos=" + position
+ + ", size=" + size
+ + "}";
+ }
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
index d9f3d6d1a..7a530456f 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
@@ -38,7 +38,7 @@ public abstract class AbstractAFPObject implements Writable {
/** Static logging instance */
protected static final Log log = LogFactory.getLog("org.apache.fop.render.afp.modca");
- private static final byte SF_CLASS = (byte)0xD3;
+ protected static final byte SF_CLASS = (byte)0xD3;
private static final byte[] SF = new byte[] {
0x5A, // Structured field identifier
diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java
index f5bc933a3..250895908 100644
--- a/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java
+++ b/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java
@@ -22,15 +22,15 @@ package org.apache.fop.render.afp.modca;
/**
* Base class for AFP descriptor objects
*/
-public abstract class AbstractDescriptor extends AbstractAFPObject {
+public abstract class AbstractDescriptor extends AbstractStructuredAFPObject {
/** width of this descriptor */
protected int width = 0;
/** height of this descriptor */
protected int height = 0;
/** width resolution of this descriptor */
- protected int widthResolution = 0;
+ protected int widthRes = 0;
/** height resolution of this descriptor */
- protected int heightResolution = 0;
+ protected int heightRes = 0;
/**
* Constructor a PresentationTextDescriptor for the specified
@@ -38,13 +38,13 @@ public abstract class AbstractDescriptor extends AbstractAFPObject {
*
* @param width The width of the page.
* @param height The height of the page.
- * @param widthResolution The width resolution of the page.
- * @param heightResolution The height resolution of the page.
+ * @param widthRes The width resolution of the page.
+ * @param heightRes The height resolution of the page.
*/
- public AbstractDescriptor(int width, int height, int widthResolution, int heightResolution) {
+ public AbstractDescriptor(int width, int height, int widthRes, int heightRes) {
this.width = width;
this.height = height;
- this.widthResolution = widthResolution;
- this.heightResolution = heightResolution;
+ this.widthRes = widthRes;
+ this.heightRes = heightRes;
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/ImageObject.java b/src/java/org/apache/fop/render/afp/modca/ImageObject.java
index 67935cb2c..04a019f5d 100644
--- a/src/java/org/apache/fop/render/afp/modca/ImageObject.java
+++ b/src/java/org/apache/fop/render/afp/modca/ImageObject.java
@@ -127,19 +127,12 @@ public class ImageObject extends AbstractDataObject {
* @param len the length of this ipd start
* @return byte[] The data stream.
*/
- private byte[] getIPDStart(int len) {
+ private byte[] getImageData(int len) {
+ byte[] data = new byte[9];
+ copySF(data, SF_CLASS, Type.DATA, Category.IMAGE);
byte[] l = BinaryUtils.convert(len + 8, 2);
- byte[] data = new byte[] {
- 0x5A, // Structured field identifier
- l[0], // Length byte 1
- l[1], // Length byte 2
- (byte) 0xD3, // Structured field id byte 1
- (byte) 0xEE, // Structured field id byte 2
- (byte) 0xFB, // Structured field id byte 3
- 0x00, // Flags
- 0x00, // Reserved
- 0x00, // Reserved
- };
+ data[1] = l[0];
+ data[2] = l[1];
return data;
}
@@ -160,7 +153,7 @@ public class ImageObject extends AbstractDataObject {
int off = 0;
while (off < b.length) {
int len = Math.min(30000, b.length - off);
- os.write(getIPDStart(len));
+ os.write(getImageData(len));
os.write(b, off, len);
off += len;
}
diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java
index dabe4ec20..d09009f64 100644
--- a/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java
+++ b/src/java/org/apache/fop/render/afp/modca/ObjectAreaDescriptor.java
@@ -19,8 +19,14 @@
package org.apache.fop.render.afp.modca;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+
+import org.apache.fop.render.afp.modca.triplets.DescriptorPositionTriplet;
+import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet;
+import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet;
+import org.apache.fop.render.afp.modca.triplets.PresentationSpaceMixingRulesTriplet;
import org.apache.fop.render.afp.tools.BinaryUtils;
/**
@@ -36,63 +42,40 @@ public class ObjectAreaDescriptor extends AbstractDescriptor {
*
* @param width The page width.
* @param height The page height.
- * @param widthResolution The page width resolution.
- * @param heightResolution The page height resolution.
+ * @param widthRes The page width resolution.
+ * @param heightRes The page height resolution.
*/
- public ObjectAreaDescriptor(int width, int height, int widthResolution, int heightResolution) {
- super(width, height, widthResolution, heightResolution);
+ public ObjectAreaDescriptor(int width, int height, int widthRes, int heightRes) {
+ super(width, height, widthRes, heightRes);
}
/** {@inheritDoc} */
- public void write(OutputStream os) throws IOException {
-
- byte[] data = new byte[29];
- data[0] = 0x5A;
+ protected byte[] getTripletData() throws IOException {
+ if (tripletData == null) {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final byte descriptorPositionId = 0x01;
+ new DescriptorPositionTriplet(descriptorPositionId).write(bos);
+ new MeasurementUnitsTriplet(widthRes, heightRes).write(bos);
+ new ObjectAreaSizeTriplet(width, height).write(bos);
+ byte[] mixingRules = new byte[] {
+ PresentationSpaceMixingRulesTriplet.RULE_FORE_ON_BACK,
+ PresentationSpaceMixingRulesTriplet.OVERPAINT
+ };
+ new PresentationSpaceMixingRulesTriplet(mixingRules).write(bos);
+ this.tripletData = bos.toByteArray();
+ }
+ return this.tripletData;
+ }
- byte[] len = BinaryUtils.convert(data.length - 1, 2);
+ /** {@inheritDoc} */
+ public void writeStart(OutputStream os) throws IOException {
+ super.writeStart(os);
+ byte[] data = new byte[9];
+ copySF(data, Type.DESCRIPTOR, Category.OBJECT_AREA);
+ byte[] len = BinaryUtils.convert(data.length + tripletData.length - 1, 2);
data[1] = len[0]; // Length
data[2] = len[1];
-
- data[3] = (byte) 0xD3;
- data[4] = (byte) 0xA6;
- data[5] = (byte) 0x6B;
- data[6] = 0x00; // Flags
- data[7] = 0x00; // Reserved
- data[8] = 0x00; // Reserved
- data[9] = 0x03; // Triplet length
- data[10] = 0x43; // tid = Descriptor Position Triplet
- data[11] = 0x01; // DesPosId = 1
- data[12] = 0x08; // Triplet length
- data[13] = 0x4B; // tid = Measurement Units Triplet
- data[14] = 0x00; // XaoBase = 10 inches
- data[15] = 0x00; // YaoBase = 10 inches
-
- // XaoUnits
- byte[] xdpi = BinaryUtils.convert(widthResolution * 10, 2);
- data[16] = xdpi[0];
- data[17] = xdpi[1];
-
- // YaoUnits
- byte[] ydpi = BinaryUtils.convert(heightResolution * 10, 2);
- data[18] = ydpi[0];
- data[19] = ydpi[1];
-
- data[20] = 0x09; // Triplet length
- data[21] = 0x4C; // tid = Object Area Size
- data[22] = 0x02; // Size Type
-
- byte[] x = BinaryUtils.convert(width, 3);
- data[23] = x[0];
- data[24] = x[1];
- data[25] = x[2];
-
- byte[] y = BinaryUtils.convert(height, 3);
- data[26] = y[0];
- data[27] = y[1];
- data[28] = y[2];
-
os.write(data);
-
}
} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java
index 0ac029b99..b144187fe 100644
--- a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java
+++ b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java
@@ -64,12 +64,12 @@ public class PageDescriptor extends AbstractDescriptor {
data[10] = 0x00; // YpgBase = 10 inches
// XpgUnits
- byte[] xdpi = BinaryUtils.convert(widthResolution * 10, 2);
+ byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2);
data[11] = xdpi[0];
data[12] = xdpi[1];
// YpgUnits
- byte[] ydpi = BinaryUtils.convert(heightResolution * 10, 2);
+ byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2);
data[13] = ydpi[0];
data[14] = ydpi[1];
diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java
index 706548d1a..2fc1a98c3 100644
--- a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java
+++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java
@@ -77,11 +77,11 @@ public class PresentationTextDescriptor extends AbstractDescriptor {
data[9] = 0x00;
data[10] = 0x00;
- byte[] xdpi = BinaryUtils.convert(widthResolution * 10, 2);
+ byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2);
data[11] = xdpi[0]; // xdpi
data[12] = xdpi[1];
- byte[] ydpi = BinaryUtils.convert(heightResolution * 10, 2);
+ byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2);
data[13] = ydpi[0]; // ydpi
data[14] = ydpi[1];
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/DescriptorPositionTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/DescriptorPositionTriplet.java
new file mode 100644
index 000000000..519b4afd4
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/DescriptorPositionTriplet.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.afp.modca.triplets;
+
+/**
+ * A descriptor position triplet
+ */
+public class DescriptorPositionTriplet extends Triplet {
+
+ /**
+ * Main constructor
+ *
+ * @param positionId the descriptor position id
+ */
+ public DescriptorPositionTriplet(byte positionId) {
+ super(Triplet.DESCRIPTOR_POSITION, positionId);
+ }
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java
index caf6e86fa..6b9e25a69 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectAreaSizeTriplet.java
@@ -29,15 +29,17 @@ public class ObjectAreaSizeTriplet extends Triplet {
/**
* Main constructor
+ *
* @param x the object area extent for the X axis
* @param y the object area extent for the Y axis
+ * @param type the object area size type
*/
- public ObjectAreaSizeTriplet(int x, int y) {
+ public ObjectAreaSizeTriplet(int x, int y, byte type) {
super(Triplet.OBJECT_AREA_SIZE);
byte[] xOASize = BinaryUtils.convert(x, 3);
byte[] yOASize = BinaryUtils.convert(y, 3);
byte[] data = new byte[] {
- 0x02, // SizeType
+ type, // SizeType
xOASize[0], // XoaSize - Object area extent for X axis
xOASize[1],
xOASize[2],
@@ -47,4 +49,14 @@ public class ObjectAreaSizeTriplet extends Triplet {
};
super.setData(data);
}
+
+ /**
+ * Main constructor
+ *
+ * @param x the object area extent for the X axis
+ * @param y the object area extent for the Y axis
+ */
+ public ObjectAreaSizeTriplet(int x, int y) {
+ this(x, y, (byte)0x02);
+ }
}
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java
new file mode 100644
index 000000000..0f2def9bf
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceMixingRulesTriplet.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp.modca.triplets;
+
+/**
+ * This triplet is used to specify the resulting appearance when data in a new
+ * presentation space is merged with data in an existing presentation space.
+ */
+public class PresentationSpaceMixingRulesTriplet extends Triplet {
+
+ /** background on background mixing rule */
+ public static final byte RULE_BACK_ON_BACK = 0x70;
+
+ /** background on foreground mixing rule */
+ public static final byte RULE_BACK_ON_FORE = 0x71;
+
+ /** foreground on background mixing rule */
+ public static final byte RULE_FORE_ON_BACK = 0x72;
+
+ /** foreground on foreground mixing rule */
+ public static final byte RULE_FORE_ON_FORE = 0x73;
+
+
+ /** overpaint */
+ public static final byte OVERPAINT = (byte)0x01;
+
+ /** underpaint */
+ public static final byte UNDERPAINT = (byte)0x02;
+
+ /** blend */
+ public static final byte BLEND = (byte)0x03;
+
+ /** MO:DCA default mixing */
+ public static final byte DEFAULT = (byte)0xFF;
+
+
+ /**
+ * Main constructor
+ *
+ * @param rules the mixing rules
+ */
+ public PresentationSpaceMixingRulesTriplet(byte[] rules) {
+ super(PRESENTATION_SPACE_MIXING_RULE, rules);
+ }
+}
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java
new file mode 100644
index 000000000..ebba65df5
--- /dev/null
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/PresentationSpaceResetMixingTriplet.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.afp.modca.triplets;
+
+/**
+ * This triplet is used to specify the resulting appearance when data in a new
+ * presentation space is merged with data in an existing presentation space.
+ */
+public class PresentationSpaceResetMixingTriplet extends Triplet {
+
+ /**
+ * Do not reset to the color of the medium prior to
+ * placing data into this MO:DCA presentation space.
+ */
+ public static final byte NOT_RESET = 0x00;
+
+ /**
+ * Reset to the color of the medium prior to placing
+ * data into this MO:DCA presentation space.
+ */
+ public static final byte RESET = 0x01;
+
+ /**
+ * Main constructor
+ *
+ * @param backgroundMixFlag the background mixing flag
+ */
+ public PresentationSpaceResetMixingTriplet(byte backgroundMixFlag) {
+ super(PRESENTATION_SPACE_RESET_MIXING, backgroundMixFlag);
+ }
+}
diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java
index 550066af1..868f28a72 100644
--- a/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java
+++ b/src/java/org/apache/fop/render/afp/modca/triplets/Triplet.java
@@ -88,18 +88,15 @@ public class Triplet extends AbstractAFPObject {
public static final byte CMR_TAG_FIDELITY = (byte)0x96;
public static final byte DEVICE_APPEARANCE = (byte)0x97;
- /**
- * the triplet identifier
- */
+ /** the triplet identifier */
private byte id;
- /**
- * the triplet's data contents
- */
+ /** the triplet's data contents */
private byte[] data;
/**
* Main constructor
+ *
* @param id the triplet identifier (see static definitions above)
* @param data the data item contained in this triplet
*/
@@ -110,6 +107,7 @@ public class Triplet extends AbstractAFPObject {
/**
* Constructor
+ *
* @param id the triplet identifier (see static definitions above)
*/
public Triplet(byte id) {
@@ -118,6 +116,7 @@ public class Triplet extends AbstractAFPObject {
/**
* Constructor
+ *
* @param id the triplet identifier (see static definitions above)
* @param content the content byte data
*/
@@ -127,6 +126,7 @@ public class Triplet extends AbstractAFPObject {
/**
* Constructor
+ *
* @param id the triplet identifier (see static definitions above)
* @param data the data item (in String form) contained in this triplet
* @throws UnsupportedEncodingException EBCIDIC encoding is not supported
@@ -135,9 +135,7 @@ public class Triplet extends AbstractAFPObject {
this(id, data.getBytes(AFPConstants.EBCIDIC_ENCODING));
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public void write(OutputStream os) throws IOException {
os.write((byte)data.length + 2);
os.write(id);
@@ -145,6 +143,8 @@ public class Triplet extends AbstractAFPObject {
}
/**
+ * Returns the triplet identifier
+ *
* @return the triplet identifier
*/
public byte getId() {
@@ -153,6 +153,7 @@ public class Triplet extends AbstractAFPObject {
/**
* Sets the data contents of this triplet
+ *
* @param data the data contents
*/
protected void setData(byte[] data) {