* @return a new graphics object
*/
public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) {
- GraphicsObject graphicsObj = factory.createGraphic();
+ GraphicsObject graphicsObj = factory.createGraphicsObject();
// paint the graphic using batik
graphicsObjectInfo.getPainter().paint(graphicsObj);
return graphicsObj;
/**
* Creates and returns a new include object.
*
- * @param name the name of this include object
+ * @param includeName the include name
* @param dataObjectInfo a data object info
*
* @return a new include object
*/
- public IncludeObject createInclude(String name, AFPDataObjectInfo dataObjectInfo) {
- IncludeObject includeObj = factory.createInclude(name);
+ public IncludeObject createInclude(String includeName, AFPDataObjectInfo dataObjectInfo) {
+ IncludeObject includeObj = factory.createInclude(includeName);
if (dataObjectInfo instanceof AFPImageObjectInfo) {
+ // IOCA image object
includeObj.setObjectType(IncludeObject.TYPE_IMAGE);
} else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) {
+ // graphics object
includeObj.setObjectType(IncludeObject.TYPE_GRAPHIC);
} else {
+ // object container
includeObj.setObjectType(IncludeObject.TYPE_OTHER);
+
+ // set mandatory object classification
Registry.ObjectType objectType = dataObjectInfo.getObjectType();
if (objectType != null) {
// set object classification
// object scope not defined
ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT,
objectType, dataInContainer, containerHasOEG, dataInOCD);
+ } else {
+ throw new IllegalStateException(
+ "Failed to set Object Classification Triplet on Object Container.");
}
}
AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
- includeObj.setObjectArea(objectAreaInfo.getX(), objectAreaInfo.getY());
+ int xOffset = objectAreaInfo.getX();
+ int yOffset = objectAreaInfo.getY();
+ includeObj.setObjectAreaOffset(xOffset, yOffset);
includeObj.setObjectAreaSize(
objectAreaInfo.getWidth(), objectAreaInfo.getHeight());
- includeObj.setOrientation(objectAreaInfo.getRotation());
+ includeObj.setObjectAreaOrientation(objectAreaInfo.getRotation());
includeObj.setMeasurementUnits(
objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes());
resourceObj.setType(ResourceObject.TYPE_OVERLAY_OBJECT);
} else if (namedObj instanceof AbstractDataObject) {
AbstractDataObject dataObj = (AbstractDataObject)namedObj;
-
- // other type by default
-// byte fqnType = FullyQualifiedNameTriplet.TYPE_OTHER_OBJECT_DATA_REF;
if (namedObj instanceof ObjectContainer) {
resourceObj.setType(ResourceObject.TYPE_OBJECT_CONTAINER);
ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT,
objectType, dataInContainer, containerHasOEG, dataInOCD);
} else if (namedObj instanceof ImageObject) {
- resourceObj.setType(ResourceObject.TYPE_IMAGE);
// ioca image type
-// fqnType = FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF;
+ resourceObj.setType(ResourceObject.TYPE_IMAGE);
} else if (namedObj instanceof GraphicsObject) {
resourceObj.setType(ResourceObject.TYPE_GRAPHIC);
} else {
throw new UnsupportedOperationException(
"Unsupported resource object for data object type " + dataObj);
}
-
- // set the map data resource
-// MapDataResource mapDataResource = factory.createMapDataResource();
-// mapDataResource.setFullyQualifiedName(
-// fqnType,
-// FullyQualifiedNameTriplet.FORMAT_CHARSTR,
-// resourceObj.getName());
-// dataObj.getObjectEnvironmentGroup().setMapDataResource(mapDataResource);
-
} else {
throw new UnsupportedOperationException(
"Unsupported resource object type " + namedObj);
RenderedImage ri = imgRend.getRenderedImage();
+
+
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
// Serialize image
imageObjectInfo.setData(baos.toByteArray());
imageObjectInfo.setDataHeight(ri.getHeight());
imageObjectInfo.setDataWidth(ri.getWidth());
+
boolean colorImages = state.isColorImages();
imageObjectInfo.setColor(colorImages);
- imageObjectInfo.setMimeType(colorImages
- ? MimeConstants.MIME_AFP_IOCA_FS45
- : MimeConstants.MIME_AFP_IOCA_FS10);
+
+ imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
imageObjectInfo.setBitsPerPixel(state.getBitsPerPixel());
AFPResourceManager resourceManager = info.getAFPResourceManager();
* @param graphicsObj the graphics object
*/
public void paint(GraphicsObject graphicsObj) {
- log.debug("Generating SVG");
+ log.debug("Painting SVG using GOCA " + graphicsObj.getName());
+
+ // set the graphics object
graphics2D.setGraphicsObject(graphicsObj);
+
+ // tell batik to paint the graphics object
root.paint(graphics2D);
+
+ // dispose of the graphics 2d implementation
graphics2D.dispose();
}
}
\ No newline at end of file
package org.apache.fop.render.afp;
+
/**
* A list of parameters associated with an image
*/
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();
+ imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
+ int resolution = state.getResolution();
objectAreaInfo.setWidthRes(resolution);
objectAreaInfo.setHeightRes(resolution);
- imageObjectInfo.setDataHeight(renderedImage.getHeight());
- imageObjectInfo.setDataWidth(renderedImage.getWidth());
+ ImageRendered imageRendered = (ImageRendered) afpImageInfo.img;
+ RenderedImage renderedImage = imageRendered.getRenderedImage();
+
+ int dataHeight = renderedImage.getHeight();
+ imageObjectInfo.setDataHeight(dataHeight);
+
+ int dataWidth = renderedImage.getWidth();
+ imageObjectInfo.setDataWidth(dataWidth);
+
+ ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baout);
+ byte[] imageData = baout.toByteArray();
boolean colorImages = state.isColorImages();
imageObjectInfo.setColor(colorImages);
- imageObjectInfo.setMimeType(colorImages
- ? MimeConstants.MIME_AFP_IOCA_FS45
- : MimeConstants.MIME_AFP_IOCA_FS10);
+
+ // convert to grayscale
+ if (!colorImages) {
+ baout.reset();
+ int bitsPerPixel = state.getBitsPerPixel();
+ imageObjectInfo.setBitsPerPixel(bitsPerPixel);
+ ImageEncodingHelper.encodeRGBAsGrayScale(
+ imageData, dataWidth, dataHeight, bitsPerPixel, baout);
+ imageData = baout.toByteArray();
+ }
+ imageObjectInfo.setData(imageData);
return imageObjectInfo;
}
return this.state;
}
+ /**
+ * Sets the default resource group file path
+ * @param filePath the default resource group file path
+ */
+ public void setDefaultResourceGroupFilePath(String filePath) {
+ resourceManager.setDefaultResourceGroupFilePath(filePath);
+ }
+
// TODO: remove this and use the superclass implementation
/** {@inheritDoc} */
protected void renderReferenceArea(Block block) {
currentBPPosition = saveBP;
}
- /**
- * Sets the default resource group file path
- * @param filePath the default resource group file path
- */
- public void setDefaultResourceGroupFilePath(String filePath) {
- resourceManager.setDefaultResourceGroupFilePath(filePath);
- }
-
}
// image information
Configuration imagesCfg = cfg.getChild("images");
if (!"color".equalsIgnoreCase(imagesCfg.getAttribute("mode", "b+w"))) {
+ afpRenderer.setColorImages(false);
afpRenderer.setBitsPerPixel(imagesCfg.getAttributeAsInteger("bits-per-pixel", 8));
} else {
afpRenderer.setColorImages(true);
}
+ // images are embedded directly without conversion to bitmapped IOCA
afpRenderer.setNativeImages(imagesCfg.getAttributeAsBoolean("native", false));
// renderer resolution
/** {@inheritDoc} */
public String toString() {
- return "AFPResourceInfo(uri=" + uri
+ return "AFPResourceInfo{uri=" + uri
+ (name != null ? ", name=" + name : "")
- + (level != null ? ", level=" + level : "") + ")";
+ + (level != null ? ", level=" + level : "")
+ + "}";
+
}
/** {@inheritDoc} */
private int instreamObjectCount = 0;
/** a mapping of resourceInfo --> include name */
- private final Map/*<ResourceInfo,String>*/ includeNameMap
- = new java.util.HashMap()/*<ResourceInfo,String>*/;
+ private final Map/*<AFPResourceInfo,String>*/ includeNameMap
+ = new java.util.HashMap()/*<AFPResourceInfo,String>*/;
/**
* Main constructor
}
// try and find an include name for the same resource
- String includeName = (String)includeNameMap.get(resourceInfo);
- if (includeName == null) {
+ String objectName = (String)includeNameMap.get(resourceInfo);
+ if (objectName == null) {
- boolean canInclude = false;
+ boolean useInclude = true;
Registry.ObjectType objectType = null;
// new resource so create
if (dataObjectInfo instanceof AFPImageObjectInfo) {
AFPImageObjectInfo imageObjectInfo = (AFPImageObjectInfo)dataObjectInfo;
namedObj = dataObjectFactory.createImage(imageObjectInfo);
- canInclude = true;
} else if (dataObjectInfo instanceof AFPGraphicsObjectInfo) {
namedObj = dataObjectFactory.createGraphic((AFPGraphicsObjectInfo)dataObjectInfo);
} else {
namedObj = dataObjectFactory.createObjectContainer(dataObjectInfo);
objectType = dataObjectInfo.getObjectType();
- canInclude = objectType != null && objectType.isIncludable();
+ useInclude = objectType != null && objectType.isIncludable();
}
// set data object viewport (i.e. position, rotation, dimension, resolution)
AFPResourceLevel resourceLevel = resourceInfo.getLevel();
ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel);
- canInclude &= resourceGroup != null;
-
- if (canInclude) {
+ useInclude &= resourceGroup != null;
+ if (useInclude) {
// 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
// add data object into its resource group destination
resourceGroup.addObject(namedObj);
- // add an include to the current page
- includeName = namedObj.getName();
+ // create the include object
+ objectName = namedObj.getName();
IncludeObject includeObject
- = dataObjectFactory.createInclude(includeName, dataObjectInfo);
+ = dataObjectFactory.createInclude(objectName, dataObjectInfo);
+
+ // add an include to the current page
dataStream.getCurrentPage().addObject(includeObject);
// record name of data object for the resource
- includeNameMap.put(resourceInfo, namedObj.getName());
+ includeNameMap.put(resourceInfo, objectName);
} else {
// not to be included so inline data object directly into the current page
dataStream.getCurrentPage().addObject(namedObj);
} else {
// an existing data resource so reference it by adding an include to the current page
IncludeObject includeObject
- = dataObjectFactory.createInclude(includeName, dataObjectInfo);
+ = dataObjectFactory.createInclude(objectName, dataObjectInfo);
dataStream.getCurrentPage().addObject(includeObject);
}
}
private int landscapeRotation = 270;
/** color image support */
- private boolean colorImages = true;
+ private boolean colorImages = false;
/** images are supported in this AFP environment */
private boolean nativeImages;
*/
public ResourceGroup getResourceGroup(AFPResourceLevel level) {
ResourceGroup resourceGroup = null;
+ if (level.isInline()) { // no resource group for inline level
+ return null;
+ }
if (level.isExternal()) {
String filePath = level.getExternalFilePath();
if (filePath == null) {
} else {
// resource group in afp document datastream
resourceGroup = dataStream.getResourceGroup(level);
-
}
return resourceGroup;
}
/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
- super.writeStart(os);
byte[] data = new byte[] {
(byte)0x68, // GBAR order code
(byte)(RES1 + (drawBoundary ? BOUNDARY : NO_BOUNDARY))
/** {@inheritDoc} */
public int getDataLength() {
- int dataLen = 14 + super.getDataLength();
- if (previous == null) {
- GraphicsChainedSegment current = this.next;
- while (current != null) {
- dataLen += current.getDataLength();
- current = current.next;
- }
- }
- return dataLen;
+ return 14 + super.getDataLength();
}
private static final byte APPEND_NEW_SEGMENT = 0;
/** {@inheritDoc} */
protected void writeStart(OutputStream os) throws IOException {
super.writeStart(os);
- int len = super.getDataLength();
- byte[] segLen = BinaryUtils.convert(len, 2);
+ byte[] data = new byte[14];
+ data[0] = 0x70; // BEGIN_SEGMENT
+ data[1] = 0x0C; // Length of following parameters
+
+ // segment name
byte[] nameBytes = getNameBytes();
- byte[] data = new byte[] {
- 0x70, // BEGIN_SEGMENT
- 0x0C, // Length of following parameters
- nameBytes[0],
- nameBytes[1],
- nameBytes[2],
- nameBytes[3],
- 0x00, // FLAG1 (ignored)
- APPEND_NEW_SEGMENT,
- segLen[0], // SEGL
- segLen[1],
- 0x00,
- 0x00,
- 0x00,
- 0x00
- };
+ System.arraycopy(nameBytes, 0, data, 2, NAME_LENGTH);
+
+ data[6] = 0x00; // FLAG1 (ignored)
+ data[7] = APPEND_NEW_SEGMENT;
+
+ int dataLength = super.getDataLength();
+ byte[] len = BinaryUtils.convert(dataLength, 2);
+ data[8] = len[0]; // SEGL
+ data[9] = len[1];
+
// P/S NAME (predecessor name)
if (previous != null) {
nameBytes = previous.getNameBytes();
protected void writeEnd(OutputStream os) throws IOException {
// I am the first segment in the chain so write out the rest
if (previous == null) {
- GraphicsChainedSegment current = this.next;
- while (current != null) {
- current.writeToStream(os);
- current = current.next;
+ for (GraphicsChainedSegment segment = next; segment != null; segment = segment.next) {
+ segment.writeToStream(os);
}
- }
+ } // else nothing todo
}
/** Begins a graphics area (start of fill) */
}
/** {@inheritDoc} */
- public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) {
+ public void addObject(PreparedAFPObject drawingOrder) {
if (currentArea != null) {
currentArea.addObject(drawingOrder);
} else {
super.addObject(drawingOrder);
}
- return drawingOrder;
}
/** {@inheritDoc} */
return 8 + super.getDataLength();
}
- /** {@inheritDoc} */
- protected void writeStart(OutputStream os) throws IOException {
- super.writeStart(os);
- int l = getDataLength();
- byte[] len = BinaryUtils.convert(l, 2);
- byte[] data = new byte[] {
- 0x5A, // Structured field identifier
- len[0], // Length byte 1
- len[1], // Length byte 2
- (byte) 0xD3, // Structured field id byte 1
- (byte) 0xEE, // Structured field id byte 2
- (byte) 0xBB, // Structured field id byte 3
- 0x00, // Flags
- 0x00, // Reserved
- 0x00 // Reserved
- };
- os.write(data);
- }
-
/**
* Begins a graphics area (start of fill)
*/
}
/** {@inheritDoc} */
- public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) {
+ public void addObject(PreparedAFPObject drawingOrder) {
if (currentSegment == null
|| (currentSegment.getDataLength() + drawingOrder.getDataLength())
>= GraphicsChainedSegment.MAX_DATA_LEN) {
newSegment();
}
currentSegment.addObject(drawingOrder);
- return drawingOrder;
+ }
+
+ /** {@inheritDoc} */
+ public void writeToStream(OutputStream os) throws IOException {
+ byte[] data = new byte[9];
+ copySF(data, SF_CLASS, Type.DATA, Category.GRAPHICS);
+ int dataLength = getDataLength();
+ byte[] len = BinaryUtils.convert(dataLength, 2);
+ data[1] = len[0]; // Length byte 1
+ data[2] = len[1]; // Length byte 2
+ os.write(data);
+
+ // get first segment in chain and write (including all its connected segments)
+ GraphicsChainedSegment firstSegment = (GraphicsChainedSegment)objects.get(0);
+ firstSegment.writeToStream(os);
}
/** {@inheritDoc} */
}
/**
- * Sets the image size parameters
- * resolution, hsize and vsize.
+ * Sets the image size parameter
*
- * @param hsize The horizontal size of the image.
- * @param vsize The vertival size of the image.
- * @param hresol The horizontal resolution of the image.
- * @param vresol The vertical resolution of the image.
+ * @param imageSizeParameter the image size parameter.
*/
- public void setImageSize(int hsize, int vsize, int hresol, int vresol) {
- imageSizeParameter = new ImageSizeParameter(hsize, vsize, hresol, vresol);
+ public void setImageSizeParameter(ImageSizeParameter imageSizeParameter) {
+ this.imageSizeParameter = imageSizeParameter;
}
/**
* Sets the image size parameters resolution, hsize and vsize.
*
* @param hsize The horizontal size of the image.
- * @param vsize The vertival size of the image.
+ * @param vsize The vertical size of the image.
* @param hresol The horizontal resolution of the image.
* @param vresol The vertical resolution of the image.
*/
public void setImageSize(int hsize, int vsize, int hresol, int vresol) {
- getImageContent().setImageSize(hsize, vsize, hresol, vresol);
+ ImageSizeParameter imageSizeParameter
+ = factory.createImageSizeParameter(hsize, vsize, hresol, vresol);
+ getImageContent().setImageSizeParameter(imageSizeParameter);
}
/**
* the object area info
*/
public void setViewport(AFPDataObjectInfo dataObjectInfo) {
+ AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
+
+ // object area descriptor
+ int width = objectAreaInfo.getWidth();
+ int height = objectAreaInfo.getHeight();
+ int widthRes = objectAreaInfo.getWidthRes();
+ int heightRes = objectAreaInfo.getHeightRes();
+ ObjectAreaDescriptor objectAreaDescriptor
+ = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes);
+ getObjectEnvironmentGroup().setObjectAreaDescriptor(objectAreaDescriptor);
+
+ // object area position
AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
AFPResourceLevel resourceLevel = resourceInfo.getLevel();
-
- // only need to set OAD and OAP inlined (pre-2000 apps)
+ ObjectAreaPosition objectAreaPosition = null;
if (resourceLevel.isInline()) {
- AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
- getObjectEnvironmentGroup().setObjectArea(objectAreaInfo);
+ int x = objectAreaInfo.getX();
+ int y = objectAreaInfo.getY();
+ int rotation = objectAreaInfo.getRotation();
+ objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation);
+ } else {
+ // positional values are specified in the oaOffset of the include object
+ objectAreaPosition = factory.createObjectAreaPosition(0, 0, 0);
}
+ getObjectEnvironmentGroup().setObjectAreaPosition(objectAreaPosition);
}
/**
if (rotation != 0) {
switch (rotation) {
case 90:
- activeEnvironmentGroup.setPosition(width, 0, rotation);
+ activeEnvironmentGroup.setObjectAreaPosition(width, 0, rotation);
break;
case 180:
- activeEnvironmentGroup.setPosition(width, height, rotation);
+ activeEnvironmentGroup.setObjectAreaPosition(width, height, rotation);
break;
case 270:
- activeEnvironmentGroup.setPosition(0, height, rotation);
+ activeEnvironmentGroup.setObjectAreaPosition(0, height, rotation);
break;
default:
}
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)
/**
* Named constructor
- *
+ *
* @param name the name of this AFP object
*/
public AbstractPreparedAFPObject(String name) {
}
/**
+ * 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() {
}
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) {
implements PreparedAFPObject {
/** list of objects contained within this container */
- protected List/*<PreparedAFPObject>*/ objects = null;
+ protected List/*<PreparedAFPObject>*/ objects
+ = new java.util.ArrayList/*<PreparedAFPObject>*/();
/**
* Default constructor
/** {@inheritDoc} */
protected void writeContent(OutputStream os) throws IOException {
- super.writeObjects(objects, os);
- }
-
- private List/*<PreparedAFPObject>*/ getObjects() {
- if (objects == null) {
- this.objects = new java.util.ArrayList/*<PreparedAFPObject>*/();
- }
- return this.objects;
+ writeObjects(objects, os);
}
/**
* Adds a given prepared object to this container
*
* @param preparedObject the prepared object
- * @return the drawingOrder if it was added, null otherwise
*/
- public PreparedAFPObject addObject(PreparedAFPObject preparedObject) {
- getObjects().add(preparedObject);
- return preparedObject;
+ public void addObject(PreparedAFPObject preparedObject) {
+ objects.add(preparedObject);
}
/**
*/
public int getDataLength() {
int dataLen = 0;
- if (objects != null) {
- Iterator it = objects.iterator();
- while (it.hasNext()) {
- Object obj = it.next();
- if (obj instanceof PreparedAFPObject) {
- dataLen += ((PreparedAFPObject)obj).getDataLength();
- }
+ Iterator it = objects.iterator();
+ while (it.hasNext()) {
+ Object obj = it.next();
+ if (obj instanceof PreparedAFPObject) {
+ PreparedAFPObject prepObj = (PreparedAFPObject)obj;
+ dataLen += prepObj.getDataLength();
}
}
return dataLen;
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.Triplet;
import org.apache.fop.render.afp.tools.BinaryUtils;
objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD));
}
- /**
- * Sets the extent of an object area in the X and Y directions
- *
- * @param x the x direction extent
- * @param y the y direction extent
- */
- public void setObjectAreaSize(int x, int y) {
- addTriplet(new ObjectAreaSizeTriplet(x, y));
- }
-
- /**
- * Sets the measurement units used to specify the units of measure
- *
- * @param xRes units per base on the x-axis
- * @param yRes units per base on the y-axis
- */
- public void setMeasurementUnits(int xRes, int yRes) {
- addTriplet(new MeasurementUnitsTriplet(xRes, xRes));
- }
-
/**
* Sets a comment on this resource
*
public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup {
/** The collection of MapCodedFont objects */
- private List/*<MapCodedFonts>*/ mapCodedFonts = null;
+ private final List/*<MapCodedFonts>*/ mapCodedFonts
+ = new java.util.ArrayList/*<MapCodedFonts>*/();
/** the collection of MapDataResource objects */
private final List mapDataResources = null;
this.factory = factory;
// Create PageDescriptor
- pageDescriptor = new PageDescriptor(width, height, widthRes, heightRes);
+ this.pageDescriptor
+ = factory.createPageDescriptor(width, height, widthRes, heightRes);
// Create ObjectAreaDescriptor
- objectAreaDescriptor = new ObjectAreaDescriptor(width, height,
- widthRes, heightRes);
+ this.objectAreaDescriptor
+ = factory.createObjectAreaDescriptor(width, height, widthRes, heightRes);
// Create PresentationTextDataDescriptor
- presentationTextDataDescriptor = new PresentationTextDescriptor(width, height,
- widthRes, heightRes);
+ this.presentationTextDataDescriptor
+ = factory.createPresentationTextDataDescriptor(width, height,
+ widthRes, heightRes);
}
/**
* @param y the y offset
* @param rotation the rotation
*/
- public void setPosition(int x, int y, int rotation) {
- // Create ObjectAreaPosition
- objectAreaPosition = new ObjectAreaPosition(x, y, rotation);
+ public void setObjectAreaPosition(int x, int y, int rotation) {
+ this.objectAreaPosition = factory.createObjectAreaPosition(x, y, rotation);
}
/**
os.write(data);
}
- private List getMapCodedFonts() {
- if (mapCodedFonts == null) {
- mapCodedFonts = new java.util.ArrayList();
- }
- return mapCodedFonts;
- }
-
/**
* Method to create a map coded font object
*
* @param orientation the orientation of the font (e.g. 0, 90, 180, 270)
*/
public void createFont(int fontRef, AFPFont font, int size, int orientation) {
- MapCodedFont mcf = getCurrentMapCodedFont();
- if (mcf == null) {
- mcf = factory.createMapCodedFont();
- getMapCodedFonts().add(mcf);
+ MapCodedFont mapCodedFont = getCurrentMapCodedFont();
+ if (mapCodedFont == null) {
+ mapCodedFont = factory.createMapCodedFont();
+ mapCodedFonts.add(mapCodedFont);
}
try {
- mcf.addFont(fontRef, font, size, orientation);
+ mapCodedFont.addFont(fontRef, font, size, orientation);
} catch (MaximumSizeExceededException msee) {
- mcf = factory.createMapCodedFont();
- getMapCodedFonts().add(mcf);
+ mapCodedFont = factory.createMapCodedFont();
+ mapCodedFonts.add(mapCodedFont);
try {
- mcf.addFont(fontRef, font, size, orientation);
+ mapCodedFont.addFont(fontRef, font, size, orientation);
} catch (MaximumSizeExceededException ex) {
// Should never happen (but log just in case)
log.error("createFont():: resulted in a MaximumSizeExceededException");
* @return the most recent Map Coded Font.
*/
private MapCodedFont getCurrentMapCodedFont() {
- int size = getMapCodedFonts().size();
+ int size = mapCodedFonts.size();
if (size > 0) {
return (MapCodedFont)mapCodedFonts.get(size - 1);
} else {
import org.apache.fop.render.afp.ioca.ImageContent;
import org.apache.fop.render.afp.ioca.ImageRasterData;
import org.apache.fop.render.afp.ioca.ImageSegment;
+import org.apache.fop.render.afp.ioca.ImageSizeParameter;
import org.apache.fop.render.afp.tools.StringUtils;
/**
*
* @return a new {@link GraphicsObject}
*/
- public GraphicsObject createGraphic() {
+ public GraphicsObject createGraphicsObject() {
String name = GRAPHIC_NAME_PREFIX
+ StringUtils.lpad(String.valueOf(++graphicCount), '0', 5);
GraphicsObject graphicsObj = new GraphicsObject(this, name);
public ObjectEnvironmentGroup createObjectEnvironmentGroup() {
String oegName = OBJECT_ENVIRONMENT_GROUP_NAME_PREFIX
+ StringUtils.lpad(String.valueOf(++objectEnvironmentGroupCount), '0', 5);
- ObjectEnvironmentGroup objectEnvironmentGroup = new ObjectEnvironmentGroup(this, oegName);
+ ObjectEnvironmentGroup objectEnvironmentGroup = new ObjectEnvironmentGroup(oegName);
return objectEnvironmentGroup;
}
return mapDataResource;
}
+ /**
+ * Creates a new PTOCA {@link PresentationTextDescriptor}
+ *
+ * @return a new {@link PresentationTextDescriptor}
+ */
+ public PresentationTextDescriptor createPresentationTextDataDescriptor(
+ int width, int height, int widthRes, int heightRes) {
+ PresentationTextDescriptor presentationTextDescriptor
+ = new PresentationTextDescriptor(width, height,
+ widthRes, heightRes);
+ return presentationTextDescriptor;
+ }
+
/**
* Creates a new MO:DCA {@link PresentationEnvironmentControl}
*
return imageRasterData;
}
+ /**
+ * Creates an new IOCA {@link ImageSizeParameter}.
+ *
+ * @param hsize The horizontal size of the image.
+ * @param vsize The vertical size of the image.
+ * @param hresol The horizontal resolution of the image.
+ * @param vresol The vertical resolution of the image.
+ * @return a new {@link ImageSizeParameter}
+ */
+ public ImageSizeParameter createImageSizeParameter(int hsize, int vsize,
+ int hresol, int vresol) {
+ ImageSizeParameter imageSizeParameter
+ = new ImageSizeParameter(hsize, vsize, hresol, vresol);
+ return imageSizeParameter;
+ }
+
}
public class GraphicsObject extends AbstractDataObject {
/** The graphics data */
- private GraphicsData graphicsData = null;
+ private GraphicsData currentGraphicsData = null;
/** list of objects contained within this container */
protected List/*<PreparedAFPObject>*/ objects
super.setViewport(dataObjectInfo);
AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
- GraphicsDataDescriptor graphicsDataDescriptor
- = factory.createGraphicsDataDescriptor(
- 0,
- objectAreaInfo.getWidth(),
- 0,
- objectAreaInfo.getHeight(),
- objectAreaInfo.getWidthRes(),
- objectAreaInfo.getHeightRes());
+ int width = objectAreaInfo.getWidth();
+ int height = objectAreaInfo.getHeight();
+ int widthRes = objectAreaInfo.getWidthRes();
+ int heightRes = objectAreaInfo.getHeightRes();
+ final int leftEdge = 0;
+ final int topEdge = 0;
+ GraphicsDataDescriptor graphicsDataDescriptor = factory.createGraphicsDataDescriptor(
+ leftEdge, width, topEdge, height, widthRes, heightRes);
getObjectEnvironmentGroup().setDataDescriptor(graphicsDataDescriptor);
}
/** {@inheritDoc} */
- public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) {
- if (graphicsData == null
- || (graphicsData.getDataLength() + drawingOrder.getDataLength())
+ public void addObject(PreparedAFPObject drawingOrder) {
+ if (currentGraphicsData == null
+ || (currentGraphicsData.getDataLength() + drawingOrder.getDataLength())
>= GraphicsData.MAX_DATA_LEN) {
newData();
}
- graphicsData.addObject(drawingOrder);
- return drawingOrder;
+ currentGraphicsData.addObject(drawingOrder);
}
/**
* @return the current graphics data
*/
private GraphicsData getData() {
- if (this.graphicsData == null) {
+ if (this.currentGraphicsData == null) {
return newData();
}
- return this.graphicsData;
+ return this.currentGraphicsData;
}
/**
* @return a newly created graphics data
*/
private GraphicsData newData() {
- this.graphicsData = factory.createGraphicsData();
- objects.add(graphicsData);
- return graphicsData;
+ this.currentGraphicsData = factory.createGraphicsData();
+ objects.add(currentGraphicsData);
+ return currentGraphicsData;
}
/**
* Sets the current color
*
- * @param col the active color to use
+ * @param color the active color to use
*/
- public void setColor(Color col) {
- addObject(new GraphicsSetProcessColor(col));
+ public void setColor(Color color) {
+ addObject(new GraphicsSetProcessColor(color));
}
/**
* @param multiplier the line width multiplier
*/
public void setLineWidth(int multiplier) {
- GraphicsSetLineWidth lw = new GraphicsSetLineWidth(multiplier);
- addObject(lw);
+ GraphicsSetLineWidth graphicsSetLineWidth = new GraphicsSetLineWidth(multiplier);
+ addObject(graphicsSetLineWidth);
}
/**
* @param type the line type
*/
public void setLineType(byte type) {
- GraphicsSetLineType lt = new GraphicsSetLineType(type);
- addObject(lt);
+ GraphicsSetLineType graphicsSetLineType = new GraphicsSetLineType(type);
+ addObject(graphicsSetLineType);
}
/**
* @param fill whether to fill the next shape
*/
public void setFill(boolean fill) {
- GraphicsSetPatternSymbol pat = new GraphicsSetPatternSymbol(
+ GraphicsSetPatternSymbol graphicsSetPattern = new GraphicsSetPatternSymbol(
fill ? GraphicsSetPatternSymbol.SOLID_FILL
: GraphicsSetPatternSymbol.NO_FILL
);
- addObject(pat);
+ addObject(graphicsSetPattern);
}
/**
* Begins a graphics area (start of fill)
*/
public void beginArea() {
- if (graphicsData == null) {
+ if (currentGraphicsData == null) {
newData();
}
- graphicsData.beginArea();
+ currentGraphicsData.beginArea();
}
/**
* Ends a graphics area (end of fill)
*/
public void endArea() {
- if (graphicsData != null) {
- graphicsData.endArea();
+ if (currentGraphicsData != null) {
+ currentGraphicsData.endArea();
}
}
import java.io.OutputStream;
import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet;
+import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet;
+import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet;
import org.apache.fop.render.afp.tools.BinaryUtils;
/**
private byte objectType = TYPE_OTHER;
/**
- * The orientation on the include object
+ * The X-axis origin of the object area
*/
- private int orientation = 0;
+ private int xoaOset = 0;
/**
- * The X-axis origin of the object area
+ * The Y-axis origin of the object area
*/
- private int xOffset = 0;
+ private int yoaOset = 0;
/**
- * The Y-axis origin of the object area
+ * The orientation on the include object
*/
- private int yOffset = 0;
+ private int oaOrent = 0;
/**
* The X-axis origin defined in the object
*/
- private int xContentOffset = 0;
+ private int xocaOset = -1;
/**
* The Y-axis origin defined in the object
*/
- private int yContentOffset = 0;
+ private int yocaOset = -1;
/**
* Constructor for the include object with the specified name, the name must
* @param orientation
* The orientation (0,90, 180, 270)
*/
- public void setOrientation(int orientation) {
+ public void setObjectAreaOrientation(int orientation) {
if (orientation == 0 || orientation == 90 || orientation == 180
|| orientation == 270) {
- this.orientation = orientation;
+ this.oaOrent = orientation;
} else {
throw new IllegalArgumentException(
"The orientation must be one of the values 0, 90, 180, 270");
* @param x the X-axis origin of the object area
* @param y the Y-axis origin of the object area
*/
- public void setObjectArea(int x, int y) {
- this.xOffset = x;
- this.yOffset = y;
+ public void setObjectAreaOffset(int x, int y) {
+ this.xoaOset = x;
+ this.yoaOset = y;
}
/**
* Sets the x and y offset of the content area to the object area
+ * used in conjunction with the {@link MappingOptionTriplet.POSITION} and
+ * {@link MappingOptionTriplet.POSITION_AND_TRIM}.
*
* @param x the X-axis origin defined in the object
* @param y the Y-axis origin defined in the object
*/
- public void setContentArea(int x, int y) {
- this.xContentOffset = x;
- this.yContentOffset = y;
+ public void setContentAreaOffset(int x, int y) {
+ this.xocaOset = x;
+ this.yocaOset = y;
}
/**
super.copySF(data, Type.INCLUDE, Category.DATA_RESOURCE);
// Set the total record length
- byte[] len = BinaryUtils.convert(35 + getTripletDataLength(), 2); //Ignore first byte
+ int tripletDataLength = getTripletDataLength();
+ byte[] len = BinaryUtils.convert(35 + tripletDataLength, 2); //Ignore first byte
data[1] = len[0];
data[2] = len[1];
data[18] = objectType;
//XoaOset (object area)
- if (xOffset >= -1) {
- byte[] x = BinaryUtils.convert(xOffset, 3);
+ if (xoaOset > -1) {
+ byte[] x = BinaryUtils.convert(xoaOset, 3);
data[19] = x[0];
data[20] = x[1];
data[21] = x[2];
}
// YoaOset (object area)
- if (yOffset > -1) {
- byte[] y = BinaryUtils.convert(yOffset, 3);
+ if (yoaOset > -1) {
+ byte[] y = BinaryUtils.convert(yoaOset, 3);
data[22] = y[0];
data[23] = y[1];
data[24] = y[2];
}
// XoaOrent/YoaOrent
- switch (orientation) {
+ switch (oaOrent) {
case -1: // use x/y axis orientation defined in object
data[25] = (byte)0xFF; // x axis rotation
data[26] = (byte)0xFF; //
data[27] = 0x00;
data[28] = 0x00;
break;
- default:
+ default: // 0 degrees
data[25] = 0x00;
data[26] = 0x00;
data[27] = 0x2D;
}
// XocaOset (object content)
- if (xContentOffset > -1) {
- byte[] y = BinaryUtils.convert(xContentOffset, 3);
- data[29] = y[0];
- data[30] = y[1];
- data[31] = y[2];
+ if (xocaOset > -1) {
+ byte[] x = BinaryUtils.convert(xocaOset, 3);
+ data[29] = x[0];
+ data[30] = x[1];
+ data[31] = x[2];
} else {
data[29] = (byte)0xFF;
data[30] = (byte)0xFF;
}
// YocaOset (object content)
- if (yContentOffset > -1) {
- byte[] y = BinaryUtils.convert(yContentOffset, 3);
+ if (yocaOset > -1) {
+ byte[] y = BinaryUtils.convert(yocaOset, 3);
data[32] = y[0];
data[33] = y[1];
data[34] = y[2];
data[33] = (byte)0xFF;
data[34] = (byte)0xFF;
}
- data[35] = 0x01;
+ // RefCSys (Reference coordinate system)
+ data[35] = 0x01; // Page or overlay coordinate system
// Write structured field data
os.write(data);
// Write triplet for FQN internal/external object reference
- os.write(tripletData);
+ if (tripletData != null) {
+ os.write(tripletData);
+ }
+ }
+
+ private String getObjectTypeName() {
+ String objectTypeName = null;
+ if (objectType == TYPE_PAGE_SEGMENT) {
+ objectTypeName = "page segment";
+ } else if (objectType == TYPE_OTHER) {
+ objectTypeName = "other";
+ } else if (objectType == TYPE_GRAPHIC) {
+ objectTypeName = "graphic";
+ } else if (objectType == TYPE_BARCODE) {
+ objectTypeName = "barcode";
+ } else if (objectType == TYPE_IMAGE) {
+ objectTypeName = "image";
+ }
+ return objectTypeName;
}
/** {@inheritDoc} */
public String toString() {
- return "IOB: " + this.getName();
+ return "IncludeObject{name=" + this.getName()
+ + ", objectType=" + getObjectTypeName()
+ + ", xoaOset=" + xoaOset
+ + ", yoaOset=" + yoaOset
+ + ", oaOrent" + oaOrent
+ + ", xocaOset=" + xocaOset
+ + ", yocaOset=" + yocaOset
+ + "}";
}
/**
public void setMappingOption(byte optionValue) {
addTriplet(new MappingOptionTriplet(optionValue));
}
+
+ /**
+ * Sets the extent of an object area in the X and Y directions
+ *
+ * @param x the x direction extent
+ * @param y the y direction extent
+ */
+ public void setObjectAreaSize(int x, int y) {
+ addTriplet(new ObjectAreaSizeTriplet(x, y));
+ }
+
+ /**
+ * Sets the measurement units used to specify the units of measure
+ *
+ * @param xRes units per base on the x-axis
+ * @param yRes units per base on the y-axis
+ */
+ public void setMeasurementUnits(int xRes, int yRes) {
+ addTriplet(new MeasurementUnitsTriplet(xRes, xRes));
+ }
+
}
\ No newline at end of file
*/
public ObjectContainer(Factory factory, String name) {
super(factory, name);
-
-// PresentationEnvironmentControl presentationEnvironmentControl
-// = factory.createPresentationEnvironmentControl();
-// getObjectEnvironmentGroup().setPresentationEnvironmentControl(
-// presentationEnvironmentControl);
-
}
/** {@inheritDoc} */
/** {@inheritDoc} */
public void setViewport(AFPDataObjectInfo dataObjectInfo) {
- super.setViewport(dataObjectInfo);
-
- AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
-
AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
AFPResourceLevel resourceLevel = resourceInfo.getLevel();
- // only need to set MCD and CDD when OC is inljned (pre-2000 apps)
+ // only need to set MCD and CDD when OC when is inlined (pre-2000 apps)
if (resourceLevel.isInline()) {
+ super.setViewport(dataObjectInfo);
+
MapContainerData mapContainerData
= factory.createMapContainerData(MappingOptionTriplet.SCALE_TO_FIT);
getObjectEnvironmentGroup().setMapContainerData(mapContainerData);
int dataWidth = dataObjectInfo.getDataWidth();
int dataHeight = dataObjectInfo.getDataHeight();
+
+ AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo();
int widthRes = objectAreaInfo.getWidthRes();
int heightRes = objectAreaInfo.getHeightRes();
+
ContainerDataDescriptor containerDataDescriptor
= factory.createContainerDataDescriptor(
dataWidth, dataHeight, widthRes, heightRes);
import java.io.IOException;
import java.io.OutputStream;
-import org.apache.fop.render.afp.AFPObjectAreaInfo;
import org.apache.fop.render.afp.tools.BinaryUtils;
/**
*/
public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject {
- private final Factory factory;
-
/** the PresentationEnvironmentControl for the object environment group */
private PresentationEnvironmentControl presentationEnvironmentControl = null;
* Constructor for the ObjectEnvironmentGroup, this takes a
* name parameter which must be 8 characters long.
*
- * @param factory the object factory
* @param name the object environment group name
*/
- public ObjectEnvironmentGroup(Factory factory, String name) {
+ public ObjectEnvironmentGroup(String name) {
super(name);
- this.factory = factory;
}
/**
- * Sets the object area parameters.
+ * Sets the Object Area Descriptor
*
- * @param info the object area info
+ * @param objectAreaDescriptor the object area descriptor
*/
- public void setObjectArea(AFPObjectAreaInfo info) {
- this.objectAreaDescriptor = factory.createObjectAreaDescriptor(
- info.getWidth(), info.getHeight(), info.getWidthRes(), info.getHeightRes());
- this.objectAreaPosition = factory.createObjectAreaPosition(
- info.getX(), info.getY(), info.getRotation());
+ public void setObjectAreaDescriptor(ObjectAreaDescriptor objectAreaDescriptor) {
+ this.objectAreaDescriptor = objectAreaDescriptor;
+ }
+
+ /**
+ * Sets the Object Area Position
+ *
+ * @param objectAreaPosition the object area position
+ */
+ public void setObjectAreaPosition(ObjectAreaPosition objectAreaPosition) {
+ this.objectAreaPosition = objectAreaPosition;
}
/** {@inheritDoc} */
byte[] data = new byte[17];
copySF(data, Type.BEGIN, Category.OBJECT_ENVIRONMENT_GROUP);
- int sfLen = data.length + getTripletDataLength() - 1;
+ int tripletDataLength = getTripletDataLength();
+ int sfLen = data.length + tripletDataLength - 1;
byte[] len = BinaryUtils.convert(sfLen, 2);
data[1] = len[0];
data[2] = len[1];
public void setMapContainerData(MapContainerData mapContainerData) {
this.mapContainerData = mapContainerData;
}
+
}
* 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.
* 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
+ * all enclosed GOCA drawing objects
*/
int getDataLength();
}
\ No newline at end of file
copySF(data, Type.BEGIN, Category.NAME_RESOURCE);
// Set the total record length
- byte[] len = BinaryUtils.convert(18 + getTripletDataLength(), 2);
+ int tripletDataLength = getTripletDataLength();
+ byte[] len = BinaryUtils.convert(18 + tripletDataLength, 2);
data[1] = len[0]; // Length byte 1
data[2] = len[1]; // Length byte 2
public static final byte TYPE_GRAPHIC = 0x03;
/** barcode object type */
- public static final byte BARCODE = 0x05;
+ public static final byte TYPE_BARCODE = 0x05;
/** image object type */
public static final byte TYPE_IMAGE = 0x06;
-// private static final byte FONT_CHARACTER_SET = 0x40;
+ /** font character set type */
+ public static final byte TYPE_FONT_CHARACTER_SET = 0x40;
-// private static final byte CODE_PAGE = 0x41;
+ /** code page type */
+ public static final byte TYPE_CODE_PAGE = 0x41;
-// private static final byte CODED_FONT = 0x42;
+ /** coded font type */
+ public static final byte TYPE_CODED_FONT = 0x42;
/** object container type */
public static final byte TYPE_OBJECT_CONTAINER = (byte) 0x92;
/** overlay object type */
public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC;
-// private static final byte PAGEDEF = (byte) 0xFD;
+ /** page def type */
+ public static final byte TYPE_PAGEDEF = (byte) 0xFD;
-// private static final byte FORMDEF = (byte) 0xFE;
+ /** 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 type the resource object type
+ * @param objectType the resource object type
*/
- public ResourceObjectTypeTriplet(byte type) {
+ public ResourceObjectTypeTriplet(byte objectType) {
super(RESOURCE_OBJECT,
new byte[] {
- type,
+ objectType,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Constant Data
}
);