--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp;
+
+import java.io.IOException;
+
+/**
+ * Abstract image configurator
+ */
+public abstract class AFPAbstractImageFactory {
+ private static final int X = 0;
+ private static final int Y = 1;
+
+ /** the AFP state */
+ protected final AFPState state;
+
+ /** foreign attribute reader */
+ private final AFPForeignAttributeReader foreignAttributeReader
+ = new AFPForeignAttributeReader();
+
+ /**
+ * Main constructor
+ *
+ * @param state the AFP state
+ */
+ public AFPAbstractImageFactory(AFPState state) {
+ this.state = state;
+ }
+
+ /**
+ * Configures the data object info
+ *
+ * @param afpImageInfo the afp image info
+ * @return the data object info
+ * @throws IOException thrown if an I/O exception of some sort has occurred.
+ */
+ public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException {
+ AFPDataObjectInfo dataObjectInfo = createDataObjectInfo();
+ dataObjectInfo.setUri(afpImageInfo.uri);
+
+ // set resource information
+ AFPResourceInfo resourceInfo
+ = foreignAttributeReader.getResourceInfo(afpImageInfo.foreignAttributes);
+ dataObjectInfo.setResourceInfo(resourceInfo);
+
+ // set object area
+ AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
+ float srcX = afpImageInfo.origin.x + (float)afpImageInfo.pos.getX();
+ float srcY = afpImageInfo.origin.y + (float)afpImageInfo.pos.getY();
+ AFPUnitConverter unitConv = state.getUnitConverter();
+ int[] coords = unitConv.mpts2units(new float[] {srcX, srcY});
+ objectAreaInfo.setX(coords[X]);
+ objectAreaInfo.setY(coords[Y]);
+ int width = Math.round(unitConv.mpt2units((float)afpImageInfo.pos.getWidth()));
+ objectAreaInfo.setWidth(width);
+ int height = Math.round(unitConv.mpt2units((float)afpImageInfo.pos.getHeight()));
+ objectAreaInfo.setHeight(height);
+ dataObjectInfo.setObjectAreaInfo(objectAreaInfo);
+ return dataObjectInfo;
+ }
+
+ /**
+ * Creates the data object information object
+ *
+ * @return the data object information object
+ */
+ protected abstract AFPDataObjectInfo createDataObjectInfo();
+}
\ No newline at end of file
import org.apache.fop.render.afp.modca.GraphicsObject;
import org.apache.fop.render.afp.modca.ImageObject;
import org.apache.fop.render.afp.modca.IncludeObject;
-import org.apache.fop.render.afp.modca.MapDataResource;
import org.apache.fop.render.afp.modca.ObjectContainer;
import org.apache.fop.render.afp.modca.Overlay;
import org.apache.fop.render.afp.modca.PageSegment;
import org.apache.fop.render.afp.modca.Registry;
import org.apache.fop.render.afp.modca.ResourceObject;
-import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet;
import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet;
import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
}
/**
- * Creates an IOCA ImageObject or an ObjectContainer as appropriate.
+ * Creates and configures an ObjectContainer.
*
- * @param imageObjectInfo the image object info
- * @return a newly created image object
+ * @param dataObjectInfo the object container info
+ * @return a newly created Object Container
*/
- public AbstractDataObject createImage(AFPImageObjectInfo imageObjectInfo) {
- AbstractDataObject dataObj = null;
- // A known object type so place in an object container
- if (imageObjectInfo.isBuffered()) {
- // IOCA bitmap image
- ImageObject imageObj = factory.createImageObject();
- if (imageObjectInfo.hasCompression()) {
- int compression = imageObjectInfo.getCompression();
- switch (compression) {
- case TIFFImage.COMP_FAX_G3_1D:
- imageObj.setEncoding(ImageContent.COMPID_G3_MH);
- break;
- case TIFFImage.COMP_FAX_G3_2D:
- imageObj.setEncoding(ImageContent.COMPID_G3_MR);
- break;
- case TIFFImage.COMP_FAX_G4_2D:
- imageObj.setEncoding(ImageContent.COMPID_G3_MMR);
- break;
- default:
- throw new IllegalStateException(
- "Invalid compression scheme: " + compression);
- }
- }
+ public ObjectContainer createObjectContainer(AFPDataObjectInfo dataObjectInfo) {
+ ObjectContainer objectContainer = factory.createObjectContainer();
- if (imageObjectInfo.isColor()) {
- imageObj.setIDESize((byte) 24);
- } else {
- imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel());
- }
- imageObj.setData(imageObjectInfo.getData());
+ // set object classification
+ Registry.ObjectType objectType = dataObjectInfo.getObjectType();
+ AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
+ AFPResourceLevel resourceLevel = resourceInfo.getLevel();
+ final boolean dataInContainer = true;
+ final boolean containerHasOEG = resourceLevel.isInline();
+ final boolean dataInOCD = true;
+ objectContainer.setObjectClassification(
+ ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT,
+ objectType, dataInContainer, containerHasOEG, dataInOCD);
+
+ objectContainer.setInputStream(dataObjectInfo.getInputStream());
+ return objectContainer;
+ }
- dataObj = imageObj;
+ /**
+ * Creates and configures an IOCA Image Object.
+ *
+ * @param imageObjectInfo the image object info
+ * @return a newly created IOCA Image Object
+ */
+ public ImageObject createImage(AFPImageObjectInfo imageObjectInfo) {
+ // IOCA bitmap image
+ ImageObject imageObj = factory.createImageObject();
+ if (imageObjectInfo.hasCompression()) {
+ int compression = imageObjectInfo.getCompression();
+ switch (compression) {
+ case TIFFImage.COMP_FAX_G3_1D:
+ imageObj.setEncoding(ImageContent.COMPID_G3_MH);
+ break;
+ case TIFFImage.COMP_FAX_G3_2D:
+ imageObj.setEncoding(ImageContent.COMPID_G3_MR);
+ break;
+ case TIFFImage.COMP_FAX_G4_2D:
+ imageObj.setEncoding(ImageContent.COMPID_G3_MMR);
+ break;
+ default:
+ throw new IllegalStateException(
+ "Invalid compression scheme: " + compression);
+ }
+ }
+ if (imageObjectInfo.isColor()) {
+ imageObj.setIDESize((byte) 24);
} else {
- ObjectContainer objectContainer = factory.createObjectContainer();
-
- Registry.ObjectType objectType = imageObjectInfo.getObjectType();
-
- objectContainer.setObjectClassification(
- ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT,
- objectType);
-
- objectContainer.setInputStream(imageObjectInfo.getInputStream());
-
- dataObj = objectContainer;
+ imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel());
}
- return dataObj;
+ imageObj.setData(imageObjectInfo.getData());
+
+ return imageObj;
}
/**
includeObj.setObjectType(IncludeObject.TYPE_GRAPHIC);
} else {
includeObj.setObjectType(IncludeObject.TYPE_OTHER);
- }
-
- Registry.ObjectType objectType = dataObjectInfo.getObjectType();
- if (objectType != null) {
- includeObj.setObjectClassification(
- // object scope not defined
- ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
- objectType);
+ Registry.ObjectType objectType = dataObjectInfo.getObjectType();
+ if (objectType != null) {
+ // set object classification
+ final boolean dataInContainer = true;
+ final boolean containerHasOEG = false; // environment parameters set in include
+ final boolean dataInOCD = true;
+ includeObj.setObjectClassification(
+ // object scope not defined
+ ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
+ objectType, dataInContainer, containerHasOEG, dataInOCD);
+ }
}
AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
AbstractDataObject dataObj = (AbstractDataObject)namedObj;
// other type by default
- byte fqnType = FullyQualifiedNameTriplet.TYPE_OTHER_OBJECT_DATA_REF;
+// byte fqnType = FullyQualifiedNameTriplet.TYPE_OTHER_OBJECT_DATA_REF;
if (namedObj instanceof ObjectContainer) {
resourceObj.setType(ResourceObject.TYPE_OBJECT_CONTAINER);
+ // set object classification
+ final boolean dataInContainer = true;
+ final boolean containerHasOEG = false; // must be included
+ final boolean dataInOCD = true;
// mandatory triplet for object container
resourceObj.setObjectClassification(
ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT,
- objectType);
+ objectType, dataInContainer, containerHasOEG, dataInOCD);
} else if (namedObj instanceof ImageObject) {
resourceObj.setType(ResourceObject.TYPE_IMAGE);
// ioca image type
- fqnType = FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF;
+// fqnType = FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF;
} else if (namedObj instanceof GraphicsObject) {
resourceObj.setType(ResourceObject.TYPE_GRAPHIC);
} else {
}
// set the map data resource
- MapDataResource mapDataResource = factory.createMapDataResource();
- mapDataResource.setFullyQualifiedName(
- fqnType,
- FullyQualifiedNameTriplet.FORMAT_CHARSTR,
- resourceObj.getName());
- dataObj.getObjectEnvironmentGroup().setMapDataResource(mapDataResource);
+// MapDataResource mapDataResource = factory.createMapDataResource();
+// mapDataResource.setFullyQualifiedName(
+// fqnType,
+// FullyQualifiedNameTriplet.FORMAT_CHARSTR,
+// resourceObj.getName());
+// dataObj.getObjectEnvironmentGroup().setMapDataResource(mapDataResource);
} else {
throw new UnsupportedOperationException(
package org.apache.fop.render.afp;
+import java.io.InputStream;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.afp.modca.Registry;
/**
* A list of parameters associated with an AFP data objects
*/
-public abstract class AFPDataObjectInfo {
+public class AFPDataObjectInfo {
private static final Log log = LogFactory.getLog("org.apache.fop.afp");
/** the object area info */
/** the data object height */
private int dataHeight;
+ /** the object data in an inputstream */
+ private InputStream inputStream;
+
+ /** the object registry mimetype */
+ private String mimeType;
+
/**
* Default constructor
*/
public AFPDataObjectInfo() {
}
+ /**
+ * Sets the image mime type
+ *
+ * @param mimeType the image mime type
+ */
+ public void setMimeType(String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+ /**
+ * Returns the mime type of this data object
+ *
+ * @return the mime type of this data object
+ */
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ /**
+ * Convenience method to return the object type
+ *
+ * @return the object type
+ */
+ public Registry.ObjectType getObjectType() {
+ return Registry.getInstance().getObjectType(getMimeType());
+ }
+
/**
* Returns the resource level at which this data object should reside
*
/** {@inheritDoc} */
public String toString() {
- return "mimeType=" + getMimeType()
+ return "AFPDataObjectInfo{"
+ + "mimeType=" + mimeType
+ ", dataWidth=" + dataWidth
+ ", dataHeight=" + dataHeight
+ (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "")
}
/**
- * Returns the mime type of this data object
+ * Sets the object data inputstream
*
- * @return the mime type of this data object
+ * @param inputStream the object data inputstream
*/
- public abstract String getMimeType();
+ public void setInputStream(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
/**
- * Convenience method to return the object type
+ * Returns the object data inputstream
*
- * @return the object type
+ * @return the object data inputstream
*/
- public Registry.ObjectType getObjectType() {
- return Registry.getInstance().getObjectType(getMimeType());
+ public InputStream getInputStream() {
+ return this.inputStream;
}
+
}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
+import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+
+/**
+ * AFP image configurator
+ */
+public class AFPDataObjectInfoFactory {
+ private final Map dataObjectInfoFactoryMap = new java.util.HashMap();
+ private final AFPState state;
+
+ /**
+ * Main constructor
+ *
+ * @param state the AFP state
+ */
+ public AFPDataObjectInfoFactory(AFPState state) {
+ this.state = state;
+ init();
+ }
+
+ /**
+ * Initialises the configurators
+ */
+ private void init() {
+ dataObjectInfoFactoryMap.put(
+ ImageRendered.class, new AFPImageRenderedFactory(state));
+ dataObjectInfoFactoryMap.put(
+ ImageRawCCITTFax.class, new AFPRawCCITTFaxFactory(state));
+ dataObjectInfoFactoryMap.put(
+ ImageRawStream.class, new AFPImageRawStreamFactory(state));
+ };
+
+ /**
+ * Returns the configurator for a given image
+ *
+ * @param img the image
+ * @return the image configurator for the image
+ */
+ public AFPAbstractImageFactory getFactory(Image img) {
+ Class clazz = img.getClass();
+ AFPAbstractImageFactory configurator
+ = (AFPAbstractImageFactory)dataObjectInfoFactoryMap.get(clazz);
+ // not directly matched so try to map ancestor
+ if (configurator == null) {
+ Iterator it = dataObjectInfoFactoryMap.keySet().iterator();
+ while (it.hasNext()) {
+ Class imageClass = (Class)it.next();
+ if (imageClass.isInstance(img)) {
+ return (AFPAbstractImageFactory)dataObjectInfoFactoryMap.get(imageClass);
+ }
+ }
+ }
+ return configurator;
+ }
+}
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.afp.goca.GraphicsSetLineType;
import org.apache.fop.render.afp.modca.GraphicsObject;
import org.apache.xmlgraphics.image.loader.ImageInfo;
ImageRendered imgRend = new ImageRendered(imageInfo, buf, null);
RenderedImage ri = imgRend.getRenderedImage();
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
// Serialize image
// create image object parameters
AFPImageObjectInfo imageObjectInfo = new AFPImageObjectInfo();
- imageObjectInfo.setBuffered(true);
if (imageInfo != null) {
imageObjectInfo.setUri(imageInfo.getOriginalURI());
- imageObjectInfo.setMimeType(imageInfo.getMimeType());
}
AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
imageObjectInfo.setData(baos.toByteArray());
imageObjectInfo.setDataHeight(ri.getHeight());
imageObjectInfo.setDataWidth(ri.getWidth());
- imageObjectInfo.setColor(state.isColorImages());
+ boolean colorImages = state.isColorImages();
+ imageObjectInfo.setColor(colorImages);
+ imageObjectInfo.setMimeType(colorImages
+ ? MimeConstants.MIME_AFP_IOCA_FS45
+ : MimeConstants.MIME_AFP_IOCA_FS10);
imageObjectInfo.setBitsPerPixel(state.getBitsPerPixel());
AFPResourceManager resourceManager = info.getAFPResourceManager();
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp;
+
+import java.awt.Point;
+import java.awt.geom.Rectangle2D;
+import java.util.Map;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+
+/**
+ * The AFP image information
+ */
+public class AFPImageInfo {
+
+ /** the image uri */
+ protected final String uri;
+
+ /** the current pos */
+ protected final Rectangle2D pos;
+
+ /** the origin */
+ protected final Point origin;
+
+ /** the foreign attributes */
+ protected final Map foreignAttributes;
+
+ /** the image info */
+ protected final ImageInfo info;
+
+ /** the image */
+ protected final Image img;
+
+ /**
+ * Main constructor
+ *
+ * @param uri the image uri
+ * @param pos the image content area
+ * @param origin the current position
+ * @param info the image info
+ * @param img the image
+ * @param foreignAttributes the foreign attributes
+ */
+ public AFPImageInfo(String uri, Rectangle2D pos, Point origin,
+ ImageInfo info, Image img, Map foreignAttributes) {
+ this.uri = uri;
+ this.pos = pos;
+ this.origin = origin;
+ this.info = info;
+ this.img = img;
+ this.foreignAttributes = foreignAttributes;
+ }
+
+}
package org.apache.fop.render.afp;
-import java.io.InputStream;
/**
* A list of parameters associated with an image
/** compression type if any */
private int compression = -1;
- /** the image mimetype */
- private String mimeType;
-
- /** is this a buffered image? */
- private boolean buffered;
-
/** the object data in a byte array */
private byte[] data;
- /** the object data in an inputstream */
- private InputStream inputStream;
-
/**
* Default constructor
*/
this.color = color;
}
- /**
- * Sets the image mime type
- *
- * @param mimeType the image mime type
- */
- public void setMimeType(String mimeType) {
- this.mimeType = mimeType;
- }
-
/**
* Returns the number of bits used per pixel
*
this.compression = compression;
}
- /** {@inheritDoc} */
- public String getMimeType() {
- return mimeType;
- }
-
- /**
- * Sets whether or not this is info about a buffered image
- *
- * @param buffered true if this is info about a buffered image
- */
- public void setBuffered(boolean buffered) {
- this.buffered = buffered;
- }
-
- /**
- * Returns true if this image info is about a buffered image
- *
- * @return true if this image info is about a buffered image
- */
- public boolean isBuffered() {
- return this.buffered;
- }
-
/**
* Sets the object data
*
return this.data;
}
- /**
- * Sets the object data inputstream
- *
- * @param inputStream the object data inputstream
- */
- public void setInputStream(InputStream inputStream) {
- this.inputStream = inputStream;
- }
-
- /**
- * Returns the object data inputstream
- *
- * @return the object data inputstream
- */
- public InputStream getInputStream() {
- return this.inputStream;
- }
-
/** {@inheritDoc} */
public String toString() {
return "AFPImageObjectInfo{" + super.toString()
- + ", mimeType=" + mimeType
- + ", buffered=" + buffered
- + ", compression=" + compression
+ + "compression=" + compression
+ ", color=" + color
+ ", bitsPerPixel=" + bitsPerPixel
+ "}";
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+
+/**
+ * A raw stream image configurator
+ */
+public class AFPImageRawStreamFactory extends AFPAbstractImageFactory {
+
+ /**
+ * Main constructor
+ *
+ * @param state the AFP state
+ */
+ public AFPImageRawStreamFactory(AFPState state) {
+ super(state);
+ }
+
+ /** {@inheritDoc} */
+ public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException {
+ AFPDataObjectInfo dataObjectInfo = super.create(afpImageInfo);
+ String mimeType = afpImageInfo.info.getMimeType();
+ if (mimeType != null) {
+ dataObjectInfo.setMimeType(mimeType);
+ }
+ ImageRawStream rawStream = (ImageRawStream) afpImageInfo.img;
+ int resolution = state.getResolution();
+
+ AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
+ objectAreaInfo.setWidthRes(resolution);
+ objectAreaInfo.setHeightRes(resolution);
+
+ InputStream inputStream = rawStream.createInputStream();
+ dataObjectInfo.setInputStream(inputStream);
+
+ int dataHeight = rawStream.getSize().getHeightPx();
+ dataObjectInfo.setDataHeight(dataHeight);
+
+ int dataWidth = rawStream.getSize().getWidthPx();
+ dataObjectInfo.setDataWidth(dataWidth);
+ return dataObjectInfo;
+ }
+
+ /** {@inheritDoc} */
+ protected AFPDataObjectInfo createDataObjectInfo() {
+ return new AFPDataObjectInfo();
+ }
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
+import org.apache.xmlgraphics.ps.ImageEncodingHelper;
+
+/**
+ * A buffered image configurator
+ */
+public class AFPImageRenderedFactory extends AFPAbstractImageFactory {
+
+ /**
+ * Main constructor
+ *
+ * @param state the AFP state
+ */
+ public AFPImageRenderedFactory(AFPState state) {
+ super(state);
+ }
+
+ /** {@inheritDoc} */
+ public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException {
+ AFPImageObjectInfo imageObjectInfo
+ = (AFPImageObjectInfo)super.create(afpImageInfo);
+
+ ImageRendered imageRendered = (ImageRendered) afpImageInfo.img;
+ RenderedImage renderedImage = imageRendered.getRenderedImage();
+
+ ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baout);
+
+ imageObjectInfo.setData(baout.toByteArray());
+
+ int resolution = state.getResolution();
+
+ AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
+ objectAreaInfo.setWidthRes(resolution);
+ objectAreaInfo.setHeightRes(resolution);
+
+ imageObjectInfo.setDataHeight(renderedImage.getHeight());
+ imageObjectInfo.setDataWidth(renderedImage.getWidth());
+
+ boolean colorImages = state.isColorImages();
+ imageObjectInfo.setColor(colorImages);
+ imageObjectInfo.setMimeType(colorImages
+ ? MimeConstants.MIME_AFP_IOCA_FS45
+ : MimeConstants.MIME_AFP_IOCA_FS10);
+
+ return imageObjectInfo;
+ }
+
+ /** {@inheritDoc} */
+ protected AFPDataObjectInfo createDataObjectInfo() {
+ return new AFPImageObjectInfo();
+ }
+}
private int widthRes;
private int heightRes;
private int rotation = 0;
- private int offsetX;
- private int offsetY;
/**
* Sets the x position of the data object
+ ", rotation=" + rotation;
}
-// public int getOffsetX() {
-// return offsetX;
-// }
-//
-// public int getOffsetY() {
-// return offsetY;
-// }
-//
-// public void setOffsetX(int afpx) {
-// this.offsetX = afpx;
-// }
-//
-// public void setOffsetY(int afpy) {
-// this.offsetY = afpy;
-// }
-
}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: $ */
+
+package org.apache.fop.render.afp;
+
+import java.io.IOException;
+
+import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
+
+/**
+ * An CITT fax image configurator
+ */
+public class AFPRawCCITTFaxFactory extends AFPAbstractImageFactory {
+
+ /**
+ * Main constructor
+ *
+ * @param state the afp state
+ */
+ public AFPRawCCITTFaxFactory(AFPState state) {
+ super(state);
+ }
+
+ /** {@inheritDoc} */
+ public AFPDataObjectInfo create(AFPImageInfo afpImageInfo) throws IOException {
+ AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)super.create(afpImageInfo);
+
+ ImageRawCCITTFax ccitt = (ImageRawCCITTFax) afpImageInfo.img;
+ imageObjectInfo.setCompression(ccitt.getCompression());
+
+ AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
+ int xresol = (int) (ccitt.getSize().getDpiHorizontal() * 10);
+ objectAreaInfo.setWidthRes(xresol);
+
+ int yresol = (int) (ccitt.getSize().getDpiVertical() * 10);
+ objectAreaInfo.setHeightRes(yresol);
+
+ imageObjectInfo.setInputStream(ccitt.createInputStream());
+
+ return imageObjectInfo;
+ }
+
+ /** {@inheritDoc} */
+ protected AFPDataObjectInfo createDataObjectInfo() {
+ return new AFPImageObjectInfo();
+ }
+}
\ No newline at end of file
import java.awt.image.RenderedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.image.loader.ImageSessionContext;
import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawCCITTFax;
-import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
-import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
import org.apache.xmlgraphics.image.loader.util.ImageUtil;
import org.apache.xmlgraphics.ps.ImageEncodingHelper;
/** the afp datastream */
private DataStream dataStream;
+ /** data object information factory */
+ private final AFPDataObjectInfoFactory dataObjectInfoFactory;
+
+
/**
* Constructor for AFPRenderer.
*/
super();
this.resourceManager = new AFPResourceManager();
this.state = new AFPState();
+ this.dataObjectInfoFactory = new AFPDataObjectInfoFactory(state);
this.unitConv = state.getUnitConverter();
}
}
private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
- ImageFlavor.RAW_JPEG, ImageFlavor.RAW_CCITTFAX, ImageFlavor.GRAPHICS2D,
- ImageFlavor.BUFFERED_IMAGE, ImageFlavor.RENDERED_IMAGE,
- ImageFlavor.XML_DOM, /*ImageFlavor.RAW_EPS*/ };
+ ImageFlavor.RAW_JPEG, ImageFlavor.RAW_CCITTFAX, ImageFlavor.RAW_EPS,
+ ImageFlavor.GRAPHICS2D, ImageFlavor.BUFFERED_IMAGE, ImageFlavor.RENDERED_IMAGE,
+ ImageFlavor.XML_DOM };
/** {@inheritDoc} */
public void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) {
if (name != null) {
dataStream.createIncludePageSegment(name, coords[X], coords[Y]);
} else {
- Point origin = new Point(currentIPPosition, currentBPPosition);
-
ImageManager manager = userAgent.getFactory().getImageManager();
ImageInfo info = null;
- InputStream in = null;
try {
ImageSessionContext sessionContext = userAgent
.getImageSessionContext();
org.apache.xmlgraphics.image.loader.Image img = manager.getImage(
info, FLAVORS, hints, sessionContext);
- if (img instanceof ImageRendered || img instanceof ImageRawStream) {
- AFPImageObjectInfo imageObjectInfo
- = getImageObjectInfo(uri, info, pos, origin, img);
- resourceManager.createObject(imageObjectInfo);
+ Point origin = new Point(currentIPPosition, currentBPPosition);
+ AFPAbstractImageFactory factory = dataObjectInfoFactory.getFactory(img);
+ if (factory != null) {
+ AFPImageInfo afpImageInfo
+ = new AFPImageInfo(uri, pos, origin, info, img, foreignAttributes);
+ AFPDataObjectInfo dataObjectInfo = null;
+ try {
+ dataObjectInfo = factory.create(afpImageInfo);
+ } catch (IOException ioe) {
+ ResourceEventProducer eventProducer
+ = ResourceEventProducer.Provider.get(userAgent.getEventBroadcaster());
+ eventProducer.imageWritingError(this, ioe);
+ throw ioe;
+ }
+ resourceManager.createObject(dataObjectInfo);
} else if (img instanceof ImageGraphics2D) { // ...and process the image
ImageGraphics2D imageG2D = (ImageGraphics2D) img;
RendererContext rendererContext = createRendererContext(
.get(userAgent.getEventBroadcaster());
eventProducer.imageIOError(this, (info != null ? info.toString()
: uri), ioe, null);
- } finally {
- if (in != null) {
- IOUtils.closeQuietly(in);
- }
}
}
}
- /**
- * Gets the AFP image object information for a given image
- *
- * @param uri the image uri
- * @param info the image info
- * @param pos the image content area
- * @param origin the current position
- * @param img the image
- * @return an image object info
- * @throws IOException thrown if an I/O exception of some sort has occurred
- */
- private AFPImageObjectInfo getImageObjectInfo(String uri, ImageInfo info, Rectangle2D pos,
- Point origin, org.apache.xmlgraphics.image.loader.Image img) throws IOException {
- AFPImageObjectInfo imageObjectInfo = new AFPImageObjectInfo();
- imageObjectInfo.setUri(uri);
- imageObjectInfo.setColor(state.isColorImages());
- imageObjectInfo.setBitsPerPixel(state.getBitsPerPixel());
- imageObjectInfo.setMimeType(info.getMimeType());
-
- AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo();
-
- float srcX = origin.x + (float)pos.getX();
- float srcY = origin.y + (float)pos.getY();
- int[] coords = unitConv.mpts2units(new float[] {srcX, srcY});
- objectAreaInfo.setX(coords[X]);
- objectAreaInfo.setY(coords[Y]);
-
- int width = Math.round(unitConv.mpt2units((float)pos.getWidth()));
- objectAreaInfo.setWidth(width);
-
- int height = Math.round(unitConv.mpt2units((float)pos.getHeight()));
- objectAreaInfo.setHeight(height);
-
- String mimeType = info.getMimeType();
- if (mimeType != null) {
- imageObjectInfo.setMimeType(mimeType);
- }
- imageObjectInfo.setObjectAreaInfo(objectAreaInfo);
-
- if (img instanceof ImageRendered) {
- imageObjectInfo.setBuffered(true);
-
- ImageRendered imageRendered = (ImageRendered) img;
- RenderedImage renderedImage = imageRendered.getRenderedImage();
-
- ByteArrayOutputStream baout = new ByteArrayOutputStream();
- try {
- // Serialize image
- // TODO Eventually, this should be changed not to buffer as
- // this
- // increases the
- // memory consumption (see PostScript output)
- ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baout);
- } catch (IOException ioe) {
- ResourceEventProducer eventProducer = ResourceEventProducer.Provider
- .get(userAgent.getEventBroadcaster());
- eventProducer.imageWritingError(this, ioe);
- throw ioe;
- }
- imageObjectInfo.setData(baout.toByteArray());
-
- int resolution = state.getResolution();
- objectAreaInfo.setWidthRes(resolution);
- objectAreaInfo.setHeightRes(resolution);
-
- imageObjectInfo.setDataHeight(renderedImage.getHeight());
- imageObjectInfo.setDataWidth(renderedImage.getWidth());
- } else {
- imageObjectInfo.setBuffered(false);
-
- ImageRawStream rawStream = (ImageRawStream) img;
- if (img instanceof ImageRawCCITTFax) {
- ImageRawCCITTFax ccitt = (ImageRawCCITTFax) img;
- imageObjectInfo.setCompression(ccitt.getCompression());
-
- int xresol = (int) (rawStream.getSize().getDpiHorizontal() * 10);
- objectAreaInfo.setWidthRes(xresol);
-
- int yresol = (int) (rawStream.getSize().getDpiVertical() * 10);
- objectAreaInfo.setHeightRes(yresol);
- } else {
- int resolution = state.getResolution();
- objectAreaInfo.setWidthRes(resolution);
- objectAreaInfo.setHeightRes(resolution);
- }
-
- InputStream inputStream = rawStream.createInputStream();
- imageObjectInfo.setInputStream(inputStream);
-
- int dataHeight = rawStream.getSize().getHeightPx();
- imageObjectInfo.setDataHeight(dataHeight);
-
- int dataWidth = rawStream.getSize().getWidthPx();
- imageObjectInfo.setDataWidth(dataWidth);
-
- }
- return imageObjectInfo;
- }
-
/**
* Writes a RenderedImage to an OutputStream as raw sRGB bitmaps.
*
private static final String NAME_EXTERNAL = "external";
private static final String[] NAMES = new String[] {
- NAME_INLINE, NAME_PAGE, NAME_PAGE_GROUP,
- NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL
+ NAME_INLINE, NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL
};
import org.apache.fop.render.afp.modca.AbstractNamedAFPObject;
import org.apache.fop.render.afp.modca.DataStream;
import org.apache.fop.render.afp.modca.Factory;
-import org.apache.fop.render.afp.modca.ImageObject;
import org.apache.fop.render.afp.modca.IncludeObject;
import org.apache.fop.render.afp.modca.Registry;
import org.apache.fop.render.afp.modca.ResourceGroup;
String includeName = (String)includeNameMap.get(resourceInfo);
if (includeName == null) {
+ boolean canInclude = false;
+ Registry.ObjectType objectType = null;
+
// new resource so create
if (dataObjectInfo instanceof AFPImageObjectInfo) {
- namedObj = dataObjectFactory.createImage((AFPImageObjectInfo)dataObjectInfo);
+ AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo;
+ namedObj = dataObjectFactory.createImage(imageObjectInfo);
+ canInclude = true;
} else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) {
namedObj = dataObjectFactory.createGraphic((AFPGraphicsObjectInfo)dataObjectInfo);
} else {
- throw new IllegalArgumentException("Unknown data object type: " + dataObjectInfo);
+ namedObj = dataObjectFactory.createObjectContainer(dataObjectInfo);
+ objectType = dataObjectInfo.getObjectType();
+ canInclude = objectType != null && objectType.isIncludable();
}
// set data object viewport (i.e. position, rotation, dimension, resolution)
}
AFPResourceLevel resourceLevel = resourceInfo.getLevel();
-
- Registry.ObjectType objectType = dataObjectInfo.getObjectType();
-
ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel);
-
- boolean canInclude = (resourceGroup != null) && (namedObj instanceof ImageObject
- || objectType != null && objectType.isIncludable());
+ canInclude &= resourceGroup != null;
if (canInclude) {
-
// if it is to reside within a resource group at print-file or external level
if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) {
-
// wrap newly created data object in a resource object
namedObj = dataObjectFactory.createResource(namedObj, resourceInfo, objectType);
}
import org.apache.fop.render.afp.modca.Factory;
import org.apache.fop.render.afp.modca.ResourceGroup;
import org.apache.fop.render.afp.modca.StreamedResourceGroup;
-import org.apache.fop.render.afp.Streamable;
/**
* Manages the streaming of the AFP output
} else {
// resource group in afp document datastream
resourceGroup = dataStream.getResourceGroup(level);
+
}
return resourceGroup;
}
*/
protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os)
throws IOException {
- if (objects != null) {
- for (Iterator it = objects.iterator(); it.hasNext();) {
+ if (objects != null && objects.size() > 0) {
+ Iterator it = objects.iterator();
+ while (it.hasNext()) {
Object object = it.next();
if (object instanceof Streamable) {
((Streamable)object).writeToStream(os);
+ it.remove(); // once written, immediately remove the object
}
}
}
protected List/*<TagLogicalElement>*/ tagLogicalElements = null;
/** The list of the include page segments */
- protected List/*<IncludePageSegment>*/ includePageSegments
- = new java.util.ArrayList/*<IncludePageSegment>*/();
+ protected List/*<IncludePageSegment>*/ includePageSegments = null;
/** The list of objects within this resource container */
protected List/*<AbstractStructuredAFPObject>*/ objects = new java.util.ArrayList();
*/
public void createIncludePageSegment(String name, int x, int y) {
IncludePageSegment ips = factory.createIncludePageSegment(name, x, y);
- includePageSegments.add(ips);
+ getIncludePageSegments().add(ips);
+ }
+
+ /**
+ * Returns the include page segments list
+ *
+ * @return the include page segments list
+ */
+ private List getIncludePageSegments() {
+ if (this.includePageSegments == null) {
+ this.includePageSegments = new java.util.ArrayList/*<IncludePageSegment>*/();
+ }
+ return this.includePageSegments;
}
/**
/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
super.writeContent(os);
- if (this instanceof PageObject || this instanceof Overlay) {
- getActiveEnvironmentGroup().writeToStream(os);
- }
- writeObjects(this.includePageSegments, os);
- writeObjects(this.tagLogicalElements, os);
writeObjects(this.objects, os);
}
* the name of the media map
*/
public void createInvokeMediumMap(String name) {
- addObject(new InvokeMediumMap(name));
+ InvokeMediumMap invokeMediumMap = factory.createInvokeMediumMap(name);
+ addObject(invokeMediumMap);
}
/** {@inheritDoc} */
*/
protected ResourceEnvironmentGroup getResourceEnvironmentGroup() {
if (resourceEnvironmentGroup == null) {
- this.resourceEnvironmentGroup = new ResourceEnvironmentGroup();
+ this.resourceEnvironmentGroup = factory.createResourceEnvironmentGroup();
}
return this.resourceEnvironmentGroup;
}
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.fop.render.afp.Streamable;
/**
* An abstract container of resource objects
*/
-public abstract class AbstractResourceGroupContainer extends AbstractPageObject {
+public abstract class AbstractResourceGroupContainer extends AbstractPageObject
+implements Streamable {
+
+ /** The container started state */
+ protected boolean started = false;
/** the resource group object */
- private ResourceGroup resourceGroup = null;
+ protected ResourceGroup resourceGroup = null;
/**
* Default constructor
return resourceGroup;
}
+// /** {@inheritDoc} */
+// protected void writeContent(OutputStream os) throws IOException {
+// if (resourceGroup != null) {
+// resourceGroup.writeToStream(os);
+// }
+// super.writeContent(os);
+// }
+
/** {@inheritDoc} */
- protected void writeContent(OutputStream os) throws IOException {
- if (resourceGroup != null) {
- resourceGroup.writeToStream(os);
+ public void writeToStream(OutputStream os) throws IOException {
+ if (!started) {
+ writeStart(os);
+ started = true;
+ }
+
+ writeContent(os);
+
+ if (complete) {
+ writeEnd(os);
+ }
+ }
+
+ /** {@inheritDoc} */
+ protected void writeObjects(Collection/*<AbstractAFPObject>*/ objects, OutputStream os)
+ throws IOException {
+ if (objects != null && objects.size() > 0) {
+ Iterator it = objects.iterator();
+ while (it.hasNext()) {
+ AbstractAFPObject ao = (AbstractAFPObject)it.next();
+ if (canWrite(ao)) {
+ ao.writeToStream(os);
+ it.remove();
+ } else {
+ break;
+ }
+ }
}
- super.writeContent(os);
+ }
+
+ /**
+ * Returns true if this object can be written
+ *
+ * @param obj an AFP object
+ * @return true if this object can be written
+ */
+ protected boolean canWrite(AbstractAFPObject obj) {
+ return obj instanceof AbstractPageObject && ((AbstractPageObject)obj).isComplete();
}
}
import java.util.List;
import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.fop.render.afp.modca.Registry.ObjectType;
import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet;
import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet;
import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet;
-import org.apache.fop.render.afp.modca.triplets.StrucFlgs;
import org.apache.fop.render.afp.modca.triplets.Triplet;
import org.apache.fop.render.afp.tools.BinaryUtils;
* @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 strucFlgs information on the structure of the object and its container
+ * @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, Registry.ObjectType objectType,
- StrucFlgs strucFlgs) {
- addTriplet(new ObjectClassificationTriplet(objectClass, objectType, strucFlgs));
- }
-
- /**
- * Sets the objects classification with the default structure flags
- *
- * @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
- */
- public void setObjectClassification(byte objectClass, Registry.ObjectType objectType) {
- setObjectClassification(objectClass, objectType, StrucFlgs.DEFAULT);
+ public void setObjectClassification(
+ byte objectClass, ObjectType objectType,
+ boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) {
+ addTriplet(
+ new ObjectClassificationTriplet(
+ objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD));
}
/**
import org.apache.commons.logging.LogFactory;
import org.apache.fop.render.afp.AFPFontAttributes;
import org.apache.fop.render.afp.AFPResourceLevel;
-import org.apache.fop.render.afp.LineDataInfo;
import org.apache.fop.render.afp.AFPTextDataInfo;
+import org.apache.fop.render.afp.LineDataInfo;
import org.apache.fop.render.afp.fonts.AFPFont;
import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Iterator;
-
-import org.apache.fop.render.afp.Streamable;
/**
* The document is the highest level of the MO:DCA data-stream document
* of the document to be presented.
*
*/
-public final class Document extends AbstractResourceEnvironmentGroupContainer implements Streamable {
-
- /** The document started state */
- private boolean started = false;
-
- /** The document completion state */
- private boolean complete = false;
+public final class Document extends AbstractResourceEnvironmentGroupContainer {
/**
* Constructor for the document object.
return this.name;
}
- /** {@inheritDoc} */
- public void writeToStream(OutputStream os) throws IOException {
- if (!started) {
- writeStart(os);
- started = true;
- }
-
- Iterator it = objects.iterator();
- while (it.hasNext()) {
- AbstractAFPObject ao = (AbstractAFPObject)it.next();
- if (ao instanceof PageGroup && ((PageGroup)ao).isComplete()
- || ao instanceof PageObject && ((PageObject)ao).isComplete()) {
- ao.writeToStream(os);
- it.remove();
- } else {
- break;
- }
- }
-
- if (complete) {
- writeEnd(os);
- }
- }
}
\ No newline at end of file
return presentationEnvironmentControl;
}
+ /**
+ * Creates a new MO:DCA {@link InvokeMediumMap}
+ *
+ * @param name the object name
+ * @return a new {@link InvokeMediumMap}
+ */
+ public InvokeMediumMap createInvokeMediumMap(String name) {
+ InvokeMediumMap invokeMediumMap = new InvokeMediumMap(name);
+ return invokeMediumMap;
+ }
+
+ /**
+ * Creates a new MO:DCA {@link ResourceEnvironmentGroup}
+ *
+ * @return a new {@link ResourceEnvironmentGroup}
+ */
+ public ResourceEnvironmentGroup createResourceEnvironmentGroup() {
+ ResourceEnvironmentGroup resourceEnvironmentGroup = new ResourceEnvironmentGroup();
+ return resourceEnvironmentGroup;
+ }
+
/**
* Creates a new IOCA {@link ImageSegment}
*
import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.commons.io.IOUtils;
import org.apache.fop.render.afp.AFPDataObjectInfo;
import org.apache.fop.render.afp.AFPObjectAreaInfo;
import org.apache.fop.render.afp.AFPResourceInfo;
final int lengthOffset = 1;
copyChunks(dataHeader, lengthOffset, MAX_DATA_LEN, inputStream, os);
+ IOUtils.closeQuietly(inputStream);
}
/** {@inheritDoc} */
os.write(data);
}
+ /** {@inheritDoc} */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os);
+
+ getActiveEnvironmentGroup().writeToStream(os);
+
+ writeObjects(includePageSegments, os);
+ writeObjects(tagLogicalElements, os);
+ writeObjects(objects, os);
+ }
+
+
/** {@inheritDoc} */
protected void writeEnd(OutputStream os) throws IOException {
byte[] data = new byte[17];
import java.io.IOException;
import java.io.OutputStream;
-import java.util.Iterator;
import java.util.List;
/**
/** The tag logical elements contained within this group */
private List tagLogicalElements = null;
- /** the page group started state */
- private boolean started = false;
-
/**
* Constructor for the PageGroup.
*
os.write(data);
}
- /** {@inheritDoc} */
- public void writeToStream(OutputStream os) throws IOException {
- if (!started) {
- writeStart(os);
- started = true;
- }
-
- Iterator it = objects.iterator();
- while (it.hasNext()) {
- AbstractAFPObject ao = (AbstractAFPObject)it.next();
- if (ao instanceof PageObject && ((PageObject)ao).isComplete()) {
- ao.writeToStream(os);
- it.remove();
- } else {
- break;
- }
- }
-
- if (complete) {
- writeEnd(os);
- }
- }
-
/** {@inheritDoc} */
public String toString() {
return this.getName();
os.write(data);
}
+ /** {@inheritDoc} */
+ protected void writeContent(OutputStream os) throws IOException {
+ super.writeContent(os);
+
+ getActiveEnvironmentGroup().writeToStream(os);
+
+ writeObjects(includePageSegments, os);
+ writeObjects(tagLogicalElements, os);
+ writeObjects(objects, os);
+ }
+
/** {@inheritDoc} */
protected void writeEnd(OutputStream os) throws IOException {
byte[] data = new byte[17];
public String toString() {
return this.getName();
}
+
+ /** {@inheritDoc} */
+ protected boolean canWrite(AbstractAFPObject ao) {
+ return true;
+ }
}
\ No newline at end of file
*/
public final class Registry {
/** 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_FS45 = 12;
private static final byte COMPID_EPS = 13;
private static final byte COMPID_TIFF = 14;
private static final byte COMPID_GIF = 22;
* Initializes the mimetype map
*/
private void init() {
+ mimeObjectTypeMap.put(
+ MimeConstants.MIME_AFP_IOCA_FS10,
+ new ObjectType(
+ COMPID_IOCA_FS10,
+ new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x05},
+ "IOCA FS10",
+ true,
+ MimeConstants.MIME_AFP_IOCA_FS10
+ )
+ );
+ mimeObjectTypeMap.put(
+ MimeConstants.MIME_AFP_IOCA_FS11,
+ new ObjectType(
+ COMPID_IOCA_FS11,
+ new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x11},
+ "IOCA FS11",
+ true,
+ MimeConstants.MIME_AFP_IOCA_FS11
+ )
+ );
+ mimeObjectTypeMap.put(
+ MimeConstants.MIME_AFP_IOCA_FS45,
+ new ObjectType(
+ COMPID_IOCA_FS45,
+ new byte[] {0x06, 0x07, 0x2B, 0x12, 0x00, 0x04, 0x01, 0x01, 0x12},
+ "IOCA FS45",
+ true,
+ MimeConstants.MIME_AFP_IOCA_FS45
+ )
+ );
mimeObjectTypeMap.put(
MimeConstants.MIME_EPS,
new ObjectType(
import java.io.UnsupportedEncodingException;
import org.apache.fop.render.afp.AFPConstants;
-import org.apache.fop.render.afp.modca.Registry;
+import org.apache.fop.render.afp.modca.Registry.ObjectType;
import org.apache.fop.render.afp.tools.StringUtils;
/**
/**
* Main constructor
*
- * @param objectClass
- * the object class type
- * @param objectType
- * the object type registry entry
- * @param strucFlgs
- * the structured flags pertaining to this object classification triplet
+ * @param objectClass the object class type
+ * @param objectType the object type registry entry
+ * @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 ObjectClassificationTriplet(byte objectClass, Registry.ObjectType objectType,
- StrucFlgs strucFlgs) {
+ public ObjectClassificationTriplet(byte objectClass, ObjectType objectType,
+ boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) {
// no object level or company name specified
- this(objectClass, objectType, strucFlgs, null, null);
+ this(objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD, null, null);
}
/**
* Fully parameterized constructor
*
- * @param objectClass
- * the object class type
- * @param objectType
- * the object type registry entry
- * @param strucFlgs
- * the structured flags pertaining to this object classification triplet
- * @param objLev
- * the release level or version number of the object type
- * @param compName
- * the name of the company or organization that owns the object definition
+ * @param objectClass the object class type
+ * @param objectType the object type registry entry
+ * @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
+ * @param objLev the release level or version number of the object type
+ * @param compName the name of the company or organization that owns the object definition
*/
- public ObjectClassificationTriplet(byte objectClass, Registry.ObjectType objectType,
- StrucFlgs strucFlgs, String objLev, String compName) {
+ public ObjectClassificationTriplet(byte objectClass, ObjectType objectType,
+ boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD,
+ String objLev, String compName) {
super(OBJECT_CLASSIFICATION);
if (objectType == null) {
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
- data[4] = strucFlgs.getValue();
- data[5] = 0x00; // StrucFlgs
+ 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)
super.setData(data);
}
+ /**
+ * Returns the structured field flags
+ *
+ * @param dataInContainer true if the object data in carried in the object container
+ * @param containerHasOEG true if the object container has an object environment group
+ * @param dataInOCD true if the object container data carries the object data
+ *
+ * @return the byte value of this structure
+ */
+ public byte[] getStrucFlgs(boolean dataInContainer, boolean containerHasOEG,
+ boolean dataInOCD) {
+ byte[] strucFlgs = new byte[2];
+ // Object Container (BOC/EOC)
+ if (dataInContainer) {
+ strucFlgs[0] |= 3 << 6;
+ } else {
+ strucFlgs[0] |= 1 << 6;
+ }
+ // Object Environment Group (OEG)
+ if (containerHasOEG) {
+ strucFlgs[0] |= 3 << 4;
+ } else {
+ strucFlgs[0] |= 1 << 4;
+ }
+ // Object Container Data (OCD) structured fields
+ if (dataInOCD) {
+ strucFlgs[0] |= 3 << 2;
+ } else {
+ strucFlgs[0] |= 1 << 2;
+ }
+ strucFlgs[1] = 0x00;
+ return strucFlgs;
+ }
}
\ 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.render.afp.modca.triplets;
-
-/**
- * Used by ObjectClassificationTriplet to provide
- * information on the structure of the object and its container
- */
-public class StrucFlgs {
-
- private static final int OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER = 1;
- private static final int OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN = 2;
- private static final int OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER = 3;
-
- private static final int OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP = 4;
- private static final int OBJECT_CONTAINER_OBJECT_ENVIRONMENT_GROUP_CONTAINMENT_UNKNOWN = 8;
- private static final int OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP = 12;
-
- private static final int OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA = 16;
- private static final int OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN = 32;
- private static final int OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA = 48;
-
-// private static final int OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER = 48;
-// private static final int OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN = 32;
-// private static final int OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER = 16;
-//
-// private static final int OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP = 12;
-// private static final int OBJECT_CONTAINER_OBJECT_ENVIRONMENT_GROUP_CONTAINMENT_UNKNOWN = 8;
-// private static final int OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP = 4;
-//
-// private static final int OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA = 3;
-// private static final int OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN = 2;
-// private static final int OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA = 1;
-
- /**
- * the default structured flags setting
- * - data is in container with no object environment group and data in object container data
- */
- public static final StrucFlgs DEFAULT = new StrucFlgs(true, false, true);
-
-
- private int value = 0;
-
- /**
- * Main constructor
- *
- * @param dataInContainer true if the object data in carried in the object container
- * @param containerHasOEG true if the object container has an object environment group
- * @param dataInOCD true if the object container data carries the object data
- */
- public StrucFlgs(boolean dataInContainer, boolean containerHasOEG, boolean dataInOCD) {
- if (dataInContainer) {
- this.value += OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER;
- } else {
- this.value += OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER;
- }
- if (containerHasOEG) {
- this.value += OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP;
- } else {
- this.value += OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP;
- }
- if (dataInOCD) {
- this.value += OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA;
- } else {
- this.value += OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA;
- }
- }
-
- /**
- * Default constructor
- */
- public StrucFlgs() {
- this.value = OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN
- + OBJECT_CONTAINER_OBJECT_ENVIRONMENT_GROUP_CONTAINMENT_UNKNOWN
- + OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN;
- }
-
- /**
- * Returns the value of structure flags value
- *
- * @return the value of structure flags value
- */
- public byte getValue() {
- return (byte)this.value;
- }
-}
\ No newline at end of file