import org.apache.commons.logging.LogFactory;
import org.apache.fop.afp.goca.GraphicsSetLineType;
import org.apache.fop.afp.modca.GraphicsObject;
+import org.apache.fop.afp.svg.AFPGraphicsConfiguration;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.svg.NativeImageHandler;
import org.apache.xmlgraphics.image.loader.ImageInfo;
/** Current AFP state */
private AFPPaintingState paintingState = null;
+ /** AFP graphics configuration */
+ private final AFPGraphicsConfiguration graphicsConfig = new AFPGraphicsConfiguration();
+
/** The AFP FontInfo */
private FontInfo fontInfo;
if (fill) {
graphicsObj.beginArea();
}
- AffineTransform trans = super.getTransform();
+ AffineTransform trans = gc.getTransform();
PathIterator iter = shape.getPathIterator(trans);
double[] dstPts = new double[6];
int[] coords = null;
mhr
);
} else {
- for (int[] openingCoords = new int[2], currCoords = new int[2];
- !iter.isDone(); iter.next()) {
+ for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) {
int type = iter.currentSegment(dstPts);
- if (type == PathIterator.SEG_MOVETO) {
- openingCoords[X] = currCoords[X] = (int)Math.round(dstPts[X]);
- openingCoords[Y] = currCoords[Y] = (int)Math.round(dstPts[Y]);
- graphicsObj.setCurrentPosition(openingCoords);
+ int numCoords;
+ if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) {
+ numCoords = 2;
+ } else if (type == PathIterator.SEG_QUADTO) {
+ numCoords = 4;
+ } else if (type == PathIterator.SEG_CUBICTO) {
+ numCoords = 6;
} else {
- int numCoords;
- if (type == PathIterator.SEG_LINETO) {
- numCoords = 2;
- } else if (type == PathIterator.SEG_QUADTO) {
- numCoords = 4;
- } else if (type == PathIterator.SEG_CUBICTO) {
- numCoords = 6;
+ // close of the graphics segment
+ if (type == PathIterator.SEG_CLOSE) {
+ // close segment by drawing to opening position
+ graphicsObj.addLine(openingCoords, true);
} else {
- // close of the graphics segment
- if (type == PathIterator.SEG_CLOSE) {
- graphicsObj.addLine(openingCoords, true);
- } else {
- log.debug("Unrecognised path iterator type: "
- + type);
- }
- continue;
- }
- coords = new int[numCoords];
- for (int i = 0; i < numCoords; i++) {
- coords[i] = (int) Math.round(dstPts[i]);
+ log.debug("Unrecognised path iterator type: "
+ + type);
}
- if (type == PathIterator.SEG_LINETO) {
- graphicsObj.addLine(coords, true);
- } else if (type == PathIterator.SEG_QUADTO
- || type == PathIterator.SEG_CUBICTO) {
- graphicsObj.addFillet(coords, true);
- }
- // update current position coordinates
- currCoords[X] = coords[coords.length - 2];
- currCoords[Y] = coords[coords.length - 1];
+ continue;
+ }
+ coords = new int[numCoords];
+ for (int i = 0; i < numCoords; i++) {
+ coords[i] = (int) Math.round(dstPts[i]);
+ }
+ if (type == PathIterator.SEG_MOVETO) {
+ graphicsObj.setCurrentPosition(coords);
+ openingCoords[X] = coords[X];
+ openingCoords[Y] = coords[Y];
+ } else if (type == PathIterator.SEG_LINETO) {
+ graphicsObj.addLine(coords, true);
+ } else if (type == PathIterator.SEG_QUADTO
+ || type == PathIterator.SEG_CUBICTO) {
+ graphicsObj.addFillet(coords, true);
}
}
}
/** {@inheritDoc} */
public GraphicsConfiguration getDeviceConfiguration() {
- return new AFPGraphicsConfiguration();
+ return graphicsConfig;
}
/** {@inheritDoc} */
+++ /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.afp;
-
-import java.awt.GraphicsDevice;
-import java.awt.Rectangle;
-import java.awt.Transparency;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.awt.image.ColorModel;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fop.svg.GraphicsConfiguration;
-
-/**
- * Our implementation of the class that returns information about
- * roughly what we can handle and want to see (alpha for example).
- */
-public class AFPGraphicsConfiguration extends GraphicsConfiguration {
- // We use this to get a good colormodel..
- private static final BufferedImage BI_WITH_ALPHA
- = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
- // We use this to get a good colormodel..
- private static final BufferedImage BI_WITHOUT_ALPHA
- = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
-
- /**
- * Construct a buffered image with an alpha channel, unless
- * transparencty is OPAQUE (no alpha at all).
- *
- * @param width the width of the image
- * @param height the height of the image
- * @param transparency the alpha value of the image
- * @return the new buffered image
- */
- public BufferedImage createCompatibleImage(int width, int height,
- int transparency) {
- if (transparency == Transparency.OPAQUE) {
- return new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
- } else {
- return new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- }
- }
-
- /**
- * Construct a buffered image with an alpha channel.
- *
- * @param width the width of the image
- * @param height the height of the image
- * @return the new buffered image
- */
- public BufferedImage createCompatibleImage(int width, int height) {
- return new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- }
-
- /**
- * TODO: This should return the page bounds in Pts,
- * I couldn't figure out how to get this for the current
- * page from the PDFDocument (this still works for now,
- * but it should be fixed...).
- *
- * @return the bounds of the PDF document page
- */
- public Rectangle getBounds() {
- return null;
- }
-
- /**
- * Return a good default color model for this 'device'.
- * @return the colour model for the configuration
- */
- public ColorModel getColorModel() {
- return BI_WITH_ALPHA.getColorModel();
- }
-
- /**
- * Return a good color model given <tt>transparency</tt>
- *
- * @param transparency the alpha value for the colour model
- * @return the colour model for the configuration
- */
- public ColorModel getColorModel(int transparency) {
- if (transparency == Transparency.OPAQUE) {
- return BI_WITHOUT_ALPHA.getColorModel();
- } else {
- return BI_WITH_ALPHA.getColorModel();
- }
- }
-
- private static final Log log = LogFactory.getLog(AFPGraphicsConfiguration.class);
-
- private AffineTransform defaultTransform = null;
- private AffineTransform normalizingTransform = null;
- private GraphicsDevice graphicsDevice = null;
-
- /**
- * The default transform (1:1).
- *
- * @return the default transform for the configuration
- */
- public AffineTransform getDefaultTransform() {
- log.debug("getDefaultTransform()");
- if (defaultTransform == null) {
- defaultTransform = new AffineTransform();
- }
- return defaultTransform;
- }
-
- /**
- * The normalizing transform (1:1) (since we currently
- * render images at 72dpi, which we might want to change
- * in the future).
- *
- * @return the normalizing transform for the configuration
- */
- public AffineTransform getNormalizingTransform() {
- log.debug("getNormalizingTransform()");
- if (normalizingTransform == null) {
- normalizingTransform = new AffineTransform(2, 0, 0, 2, 0, 0);
- }
- return normalizingTransform;
- }
-
- /**
- * {@inheritDoc}
- */
- public GraphicsDevice getDevice() {
- log.debug("getDevice()");
- if (graphicsDevice == null) {
- graphicsDevice = new AFPGraphicsDevice(this);
- }
- return graphicsDevice;
- }
-}
+++ /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.afp;
-
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-
-
-/**
- * This implements the GraphicsDevice interface as appropriate for
- * an AFPGraphics2D.
- */
-public class AFPGraphicsDevice extends GraphicsDevice {
-
- /**
- * The Graphics Config that created us...
- */
- protected GraphicsConfiguration gc;
-
- /**
- * Create a new AF{ graphics device.
- *
- * @param gc The graphics configuration we should reference
- */
- public AFPGraphicsDevice(AFPGraphicsConfiguration gc) {
- this.gc = gc;
- }
-
- /**
- * Return an array of our one GraphicsConfig
- *
- * @return an array containing the one graphics configuration
- */
- public GraphicsConfiguration[] getConfigurations() {
- return new GraphicsConfiguration[] {gc};
- }
-
- /**
- * Return out sole GraphicsConfig.
- *
- * @return the graphics configuration that created this object
- */
- public GraphicsConfiguration getDefaultConfiguration() {
- return this.gc;
- }
-
- /**
- * Generate an IdString..
- *
- * @return the ID string for this device, uses toString
- */
- public String getIDstring() {
- return toString();
- }
-
- /**
- * Let the caller know that we are "a printer"
- *
- * @return the type which is always printer
- */
- public int getType() {
- return GraphicsDevice.TYPE_PRINTER;
- }
-}
public class RasterFont extends AFPFont {
/** Static logging instance */
- protected static final Log log = LogFactory.getLog("org.apache.xmlgraphics.afp.fonts");
+ protected static final Log log = LogFactory.getLog("org.apache.fop.afp.fonts");
private final Map/*<String,CharacterSet>*/ charSets
= new java.util.HashMap/*<String,CharacterSet>*/();
package org.apache.fop.afp.goca;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;
/**
* A base class encapsulating the structure of coordinate based GOCA objects
*/
-public abstract class AbstractGraphicsCoord extends AbstractPreparedAFPObject {
+public abstract class AbstractGraphicsCoord extends AbstractNamedAFPObject
+ implements StructuredDataObject {
/** array of x/y coordinates */
protected int[] coords = null;
*/
public AbstractGraphicsCoord(int[] coords) {
this.coords = coords;
- prepareData();
}
/**
this(new int[] {x1, y1, x2, y2});
}
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 2 + (coords.length * 2);
+ }
+
/**
- * Returns the order code to use
+ * Returns the order code of this structured field
*
- * @return the order code to use
+ * @return the order code of this structured field
*/
- protected abstract byte getOrderCode();
+ abstract byte getOrderCode();
/**
- * Returns the length of this order code (typically this is the same as the coordinate length)
+ * Returns the coordinate data start index
*
- * @return the length of this order code
+ * @return the coordinate data start index
*/
- protected int getLength() {
- return this.coords.length * 2;
+ int getCoordinateDataStartIndex() {
+ return 2;
}
/**
- * Creates a newly created and initialized byte data
+ * Returns the coordinate data
*
- * @return a newly created and initialized byte data
+ * @return the coordinate data
*/
- protected byte[] createData() {
- int len = getLength();
- byte[] data = new byte[len + 2];
- data[0] = getOrderCode(); // ORDER CODE
- data[1] = (byte)len; // LENGTH
+ byte[] getData() {
+ int len = getDataLength();
+ byte[] data = new byte[len];
+ data[0] = getOrderCode();
+ data[1] = (byte)(len - 2);
+
+ if (coords != null) {
+ addCoords(data, getCoordinateDataStartIndex());
+ }
+
return data;
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = createData();
- int fromIndex = data.length - getLength();
- addCoords(data, fromIndex);
+ public void writeToStream(OutputStream os) throws IOException {
+ os.write(getData());
}
/**
--- /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.afp.goca;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
+
+/**
+ * A base container of prepared structured AFP objects
+ */
+public abstract class AbstractGraphicsObjectContainer extends AbstractNamedAFPObject
+implements StructuredDataObject {
+
+ /** list of objects contained within this container */
+ protected List/*<StructuredDataObject>*/ objects
+ = new java.util.ArrayList/*<StructuredDataObject>*/();
+
+ /**
+ * Default constructor
+ */
+ protected AbstractGraphicsObjectContainer() {
+ }
+
+ /**
+ * Named constructor
+ *
+ * @param name the name of the container
+ */
+ protected AbstractGraphicsObjectContainer(String name) {
+ super(name);
+ }
+
+ /** {@inheritDoc} */
+ protected void writeContent(OutputStream os) throws IOException {
+ writeObjects(objects, os);
+ }
+
+ /**
+ * Adds a given graphics object to this container
+ *
+ * @param drawingOrder the graphics object
+ */
+ public void addObject(StructuredDataObject drawingOrder) {
+ objects.add(drawingOrder);
+ }
+
+ /**
+ * Returns the current data length
+ *
+ * @return the current data length of this container including
+ * all enclosed objects (and their containers)
+ */
+ public int getDataLength() {
+ int dataLen = 0;
+ Iterator it = objects.iterator();
+ while (it.hasNext()) {
+ dataLen += ((StructuredDataObject)it.next()).getDataLength();
+ }
+ return dataLen;
+ }
+}
--- /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.afp.goca;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.fop.afp.AFPConstants;
+
+public abstract class AbstractGraphicsString extends AbstractGraphicsCoord {
+
+ /** Up to 255 bytes of character data */
+ protected static final int MAX_STR_LEN = 255;
+
+ /** the string to draw */
+ protected final String str;
+
+ /**
+ * Constructor (relative)
+ *
+ * @param str the text string
+ */
+ public AbstractGraphicsString(String str) {
+ super(null);
+ if (str.length() > MAX_STR_LEN) {
+ str = str.substring(0, MAX_STR_LEN);
+ log.warn("truncated character string, longer than " + MAX_STR_LEN + " chars");
+ }
+ this.str = str;
+ }
+
+ /**
+ * Constructor (absolute)
+ *
+ * @param str the text string
+ * @param x the x coordinate
+ * @param y the y coordinate
+ */
+ public AbstractGraphicsString(String str, int x, int y) {
+ super(x, y);
+ this.str = str;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 2 + str.length();
+ }
+
+ /**
+ * Returns the text string as an encoded byte array
+ *
+ * @return the text string as an encoded byte array
+ */
+ protected byte[] getStringAsBytes() throws UnsupportedEncodingException {
+ return str.getBytes(AFPConstants.EBCIDIC_ENCODING);
+ }
+
+}
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.AbstractPreparedObjectContainer;
/**
* A GOCA graphics area (container for filled shapes/objects)
*/
-public final class GraphicsArea extends AbstractPreparedObjectContainer {
+public final class GraphicsArea extends AbstractGraphicsObjectContainer {
private static final int RES1 = 1;
private static final int BOUNDARY = 2;
/** {@inheritDoc} */
public int getDataLength() {
- // start len + end len + data len
return 4 + super.getDataLength();
}
/** {@inheritDoc} */
protected void writeEnd(OutputStream os) throws IOException {
- byte[] endData = new byte[] {
+ byte[] data = new byte[] {
(byte)0x60, // GEAR order code
0x00, // LENGTH
};
- os.write(endData);
+ os.write(data);
}
/** {@inheritDoc} */
package org.apache.fop.afp.goca;
+import java.io.IOException;
+import java.io.OutputStream;
+
/**
* A GOCA graphics rectangular box
*/
}
/** {@inheritDoc} */
- protected byte getOrderCode() {
- return (byte)0xC0;
+ public int getDataLength() {
+ return 12;
}
/** {@inheritDoc} */
- protected int getLength() {
- return 10;
+ int getCoordinateDataStartIndex() {
+ return 4;
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = createData();
- final int fromIndex = 4;
- addCoords(data, fromIndex);
+ byte getOrderCode() {
+ return (byte)0xC0;
}
/** {@inheritDoc} */
- protected byte[] createData() {
- byte[] data = super.createData();
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
data[2] = (byte)0x20; // CONTROL draw control flags
data[3] = 0x00; // reserved
- return data;
+
+ os.write(data);
}
}
\ No newline at end of file
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.AbstractPreparedObjectContainer;
-import org.apache.fop.afp.modca.PreparedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;
/**
* A GOCA graphics segment
*/
-public final class GraphicsChainedSegment extends AbstractPreparedObjectContainer {
+public final class GraphicsChainedSegment extends AbstractGraphicsObjectContainer {
/** The maximum segment data length */
protected static final int MAX_DATA_LEN = 8192;
return NAME_LENGTH;
}
+ /** {@inheritDoc} */
+ byte getOrderCode() {
+ return 0x70;
+ }
+
/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
super.writeStart(os);
byte[] data = new byte[14];
- data[0] = 0x70; // BEGIN_SEGMENT
+ data[0] = getOrderCode(); // BEGIN_SEGMENT
data[1] = 0x0C; // Length of following parameters
// segment name
}
/** {@inheritDoc} */
- public void addObject(PreparedAFPObject drawingOrder) {
+ public void addObject(StructuredDataObject drawingOrder) {
if (currentArea != null) {
currentArea.addObject(drawingOrder);
} else {
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.AbstractPreparedObjectContainer;
-import org.apache.fop.afp.modca.PreparedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;
import org.apache.fop.afp.util.StringUtils;
/**
* A GOCA graphics data
*/
-public final class GraphicsData extends AbstractPreparedObjectContainer {
+public final class GraphicsData extends AbstractGraphicsObjectContainer {
/** The maximum graphics data length */
public static final int MAX_DATA_LEN = 32767;
/** The graphics segment */
- private GraphicsChainedSegment currentSegment = null;
+ private GraphicsChainedSegment segment = null;
/** {@inheritDoc} */
public int getDataLength() {
* @return the current graphics chained segment
*/
private GraphicsChainedSegment getSegment() {
- if (currentSegment == null) {
+ if (segment == null) {
newSegment();
}
- return this.currentSegment;
+ return this.segment;
}
/**
*/
public GraphicsChainedSegment newSegment() {
String name = createSegmentName();
- if (currentSegment == null) {
- this.currentSegment = new GraphicsChainedSegment(name);
+ if (segment == null) {
+ this.segment = new GraphicsChainedSegment(name);
} else {
- this.currentSegment = new GraphicsChainedSegment(name, currentSegment);
+ this.segment = new GraphicsChainedSegment(name, segment);
}
- super.addObject(currentSegment);
- return currentSegment;
+ super.addObject(segment);
+ return segment;
}
/** {@inheritDoc} */
- public void addObject(PreparedAFPObject drawingOrder) {
- if (currentSegment == null
- || (currentSegment.getDataLength() + drawingOrder.getDataLength())
+ public void addObject(StructuredDataObject drawingOrder) {
+ if (segment == null
+ || (segment.getDataLength() + drawingOrder.getDataLength())
>= GraphicsChainedSegment.MAX_DATA_LEN) {
newSegment();
}
- currentSegment.addObject(drawingOrder);
+ segment.addObject(drawingOrder);
}
/** {@inheritDoc} */
super(coords);
}
- /** {@inheritDoc} */
- protected byte getOrderCode() {
+ byte getOrderCode() {
return (byte)0xC5;
}
package org.apache.fop.afp.goca;
+
/**
* A GOCA graphics curved tangential line to a specified set of
* straight lines drawn from the given position or current position
}
/** {@inheritDoc} */
- protected byte getOrderCode() {
+ byte getOrderCode() {
return (byte)0x85;
}
-
}
\ No newline at end of file
package org.apache.fop.afp.goca;
+import java.io.IOException;
+import java.io.OutputStream;
+
import org.apache.fop.afp.util.BinaryUtils;
/**
* A GOCA graphics arc (circle/ellipse)
*/
public class GraphicsFullArc extends AbstractGraphicsCoord {
+
/** the integer portion of the multiplier */
private final int mh;
super(x, y);
this.mh = mh;
this.mhr = mhr;
- // integer portion of multiplier
- data[data.length - 2] = BinaryUtils.convert(mh, 1)[0];
- // fractional portion of multiplier
- data[data.length - 1] = BinaryUtils.convert(mhr, 1)[0];
}
/** {@inheritDoc} */
- protected byte getOrderCode() {
- return (byte)0xC7;
+ public int getDataLength() {
+ return 8;
}
/** {@inheritDoc} */
- protected int getLength() {
- return super.getLength() + 2;
+ byte getOrderCode() {
+ return (byte)0xC7;
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = super.createData();
- final int fromIndex = 2;
- super.addCoords(data, fromIndex);
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+
+ // integer portion of multiplier
+ data[6] = BinaryUtils.convert(mh, 1)[0];
+
+ // fractional portion of multiplier
+ data[7] = BinaryUtils.convert(mhr, 1)[0];
+
+ os.write(data);
}
/** {@inheritDoc} */
+ ", mhr=" + mhr
+ "}";
}
+
}
\ No newline at end of file
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.AbstractStructuredAFPObject;
+import org.apache.fop.afp.modca.AbstractStructuredObject;
import org.apache.fop.afp.util.BinaryUtils;
/**
* A GOCA Image
*/
-public class GraphicsImage extends AbstractStructuredAFPObject {
+public class GraphicsImage extends AbstractStructuredObject {
/** x coordinate */
private final int x;
/**
* A GOCA graphics straight line drawn from the
- * given position
+ * given absolute position
*/
public class GraphicsLine extends AbstractGraphicsCoord {
}
/** {@inheritDoc} */
- protected byte getOrderCode() {
+ byte getOrderCode() {
return (byte)0xC1;
}
}
/** {@inheritDoc} */
- protected byte getOrderCode() {
+ byte getOrderCode() {
return (byte)0x81;
}
package org.apache.fop.afp.goca;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
import org.apache.fop.afp.util.BinaryUtils;
/**
* Sets the current character set (font) to be used for following graphics strings
*/
-public class GraphicsSetCharacterSet extends AbstractPreparedAFPObject {
+public class GraphicsSetCharacterSet extends AbstractNamedAFPObject
+ implements StructuredDataObject {
/** font character set reference */
private final int fontReference;
*/
public GraphicsSetCharacterSet(int fontReference) {
this.fontReference = fontReference;
- prepareData();
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = new byte[] {
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = new byte[] {
0x38, // GSCS order code
BinaryUtils.convert(fontReference)[0]
};
+ os.write(data);
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 2;
}
/** {@inheritDoc} */
public String toString() {
return "GraphicsSetCharacterSet(" + fontReference + ")";
}
+
}
\ No newline at end of file
package org.apache.fop.afp.goca;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
/**
* Sets the value of the current line type attribute when stroking GOCA shapes (structured fields)
*/
-public class GraphicsSetLineType extends AbstractPreparedAFPObject {
+public class GraphicsSetLineType extends AbstractNamedAFPObject
+implements StructuredDataObject {
/** the default line type */
public static final byte DEFAULT = 0x00; // normally SOLID
*/
public GraphicsSetLineType(byte type) {
this.type = type;
- prepareData();
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = new byte[] {
- 0x18, // GSLW order code
- type // line type
+ public int getDataLength() {
+ return 2;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = new byte[] {
+ 0x18, // GSLW order code
+ type // line type
};
+ os.write(data);
}
private static final String[] TYPES = {
package org.apache.fop.afp.goca;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
/**
* Sets the line width to use when stroking GOCA shapes (structured fields)
*/
-public class GraphicsSetLineWidth extends AbstractPreparedAFPObject {
+public class GraphicsSetLineWidth extends AbstractNamedAFPObject implements StructuredDataObject {
+
/** line width multiplier */
private int multiplier = 1;
*/
public GraphicsSetLineWidth(int multiplier) {
this.multiplier = multiplier;
- prepareData();
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = new byte[] {
+ public int getDataLength() {
+ return 2;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = new byte[] {
0x19, // GSLW order code
(byte)multiplier // MH (line-width)
};
+ os.write(data);
}
/** {@inheritDoc} */
package org.apache.fop.afp.goca;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import java.io.IOException;
+import java.io.OutputStream;
-public class GraphicsSetMix extends AbstractPreparedAFPObject {
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+
+public class GraphicsSetMix extends AbstractNamedAFPObject {
public static final byte MODE_DEFAULT = 0x00;
public static final byte MODE_OVERPAINT = 0x02;
*/
public GraphicsSetMix(byte mode) {
this.mode = mode;
- prepareData();
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = new byte[] {
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = new byte[] {
0x0C, // GSMX order code
mode // MODE (mix mode value)
};
+ os.write(data);
}
/** {@inheritDoc} */
package org.apache.fop.afp.goca;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
/**
* Sets the pattern symbol to use when filling following GOCA structured fields
*/
-public class GraphicsSetPatternSymbol extends AbstractPreparedAFPObject {
+public class GraphicsSetPatternSymbol extends AbstractNamedAFPObject
+implements StructuredDataObject {
+
/** dotted density 1 */
public static final byte DOTTED_DENSITY_1 = 0x01;
*/
public GraphicsSetPatternSymbol(byte symb) {
this.symbol = symb;
- prepareData();
}
/** {@inheritDoc} */
- protected void prepareData() {
- super.data = new byte[] {
+ public int getDataLength() {
+ return 2;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = new byte[] {
0x28, // GSPT order code
symbol
};
+ os.write(data);
}
/** {@inheritDoc} */
import java.awt.Color;
import java.awt.color.ColorSpace;
+import java.io.IOException;
+import java.io.OutputStream;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
+import org.apache.fop.afp.modca.AbstractNamedAFPObject;
+import org.apache.fop.afp.modca.StructuredDataObject;
/**
* Sets the current processing color for the following GOCA structured fields
*/
-public class GraphicsSetProcessColor extends AbstractPreparedAFPObject {
- /** the color to set */
+public class GraphicsSetProcessColor extends AbstractNamedAFPObject
+implements StructuredDataObject {
+
private final Color color;
+ private final float[] colorComponents;
+
/**
* Main constructor
*
*/
public GraphicsSetProcessColor(Color color) {
this.color = color;
- prepareData();
+ this.colorComponents = color.getColorComponents(null);
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 12 + colorComponents.length;
}
/** {@inheritDoc} */
- protected void prepareData() {
+ byte getOrderCode() {
+ return (byte)0xB2;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+
// COLSPCE
byte colspace;
int colSpaceType = color.getColorSpace().getType();
}
// COLSIZE(S)
- float[] colcomp = color.getColorComponents(null);
byte[] colsizes = new byte[] {0x00, 0x00, 0x00, 0x00};
- for (int i = 0; i < colcomp.length; i++) {
+ for (int i = 0; i < colorComponents.length; i++) {
colsizes[i] = (byte)8;
}
- int len = 10 + colcomp.length;
- super.data = new byte[len + 2];
- data[0] = (byte)0xB2; // GSPCOL order code
- data[1] = (byte)len; // LEN
+ int len = getDataLength();
+ byte[] data = new byte[len];
+ data[0] = getOrderCode(); // GSPCOL order code
+ data[1] = (byte)(len - 2); // LEN
data[2] = 0x00; // reserved; must be zero
data[3] = colspace; // COLSPCE
data[4] = 0x00; // reserved; must be zero
data[9] = colsizes[1];
data[10] = colsizes[2];
data[11] = colsizes[3];
+
// COLVALUE(S)
- for (int i = 0; i < colcomp.length; i++) {
- data[i + 12] = (byte)(colcomp[i] * 255);
+ for (int i = 0; i < colorComponents.length; i++) {
+ data[i + 12] = (byte)(colorComponents[i] * 255);
}
+
+ os.write(data);
}
/** {@inheritDoc} */
package org.apache.fop.afp.goca;
-import java.io.UnsupportedEncodingException;
-
-import org.apache.fop.afp.AFPConstants;
-import org.apache.fop.afp.modca.AbstractPreparedAFPObject;
-import org.apache.fop.afp.util.BinaryUtils;
+import java.io.IOException;
+import java.io.OutputStream;
/**
* A GOCA graphics string
*/
-public class GraphicsString extends AbstractPreparedAFPObject {
- /** Up to 255 bytes of character data */
- private static final int MAX_STR_LEN = 255;
-
- /** drawn from the current position */
- private boolean fromCurrentPosition = false;
-
- /** the string to draw */
- private String str = null;
-
- /** x coordinate */
- private int x;
-
- /** y coordinate */
- private int y;
-
- /**
- * Constructor
- *
- * @param str the character string
- */
- public GraphicsString(String str) {
- this.str = str;
- fromCurrentPosition = true;
- prepareData();
- }
+public class GraphicsString extends AbstractGraphicsString {
/**
* Constructor
* @param y the y coordinate
*/
public GraphicsString(String str, int x, int y) {
- this.str = str;
- this.x = x;
- this.y = y;
- prepareData();
+ super(str, x, y);
+ }
+
+ /** {@inheritDoc} */
+ byte getOrderCode() {
+ return (byte)0xC3;
}
/** {@inheritDoc} */
- protected void prepareData() {
- int maxStrLen = MAX_STR_LEN - (fromCurrentPosition ? 0 : 4);
- if (str.length() > maxStrLen) {
- str = str.substring(0, maxStrLen);
- log.warn("truncated character string, longer than " + maxStrLen + " chars");
- }
- byte[] strData = null;
- try {
- strData = str.getBytes(AFPConstants.EBCIDIC_ENCODING);
- } catch (UnsupportedEncodingException ex) {
- log.error("unsupported encoding: " + ex.getMessage());
- }
- int len = strData.length;
- if (fromCurrentPosition) {
- data = new byte[len + 2];
- data[0] = (byte)0x83;
- data[1] = (byte)len;
- System.arraycopy(strData, 0, data, 2, strData.length);
- } else {
- len += 4; // x/y coordinates
- byte[] osx = BinaryUtils.convert(x, 2);
- byte[] osy = BinaryUtils.convert(y, 2);
- data = new byte[len + 2];
- data[0] = (byte)0xC3;
- data[1] = (byte)len;
- data[2] = osx[0];
- data[3] = osx[1];
- data[4] = osy[0];
- data[5] = osy[1];
- System.arraycopy(strData, 0, data, 6, strData.length);
- }
+ public int getDataLength() {
+ return super.getDataLength() + (coords.length * 2);
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ byte[] strData = getStringAsBytes();
+ System.arraycopy(strData, 0, data, 6, strData.length);
+
+ os.write(data);
}
/** {@inheritDoc} */
public String toString() {
- String string = "GraphicsString{str='" + str + "'";
- if (!fromCurrentPosition) {
- string += ",x=" + x + ",y=" + y;
- }
- string += "}";
- return string;
+ return "GraphicsString{x=" + coords[0] + ", y=" + coords[1] + "str='" + str + "'" + "}";
}
}
\ No newline at end of file
--- /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.afp.goca;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A GOCA graphics string
+ */
+public class GraphicsStringRelative extends AbstractGraphicsString {
+
+ /**
+ * Constructor
+ *
+ * @param str the character string
+ */
+ public GraphicsStringRelative(String str) {
+ super(str);
+ }
+
+ /** {@inheritDoc} */
+ byte getOrderCode() {
+ return (byte)0x83;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ byte[] strData = getStringAsBytes();
+ System.arraycopy(strData, 0, data, 2, strData.length);
+ os.write(data);
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "GraphicsStringRelative{str='" + str + "'" + "}";
+ }
+
+}
\ No newline at end of file
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.AbstractStructuredAFPObject;
+import org.apache.fop.afp.modca.AbstractStructuredObject;
/**
* An IOCA Image Content
*/
-public class ImageContent extends AbstractStructuredAFPObject {
+public class ImageContent extends AbstractStructuredObject {
/**
* The CCITT T.4 Group 3 Coding Standard (G3 MH-Modified Huffman) is a
package org.apache.fop.afp.modca;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.afp.Streamable;
+import org.apache.fop.afp.util.BinaryUtils;
/**
* This is the base class for all data stream objects. Page objects are
}
}
+ /**
+ * Reads data chunks from an inputstream
+ * and then formats them with a structured header to a given outputstream
+ *
+ * @param dataHeader the header data
+ * @param lengthOffset offset of length field in data chunk
+ * @param maxChunkLength the maximum chunk length
+ * @param inputStream the inputstream to read from
+ * @param outputStream the outputstream to write to
+ * @throws IOException thrown if an I/O exception of some sort has occurred.
+ */
+ protected static void copyChunks(byte[] dataHeader, int lengthOffset,
+ int maxChunkLength, InputStream inputStream, OutputStream outputStream)
+ throws IOException {
+ int headerLen = dataHeader.length - lengthOffset;
+ // length field is just before data so do not include in data length
+ if (headerLen == 2) {
+ headerLen = 0;
+ }
+ byte[] data = new byte[maxChunkLength];
+ int numBytesRead = 0;
+ while ((numBytesRead = inputStream.read(data, 0, maxChunkLength)) > 0) {
+ byte[] len = BinaryUtils.convert(headerLen + numBytesRead, 2);
+ dataHeader[lengthOffset] = len[0]; // Length byte 1
+ dataHeader[lengthOffset + 1] = len[1]; // Length byte 2
+ outputStream.write(dataHeader);
+ outputStream.write(data, 0, numBytesRead);
+ }
+ }
+
+ /**
+ * Writes data chunks to a given outputstream
+ *
+ * @param data the data byte array
+ * @param dataHeader the header data
+ * @param lengthOffset offset of length field in data chunk
+ * @param maxChunkLength the maximum chunk length
+ * @param os the outputstream to write to
+ * @throws IOException thrown if an I/O exception of some sort has occurred.
+ */
+ protected static void writeChunksToStream(byte[] data, byte[] dataHeader,
+ int lengthOffset, int maxChunkLength, OutputStream os) throws IOException {
+ int dataLength = data.length;
+ int numFullChunks = dataLength / maxChunkLength;
+ int lastChunkLength = dataLength % maxChunkLength;
+
+ int headerLen = dataHeader.length - lengthOffset;
+ // length field is just before data so do not include in data length
+ if (headerLen == 2) {
+ headerLen = 0;
+ }
+
+ byte[] len;
+ int off = 0;
+ if (numFullChunks > 0) {
+ // write out full data chunks
+ len = BinaryUtils.convert(headerLen + maxChunkLength, 2);
+ dataHeader[lengthOffset] = len[0]; // Length byte 1
+ dataHeader[lengthOffset + 1] = len[1]; // Length byte 2
+ for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) {
+ os.write(dataHeader);
+ os.write(data, off, maxChunkLength);
+ }
+ }
+
+ if (lastChunkLength > 0) {
+ // write last data chunk
+ len = BinaryUtils.convert(headerLen + lastChunkLength, 2);
+ dataHeader[lengthOffset] = len[0]; // Length byte 1
+ dataHeader[lengthOffset + 1] = len[1]; // Length byte 2
+ os.write(dataHeader);
+ os.write(data, off, lastChunkLength);
+ }
+ }
+
/** structured field type codes */
public interface Type {
/**
* Base class for AFP descriptor objects
*/
-public abstract class AbstractDescriptor extends AbstractStructuredAFPObject {
+public abstract class AbstractDescriptor extends AbstractTripletStructuredObject {
/** width of this descriptor */
protected int width = 0;
/** height of this descriptor */
* This is the base class for all named data stream objects.
* A named data stream object has an 8 byte EBCIDIC name.
*/
-public abstract class AbstractNamedAFPObject extends AbstractStructuredAFPObject {
+public abstract class AbstractNamedAFPObject extends AbstractTripletStructuredObject {
private static final int DEFAULT_NAME_LENGTH = 8;
+++ /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.afp.modca;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * A base class that carries out early preparation of structured field data
- * for the AFP object (so the data length can be pre-calculated)
- */
-public abstract class AbstractPreparedAFPObject extends AbstractNamedAFPObject
-implements PreparedAFPObject {
-
- /** structured field data to be written */
- protected byte[] data = null;
-
- /**
- * Default constructor
- */
- public AbstractPreparedAFPObject() {
- }
-
- /**
- * Named constructor
- *
- * @param name the name of this AFP object
- */
- public AbstractPreparedAFPObject(String name) {
- super(name);
- }
-
- /** {@inheritDoc} */
- protected void writeContent(OutputStream os) throws IOException {
- super.writeContent(os); // write triplets
- if (this.data != null) {
- os.write(this.data);
- }
- }
-
- /**
- * Return the start data length of this structured field
- *
- * @return the start data length of this structured field
- */
- protected int getStartDataLength() {
- return 0;
- }
-
- /**
- * Return the data length of the structured field data of this AFP object
- *
- * @return the data length of the structured field data of this AFP object
- */
- public int getDataLength() {
- if (this.data != null) {
- return this.data.length;
- }
- return 0;
- }
-
- /**
- * Return the structured field length
- *
- * @return the structured field length
- */
- protected int getLength() {
- return getStartDataLength() + getTripletDataLength() + getDataLength();
- }
-
- /**
- * Sets the data
- *
- * @param data the data
- */
- protected void setData(byte[] data) {
- this.data = data;
- }
-}
\ No newline at end of file
+++ /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.afp.modca;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A base container of prepared structured AFP objects
- */
-public abstract class AbstractPreparedObjectContainer extends AbstractNamedAFPObject
-implements PreparedAFPObject {
-
- /** list of objects contained within this container */
- protected List/*<PreparedAFPObject>*/ objects
- = new java.util.ArrayList/*<PreparedAFPObject>*/();
-
- /**
- * Default constructor
- */
- protected AbstractPreparedObjectContainer() {
- }
-
- /**
- * Named constructor
- *
- * @param name the name of the container
- */
- protected AbstractPreparedObjectContainer(String name) {
- super(name);
- }
-
- /** {@inheritDoc} */
- protected void writeContent(OutputStream os) throws IOException {
- writeObjects(objects, os);
- }
-
- /**
- * Adds a given prepared object to this container
- *
- * @param preparedObject the prepared object
- */
- public void addObject(PreparedAFPObject preparedObject) {
- objects.add(preparedObject);
- }
-
- /**
- * Returns the current data length
- *
- * @return the current data length of this container including
- * all enclosed objects (and their containers)
- */
- public int getDataLength() {
- int dataLen = 0;
- Iterator it = objects.iterator();
- while (it.hasNext()) {
- Object obj = it.next();
- if (obj instanceof PreparedAFPObject) {
- PreparedAFPObject prepObj = (PreparedAFPObject)obj;
- dataLen += prepObj.getDataLength();
- }
- }
- return dataLen;
- }
-}
+++ /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.afp.modca;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.fop.afp.modca.Registry.ObjectType;
-import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
-import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet;
-import org.apache.fop.afp.modca.triplets.Triplet;
-import org.apache.fop.afp.util.BinaryUtils;
-
-/**
- * An abstract class encapsulating an MODCA structured object
- */
-public abstract class AbstractStructuredAFPObject extends AbstractAFPObject {
- /**
- * list of object triplets
- */
- protected List/*<Triplet>*/ triplets = null;
-
- /**
- * triplet data created from triplet list
- */
- protected byte[] tripletData = null;
-
- /**
- * Default constructor
- */
- protected AbstractStructuredAFPObject() {
- }
-
- /**
- * Returns the triplet data length
- *
- * @return the triplet data length
- */
- protected int getTripletDataLength() {
- if (tripletData == null) {
- try {
- getTripletData();
- } catch (IOException e) {
- log.error("failed to get triplet data");
- }
- }
- if (tripletData != null) {
- return tripletData.length;
- }
- return 0;
- }
-
- /**
- * Returns the triplet data
- *
- * @return the triplet data
- * @throws IOException throws an I/O exception if one occurred
- */
- protected byte[] getTripletData() throws IOException {
- if (tripletData == null && triplets != null) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- writeObjects(triplets, baos);
- this.tripletData = baos.toByteArray();
- triplets = null; // gc
- }
- return this.tripletData;
- }
-
- /**
- * Writes any triplet data
- *
- * @param os The stream to write to
- * @throws IOException The stream to write to
- */
- protected void writeTriplets(OutputStream os) throws IOException {
- if (tripletData != null) {
- os.write(tripletData);
- } else if (triplets != null) {
- writeObjects(triplets, os);
- triplets = null; // gc
- }
- }
-
- /**
- * Helper method to write the start of the Object.
- *
- * @param os The stream to write to
- * @throws IOException throws an I/O exception if one occurred
- */
- protected void writeStart(OutputStream os) throws IOException {
- getTripletData();
- }
-
- /**
- * Helper method to write the end of the Object.
- *
- * @param os The stream to write to
- * @throws IOException an I/O exception if one occurred
- */
- protected void writeEnd(OutputStream os) throws IOException {
- }
-
- /**
- * Helper method to write the contents of the Object.
- *
- * @param os The stream to write to
- * @throws IOException throws an I/O exception if one occurred
- */
- protected void writeContent(OutputStream os) throws IOException {
- writeTriplets(os);
- }
-
- /** {@inheritDoc} */
- public void writeToStream(OutputStream os) throws IOException {
- writeStart(os);
- writeContent(os);
- writeEnd(os);
- }
-
- /**
- * Returns the first matching triplet found in the structured field triplet list
- *
- * @param tripletId the triplet identifier
- */
- private Triplet getTriplet(byte tripletId) {
- Iterator it = getTriplets().iterator();
- while (it.hasNext()) {
- Triplet triplet = (Triplet)it.next();
- if (triplet.getId() == tripletId) {
- return triplet;
- }
- }
- return null;
- }
-
- /**
- * Returns true of this structured field has the given triplet
- *
- * @param tripletId the triplet identifier
- * @return true if the structured field has the given triplet
- */
- public boolean hasTriplet(byte tripletId) {
- return getTriplet(tripletId) != null;
- }
-
- /**
- * Adds a triplet to this structured object
- *
- * @param triplet the triplet to add
- */
- protected void addTriplet(Triplet triplet) {
- getTriplets().add(triplet);
- }
-
- /**
- * Adds a list of triplets to the triplets contained within this structured field
- *
- * @param tripletCollection a collection of triplets
- */
- public void addTriplets(Collection/*<Triplet>*/ tripletCollection) {
- if (tripletCollection != null) {
- getTriplets().addAll(tripletCollection);
- }
- }
-
- /** @return the triplet list pertaining to this resource */
- protected List/*<Triplet>*/ getTriplets() {
- if (triplets == null) {
- triplets = new java.util.ArrayList();
- }
- return triplets;
- }
-
- /**
- * Sets the fully qualified name of this resource
- *
- * @param fqnType the fully qualified name type of this resource
- * @param fqnFormat the fully qualified name format of this resource
- * @param fqName the fully qualified name of this resource
- */
- public void setFullyQualifiedName(byte fqnType, byte fqnFormat, String fqName) {
- addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqName));
- }
-
- /** @return the fully qualified name of this triplet or null if it does not exist */
- public String getFullyQualifiedName() {
- FullyQualifiedNameTriplet fqNameTriplet
- = (FullyQualifiedNameTriplet)getTriplet(Triplet.FULLY_QUALIFIED_NAME);
- if (fqNameTriplet != null) {
- return fqNameTriplet.getFullyQualifiedName();
- }
- log.warn(this + " has no fully qualified name");
- return null;
- }
-
- /**
- * Sets the objects classification
- *
- * @param objectClass the classification of the object
- * @param objectType the MOD:CA registry object type entry for the given
- * object/component type of the object
- * @param dataInContainer whether the data resides in the container
- * @param containerHasOEG whether the container has an object environment group
- * @param dataInOCD whether the data resides in a object container data structured field
- */
- public void setObjectClassification(
- byte objectClass, ObjectType objectType,
- boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) {
- addTriplet(
- new ObjectClassificationTriplet(
- objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD));
- }
-
- /**
- * Sets a comment on this resource
- *
- * @param comment a comment string
- */
- public void setComment(String comment) {
- try {
- addTriplet(new Triplet(Triplet.COMMENT, comment));
- } catch (UnsupportedEncodingException e) {
- log.error(e.getMessage());
- }
- }
-
- /**
- * Reads data chunks from an inputstream
- * and then formats them with a structured header to a given outputstream
- *
- * @param dataHeader the header data
- * @param lengthOffset offset of length field in data chunk
- * @param maxChunkLength the maximum chunk length
- * @param inputStream the inputstream to read from
- * @param outputStream the outputstream to write to
- * @throws IOException thrown if an I/O exception of some sort has occurred.
- */
- protected static void copyChunks(byte[] dataHeader, int lengthOffset,
- int maxChunkLength, InputStream inputStream, OutputStream outputStream)
- throws IOException {
- int headerLen = dataHeader.length - lengthOffset;
- // length field is just before data so do not include in data length
- if (headerLen == 2) {
- headerLen = 0;
- }
- byte[] data = new byte[maxChunkLength];
- int numBytesRead = 0;
- while ((numBytesRead = inputStream.read(data, 0, maxChunkLength)) > 0) {
- byte[] len = BinaryUtils.convert(headerLen + numBytesRead, 2);
- dataHeader[lengthOffset] = len[0]; // Length byte 1
- dataHeader[lengthOffset + 1] = len[1]; // Length byte 2
- outputStream.write(dataHeader);
- outputStream.write(data, 0, numBytesRead);
- }
- }
-
- /**
- * Writes data chunks to a given outputstream
- *
- * @param data the data byte array
- * @param dataHeader the header data
- * @param lengthOffset offset of length field in data chunk
- * @param maxChunkLength the maximum chunk length
- * @param os the outputstream to write to
- * @throws IOException thrown if an I/O exception of some sort has occurred.
- */
- protected static void writeChunksToStream(byte[] data, byte[] dataHeader,
- int lengthOffset, int maxChunkLength, OutputStream os) throws IOException {
- int dataLength = data.length;
- int numFullChunks = dataLength / maxChunkLength;
- int lastChunkLength = dataLength % maxChunkLength;
-
- int headerLen = dataHeader.length - lengthOffset;
- // length field is just before data so do not include in data length
- if (headerLen == 2) {
- headerLen = 0;
- }
-
- byte[] len;
- int off = 0;
- if (numFullChunks > 0) {
- // write out full data chunks
- len = BinaryUtils.convert(headerLen + maxChunkLength, 2);
- dataHeader[lengthOffset] = len[0]; // Length byte 1
- dataHeader[lengthOffset + 1] = len[1]; // Length byte 2
- for (int i = 0; i < numFullChunks; i++, off += maxChunkLength) {
- os.write(dataHeader);
- os.write(data, off, maxChunkLength);
- }
- }
-
- if (lastChunkLength > 0) {
- // write last data chunk
- len = BinaryUtils.convert(headerLen + lastChunkLength, 2);
- dataHeader[lengthOffset] = len[0]; // Length byte 1
- dataHeader[lengthOffset + 1] = len[1]; // Length byte 2
- os.write(dataHeader);
- os.write(data, off, lastChunkLength);
- }
- }
-}
--- /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.afp.modca;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * An abstract class encapsulating an MODCA structured object
+ */
+public abstract class AbstractStructuredObject extends AbstractAFPObject {
+
+ /**
+ * Default constructor
+ */
+ protected AbstractStructuredObject() {
+ }
+
+ /**
+ * Helper method to write the start of the Object.
+ *
+ * @param os The stream to write to
+ * @throws IOException throws an I/O exception if one occurred
+ */
+ protected void writeStart(OutputStream os) throws IOException {
+ }
+
+ /**
+ * Helper method to write the end of the Object.
+ *
+ * @param os The stream to write to
+ * @throws IOException an I/O exception if one occurred
+ */
+ protected void writeEnd(OutputStream os) throws IOException {
+ }
+
+ /**
+ * Helper method to write the contents of the Object.
+ *
+ * @param os The stream to write to
+ * @throws IOException throws an I/O exception if one occurred
+ */
+ protected void writeContent(OutputStream os) throws IOException {
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ writeStart(os);
+ writeContent(os);
+ writeEnd(os);
+ }
+}
--- /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.afp.modca;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.fop.afp.modca.Registry.ObjectType;
+import org.apache.fop.afp.modca.triplets.AbstractTriplet;
+import org.apache.fop.afp.modca.triplets.CommentTriplet;
+import org.apache.fop.afp.modca.triplets.FullyQualifiedNameTriplet;
+import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet;
+
+public class AbstractTripletStructuredObject extends AbstractStructuredObject {
+
+ /** list of object triplets */
+ protected List/*<AbstractTriplet>*/ triplets = new java.util.ArrayList/*<AbstractTriplet>*/();
+
+ /**
+ * Returns the triplet data length
+ *
+ * @return the triplet data length
+ */
+ protected int getTripletDataLength() {
+ int dataLength = 0;
+ if (hasTriplets()) {
+ Iterator it = triplets.iterator();
+ while (it.hasNext()) {
+ AbstractTriplet triplet = (AbstractTriplet)it.next();
+ dataLength += triplet.getDataLength();
+ }
+ }
+ return dataLength;
+ }
+
+ /**
+ * Returns true when this structured field contains triplets
+ *
+ * @return true when this structured field contains triplets
+ */
+ public boolean hasTriplets() {
+ return triplets.size() > 0;
+ }
+
+ /**
+ * Writes any triplet data
+ *
+ * @param os The stream to write to
+ * @throws IOException The stream to write to
+ */
+ protected void writeTriplets(OutputStream os) throws IOException {
+ if (hasTriplets()) {
+ writeObjects(triplets, os);
+ triplets = null; // gc
+ }
+ }
+
+ /**
+ * Returns the first matching triplet found in the structured field triplet list
+ *
+ * @param tripletId the triplet identifier
+ */
+ private AbstractTriplet getTriplet(byte tripletId) {
+ Iterator it = getTriplets().iterator();
+ while (it.hasNext()) {
+ AbstractTriplet triplet = (AbstractTriplet)it.next();
+ if (triplet.getId() == tripletId) {
+ return triplet;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns true of this structured field has the given triplet
+ *
+ * @param tripletId the triplet identifier
+ * @return true if the structured field has the given triplet
+ */
+ public boolean hasTriplet(byte tripletId) {
+ return getTriplet(tripletId) != null;
+ }
+
+ /**
+ * Adds a triplet to this structured object
+ *
+ * @param triplet the triplet to add
+ */
+ protected void addTriplet(AbstractTriplet triplet) {
+ triplets.add(triplet);
+ }
+
+ /**
+ * Adds a list of triplets to the triplets contained within this structured field
+ *
+ * @param tripletCollection a collection of triplets
+ */
+ public void addTriplets(Collection/*<Triplet>*/ tripletCollection) {
+ if (tripletCollection != null) {
+ triplets.addAll(tripletCollection);
+ }
+ }
+
+ /** @return the triplet list pertaining to this resource */
+ protected List/*<Triplet>*/ getTriplets() {
+ return triplets;
+ }
+
+ /**
+ * Sets the fully qualified name of this resource
+ *
+ * @param fqnType the fully qualified name type of this resource
+ * @param fqnFormat the fully qualified name format of this resource
+ * @param fqName the fully qualified name of this resource
+ */
+ public void setFullyQualifiedName(byte fqnType, byte fqnFormat, String fqName) {
+ addTriplet(new FullyQualifiedNameTriplet(fqnType, fqnFormat, fqName));
+ }
+
+ /** @return the fully qualified name of this triplet or null if it does not exist */
+ public String getFullyQualifiedName() {
+ FullyQualifiedNameTriplet fqNameTriplet
+ = (FullyQualifiedNameTriplet)getTriplet(AbstractTriplet.FULLY_QUALIFIED_NAME);
+ if (fqNameTriplet != null) {
+ return fqNameTriplet.getFullyQualifiedName();
+ }
+ log.warn(this + " has no fully qualified name");
+ return null;
+ }
+
+ /**
+ * Sets the objects classification
+ *
+ * @param objectClass the classification of the object
+ * @param objectType the MOD:CA registry object type entry for the given
+ * object/component type of the object
+ * @param dataInContainer whether the data resides in the container
+ * @param containerHasOEG whether the container has an object environment group
+ * @param dataInOCD whether the data resides in a object container data structured field
+ */
+ public void setObjectClassification(
+ byte objectClass, ObjectType objectType,
+ boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) {
+ addTriplet(
+ new ObjectClassificationTriplet(
+ objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD));
+ }
+
+ /**
+ * Sets a comment on this resource
+ *
+ * @param commentString a comment string
+ */
+ public void setComment(String commentString) {
+ addTriplet(new CommentTriplet(AbstractTriplet.COMMENT, commentString));
+ }
+
+}
public class GraphicsObject extends AbstractDataObject {
/** The graphics data */
- private GraphicsData currentGraphicsData = null;
+ private GraphicsData data = null;
/** list of objects contained within this container */
- protected List/*<PreparedAFPObject>*/ objects
- = new java.util.ArrayList/*<PreparedAFPObject>*/();
+ protected List/*<GraphicsDrawingOrder>*/ objects
+ = new java.util.ArrayList/*<GraphicsDrawingOrder>*/();
/**
* Default constructor
}
/** {@inheritDoc} */
- public void addObject(PreparedAFPObject drawingOrder) {
- if (currentGraphicsData == null
- || (currentGraphicsData.getDataLength() + drawingOrder.getDataLength())
+ public void addObject(StructuredDataObject drawingOrder) {
+ if (data == null
+ || (data.getDataLength() + drawingOrder.getDataLength())
>= GraphicsData.MAX_DATA_LEN) {
newData();
}
- currentGraphicsData.addObject(drawingOrder);
+ data.addObject(drawingOrder);
}
/**
* @return the current graphics data
*/
private GraphicsData getData() {
- if (this.currentGraphicsData == null) {
+ if (this.data == null) {
return newData();
}
- return this.currentGraphicsData;
+ return this.data;
}
/**
* @return a newly created graphics data
*/
private GraphicsData newData() {
- this.currentGraphicsData = factory.createGraphicsData();
- objects.add(currentGraphicsData);
- return currentGraphicsData;
+ this.data = factory.createGraphicsData();
+ objects.add(data);
+ return data;
}
/**
* Begins a graphics area (start of fill)
*/
public void beginArea() {
- if (currentGraphicsData == null) {
+ if (data == null) {
newData();
}
- currentGraphicsData.beginArea();
+ data.beginArea();
}
/**
* Ends a graphics area (end of fill)
*/
public void endArea() {
- if (currentGraphicsData != null) {
- currentGraphicsData.endArea();
+ if (data != null) {
+ data.endArea();
}
}
os.write(data);
// Write triplet for FQN internal/external object reference
- if (tripletData != null) {
- os.write(tripletData);
- }
+ writeTriplets(os);
}
private String getObjectTypeName() {
* the Map Coded Font structured field specifies a set of resource attributes
* for the coded font.
*/
-public class MapCodedFont extends AbstractStructuredAFPObject {
+public class MapCodedFont extends AbstractStructuredObject {
/**
* The collection of map coded fonts (maximum of 254)
* The Map Container Data structured field specifies how a presentation data object
* that is carried in an Object Container is mapped into its object area.
*/
-public class MapContainerData extends AbstractStructuredAFPObject {
+public class MapContainerData extends AbstractTripletStructuredObject {
/**
* Main constructor
byte[] data = new byte[11];
copySF(data, Type.MAP, Category.OBJECT_CONTAINER);
int tripletLen = getTripletDataLength();
+
byte[] len = BinaryUtils.convert(10 + tripletLen, 2);
data[1] = len[0];
data[2] = len[1];
+
len = BinaryUtils.convert(2 + tripletLen, 2);
data[9] = len[0];
data[10] = len[1];
os.write(data);
- os.write(tripletData);
+ writeTriplets(os);
}
}
* The Map Data Resource structured field specifies resources that are
* required for presentation.
*/
-public class MapDataResource extends AbstractStructuredAFPObject {
+public class MapDataResource extends AbstractTripletStructuredObject {
/**
* Main constructor
data[10] = len[1];
os.write(data);
- os.write(tripletData);
+ writeTriplets(os);
}
}
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.fop.afp.modca.triplets.DescriptorPositionTriplet;
import org.apache.fop.afp.modca.triplets.MeasurementUnitsTriplet;
import org.apache.fop.afp.modca.triplets.ObjectAreaSizeTriplet;
import org.apache.fop.afp.modca.triplets.PresentationSpaceResetMixingTriplet;
-import org.apache.fop.afp.modca.triplets.Triplet;
import org.apache.fop.afp.util.BinaryUtils;
/**
super(width, height, widthRes, heightRes);
}
- /** {@inheritDoc} */
- protected byte[] getTripletData() throws IOException {
- if (tripletData == null) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- // Specifies the associated ObjectAreaPosition structured field
- final byte oapId = 0x01;
- Triplet triplet = new Triplet(Triplet.DESCRIPTOR_POSITION, oapId);
- triplet.writeToStream(baos);
-
- triplet = new MeasurementUnitsTriplet(widthRes, heightRes);
- triplet.writeToStream(baos);
-
- triplet = new ObjectAreaSizeTriplet(width, height);
- triplet.writeToStream(baos);
-
- triplet = new PresentationSpaceResetMixingTriplet(
- PresentationSpaceResetMixingTriplet.NOT_RESET);
- triplet.writeToStream(baos);
-
- this.tripletData = baos.toByteArray();
- }
- return this.tripletData;
- }
+ private static final byte oapId = 0x01;
/** {@inheritDoc} */
- public void writeStart(OutputStream os) throws IOException {
- super.writeStart(os);
+ public void writeToStream(OutputStream os) throws IOException {
+ // add triplets
+ addTriplet(new DescriptorPositionTriplet(oapId));
+ addTriplet(new MeasurementUnitsTriplet(widthRes, heightRes));
+ addTriplet(new ObjectAreaSizeTriplet(width, height));
+ addTriplet(new PresentationSpaceResetMixingTriplet(
+ PresentationSpaceResetMixingTriplet.NOT_RESET));
+
byte[] data = new byte[9];
copySF(data, Type.DESCRIPTOR, Category.OBJECT_AREA);
- byte[] len = BinaryUtils.convert(data.length + tripletData.length - 1, 2);
+
+ int tripletDataLength = getTripletDataLength();
+ byte[] len = BinaryUtils.convert(data.length + tripletDataLength, 2);
data[1] = len[0]; // Length
data[2] = len[1];
os.write(data);
+
+ writeTriplets(os);
}
}
+++ /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.afp.modca;
-
-/**
- * An AFP object which is able to know its own data length before write()
- */
-public interface PreparedAFPObject {
-
- /**
- * Returns the current data length of this container
- *
- * @return the current data length of this container including
- * all enclosed GOCA drawing objects
- */
- int getDataLength();
-}
\ No newline at end of file
* 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.
/**
* The Preprocess Presentation Object structured field specifies presentation
- * parameters for a data object that has been mapped as a resource.
+ * parameters for a data object that has been mapped as a resource.
*/
-public class PreprocessPresentationObject extends AbstractStructuredAFPObject {
+public class PreprocessPresentationObject extends AbstractTripletStructuredObject {
private static final byte TYPE_OTHER = (byte)0x92;
private static final byte TYPE_OVERLAY = (byte)0xDF;
private static final byte TYPE_IMAGE = (byte)0xFB;
-
+
private byte objType = TYPE_OTHER;
private byte objOrent = 0; // object always processed at 0 degree orientation
private int objXOffset = -1;
private int objYOffset = -1;
-
+
/**
* Main constructor
- *
- * @param prePresObj the presentation object to be preprocessed
+ *
+ * @param prePresObj the presentation object to be preprocessed
*/
- public PreprocessPresentationObject(AbstractStructuredAFPObject prePresObj) {
+ public PreprocessPresentationObject(AbstractTripletStructuredObject prePresObj) {
if (prePresObj instanceof ImageObject || prePresObj instanceof Overlay) {
if (prePresObj instanceof ImageObject) {
this.objType = TYPE_IMAGE;
this.objType = TYPE_OVERLAY;
}
setFullyQualifiedName(
- FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
+ FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF,
FullyQualifiedNameTriplet.FORMAT_CHARSTR,
prePresObj.getFullyQualifiedName());
} else {
this.objType = TYPE_OTHER;
}
}
-
+
public static final byte ORIENTATION_ZERO_DEGREES = 1;
public static final byte ORIENTATION_90_DEGREES = 2;
public static final byte ORIENTATION_180_DEGREES = 4;
public static final byte ORIENTATION_270_DEGREES = 8;
-
+
/**
* Sets the object orientations relative to media leading edge
- *
+ *
* @param orientation the object orientations relative to media leading edge
*/
public void setOrientation(byte orientation) {
- objOrent = (byte)orientation;
+ objOrent = orientation;
}
-
+
/**
* Sets the X axis origin for object content
- *
+ *
* @param xOffset the X axis origin for object content
*/
public void setXOffset(int xOffset) {
- this.objXOffset = xOffset;
+ this.objXOffset = xOffset;
}
-
+
/**
* Sets the Y axis origin for object content
- *
+ *
* @param yOffset the Y axis origin for object content
*/
public void setYOffset(int yOffset) {
os.write(data);
}
-
+
/** {@inheritDoc} */
public void writeContent(OutputStream os) throws IOException {
byte[] data = new byte[12];
data[11] = (byte)0xFF; // YocaOset
}
os.write(data);
-
+
// Triplets
super.writeContent(os);
}
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.triplets.Triplet;
import org.apache.fop.afp.util.BinaryUtils;
/**
* affect the rendering of presentation data and the appearance that is to be assumed
* by the presentation device.
*/
-public class PresentationEnvironmentControl extends AbstractStructuredAFPObject {
+public class PresentationEnvironmentControl extends AbstractTripletStructuredObject {
/**
* Main constructor
public PresentationEnvironmentControl() {
}
- /**
- * Sets the object offset
- */
- public void setObjectOffset() {
- addTriplet(new ObjectOffsetTriplet());
- }
-
- /**
- * Sets the rendering intent
- */
- public void setRenderingIntent() {
- addTriplet(new RenderingIntentTriplet());
- }
-
- /**
- * Sets the device appearance
- */
- public void setDeviceAppearance() {
- addTriplet(new DeviceAppearanceTriplet());
- }
-
/** {@inheritDoc} */
public void writeToStream(OutputStream os) throws IOException {
byte[] data = new byte[11];
data[10] = 0x00; // Reserved; must be zero
os.write(data);
- os.write(tripletData);
+
+ writeTriplets(os);
}
+// /**
+// * Sets the object offset
+// */
+// public void setObjectOffset() {
+// addTriplet(new ObjectOffsetTriplet());
+// }
+//
+// /**
+// * Sets the rendering intent
+// */
+// public void setRenderingIntent() {
+// addTriplet(new RenderingIntentTriplet());
+// }
+//
+// /**
+// * Sets the device appearance
+// */
+// public void setDeviceAppearance() {
+// addTriplet(new DeviceAppearanceTriplet());
+// }
+
+
// TODO
- private class DeviceAppearanceTriplet extends Triplet {
- public DeviceAppearanceTriplet() {
- super(Triplet.DEVICE_APPEARANCE);
- }
- }
+// private class DeviceAppearanceTriplet extends AbstractTriplet {
+// public DeviceAppearanceTriplet() {
+// super(AbstractTriplet.DEVICE_APPEARANCE);
+// }
+// }
// TODO
- private class RenderingIntentTriplet extends Triplet {
- public RenderingIntentTriplet() {
- super(Triplet.RENDERING_INTENT);
- }
- }
+// private class RenderingIntentTriplet extends AbstractTriplet {
+// public RenderingIntentTriplet() {
+// super(AbstractTriplet.RENDERING_INTENT);
+// }
+// }
// TODO
- private class ObjectOffsetTriplet extends Triplet {
- public ObjectOffsetTriplet() {
- super(Triplet.OBJECT_OFFSET);
- }
- }
+// private class ObjectOffsetTriplet extends AbstractTriplet {
+// public ObjectOffsetTriplet() {
+// super(AbstractTriplet.OBJECT_OFFSET);
+// }
+// }
}
/** IOB supported object types */
private static final byte COMPID_IOCA_FS10 = 5;
private static final byte COMPID_IOCA_FS11 = 11;
+ private static final byte COMPID_IOCA_FS40 = 55;
private static final byte COMPID_IOCA_FS45 = 12;
private static final byte COMPID_EPS = 13;
private static final byte COMPID_TIFF = 14;
private static final byte COMPID_PDF_SINGLE_PAGE = 25;
private static final byte COMPID_PCL_PAGE_OBJECT = 34;
+ private static final byte COMPID_TRUETYPE_OPENTYPE_FONT_RESOURCE_OBJECT = 51;
+ private static final byte COMPID_TRUETYPE_OPENTYPE_FONT_COLLECTION_RESOURCE_OBJECT = 53;
+
/** mime type entry mapping */
private final java.util.Map/*<String, ObjectType>*/ mimeObjectTypeMap
= Collections.synchronizedMap(
MimeConstants.MIME_AFP_IOCA_FS11
)
);
+// mimeObjectTypeMap.put(
+// MimeConstants.MIME_AFP_IOCA_FS40,
+// new ObjectType(
+// COMPID_IOCA_FS40,
+// new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x37},
+// "IOCA FS40",
+// true,
+// MimeConstants.MIME_AFP_IOCA_FS40
+// )
+//);
mimeObjectTypeMap.put(
MimeConstants.MIME_AFP_IOCA_FS45,
new ObjectType(
MimeConstants.MIME_PCL
)
);
+// mimeObjectTypeMap.put(
+// null,
+// new ObjectType(
+// COMPID_TRUETYPE_OPENTYPE_FONT_RESOURCE_OBJECT,
+// new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x33},
+// "TrueType/OpenType Font Resource Object",
+// true,
+// null
+// )
+// );
+// mimeObjectTypeMap.put(
+// null,
+// new ObjectType(
+// COMPID_TRUETYPE_OPENTYPE_FONT_COLLECTION_RESOURCE_OBJECT,
+// new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x35},
+// "TrueType/OpenType Font Collection Resource Object",
+// true,
+// null
+// )
+// );
}
/**
*/
public ObjectType(byte componentId, byte[] oid, String name,
boolean includable, String mimeType) {
+ this.componentId = componentId;
+ this.oid = oid;
this.name = name;
this.includable = includable;
this.mimeType = mimeType;
- this.componentId = componentId;
- this.oid = oid;
}
/**
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.afp.modca.triplets.Triplet;
+import org.apache.fop.afp.modca.triplets.ResourceObjectTypeTriplet;
import org.apache.fop.afp.util.BinaryUtils;
/**
* This resource structured field begins an envelope that is used to carry
* resource objects in print-file-level (external) resource groups.
*/
-public class ResourceObject extends AbstractPreparedAFPObject {
+public class ResourceObject extends AbstractNamedAFPObject {
+
+ /** graphics object type */
+ public static final byte TYPE_GRAPHIC = 0x03;
+
+ /** barcode object type */
+ public static final byte TYPE_BARCODE = 0x05;
+
+ /** image object type */
+ public static final byte TYPE_IMAGE = 0x06;
+
+ /** font character set type */
+ public static final byte TYPE_FONT_CHARACTER_SET = 0x40;
+
+ /** code page type */
+ public static final byte TYPE_CODE_PAGE = 0x41;
+
+ /** coded font type */
+ public static final byte TYPE_CODED_FONT = 0x42;
+
+ /** object container type */
+ public static final byte TYPE_OBJECT_CONTAINER = (byte) 0x92;
+
+ /** document object type */
+ public static final byte TYPE_DOCUMENT = (byte) 0xA8;
+
+ /** page segment object type */
+ public static final byte TYPE_PAGE_SEGMENT = (byte) 0xFB;
+
+ /** overlay object type */
+ public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC;
+
+ /** page def type */
+ public static final byte TYPE_PAGEDEF = (byte) 0xFD;
+
+ /** form def type */
+ public static final byte TYPE_FORMDEF = (byte) 0xFE;
private AbstractNamedAFPObject namedObject;
/**
* Sets the data object referenced by this resource object
*
- * @param obj the named data object
+ * @param namedObject the named data object
*/
- public void setDataObject(AbstractNamedAFPObject obj) {
- this.namedObject = obj;
+ public void setDataObject(AbstractNamedAFPObject namedObject) {
+ this.namedObject = namedObject;
}
/**
data[18] = 0x00; // Reserved
os.write(data);
+
+ // Write triplets
+ writeTriplets(os);
}
/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
- super.writeContent(os); // write triplets
if (namedObject != null) {
namedObject.writeToStream(os);
}
getTriplets().add(new ResourceObjectTypeTriplet(type));
}
- /** graphics object type */
- public static final byte TYPE_GRAPHIC = 0x03;
-
- /** barcode object type */
- public static final byte TYPE_BARCODE = 0x05;
-
- /** image object type */
- public static final byte TYPE_IMAGE = 0x06;
-
- /** font character set type */
- public static final byte TYPE_FONT_CHARACTER_SET = 0x40;
-
- /** code page type */
- public static final byte TYPE_CODE_PAGE = 0x41;
-
- /** coded font type */
- public static final byte TYPE_CODED_FONT = 0x42;
-
- /** object container type */
- public static final byte TYPE_OBJECT_CONTAINER = (byte) 0x92;
-
- /** document object type */
- public static final byte TYPE_DOCUMENT = (byte) 0xA8;
-
- /** page segment object type */
- public static final byte TYPE_PAGE_SEGMENT = (byte) 0xFB;
-
- /** overlay object type */
- public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC;
-
- /** page def type */
- public static final byte TYPE_PAGEDEF = (byte) 0xFD;
-
- /** form def type */
- public static final byte TYPE_FORMDEF = (byte) 0xFE;
-
-
- /** resource object type triplet */
- private class ResourceObjectTypeTriplet extends Triplet {
-
- private static final byte RESOURCE_OBJECT = 0x21;
-
- /**
- * Main constructor
- *
- * @param objectType the resource object type
- */
- public ResourceObjectTypeTriplet(byte objectType) {
- super(RESOURCE_OBJECT,
- new byte[] {
- objectType,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Constant Data
- }
- );
- }
- }
}
--- /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.afp.modca;
+
+/**
+ * An AFP object which is able to know its own data length before writeToStream()
+ */
+public interface StructuredDataObject {
+
+ /**
+ * Returns the data length of this structured field
+ *
+ * @return the data length of this structured field
+ */
+ int getDataLength();
+}
\ No newline at end of file
--- /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.afp.modca.triplets;
+
+import org.apache.fop.afp.Streamable;
+import org.apache.fop.afp.modca.StructuredDataObject;
+
+/**
+ * A simple implementation of a MOD:CA triplet
+ */
+public abstract class AbstractTriplet implements Streamable, StructuredDataObject {
+ public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01;
+
+ /** Triplet identifiers */
+ public static final byte FULLY_QUALIFIED_NAME = 0x02;
+ public static final byte MAPPING_OPTION = 0x04;
+ public static final byte OBJECT_CLASSIFICATION = 0x10;
+ public static final byte MODCA_INTERCHANGE_SET = 0x18;
+ public static final byte FONT_DESCRIPTOR_SPECIFICATION = 0x1F;
+ public static final byte OBJECT_FUNCTION_SET_SPECIFICATION = 0x21;
+ public static final byte EXTENDED_RESOURCE_LOCAL_IDENTIFIER = 0x22;
+ public static final byte RESOURCE_LOCAL_IDENTIFIER = 0x24;
+ public static final byte RESOURCE_SECTION_NUMBER = 0x25;
+ public static final byte CHARACTER_ROTATION = 0x26;
+ public static final byte OBJECT_BYTE_OFFSET = 0x2D;
+ public static final byte ATTRIBUTE_VALUE = 0x36;
+ public static final byte DESCRIPTOR_POSITION = 0x43;
+ public static final byte MEDIA_EJECT_CONTROL = 0x45;
+ public static final byte PAGE_OVERLAY_CONDITIONAL_PROCESSING = 0x46;
+ public static final byte RESOURCE_USAGE_ATTRIBUTE = 0x47;
+ public static final byte MEASUREMENT_UNITS = 0x4B;
+ public static final byte OBJECT_AREA_SIZE = 0x4C;
+ public static final byte AREA_DEFINITION = 0x4D;
+ public static final byte COLOR_SPECIFICATION = 0x4E;
+ public static final byte ENCODING_SCHEME_ID = 0x50;
+ public static final byte MEDIUM_MAP_PAGE_NUMBER = 0x56;
+ public static final byte OBJECT_BYTE_EXTENT = 0x57;
+ public static final byte OBJECT_STRUCTURED_FIELD_OFFSET = 0x58;
+ public static final byte OBJECT_STRUCTURED_FIELD_EXTENT = 0x59;
+ public static final byte OBJECT_OFFSET = 0x5A;
+ public static final byte FONT_HORIZONTAL_SCALE_FACTOR = 0x5D;
+ public static final byte OBJECT_COUNT = 0x5E;
+ public static final byte OBJECT_DATE_AND_TIMESTAMP = 0x62;
+ public static final byte COMMENT = 0x65;
+ public static final byte MEDIUM_ORIENTATION = 0x68;
+ public static final byte RESOURCE_OBJECT_INCLUDE = 0x6C;
+ public static final byte PRESENTATION_SPACE_RESET_MIXING = 0x70;
+ public static final byte PRESENTATION_SPACE_MIXING_RULE = 0x71;
+ public static final byte UNIVERSAL_DATE_AND_TIMESTAMP = 0x72;
+ public static final byte TONER_SAVER = 0x74;
+ public static final byte COLOR_FIDELITY = 0x75;
+ public static final byte FONT_FIDELITY = 0x78;
+ public static final byte ATTRIBUTE_QUALIFIER = (byte)0x80;
+ public static final byte PAGE_POSITION_INFORMATION = (byte)0x81;
+ public static final byte PARAMETER_VALUE = (byte)0x82;
+ public static final byte PRESENTATION_CONTROL = (byte)0x83;
+ public static final byte FONT_RESOLUTION_AND_METRIC_TECHNOLOGY = (byte)0x84;
+ public static final byte FINISHING_OPERATION = (byte)0x85;
+ public static final byte TEXT_FIDELITY = (byte)0x86;
+ public static final byte MEDIA_FIDELITY = (byte)0x87;
+ public static final byte FINISHING_FIDELITY = (byte)0x88;
+ public static final byte DATA_OBJECT_FONT_DESCRIPTOR = (byte)0x8B;
+ public static final byte LOCALE_SELECTOR = (byte)0x8C;
+ public static final byte UP3I_FINISHING_OPERATION = (byte)0x8E;
+ public static final byte COLOR_MANAGEMENT_RESOURCE_DESCRIPTOR = (byte)0x91;
+ public static final byte RENDERING_INTENT = (byte)0x95;
+ public static final byte CMR_TAG_FIDELITY = (byte)0x96;
+ public static final byte DEVICE_APPEARANCE = (byte)0x97;
+
+ /** the triplet identifier */
+ protected final byte id;
+
+ /**
+ * Constructor
+ *
+ * @param id the triplet identifier (see static definitions above)
+ */
+ public AbstractTriplet(byte id) {
+ this.id = id;
+ }
+
+ /**
+ * Returns the triplet identifier
+ *
+ * @return the triplet identifier
+ */
+ public byte getId() {
+ return this.id;
+ }
+
+ /**
+ * Returns the structured triplet data array
+ *
+ * @return the structured triplet data array
+ */
+ public byte[] getData() {
+ int dataLen = getDataLength();
+ byte[] data = new byte[dataLen];
+ data[0] = (byte)dataLen;
+ data[1] = id;
+ return data;
+ }
+}
--- /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.afp.modca.triplets;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.AFPConstants;
+
+/**
+ * An inline comment triplet.
+ */
+public class CommentTriplet extends AbstractTriplet {
+
+ private final String commentString;
+
+ public CommentTriplet(byte id, String commentString) {
+ super(id);
+ this.commentString = commentString;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 2 + commentString.length();
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ byte[] strData = commentString.getBytes(AFPConstants.EBCIDIC_ENCODING);
+ System.arraycopy(strData, 0, data, 2, strData.length);
+ os.write(data);
+ }
+
+}
--- /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.afp.modca.triplets;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class DescriptorPositionTriplet extends AbstractTriplet {
+
+ private final byte oapId;
+
+ /**
+ * Main constructor
+ *
+ * @param oapId the object area position id
+ */
+ public DescriptorPositionTriplet(byte oapId) {
+ super(DESCRIPTOR_POSITION);
+ this.oapId = oapId;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 3;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = oapId;
+ os.write(data);
+ }
+}
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
import org.apache.fop.afp.util.BinaryUtils;
/**
* resource name by a map structured field, such as a Map Data Resource structured
* field, or a Map Media Type structured field.
*/
-public class ExtendedResourceLocalIdentifierTriplet extends Triplet {
+public class ExtendedResourceLocalIdentifierTriplet extends AbstractTriplet {
/** the image resource type */
public static final byte TYPE_IMAGE_RESOURCE = 0x10;
/** the retired value type */
public static final byte TYPE_MEDIA_RESOURCE = 0x40;
+ /** the resource type */
+ private final byte type;
+
+ /** the resource local id */
+ private final int localId;
+
/**
* Main constructor
*
* @param localId the resource local id
*/
public ExtendedResourceLocalIdentifierTriplet(byte type, int localId) {
- super(Triplet.EXTENDED_RESOURCE_LOCAL_IDENTIFIER);
- byte[] data = new byte[5];
- data[0] = type;
- byte[] resLID = BinaryUtils.convert(localId, 4);
- System.arraycopy(resLID, 0, data, 1, resLID.length);
- super.setData(data);
+ super(AbstractTriplet.EXTENDED_RESOURCE_LOCAL_IDENTIFIER);
+ this.type = type;
+ this.localId = localId;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = type;
+ byte[] resLID = BinaryUtils.convert(localId, 4); // 4 bytes
+ System.arraycopy(resLID, 0, data, 3, resLID.length);
+ os.write(data);
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 7;
}
}
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import org.apache.fop.afp.AFPConstants;
/**
* A Fully Qualified Name triplet enable the identification and referencing of
- * objects using Gloabl Identifiers (GIDs).
+ * objects using Gloabl Identifiers (GIDs).
*/
-public class FullyQualifiedNameTriplet extends Triplet {
+public class FullyQualifiedNameTriplet extends AbstractTriplet {
// Specifies how the GID will be used
/** This GID replaces the first parameter in the structured field that contains a GID name. */
public static final byte TYPE_REPLACE_FIRST_GID_NAME = 0x01;
-
+
/** This triplet contains the name of a font family. */
public static final byte TYPE_FONT_FAMILY_NAME = 0x07;
-
+
/** This triplet contains the name of a font typeface. */
public static final byte TYPE_FONT_TYPEFACE_NAME = 0x08;
-
+
/** This triplet specifies a reference to the MO:DCA resource hierarchy. */
public static final byte TYPE_MODCA_RESOURCE_HIERARCHY_REF = 0x09;
-
+
/** The triplet contains a GID reference to a begin resource group structured field. */
public static final byte TYPE_BEGIN_RESOURCE_GROUP_REF = 0x0A;
-
+
/** The triplet contains a GID reference to a document attribute. */
public static final byte TYPE_ATTRIBUTE_GID = 0x0B;
-
+
/** The triplet contains the GID of a process element. */
public static final byte TYPE_PROCESS_ELEMENT_GID = 0x0C;
-
+
/** The triplet contains a reference to a begin page group structured field. */
public static final byte TYPE_BEGIN_PAGE_GROUP_REF = 0x0D;
-
+
/** The triplet contains a reference to a media type. */
public static final byte TYPE_MEDIA_TYPE_REF = 0x11;
-
+
/** The triplet contains a reference to a color management resource. */
public static final byte TYPE_COLOR_MANAGEMENT_RESOURCE_REF = 0x41;
/** The triplet contains a reference to a data-object font file that defines a base font. */
public static final byte TYPE_DATA_OBJECT_FONT_BASE_FONT_ID = 0x6E;
-
+
/** The triplet contains a reference to a data-object font file that defines a linked font. */
public static final byte TYPE_DATA_OBJECT_FONT_LINKED_FONT_ID = 0x7E;
-
- /** The triplet contains a reference to a begin document structured field. */
+
+ /** The triplet contains a reference to a begin document structured field. */
public static final byte TYPE_BEGIN_DOCUMENT_REF = (byte)0x83;
-
+
/**
* The triplet contains a reference to a begin structured field associated with a resource;
* or contains a GID reference to a coded font.
*/
public static final byte TYPE_BEGIN_RESOURCE_OBJECT_REF = (byte)0x84;
-
+
/**
* The triplet contains a GID reference to a code page that specifies the code points and
* graphic character names for a coded font.
*/
public static final byte TYPE_CODE_PAGE_NAME_REF = (byte)0x85;
-
- /**
+
+ /**
* The triplet contains a GID name reference to a font character set that specifies
* a set of graphics characters.
*/
public static final byte TYPE_FONT_CHARSET_NAME_REF = (byte)0x86;
-
+
/** The triplet contains a GID reference to a begin page structured field. */
public static final byte TYPE_BEGIN_PAGE_REF = (byte)0x87;
-
+
/** The triplet contains a GID reference to a begin medium map structured field. */
public static final byte TYPE_BEGIN_MEDIUM_MAP_REF = (byte)0x8D;
-
+
/**
* The triplet contains a GID reference to a coded font, which identifies a specific
* code page and a specific font character set.
*/
public static final byte TYPE_CODED_FONT_NAME_REF = (byte)0x8E;
-
+
/** The triplet contains a GID reference to a begin document index structured field. */
- public static final byte TYPE_BEGIN_DOCUMENT_INDEX_REF = (byte)0x98;
-
+ public static final byte TYPE_BEGIN_DOCUMENT_INDEX_REF = (byte)0x98;
+
/** The triplet contains a GID reference to a begin overlay structured field. */
public static final byte TYPE_BEGIN_OVERLAY_REF = (byte)0xB0;
-
+
/** The triplet contains a GID reference to a resource used by a data object. */
public static final byte TYPE_DATA_OBJECT_INTERNAL_RESOURCE_REF = (byte)0xBE;
-
+
/** The triplet contains a GID reference to an index element structured field. */
public static final byte TYPE_INDEX_ELEMENT_GID = (byte)0xCA;
-
+
/**
* The triplet contains a reference to other object data which may or may
* not be defined by an IBM presentation architecture.
*/
public static final byte TYPE_OTHER_OBJECT_DATA_REF = (byte)0xCE;
-
+
/**
* The triplet contains a reference to a resource used by a data object.
* The GID may be a filename or any other identifier associated with the
*/
public static final byte TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF = (byte)0xDE;
-
+
// GID Format
-
+
/** The GID is a character encoded name. */
public static final byte FORMAT_CHARSTR = (byte)0x00;
-
+
/** the GID is a ASN.1 object identifier (OID). */
public static final byte FORMAT_OID = (byte)0x10;
/** the GID is a uniform resource locator (URL). */
public static final byte FORMAT_URL = (byte)0x20;
-
- private String fqName;
-
- /**
- * @return the actual fully qualified name of this triplet
- */
- public String getFullyQualifiedName() {
- return fqName;
- }
+ /** the fully qualified name type */
+ private final byte type;
+
+ /** the fully qualified name format */
+ private final byte format;
+
+ /** the actual fully qualified name */
+ private final String fqName;
/**
* Main constructor
- *
+ *
* @param type the fully qualified name type
* @param format the fully qualified name format
* @param fqName the fully qualified name
*/
public FullyQualifiedNameTriplet(byte type, byte format, String fqName) {
super(FULLY_QUALIFIED_NAME);
-
+ this.type = type;
+ this.format = format;
this.fqName = fqName;
+ }
+ /**
+ * Returns the actual fully qualified name
+ *
+ * @return the actual fully qualified name
+ */
+ public String getFullyQualifiedName() {
+ return fqName;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return this.fqName;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 4 + fqName.length();
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = type;
+ data[3] = format;
+
+ // FQName
byte[] fqNameBytes;
- String encoding = AFPConstants.EBCIDIC_ENCODING;
+ String encoding = AFPConstants.EBCIDIC_ENCODING;
if (format == FORMAT_URL) {
- encoding = AFPConstants.US_ASCII_ENCODING;
+ encoding = AFPConstants.US_ASCII_ENCODING;
}
try {
fqNameBytes = fqName.getBytes(encoding);
throw new IllegalArgumentException(
encoding + " encoding failed");
}
+ System.arraycopy(fqNameBytes, 0, data, 4, fqNameBytes.length);
- byte[] data = new byte[2 + fqNameBytes.length];
- data[0] = type;
- data[1] = format;
- // FQName
- System.arraycopy(fqNameBytes, 0, data, 2, fqNameBytes.length);
-
- super.setData(data);
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString() {
- return this.fqName;
+ os.write(data);
}
}
\ No newline at end of file
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
/**
* Specifies the mapping of data object presentation space to object area
*/
-public class MappingOptionTriplet extends Triplet {
+public class MappingOptionTriplet extends AbstractTriplet {
/**
* the data object is placed in the upper left corner, all data must be presented
* within the object area extents
* the object area extents will be presented but data that falls outside will not be presented
*/
public static final byte POSITION_AND_TRIM = 0x10;
-
+
/**
* the data object is centred and symmetrically scaled up or down
* while preserving aspect ratio
*/
public static final byte SCALE_TO_FIT = 0x20;
-
+
/**
* the data object is centred, all data that falls within the object area extents
* will be presented but data that falls outside will not be presented
*/
public static final byte CENTER_AND_TRIM = 0x30;
-
+
// public static final byte MIGRATION_MAPPING_1 = 0x41;
// public static final byte MIGRATION_MAPPING_2 = 0x42;
// public static final byte MIGRATION_MAPPING_3 = 0x50;
-
+
/** the data object is centred, aspect ratio is not always preserved */
public static final byte SCALE_TO_FILL = 0x60;
-
+
/** used to map ip3i print data objects */
public static final byte UP3I_PRINT_DATA = 0x70;
+ private final byte mapValue;
+
/**
* Main constructor
- *
+ *
* @param mapValue the mapping option to use
*/
public MappingOptionTriplet(byte mapValue) {
- super(Triplet.MAPPING_OPTION, mapValue);
+ super(AbstractTriplet.MAPPING_OPTION);
+ this.mapValue = mapValue;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 3;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = mapValue;
+
+ os.write(data);
}
}
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
import org.apache.fop.afp.util.BinaryUtils;
/**
* The Measurement Units triplet is used to specify the units of measure
* for a presentation space
*/
-public class MeasurementUnitsTriplet extends Triplet {
+public class MeasurementUnitsTriplet extends AbstractTriplet {
- private static final byte TEN_INCHES = 0x00;
+ private static final byte TEN_INCHES = 0x00;
private static final byte TEN_CM = 0x01;
-
+ private final int xRes;
+ private final int yRes;
+
/**
* Main constructor
- *
+ *
* @param xRes units per base on the x-axis
* @param yRes units per base on the y-axis
*/
public MeasurementUnitsTriplet(int xRes, int yRes) {
super(MEASUREMENT_UNITS);
- //TODO: units correct?
+ this.xRes = xRes;
+ this.yRes = yRes;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 8;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+
+ data[2] = TEN_INCHES; // XoaBase
+ data[3] = TEN_INCHES; // YoaBase
+
byte[] xUnits = BinaryUtils.convert(xRes * 10, 2);
+ data[4] = xUnits[0]; // XoaUnits (x units per unit base)
+ data[5] = xUnits[1];
+
byte[] yUnits = BinaryUtils.convert(yRes * 10, 2);
- byte[] data = new byte[] {
- TEN_INCHES, // XoaBase
- TEN_INCHES, // YoaBase
- xUnits[0], // XoaUnits (x units per unit base)
- xUnits[1],
- yUnits[0], // YoaUnits (y units per unit base)
- yUnits[1]
- };
- super.setData(data);
+ data[6] = yUnits[0]; // YoaUnits (y units per unit base)
+ data[7] = yUnits[1];
+
+ os.write(data);
}
}
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
import org.apache.fop.afp.util.BinaryUtils;
/**
* The Object Area Size triplet is used to specify the extent of an object area
* in the X and Y directions
*/
-public class ObjectAreaSizeTriplet extends Triplet {
+public class ObjectAreaSizeTriplet extends AbstractTriplet {
+
+ private final int x;
+ private final int y;
+ private final byte type;
/**
* 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, byte type) {
- super(Triplet.OBJECT_AREA_SIZE);
- byte[] xOASize = BinaryUtils.convert(x, 3);
- byte[] yOASize = BinaryUtils.convert(y, 3);
- byte[] data = new byte[] {
- type, // SizeType
- xOASize[0], // XoaSize - Object area extent for X axis
- xOASize[1],
- xOASize[2],
- yOASize[0], // YoaSize - Object area extent for Y axis
- yOASize[1],
- yOASize[2]
- };
- super.setData(data);
+ super(AbstractTriplet.OBJECT_AREA_SIZE);
+ this.x = x;
+ this.y = y;
+ this.type = type;
}
/**
* 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);
}
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 9;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+
+ data[2] = type; // SizeType
+
+ byte[] xOASize = BinaryUtils.convert(x, 3);
+ data[3] = xOASize[0]; // XoaSize - Object area extent for X axis
+ data[4] = xOASize[1];
+ data[5] = xOASize[2];
+
+ byte[] yOASize = BinaryUtils.convert(y, 3);
+ data[6] = yOASize[0]; // YoaSize - Object area extent for Y axis
+ data[7] = yOASize[1];
+ data[8] = yOASize[2];
+
+ os.write(data);
+ }
}
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
import org.apache.fop.afp.util.BinaryUtils;
/**
* The Object Byte Extent triplet is used to specify the number of bytes contained in an object
*/
-public class ObjectByteExtentTriplet extends Triplet {
+public class ObjectByteExtentTriplet extends AbstractTriplet {
+
+ private final int byteExt;
/**
* Main constructor
*/
public ObjectByteExtentTriplet(int byteExt) {
super(OBJECT_BYTE_EXTENT);
- byte[] data = BinaryUtils.convert(byteExt, 4);
- super.setData(data);
+ this.byteExt = byteExt;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 6;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ byte[] extData = BinaryUtils.convert(byteExt, 4);
+ System.arraycopy(extData, 0, data, 2, extData.length);
+ os.write(data);
}
}
package org.apache.fop.afp.modca.triplets;
-import java.io.UnsupportedEncodingException;
+import java.io.IOException;
+import java.io.OutputStream;
import org.apache.fop.afp.AFPConstants;
import org.apache.fop.afp.modca.Registry.ObjectType;
* The Object Classification is used to classify and identify object data.
* The object data may or may not be defined by an IBM presentation architecture
*/
-public class ObjectClassificationTriplet extends Triplet {
+public class ObjectClassificationTriplet extends AbstractTriplet {
/**
* The scope of this object is the including page or overlay
*/
public static final byte CLASS_DATA_OBJECT_FONT = 0x41;
+ /** the object class */
+ private final byte objectClass;
+
+ /** the object type */
+ private final ObjectType objectType;
+
+ /** whether the container has an object environment group */
+ private final boolean containerHasOEG;
+
+ /** whether the data resides within the container */
+ private final boolean dataInContainer;
+
+ /** whether the data resides within the object container data */
+ private final boolean dataInOCD;
+
+ /** the object level (version) */
+ private final String objectLevel;
+
+ /** the company/organization name */
+ private final String companyName;
+
+
/**
* Main constructor
*
this(objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD, null, null);
}
-
- private static final int OBJECT_LEVEL_LEN = 8;
- private static final int OBJECT_TYPE_NAME_LEN = 32;
- private static final int COMPANY_NAME_LEN = 32;
-
/**
* Fully parameterized constructor
*
String objLev, String compName) {
super(OBJECT_CLASSIFICATION);
+ this.objectClass = objectClass;
if (objectType == null) {
throw new IllegalArgumentException("MO:DCA Registry object type is null");
}
-
- byte[] data = new byte[94];
- data[0] = 0x00; // reserved (must be zero)
- data[1] = objectClass; // ObjClass
- data[2] = 0x00; // reserved (must be zero)
- data[3] = 0x00; // reserved (must be zero)
-
- // StrucFlgs - Information on the structure of the object container
- byte[] strucFlgs = getStrucFlgs(dataInContainer, containerHasOEG, dataInOCD);
- data[4] = strucFlgs[0];
- data[5] = strucFlgs[1];
-
- byte[] oid = objectType.getOID();
- // RegObjId - MOD:CA-registered ASN.1 OID for object type (8-23)
- System.arraycopy(oid, 0, data, 6, oid.length);
-
- // ObjTpName - name of object type (24-55)
- byte[] objTpName;
- try {
- objTpName = StringUtils.rpad(objectType.getName(), ' ', OBJECT_TYPE_NAME_LEN).getBytes(
- AFPConstants.EBCIDIC_ENCODING);
- System.arraycopy(objTpName, 0, data, 22, objTpName.length);
- } catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException("an encoding exception occurred");
- }
-
- // ObjLev - release level or version number of object type (56-63)
- byte[] objectLevel;
- try {
- objectLevel = StringUtils.rpad(objLev, ' ', OBJECT_LEVEL_LEN).getBytes(
- AFPConstants.EBCIDIC_ENCODING);
- } catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException("an encoding exception occurred");
- }
- System.arraycopy(objectLevel, 0, data, 54, objectLevel.length);
-
- // CompName - name of company or organization that owns object definition (64-95)
- byte[] companyName;
- try {
- companyName = StringUtils.rpad(compName, ' ', COMPANY_NAME_LEN).getBytes(
- AFPConstants.EBCIDIC_ENCODING);
- } catch (UnsupportedEncodingException e) {
- throw new IllegalArgumentException("an encoding exception occurred");
- }
- System.arraycopy(companyName, 0, data, 62, companyName.length);
-
- super.setData(data);
+ this.objectType = objectType;
+ this.dataInContainer = dataInContainer;
+ this.containerHasOEG = containerHasOEG;
+ this.dataInOCD = dataInOCD;
+ this.objectLevel = objLev;
+ this.companyName = compName;
}
/**
*
* @return the byte value of this structure
*/
- public byte[] getStrucFlgs(boolean dataInContainer, boolean containerHasOEG,
+ public byte[] getStructureFlagsAsBytes(boolean dataInContainer, boolean containerHasOEG,
boolean dataInOCD) {
byte[] strucFlgs = new byte[2];
// Object Container (BOC/EOC)
strucFlgs[1] = 0x00;
return strucFlgs;
}
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 95;
+ }
+
+ private static final int OBJECT_LEVEL_LEN = 8;
+ private static final int OBJECT_TYPE_NAME_LEN = 32;
+ private static final int COMPANY_NAME_LEN = 32;
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = 0x00; // reserved (must be zero)
+ data[3] = objectClass; // ObjClass
+ data[4] = 0x00; // reserved (must be zero)
+ data[5] = 0x00; // reserved (must be zero)
+
+ // StrucFlgs - Information on the structure of the object container
+ byte[] structureFlagsBytes = getStructureFlagsAsBytes(dataInContainer, containerHasOEG, dataInOCD);
+ data[6] = structureFlagsBytes[0];
+ data[7] = structureFlagsBytes[1];
+
+ byte[] objectIdBytes = objectType.getOID();
+ // RegObjId - MOD:CA-registered ASN.1 OID for object type (8-23)
+ System.arraycopy(objectIdBytes, 0, data, 8, objectIdBytes.length);
+
+ // ObjTpName - name of object type (24-55)
+ byte[] objectTypeNameBytes;
+ objectTypeNameBytes
+ = StringUtils.rpad(objectType.getName(), ' ', OBJECT_TYPE_NAME_LEN).getBytes(
+ AFPConstants.EBCIDIC_ENCODING);
+ System.arraycopy(objectTypeNameBytes, 0, data, 24, objectTypeNameBytes.length);
+
+ // ObjLev - release level or version number of object type (56-63)
+ byte[] objectLevelBytes;
+ objectLevelBytes = StringUtils.rpad(objectLevel, ' ', OBJECT_LEVEL_LEN).getBytes(
+ AFPConstants.EBCIDIC_ENCODING);
+ System.arraycopy(objectLevelBytes, 0, data, 56, objectLevelBytes.length);
+
+ // CompName - name of company or organization that owns object definition (64-95)
+ byte[] companyNameBytes;
+ companyNameBytes = StringUtils.rpad(companyName, ' ', COMPANY_NAME_LEN).getBytes(
+ AFPConstants.EBCIDIC_ENCODING);
+ System.arraycopy(companyNameBytes, 0, data, 64, companyNameBytes.length);
+
+ os.write(data);
+ }
}
\ No newline at end of file
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
/**
* 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 {
+public class PresentationSpaceMixingRulesTriplet extends AbstractTriplet {
- /** background on background mixing rule */
+ /** background on background mixing rule */
public static final byte RULE_BACK_ON_BACK = 0x70;
- /** background on foreground mixing rule */
+ /** background on foreground mixing rule */
public static final byte RULE_BACK_ON_FORE = 0x71;
- /** foreground on background mixing rule */
+ /** foreground on background mixing rule */
public static final byte RULE_FORE_ON_BACK = 0x72;
- /** foreground on foreground mixing rule */
+ /** 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;
/** MO:DCA default mixing */
public static final byte DEFAULT = (byte)0xFF;
-
-
+
+ /** the mixing rules */
+ private final byte[] rules;
+
/**
* Main constructor
- *
+ *
* @param rules the mixing rules
*/
public PresentationSpaceMixingRulesTriplet(byte[] rules) {
- super(PRESENTATION_SPACE_MIXING_RULE, rules);
+ super(PRESENTATION_SPACE_MIXING_RULE);
+ this.rules = rules;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 2 + rules.length;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ System.arraycopy(rules, 0, data, 2, rules.length);
+ os.write(data);
}
}
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
/**
* 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 {
+public class PresentationSpaceResetMixingTriplet extends AbstractTriplet {
/**
* 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;
-
+
+ private final byte backgroundMixFlag;
+
/**
* Main constructor
- *
+ *
* @param backgroundMixFlag the background mixing flag
*/
public PresentationSpaceResetMixingTriplet(byte backgroundMixFlag) {
- super(PRESENTATION_SPACE_RESET_MIXING, backgroundMixFlag);
+ super(PRESENTATION_SPACE_RESET_MIXING);
+ this.backgroundMixFlag = backgroundMixFlag;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 3;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = backgroundMixFlag;
+ os.write(data);
}
}
* 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.
package org.apache.fop.afp.modca.triplets;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/** resource object type triplet */
+public class ResourceObjectTypeTriplet extends AbstractTriplet {
+
+ private static final byte RESOURCE_OBJECT = 0x21;
+
+ /** the resource object type */
+ private final byte objectType;
+
+ /**
+ * Main constructor
+ *
+ * @param objectType the resource object type
+ */
+ public ResourceObjectTypeTriplet(byte objectType) {
+ super(RESOURCE_OBJECT);
+ this.objectType = objectType;
+ }
+
+ /** {@inheritDoc} */
+ public int getDataLength() {
+ return 10;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = getData();
+ data[2] = objectType;
+ os.write(data);
+ }
+}
+++ /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.afp.modca.triplets;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-
-import org.apache.fop.afp.AFPConstants;
-import org.apache.fop.afp.Streamable;
-
-/**
- * A simple implementation of a MOD:CA triplet
- */
-public class Triplet implements Streamable {
- public static final byte CODED_GRAPHIC_CHARACTER_SET_GLOBAL_IDENTIFIER = 0x01;
-
- /** Triplet identifiers */
- public static final byte FULLY_QUALIFIED_NAME = 0x02;
- public static final byte MAPPING_OPTION = 0x04;
- public static final byte OBJECT_CLASSIFICATION = 0x10;
- public static final byte MODCA_INTERCHANGE_SET = 0x18;
- public static final byte FONT_DESCRIPTOR_SPECIFICATION = 0x1F;
- public static final byte OBJECT_FUNCTION_SET_SPECIFICATION = 0x21;
- public static final byte EXTENDED_RESOURCE_LOCAL_IDENTIFIER = 0x22;
- public static final byte RESOURCE_LOCAL_IDENTIFIER = 0x24;
- public static final byte RESOURCE_SECTION_NUMBER = 0x25;
- public static final byte CHARACTER_ROTATION = 0x26;
- public static final byte OBJECT_BYTE_OFFSET = 0x2D;
- public static final byte ATTRIBUTE_VALUE = 0x36;
- public static final byte DESCRIPTOR_POSITION = 0x43;
- public static final byte MEDIA_EJECT_CONTROL = 0x45;
- public static final byte PAGE_OVERLAY_CONDITIONAL_PROCESSING = 0x46;
- public static final byte RESOURCE_USAGE_ATTRIBUTE = 0x47;
- public static final byte MEASUREMENT_UNITS = 0x4B;
- public static final byte OBJECT_AREA_SIZE = 0x4C;
- public static final byte AREA_DEFINITION = 0x4D;
- public static final byte COLOR_SPECIFICATION = 0x4E;
- public static final byte ENCODING_SCHEME_ID = 0x50;
- public static final byte MEDIUM_MAP_PAGE_NUMBER = 0x56;
- public static final byte OBJECT_BYTE_EXTENT = 0x57;
- public static final byte OBJECT_STRUCTURED_FIELD_OFFSET = 0x58;
- public static final byte OBJECT_STRUCTURED_FIELD_EXTENT = 0x59;
- public static final byte OBJECT_OFFSET = 0x5A;
- public static final byte FONT_HORIZONTAL_SCALE_FACTOR = 0x5D;
- public static final byte OBJECT_COUNT = 0x5E;
- public static final byte OBJECT_DATE_AND_TIMESTAMP = 0x62;
- public static final byte COMMENT = 0x65;
- public static final byte MEDIUM_ORIENTATION = 0x68;
- public static final byte RESOURCE_OBJECT_INCLUDE = 0x6C;
- public static final byte PRESENTATION_SPACE_RESET_MIXING = 0x70;
- public static final byte PRESENTATION_SPACE_MIXING_RULE = 0x71;
- public static final byte UNIVERSAL_DATE_AND_TIMESTAMP = 0x72;
- public static final byte TONER_SAVER = 0x74;
- public static final byte COLOR_FIDELITY = 0x75;
- public static final byte FONT_FIDELITY = 0x78;
- public static final byte ATTRIBUTE_QUALIFIER = (byte)0x80;
- public static final byte PAGE_POSITION_INFORMATION = (byte)0x81;
- public static final byte PARAMETER_VALUE = (byte)0x82;
- public static final byte PRESENTATION_CONTROL = (byte)0x83;
- public static final byte FONT_RESOLUTION_AND_METRIC_TECHNOLOGY = (byte)0x84;
- public static final byte FINISHING_OPERATION = (byte)0x85;
- public static final byte TEXT_FIDELITY = (byte)0x86;
- public static final byte MEDIA_FIDELITY = (byte)0x87;
- public static final byte FINISHING_FIDELITY = (byte)0x88;
- public static final byte DATA_OBJECT_FONT_DESCRIPTOR = (byte)0x8B;
- public static final byte LOCALE_SELECTOR = (byte)0x8C;
- public static final byte UP3I_FINISHING_OPERATION = (byte)0x8E;
- public static final byte COLOR_MANAGEMENT_RESOURCE_DESCRIPTOR = (byte)0x91;
- public static final byte RENDERING_INTENT = (byte)0x95;
- public static final byte CMR_TAG_FIDELITY = (byte)0x96;
- public static final byte DEVICE_APPEARANCE = (byte)0x97;
-
- /** the triplet identifier */
- private final byte id;
-
- /** 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
- */
- public Triplet(byte id, byte[] data) {
- this(id);
- setData(data);
- }
-
- /**
- * Constructor
- *
- * @param id the triplet identifier (see static definitions above)
- */
- public Triplet(byte id) {
- this.id = id;
- }
-
- /**
- * Constructor
- *
- * @param id the triplet identifier (see static definitions above)
- * @param content the content byte data
- */
- public Triplet(byte id, byte content) {
- this(id, new byte[] {content});
- }
-
- /**
- * 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
- */
- public Triplet(byte id, String data) throws UnsupportedEncodingException {
- this(id, data.getBytes(AFPConstants.EBCIDIC_ENCODING));
- }
-
- /** {@inheritDoc} */
- public void writeToStream(OutputStream os) throws IOException {
- os.write((byte)data.length + 2);
- os.write(id);
- os.write(data);
- }
-
- /**
- * Returns the triplet identifier
- *
- * @return the triplet identifier
- */
- public byte getId() {
- return this.id;
- }
-
- /**
- * Sets the data contents of this triplet
- *
- * @param data the data contents
- */
- protected void setData(byte[] data) {
- this.data = data;
- }
-}
--- /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.afp.svg;
+
+import java.awt.GraphicsDevice;
+import java.awt.Rectangle;
+import java.awt.Transparency;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.svg.GraphicsConfiguration;
+
+/**
+ * Our implementation of the class that returns information about
+ * roughly what we can handle and want to see (alpha for example).
+ */
+public class AFPGraphicsConfiguration extends GraphicsConfiguration {
+ // We use this to get a good colormodel..
+ private static final BufferedImage BI_WITH_ALPHA
+ = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+ // We use this to get a good colormodel..
+ private static final BufferedImage BI_WITHOUT_ALPHA
+ = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
+
+ /**
+ * Construct a buffered image with an alpha channel, unless
+ * transparencty is OPAQUE (no alpha at all).
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @param transparency the alpha value of the image
+ * @return the new buffered image
+ */
+ public BufferedImage createCompatibleImage(int width, int height,
+ int transparency) {
+ if (transparency == Transparency.OPAQUE) {
+ return new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_RGB);
+ } else {
+ return new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ }
+ }
+
+ /**
+ * Construct a buffered image with an alpha channel.
+ *
+ * @param width the width of the image
+ * @param height the height of the image
+ * @return the new buffered image
+ */
+ public BufferedImage createCompatibleImage(int width, int height) {
+ return new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_ARGB);
+ }
+
+ /**
+ * TODO: This should return the page bounds in Pts,
+ * I couldn't figure out how to get this for the current
+ * page (this still works for now,
+ * but it should be fixed...).
+ *
+ * @return the bounds of the page
+ */
+ public Rectangle getBounds() {
+ return null;
+ }
+
+ /**
+ * Return a good default color model for this 'device'.
+ * @return the colour model for the configuration
+ */
+ public ColorModel getColorModel() {
+ return BI_WITH_ALPHA.getColorModel();
+ }
+
+ /**
+ * Return a good color model given <tt>transparency</tt>
+ *
+ * @param transparency the alpha value for the colour model
+ * @return the colour model for the configuration
+ */
+ public ColorModel getColorModel(int transparency) {
+ if (transparency == Transparency.OPAQUE) {
+ return BI_WITHOUT_ALPHA.getColorModel();
+ } else {
+ return BI_WITH_ALPHA.getColorModel();
+ }
+ }
+
+ private static final Log log = LogFactory.getLog(AFPGraphicsConfiguration.class);
+
+ private AffineTransform defaultTransform = null;
+ private AffineTransform normalizingTransform = null;
+ private final GraphicsDevice graphicsDevice = new AFPGraphicsDevice(this);;
+
+ /**
+ * The default transform (1:1).
+ *
+ * @return the default transform for the configuration
+ */
+ public AffineTransform getDefaultTransform() {
+ log.debug("getDefaultTransform()");
+ if (defaultTransform == null) {
+ defaultTransform = new AffineTransform();
+ }
+ return defaultTransform;
+ }
+
+ /**
+ * The normalizing transform (1:1) (since we currently
+ * render images at 72dpi, which we might want to change
+ * in the future).
+ *
+ * @return the normalizing transform for the configuration
+ */
+ public AffineTransform getNormalizingTransform() {
+ log.debug("getNormalizingTransform()");
+ if (normalizingTransform == null) {
+ normalizingTransform = new AffineTransform(2, 0, 0, 2, 0, 0);
+ }
+ return normalizingTransform;
+ }
+
+ /** {@inheritDoc} */
+ public GraphicsDevice getDevice() {
+ log.debug("getDevice()");
+ return graphicsDevice;
+ }
+}
--- /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.afp.svg;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+
+/**
+ * This implements the GraphicsDevice interface as appropriate for
+ * an AFPGraphics2D.
+ */
+public class AFPGraphicsDevice extends GraphicsDevice {
+
+ /**
+ * The Graphics Config that created us...
+ */
+ protected GraphicsConfiguration gc;
+
+ /**
+ * Create a new AF{ graphics device.
+ *
+ * @param gc The graphics configuration we should reference
+ */
+ public AFPGraphicsDevice(AFPGraphicsConfiguration gc) {
+ this.gc = gc;
+ }
+
+ /**
+ * Return an array of our one GraphicsConfig
+ *
+ * @return an array containing the one graphics configuration
+ */
+ public GraphicsConfiguration[] getConfigurations() {
+ return new GraphicsConfiguration[] {gc};
+ }
+
+ /**
+ * Return out sole GraphicsConfig.
+ *
+ * @return the graphics configuration that created this object
+ */
+ public GraphicsConfiguration getDefaultConfiguration() {
+ return this.gc;
+ }
+
+ /**
+ * Generate an IdString..
+ *
+ * @return the ID string for this device, uses toString
+ */
+ public String getIDstring() {
+ return toString();
+ }
+
+ /**
+ * Let the caller know that we are "a printer"
+ *
+ * @return the type which is always printer
+ */
+ public int getType() {
+ return GraphicsDevice.TYPE_PRINTER;
+ }
+}
* @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
*/
public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHandler {
-
private static final AffineTransform IDENTITY_TRANSFORM = new AffineTransform();
/** The number of decimal places. */