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) {
protected long position;
protected int size;
protected String objectName;
+
+ public String toString() {
+ return "Record{name=" + objectName
+ + ", pos=" + position
+ + ", size=" + size
+ + "}";
+ }
}
}
/** 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
/**
* 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
*
* @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;
}
}
* @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;
}
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;
}
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;
/**
*
* @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
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];
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];
--- /dev/null
+/*
+ * 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
/**
* 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],
};
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);
+ }
}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
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
*/
/**
* Constructor
+ *
* @param id the triplet identifier (see static definitions above)
*/
public Triplet(byte id) {
/**
* Constructor
+ *
* @param id the triplet identifier (see static definitions above)
* @param content the content byte data
*/
/**
* 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
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);
}
/**
+ * Returns the triplet identifier
+ *
* @return the triplet identifier
*/
public byte getId() {
/**
* Sets the data contents of this triplet
+ *
* @param data the data contents
*/
protected void setData(byte[] data) {