diff options
Diffstat (limited to 'src/java')
29 files changed, 394 insertions, 316 deletions
diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java index cba8bd71e..d31b79cc4 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java @@ -120,7 +120,7 @@ public class AFPDataObjectFactory { * @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; @@ -129,20 +129,25 @@ public class AFPDataObjectFactory { /** * 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 @@ -153,17 +158,22 @@ public class AFPDataObjectFactory { // 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()); @@ -199,9 +209,6 @@ public class AFPDataObjectFactory { 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); @@ -214,24 +221,14 @@ public class AFPDataObjectFactory { 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); diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java index e5049ce07..cb33e5a5a 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java @@ -426,6 +426,9 @@ public class AFPGraphics2D extends AbstractGraphics2D { RenderedImage ri = imgRend.getRenderedImage(); + + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { // Serialize image @@ -465,11 +468,11 @@ public class AFPGraphics2D extends AbstractGraphics2D { 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(); diff --git a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java b/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java index 79788b091..b794ff93c 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java @@ -59,9 +59,15 @@ public class AFPGraphicsObjectPainter { * @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 diff --git a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java index 23bef01de..c4b901b7c 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java @@ -20,6 +20,7 @@ package org.apache.fop.render.afp; + /** * A list of parameters associated with an image */ diff --git a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java index 15d7a3173..4ce6b27b0 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java @@ -46,28 +46,39 @@ public class AFPImageRenderedFactory extends AFPDataObjectInfoFactory { 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; } diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 056792fdd..9a7fa7515 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -805,6 +805,14 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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) { @@ -841,12 +849,4 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { 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); - } - } diff --git a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java index 794f5bda8..85784af55 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java @@ -235,10 +235,12 @@ public class AFPRendererConfigurator extends PrintRendererConfigurator { // 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 diff --git a/src/java/org/apache/fop/render/afp/AFPResourceInfo.java b/src/java/org/apache/fop/render/afp/AFPResourceInfo.java index d6d308883..cdb7c0961 100644 --- a/src/java/org/apache/fop/render/afp/AFPResourceInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPResourceInfo.java @@ -94,9 +94,11 @@ public class AFPResourceInfo { /** {@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} */ diff --git a/src/java/org/apache/fop/render/afp/AFPResourceManager.java b/src/java/org/apache/fop/render/afp/AFPResourceManager.java index 566834e4b..5a28efe26 100644 --- a/src/java/org/apache/fop/render/afp/AFPResourceManager.java +++ b/src/java/org/apache/fop/render/afp/AFPResourceManager.java @@ -54,8 +54,8 @@ public class AFPResourceManager { 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 @@ -127,23 +127,22 @@ public class AFPResourceManager { } // 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) @@ -154,9 +153,8 @@ public class AFPResourceManager { 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 @@ -166,14 +164,16 @@ public class AFPResourceManager { // 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); @@ -181,7 +181,7 @@ public class AFPResourceManager { } 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); } } diff --git a/src/java/org/apache/fop/render/afp/AFPState.java b/src/java/org/apache/fop/render/afp/AFPState.java index 709e151f6..2f01e8371 100644 --- a/src/java/org/apache/fop/render/afp/AFPState.java +++ b/src/java/org/apache/fop/render/afp/AFPState.java @@ -41,7 +41,7 @@ public class AFPState extends org.apache.fop.render.AbstractState implements Clo 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; diff --git a/src/java/org/apache/fop/render/afp/AFPStreamer.java b/src/java/org/apache/fop/render/afp/AFPStreamer.java index 25a631aa9..0759b85fc 100644 --- a/src/java/org/apache/fop/render/afp/AFPStreamer.java +++ b/src/java/org/apache/fop/render/afp/AFPStreamer.java @@ -117,6 +117,9 @@ public class AFPStreamer implements Streamable { */ 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) { @@ -147,7 +150,6 @@ public class AFPStreamer implements Streamable { } else { // resource group in afp document datastream resourceGroup = dataStream.getResourceGroup(level); - } return resourceGroup; } diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java b/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java index 06cc8451f..7ad6ede27 100644 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsArea.java @@ -53,7 +53,6 @@ public final class GraphicsArea extends AbstractPreparedObjectContainer { /** {@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)) diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java index 89803507c..ba4ccea86 100644 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java @@ -69,15 +69,7 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine /** {@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; @@ -94,26 +86,23 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine /** {@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(); @@ -126,12 +115,10 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine 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) */ @@ -146,13 +133,12 @@ public final class GraphicsChainedSegment extends AbstractPreparedObjectContaine } /** {@inheritDoc} */ - public PreparedAFPObject addObject(PreparedAFPObject drawingOrder) { + public void addObject(PreparedAFPObject drawingOrder) { if (currentArea != null) { currentArea.addObject(drawingOrder); } else { super.addObject(drawingOrder); } - return drawingOrder; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/goca/GraphicsData.java b/src/java/org/apache/fop/render/afp/goca/GraphicsData.java index ad346dfb7..538933a03 100644 --- a/src/java/org/apache/fop/render/afp/goca/GraphicsData.java +++ b/src/java/org/apache/fop/render/afp/goca/GraphicsData.java @@ -43,25 +43,6 @@ public final class GraphicsData extends AbstractPreparedObjectContainer { 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) */ @@ -116,14 +97,28 @@ public final class GraphicsData extends AbstractPreparedObjectContainer { } /** {@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} */ diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageContent.java b/src/java/org/apache/fop/render/afp/ioca/ImageContent.java index a0e14e12e..7143b986c 100644 --- a/src/java/org/apache/fop/render/afp/ioca/ImageContent.java +++ b/src/java/org/apache/fop/render/afp/ioca/ImageContent.java @@ -89,16 +89,12 @@ public class ImageContent extends AbstractStructuredAFPObject { } /** - * 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; } /** diff --git a/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java b/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java index e5e1bbd23..8f6e6a59c 100644 --- a/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java +++ b/src/java/org/apache/fop/render/afp/ioca/ImageSegment.java @@ -67,12 +67,14 @@ public class ImageSegment extends AbstractNamedAFPObject { * 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); } /** diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java index b0d59ced7..b59af4157 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java @@ -57,14 +57,31 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject { * 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); } /** diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java index 7dcd7ea35..3ce108bfc 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -278,13 +278,13 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { 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: } diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java index 16ed036f2..42b729cf0 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java @@ -22,7 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; - /** * A base class that carries out early preparation of structured field data * for the AFP object (so the data length can be pre-calculated) @@ -41,7 +40,7 @@ implements PreparedAFPObject { /** * Named constructor - * + * * @param name the name of this AFP object */ public AbstractPreparedAFPObject(String name) { @@ -57,13 +56,17 @@ implements PreparedAFPObject { } /** + * 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() { @@ -72,17 +75,19 @@ implements PreparedAFPObject { } 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) { diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java index f16d2df81..5d32a6b9b 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java @@ -31,7 +31,8 @@ public abstract class AbstractPreparedObjectContainer extends AbstractNamedAFPOb 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 @@ -50,25 +51,16 @@ implements PreparedAFPObject { /** {@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); } /** @@ -79,13 +71,12 @@ implements PreparedAFPObject { */ 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; diff --git a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java index 4c31472bd..dee0366cb 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java @@ -30,8 +30,6 @@ 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.Triplet; import org.apache.fop.render.afp.tools.BinaryUtils; @@ -235,26 +233,6 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } /** - * 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 * * @param comment a comment string diff --git a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java index c254ef17b..da418aca6 100644 --- a/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java @@ -41,7 +41,8 @@ import org.apache.fop.render.afp.fonts.AFPFont; 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; @@ -79,15 +80,17 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { 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); } /** @@ -97,9 +100,8 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { * @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); } /** @@ -156,13 +158,6 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { os.write(data); } - private List getMapCodedFonts() { - if (mapCodedFonts == null) { - mapCodedFonts = new java.util.ArrayList(); - } - return mapCodedFonts; - } - /** * Method to create a map coded font object * @@ -172,20 +167,20 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { * @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"); @@ -200,7 +195,7 @@ public final class ActiveEnvironmentGroup extends AbstractEnvironmentGroup { * @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 { diff --git a/src/java/org/apache/fop/render/afp/modca/Factory.java b/src/java/org/apache/fop/render/afp/modca/Factory.java index c8e8669a5..d45684a70 100644 --- a/src/java/org/apache/fop/render/afp/modca/Factory.java +++ b/src/java/org/apache/fop/render/afp/modca/Factory.java @@ -27,6 +27,7 @@ import org.apache.fop.render.afp.goca.GraphicsData; 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; /** @@ -147,7 +148,7 @@ public class Factory { * * @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); @@ -390,7 +391,7 @@ public class Factory { 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; } @@ -507,6 +508,19 @@ public class Factory { } /** + * 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 a new {@link PresentationEnvironmentControl} @@ -571,4 +585,20 @@ public class Factory { 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; + } + } diff --git a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java index c5be86023..4d33b28de 100644 --- a/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java +++ b/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java @@ -48,7 +48,7 @@ import org.apache.fop.render.afp.goca.GraphicsString; 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 @@ -69,27 +69,26 @@ public class GraphicsObject extends AbstractDataObject { 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); } /** @@ -98,10 +97,10 @@ public class GraphicsObject extends AbstractDataObject { * @return the current graphics data */ private GraphicsData getData() { - if (this.graphicsData == null) { + if (this.currentGraphicsData == null) { return newData(); } - return this.graphicsData; + return this.currentGraphicsData; } /** @@ -110,18 +109,18 @@ public class GraphicsObject extends AbstractDataObject { * @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)); } /** @@ -139,8 +138,8 @@ public class GraphicsObject extends AbstractDataObject { * @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); } /** @@ -149,8 +148,8 @@ public class GraphicsObject extends AbstractDataObject { * @param type the line type */ public void setLineType(byte type) { - GraphicsSetLineType lt = new GraphicsSetLineType(type); - addObject(lt); + GraphicsSetLineType graphicsSetLineType = new GraphicsSetLineType(type); + addObject(graphicsSetLineType); } /** @@ -159,11 +158,11 @@ public class GraphicsObject extends AbstractDataObject { * @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); } /** @@ -254,18 +253,18 @@ public class GraphicsObject extends AbstractDataObject { * 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(); } } diff --git a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java index 0c8afd98e..336f2700f 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -23,6 +23,8 @@ import java.io.IOException; 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; /** @@ -71,29 +73,29 @@ public class IncludeObject extends AbstractNamedAFPObject { 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 @@ -112,10 +114,10 @@ public class IncludeObject extends AbstractNamedAFPObject { * @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"); @@ -128,20 +130,22 @@ public class IncludeObject extends AbstractNamedAFPObject { * @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; } /** @@ -159,7 +163,8 @@ public class IncludeObject extends AbstractNamedAFPObject { 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]; @@ -167,8 +172,8 @@ public class IncludeObject extends AbstractNamedAFPObject { 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]; @@ -179,8 +184,8 @@ public class IncludeObject extends AbstractNamedAFPObject { } // 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]; @@ -191,7 +196,7 @@ public class IncludeObject extends AbstractNamedAFPObject { } // 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; // @@ -216,7 +221,7 @@ public class IncludeObject extends AbstractNamedAFPObject { data[27] = 0x00; data[28] = 0x00; break; - default: + default: // 0 degrees data[25] = 0x00; data[26] = 0x00; data[27] = 0x2D; @@ -225,11 +230,11 @@ public class IncludeObject extends AbstractNamedAFPObject { } // 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; @@ -237,8 +242,8 @@ public class IncludeObject extends AbstractNamedAFPObject { } // 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]; @@ -247,18 +252,44 @@ public class IncludeObject extends AbstractNamedAFPObject { 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 + + "}"; } /** @@ -269,4 +300,25 @@ public class IncludeObject extends AbstractNamedAFPObject { 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 diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java index cb8a85fb3..d9a7c2895 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java @@ -49,12 +49,6 @@ public class ObjectContainer extends AbstractDataObject { */ public ObjectContainer(Factory factory, String name) { super(factory, name); - -// PresentationEnvironmentControl presentationEnvironmentControl -// = factory.createPresentationEnvironmentControl(); -// getObjectEnvironmentGroup().setPresentationEnvironmentControl( -// presentationEnvironmentControl); - } /** {@inheritDoc} */ @@ -93,23 +87,24 @@ public class ObjectContainer extends AbstractDataObject { /** {@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); diff --git a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java index 48aa9aa6c..7c44701bf 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java @@ -22,7 +22,6 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; -import org.apache.fop.render.afp.AFPObjectAreaInfo; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -38,8 +37,6 @@ 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; @@ -62,24 +59,28 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { * 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} */ @@ -87,7 +88,8 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { 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]; @@ -167,4 +169,5 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { public void setMapContainerData(MapContainerData mapContainerData) { this.mapContainerData = mapContainerData; } + } diff --git a/src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java b/src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java index c62577ca6..6856d3287 100644 --- a/src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java @@ -5,9 +5,9 @@ * 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. @@ -23,9 +23,12 @@ package org.apache.fop.render.afp.modca; * An AFP object which is able to know its own data length before write() */ public interface PreparedAFPObject { + /** + * Returns the current data length of this container + * * @return the current data length of this container including - * all enclosed GOCA drawing objects + * all enclosed GOCA drawing objects */ int getDataLength(); }
\ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java index a65394c39..edbe30226 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java @@ -68,7 +68,8 @@ public class ResourceObject extends AbstractPreparedAFPObject { 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 @@ -112,16 +113,19 @@ public class ResourceObject extends AbstractPreparedAFPObject { 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; @@ -135,10 +139,14 @@ public class ResourceObject extends AbstractPreparedAFPObject { /** 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; @@ -146,12 +154,12 @@ public class ResourceObject extends AbstractPreparedAFPObject { /** * 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 } ); |