From a153841f94703d85d500e008614af8e4db3a1fc2 Mon Sep 17 00:00:00 2001 From: Adrian Cumiskey Date: Fri, 29 Aug 2008 17:45:04 +0000 Subject: [PATCH] ObjectContainer/IncludeObject structure fixes. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@690345 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/afp/AFPDataObjectFactory.java | 113 +++++++++++------- .../fop/render/afp/AFPDataObjectInfo.java | 42 +++++-- .../apache/fop/render/afp/AFPGraphics2D.java | 8 +- .../fop/render/afp/AFPImageObjectInfo.java | 83 +++++++------ .../apache/fop/render/afp/AFPRenderer.java | 33 +++-- .../fop/render/afp/AFPResourceLevel.java | 49 ++++---- .../fop/render/afp/AFPResourceManager.java | 14 ++- .../apache/fop/render/afp/AFPSVGHandler.java | 37 ++---- ...TextDataInfo.java => AFPTextDataInfo.java} | 2 +- .../render/afp/modca/AbstractDataObject.java | 17 ++- .../render/afp/modca/AbstractPageObject.java | 4 +- .../modca/AbstractStructuredAFPObject.java | 45 +++++-- .../afp/modca/ContainerDataDescriptor.java | 25 ++-- .../fop/render/afp/modca/DataStream.java | 4 +- .../apache/fop/render/afp/modca/Factory.java | 41 ++++++- .../afp/modca/GraphicsDataDescriptor.java | 17 ++- .../fop/render/afp/modca/ImageObject.java | 8 +- .../fop/render/afp/modca/IncludeObject.java | 10 ++ .../fop/render/afp/modca/MapDataResource.java | 52 ++------ .../fop/render/afp/modca/ObjectContainer.java | 63 ++++++---- .../afp/modca/ObjectEnvironmentGroup.java | 58 ++++++++- .../fop/render/afp/modca/PageDescriptor.java | 8 +- .../afp/modca/PresentationTextData.java | 4 +- .../afp/modca/PresentationTextDescriptor.java | 12 +- .../afp/modca/PresentationTextObject.java | 4 +- .../fop/render/afp/modca/ResourceObject.java | 15 ++- ...xtendedResourceLocalIdentifierTriplet.java | 55 +++++++++ .../triplets/ObjectByteExtentTriplet.java | 39 ++++++ .../render/afp/modca/triplets/StrucFlgs.java | 40 +++---- 29 files changed, 594 insertions(+), 308 deletions(-) rename src/java/org/apache/fop/render/afp/{TextDataInfo.java => AFPTextDataInfo.java} (99%) create mode 100644 src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java create mode 100644 src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java index 401d2d486..7c89c7ffc 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java @@ -27,11 +27,14 @@ import org.apache.fop.render.afp.modca.Factory; import org.apache.fop.render.afp.modca.GraphicsObject; import org.apache.fop.render.afp.modca.ImageObject; import org.apache.fop.render.afp.modca.IncludeObject; +import org.apache.fop.render.afp.modca.MapDataResource; import org.apache.fop.render.afp.modca.ObjectContainer; import org.apache.fop.render.afp.modca.Overlay; import org.apache.fop.render.afp.modca.PageSegment; import org.apache.fop.render.afp.modca.Registry; import org.apache.fop.render.afp.modca.ResourceObject; +import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; import org.apache.xmlgraphics.image.codec.tiff.TIFFImage; @@ -58,21 +61,10 @@ public class AFPDataObjectFactory { * @return a newly created image object */ public AbstractDataObject createImage(AFPImageObjectInfo imageObjectInfo) { - AbstractDataObject dataObj; - Registry.ObjectType objectType = imageObjectInfo.getObjectType(); - - // A known object type so place in container - if (objectType != null) { - ObjectContainer objectContainer = factory.createObjectContainer(); - - objectContainer.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); - - objectContainer.setData(imageObjectInfo.getData()); - - dataObj = objectContainer; - } else { + AbstractDataObject dataObj = null; + // A known object type so place in an object container + if (imageObjectInfo.isBuffered()) { + // IOCA bitmap image ImageObject imageObj = factory.createImageObject(); if (imageObjectInfo.hasCompression()) { int compression = imageObjectInfo.getCompression(); @@ -92,18 +84,27 @@ public class AFPDataObjectFactory { } } -// imageObjectInfo.getDataWidth(), imageObjectInfo.getDataHeight(), -// objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); - - if (imageObjectInfo.isBuffered()) { - if (imageObjectInfo.isColor()) { - imageObj.setIDESize((byte) 24); - } else { - imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel()); - } - imageObj.setData(imageObjectInfo.getData()); + if (imageObjectInfo.isColor()) { + imageObj.setIDESize((byte) 24); + } else { + imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel()); } + imageObj.setData(imageObjectInfo.getData()); + dataObj = imageObj; + + } else { + ObjectContainer objectContainer = factory.createObjectContainer(); + + Registry.ObjectType objectType = imageObjectInfo.getObjectType(); + + objectContainer.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + + objectContainer.setInputStream(imageObjectInfo.getInputStream()); + + dataObj = objectContainer; } return dataObj; } @@ -115,8 +116,8 @@ public class AFPDataObjectFactory { * @return a new graphics object */ public GraphicsObject createGraphic(AFPGraphicsObjectInfo graphicsObjectInfo) { - // paint the graphic using batik GraphicsObject graphicsObj = factory.createGraphic(); + // paint the graphic using batik graphicsObjectInfo.getPainter().paint(graphicsObj); return graphicsObj; } @@ -143,6 +144,7 @@ public class AFPDataObjectFactory { Registry.ObjectType objectType = dataObjectInfo.getObjectType(); if (objectType != null) { includeObj.setObjectClassification( + // object scope not defined ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, objectType); } @@ -159,7 +161,7 @@ public class AFPDataObjectFactory { includeObj.setMeasurementUnits( objectAreaInfo.getWidthRes(), objectAreaInfo.getHeightRes()); -// includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); + includeObj.setMappingOption(MappingOptionTriplet.SCALE_TO_FIT); return includeObj; } @@ -167,12 +169,12 @@ public class AFPDataObjectFactory { /** * Creates a resource object wrapper for named includable data objects * - * @param dataObj an named object + * @param namedObj an named object * @param resourceInfo resource information * @param objectType the object type * @return a new resource object wrapper */ - public ResourceObject createResource(AbstractNamedAFPObject dataObj, + public ResourceObject createResource(AbstractNamedAFPObject namedObj, AFPResourceInfo resourceInfo, Registry.ObjectType objectType) { ResourceObject resourceObj = null; String resourceName = resourceInfo.getName(); @@ -181,30 +183,51 @@ public class AFPDataObjectFactory { } else { resourceObj = factory.createResource(); } - if (dataObj instanceof ObjectContainer) { - resourceObj.setType(ResourceObject.TYPE_OBJECT_CONTAINER); - - // mandatory triplet for object container - resourceObj.setObjectClassification( - ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, - objectType); - } else if (dataObj instanceof ImageObject) { - resourceObj.setType(ResourceObject.TYPE_IMAGE); - } else if (dataObj instanceof GraphicsObject) { - resourceObj.setType(ResourceObject.TYPE_GRAPHIC); - } else if (dataObj instanceof Document) { + if (namedObj instanceof Document) { resourceObj.setType(ResourceObject.TYPE_DOCUMENT); - } else if (dataObj instanceof PageSegment) { + } else if (namedObj instanceof PageSegment) { resourceObj.setType(ResourceObject.TYPE_PAGE_SEGMENT); - } else if (dataObj instanceof Overlay) { + } else if (namedObj instanceof Overlay) { 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); + + // mandatory triplet for object container + resourceObj.setObjectClassification( + ObjectClassificationTriplet.CLASS_TIME_INVARIANT_PAGINATED_PRESENTATION_OBJECT, + objectType); + } else if (namedObj instanceof ImageObject) { + resourceObj.setType(ResourceObject.TYPE_IMAGE); + // ioca image type + fqnType = FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF; + } 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 " + dataObj); + "Unsupported resource object type " + namedObj); } - resourceObj.setDataObject(dataObj); + // set the resource information/classification on the data object + resourceObj.setDataObject(namedObj); return resourceObj; } diff --git a/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java index 206c5b332..3f0d23b9d 100644 --- a/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPDataObjectInfo.java @@ -35,7 +35,11 @@ public abstract class AFPDataObjectInfo { /** resource info */ private AFPResourceInfo resourceInfo; - private byte[] data; + /** the data object width */ + private int dataWidth; + + /** the data object height */ + private int dataHeight; /** * Default constructor @@ -85,6 +89,8 @@ public abstract class AFPDataObjectInfo { /** {@inheritDoc} */ public String toString() { return "mimeType=" + getMimeType() + + ", dataWidth=" + dataWidth + + ", dataHeight=" + dataHeight + (objectAreaInfo != null ? ", objectAreaInfo=" + objectAreaInfo : "") + (resourceInfo != null ? ", resourceInfo=" + resourceInfo : ""); } @@ -108,21 +114,39 @@ public abstract class AFPDataObjectInfo { } /** - * Sets the object data + * Returns the image data width + * + * @return the image data width + */ + public int getDataWidth() { + return dataWidth; + } + + /** + * Sets the image data width + * + * @param imageDataWidth the image data width + */ + public void setDataWidth(int imageDataWidth) { + this.dataWidth = imageDataWidth; + } + + /** + * Returns the image data height * - * @param data a data byte array + * @return the image data height */ - public void setData(byte[] data) { - this.data = data; + public int getDataHeight() { + return dataHeight; } /** - * Returns the object data + * Sets the image data height * - * @return the object data as byte array + * @param imageDataHeight the image data height */ - public byte[] getData() { - return this.data; + public void setDataHeight(int imageDataHeight) { + this.dataHeight = imageDataHeight; } /** diff --git a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java index 3d237c402..359e2dc8b 100644 --- a/src/java/org/apache/fop/render/afp/AFPGraphics2D.java +++ b/src/java/org/apache/fop/render/afp/AFPGraphics2D.java @@ -325,13 +325,13 @@ public class AFPGraphics2D extends AbstractGraphics2D { /** {@inheritDoc} */ public void draw(Shape shape) { - log.debug("draw() shape=" + shape); +// log.debug("draw() shape=" + shape); doDrawing(shape, false); } /** {@inheritDoc} */ public void fill(Shape shape) { - log.debug("fill() shape=" + shape); +// log.debug("fill() shape=" + shape); doDrawing(shape, true); } @@ -446,10 +446,6 @@ public class AFPGraphics2D extends AbstractGraphics2D { AFPObjectAreaInfo objectAreaInfo = new AFPObjectAreaInfo(); -// float[] srcPts = new float[] {x, y}; -// int[] coords = unitConv.mpts2units(srcPts); -// objectAreaInfo.setX(coords[X]); -// objectAreaInfo.setY(coords[Y]); AffineTransform at = gc.getTransform(); float[] srcPts = new float[] {x, y}; float[] dstPts = new float[2]; diff --git a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java index b62ea3766..0aa1c0e5f 100644 --- a/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java @@ -19,19 +19,33 @@ package org.apache.fop.render.afp; +import java.io.InputStream; /** * A list of parameters associated with an image */ public class AFPImageObjectInfo extends AFPDataObjectInfo { + /** number of bits per pixel used */ private int bitsPerPixel; + + /** is this a color image? */ private boolean color; + + /** compression type if any */ private int compression = -1; - private int dataWidth; - private int dataHeight; + + /** the image mimetype */ private String mimeType; + + /** is this a buffered image? */ private boolean buffered; + /** the object data in a byte array */ + private byte[] data; + + /** the object data in an inputstream */ + private InputStream inputStream; + /** * Default constructor */ @@ -111,72 +125,73 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo { this.compression = compression; } + /** {@inheritDoc} */ + public String getMimeType() { + return mimeType; + } + /** - * Returns the image data width + * Sets whether or not this is info about a buffered image * - * @return the image data width + * @param buffered true if this is info about a buffered image */ - public int getDataWidth() { - return dataWidth; + public void setBuffered(boolean buffered) { + this.buffered = buffered; } /** - * Sets the image data width + * Returns true if this image info is about a buffered image * - * @param imageDataWidth the image data width + * @return true if this image info is about a buffered image */ - public void setDataWidth(int imageDataWidth) { - this.dataWidth = imageDataWidth; + public boolean isBuffered() { + return this.buffered; } /** - * Returns the image data height + * Sets the object data * - * @return the image data height + * @param data the object data */ - public int getDataHeight() { - return dataHeight; + public void setData(byte[] data) { + this.data = data; } /** - * Sets the image data height + * Returns the object data * - * @param imageDataHeight the image data height + * @return the object data */ - public void setDataHeight(int imageDataHeight) { - this.dataHeight = imageDataHeight; - } - - /** {@inheritDoc} */ - public String getMimeType() { - return mimeType; + public byte[] getData() { + return this.data; } /** - * Sets whether or not this is info about a buffered image + * Sets the object data inputstream * - * @param buffered true if this is info about a buffered image + * @param inputStream the object data inputstream */ - public void setBuffered(boolean buffered) { - this.buffered = buffered; + public void setInputStream(InputStream inputStream) { + this.inputStream = inputStream; } /** - * Returns true if this image info is about a buffered image + * Returns the object data inputstream * - * @return true if this image info is about a buffered image + * @return the object data inputstream */ - public boolean isBuffered() { - return this.buffered; + public InputStream getInputStream() { + return this.inputStream; } /** {@inheritDoc} */ public String toString() { return "AFPImageObjectInfo{" + super.toString() - + ", dataWidth=" + dataWidth - + ", dataHeight=" + dataHeight + + ", mimeType=" + mimeType + + ", buffered=" + buffered + + ", compression=" + compression + ", color=" + color - + ", bitPerPixel=" + bitsPerPixel + + ", bitsPerPixel=" + bitsPerPixel + "}"; } diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index adc67d037..b96c360fe 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -411,8 +411,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { org.apache.xmlgraphics.image.loader.Image img = manager.getImage( info, FLAVORS, hints, sessionContext); - if (/*img instanceof ImageRawJPEG || */img instanceof ImageRawStream - || img instanceof ImageRendered) { + if (img instanceof ImageRendered || img instanceof ImageRawStream) { AFPImageObjectInfo imageObjectInfo = getImageObjectInfo(uri, info, pos, origin, img); resourceManager.createObject(imageObjectInfo); @@ -525,21 +524,24 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { } else { imageObjectInfo.setBuffered(false); -// int resolution = state.getResolution(); -// objectAreaInfo.setWidthRes(resolution); -// objectAreaInfo.setHeightRes(resolution); - ImageRawStream rawStream = (ImageRawStream) img; + if (img instanceof ImageRawCCITTFax) { + ImageRawCCITTFax ccitt = (ImageRawCCITTFax) img; + imageObjectInfo.setCompression(ccitt.getCompression()); - int xresol = (int) (rawStream.getSize().getDpiHorizontal() * 10); - objectAreaInfo.setWidthRes(xresol); + int xresol = (int) (rawStream.getSize().getDpiHorizontal() * 10); + objectAreaInfo.setWidthRes(xresol); - int yresol = (int) (rawStream.getSize().getDpiVertical() * 10); - objectAreaInfo.setHeightRes(yresol); + int yresol = (int) (rawStream.getSize().getDpiVertical() * 10); + objectAreaInfo.setHeightRes(yresol); + } else { + int resolution = state.getResolution(); + objectAreaInfo.setWidthRes(resolution); + objectAreaInfo.setHeightRes(resolution); + } InputStream inputStream = rawStream.createInputStream(); - byte[] buf = IOUtils.toByteArray(inputStream); - imageObjectInfo.setData(buf); + imageObjectInfo.setInputStream(inputStream); int dataHeight = rawStream.getSize().getHeightPx(); imageObjectInfo.setDataHeight(dataHeight); @@ -547,10 +549,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { int dataWidth = rawStream.getSize().getWidthPx(); imageObjectInfo.setDataWidth(dataWidth); - if (img instanceof ImageRawCCITTFax) { - ImageRawCCITTFax ccitt = (ImageRawCCITTFax) img; - imageObjectInfo.setCompression(ccitt.getCompression()); - } } return imageObjectInfo; } @@ -635,7 +633,6 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** {@inheritDoc} */ public void renderText(TextArea text) { -// log.debug(text.getText()); renderInlineAreaBackAndBorders(text); String name = getInternalFontNameForArea(text); @@ -700,7 +697,7 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { int interCharacterAdjustment = Math.round(unitConv.mpt2units(text.getTextLetterSpaceAdjust())); - TextDataInfo textDataInfo = new TextDataInfo(); + AFPTextDataInfo textDataInfo = new AFPTextDataInfo(); textDataInfo.setFontReference(fontReference); textDataInfo.setX(coords[X]); textDataInfo.setY(coords[Y]); diff --git a/src/java/org/apache/fop/render/afp/AFPResourceLevel.java b/src/java/org/apache/fop/render/afp/AFPResourceLevel.java index a7c6bf44b..ea6c31a6a 100644 --- a/src/java/org/apache/fop/render/afp/AFPResourceLevel.java +++ b/src/java/org/apache/fop/render/afp/AFPResourceLevel.java @@ -24,30 +24,35 @@ package org.apache.fop.render.afp; */ public class AFPResourceLevel { + /** directly in page **/ + public static final int INLINE = 0; + /** page level **/ - public static final int PAGE = 0; + public static final int PAGE = 1; /** page group level **/ - public static final int PAGE_GROUP = 1; + public static final int PAGE_GROUP = 2; /** document level **/ - public static final int DOCUMENT = 2; + public static final int DOCUMENT = 3; /** print file level **/ - public static final int PRINT_FILE = 3; + public static final int PRINT_FILE = 4; /** external level **/ - public static final int EXTERNAL = 4; + public static final int EXTERNAL = 5; + private static final String NAME_INLINE = "inline"; private static final String NAME_PAGE = "page"; private static final String NAME_PAGE_GROUP = "page-group"; private static final String NAME_DOCUMENT = "document"; private static final String NAME_PRINT_FILE = "print-file"; private static final String NAME_EXTERNAL = "external"; - private static final String[] NAMES - = new String[] {NAME_PAGE, NAME_PAGE_GROUP, NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL}; - + private static final String[] NAMES = new String[] { + NAME_INLINE, NAME_PAGE, NAME_PAGE_GROUP, + NAME_DOCUMENT, NAME_PRINT_FILE, NAME_EXTERNAL + }; /** where the resource will reside in the AFP output */ @@ -96,57 +101,57 @@ public class AFPResourceLevel { } /** - * Returns true if this is a page level + * Returns true if this is at page level * - * @return true if this is a page level + * @return true if this is at page level */ public boolean isPage() { return level == PAGE; } /** - * Returns true if this is page group level + * Returns true if this is at page group level * - * @return true if this is page group level + * @return true if this is at page group level */ public boolean isPageGroup() { return level == PAGE_GROUP; } /** - * Returns true if this is document level + * Returns true if this is at document level * - * @return true if this is document level + * @return true if this is at document level */ public boolean isDocument() { return level == DOCUMENT; } /** - * Returns true if this is external level + * Returns true if this is at external level * - * @return true if this is external level + * @return true if this is at external level */ public boolean isExternal() { return level == EXTERNAL; } /** - * Returns true if this is print-file level + * Returns true if this is at print-file level * - * @return true if this is print-file level + * @return true if this is at print-file level */ public boolean isPrintFile() { return level == PRINT_FILE; } /** - * Returns true if this resource level is inlined + * Returns true if this resource level is inline * - * @return true if this resource level is inlined + * @return true if this resource level is inline */ - public boolean isInlined() { - return isPage() || isPageGroup() || isDocument(); + public boolean isInline() { + return level == INLINE; } /** diff --git a/src/java/org/apache/fop/render/afp/AFPResourceManager.java b/src/java/org/apache/fop/render/afp/AFPResourceManager.java index f8138b732..cf0b490c3 100644 --- a/src/java/org/apache/fop/render/afp/AFPResourceManager.java +++ b/src/java/org/apache/fop/render/afp/AFPResourceManager.java @@ -140,6 +140,7 @@ public class AFPResourceManager { throw new IllegalArgumentException("Unknown data object type: " + dataObjectInfo); } + // set data object viewport (i.e. position, rotation, dimension, resolution) if (namedObj instanceof AbstractDataObject) { AbstractDataObject dataObj = (AbstractDataObject)namedObj; dataObj.setViewport(dataObjectInfo); @@ -148,17 +149,22 @@ public class AFPResourceManager { AFPResourceLevel resourceLevel = resourceInfo.getLevel(); Registry.ObjectType objectType = dataObjectInfo.getObjectType(); - boolean canInclude = (namedObj instanceof ImageObject + + ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel); + + boolean canInclude = (resourceGroup != null) && (namedObj instanceof ImageObject || objectType != null && objectType.isIncludable()); + if (canInclude) { + // if it is to reside within a resource group at print-file or external level if (resourceLevel.isPrintFile() || resourceLevel.isExternal()) { + // wrap newly created data object in a resource object namedObj = dataObjectFactory.createResource(namedObj, resourceInfo, objectType); } // add data object into its resource group destination - ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel); resourceGroup.addObject(namedObj); // add an include to the current page @@ -170,11 +176,11 @@ public class AFPResourceManager { // record name of data object for the resource includeNameMap.put(resourceInfo, namedObj.getName()); } else { - // add data object directly into the current page + // not to be included so inline data object directly into the current page dataStream.getCurrentPage().addObject(namedObj); } } else { - // existing resource so reference by adding an include to the current page + // an existing data resource so reference it by adding an include to the current page IncludeObject includeObject = dataObjectFactory.createInclude(includeName, dataObjectInfo); dataStream.getCurrentPage().addObject(includeObject); diff --git a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java index 8ea7467e5..5d9fcdb7d 100644 --- a/src/java/org/apache/fop/render/afp/AFPSVGHandler.java +++ b/src/java/org/apache/fop/render/afp/AFPSVGHandler.java @@ -37,6 +37,7 @@ import org.apache.fop.render.AbstractGenericSVGHandler; import org.apache.fop.render.Renderer; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RendererContextConstants; +import org.apache.fop.render.RendererContext.RendererContextWrapper; import org.apache.fop.svg.SVGEventProducer; import org.apache.fop.svg.SVGUserAgent; import org.apache.xmlgraphics.util.QName; @@ -90,6 +91,9 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { return afpi; } + private static final int X = 0; + private static final int Y = 1; + /** * Render the SVG document. * @@ -124,32 +128,13 @@ public class AFPSVGHandler extends AbstractGenericSVGHandler { AFPUnitConverter unitConv = state.getUnitConverter(); -// RendererContextWrapper rctx = RendererContext.wrapRendererContext(context); -// int currx = rctx.getCurrentXPosition(); -// int curry = rctx.getCurrentYPosition(); -// int afpx = Math.round(unitConv.mpt2units(currx)); -// int afpy = Math.round(unitConv.mpt2units(curry)); -// objectAreaInfo.setOffsetX(afpx); -// objectAreaInfo.setOffsetY(afpy); - - AffineTransform at = state.getData().getTransform(); - float transX = (float)at.getTranslateX(); - float transY = (float)at.getTranslateY(); -// int afpx = Math.round(unitConv.mpt2units(currx)); -// objectAreaInfo.setX(afpx); -// int afpy = Math.round(unitConv.mpt2units(curry)); -// objectAreaInfo.setY(afpy); -// objectAreaInfo.setX(coords[0]); -// objectAreaInfo.setY(coords[1]); - objectAreaInfo.setX(Math.round(transX)); - objectAreaInfo.setY(Math.round(transY)); - -// AffineTransform at = currentState.getData().getTransform(); -// int x = (int)Math.round(at.getTranslateX()); -// objectAreaInfo.setX(x); -// -// int y = (int)Math.round(at.getTranslateY()); -// objectAreaInfo.setY(y); + RendererContextWrapper rctx = RendererContext.wrapRendererContext(context); + int currx = rctx.getCurrentXPosition(); + int curry = rctx.getCurrentYPosition(); + float[] srcPts = {currx, curry}; + int[] coords = unitConv.mpts2units(srcPts); + objectAreaInfo.setX(coords[X]); + objectAreaInfo.setY(coords[Y]); int resolution = afpInfo.getResolution(); objectAreaInfo.setWidthRes(resolution); diff --git a/src/java/org/apache/fop/render/afp/TextDataInfo.java b/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java similarity index 99% rename from src/java/org/apache/fop/render/afp/TextDataInfo.java rename to src/java/org/apache/fop/render/afp/AFPTextDataInfo.java index a10b10671..dc507580a 100644 --- a/src/java/org/apache/fop/render/afp/TextDataInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPTextDataInfo.java @@ -24,7 +24,7 @@ import java.awt.Color; /** * Text data information */ -public class TextDataInfo { +public class AFPTextDataInfo { private int fontReference; 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 8eccbcc2e..b0d59ced7 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java @@ -24,6 +24,8 @@ import java.io.OutputStream; import org.apache.fop.render.afp.AFPDataObjectInfo; import org.apache.fop.render.afp.AFPObjectAreaInfo; +import org.apache.fop.render.afp.AFPResourceInfo; +import org.apache.fop.render.afp.AFPResourceLevel; /** * Abstract base class used by the ImageObject and GraphicsObject which both @@ -55,8 +57,14 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject { * the object area info */ public void setViewport(AFPDataObjectInfo dataObjectInfo) { - AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); - getObjectEnvironmentGroup().setObjectArea(objectAreaInfo); + AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); + AFPResourceLevel resourceLevel = resourceInfo.getLevel(); + + // only need to set OAD and OAP inlined (pre-2000 apps) + if (resourceLevel.isInline()) { + AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); + getObjectEnvironmentGroup().setObjectArea(objectAreaInfo); + } } /** @@ -64,7 +72,7 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject { * * @return the object environment group */ - protected ObjectEnvironmentGroup getObjectEnvironmentGroup() { + public ObjectEnvironmentGroup getObjectEnvironmentGroup() { if (objectEnvironmentGroup == null) { this.objectEnvironmentGroup = factory.createObjectEnvironmentGroup(); } @@ -73,9 +81,10 @@ public abstract class AbstractDataObject extends AbstractNamedAFPObject { /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); + super.writeContent(os); // write triplets if (objectEnvironmentGroup != null) { objectEnvironmentGroup.writeToStream(os); } } + } 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 c986e7eca..6a05a8044 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java @@ -24,7 +24,7 @@ import java.io.OutputStream; import java.util.List; import org.apache.fop.render.afp.LineDataInfo; -import org.apache.fop.render.afp.TextDataInfo; +import org.apache.fop.render.afp.AFPTextDataInfo; import org.apache.fop.render.afp.fonts.AFPFont; /** @@ -170,7 +170,7 @@ public abstract class AbstractPageObject extends AbstractNamedAFPObject { * @param textDataInfo * the afp text data */ - public void createText(TextDataInfo textDataInfo) { + public void createText(AFPTextDataInfo textDataInfo) { getPresentationTextObject().createTextData(textDataInfo); } 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 070ee1edb..52dc3d3c7 100644 --- a/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java +++ b/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java @@ -20,6 +20,7 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Collection; @@ -28,7 +29,6 @@ import java.util.List; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; -import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; import org.apache.fop.render.afp.modca.triplets.MeasurementUnitsTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectAreaSizeTriplet; import org.apache.fop.render.afp.modca.triplets.ObjectClassificationTriplet; @@ -171,7 +171,7 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { * * @param triplet the triplet to add */ - private void addTriplet(Triplet triplet) { + protected void addTriplet(Triplet triplet) { getTriplets().add(triplet); } @@ -260,15 +260,6 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { addTriplet(new MeasurementUnitsTriplet(xRes, xRes)); } - /** - * Sets the mapping option - * - * @param optionValue the mapping option value - */ - public void setMappingOption(byte optionValue) { - addTriplet(new MappingOptionTriplet(optionValue)); - } - /** * Sets a comment on this resource * @@ -282,10 +273,40 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject { } } + /** + * Reads data chunks from an inputstream + * and then formats them with a structured header to a given outputstream + * + * @param dataHeader the header data + * @param lengthOffset offset of length field in data chunk + * @param maxChunkLength the maximum chunk length + * @param inputStream the inputstream to read from + * @param outputStream the outputstream to write to + * @throws IOException thrown if an I/O exception of some sort has occurred. + */ + protected static void copyChunks(byte[] dataHeader, int lengthOffset, + int maxChunkLength, InputStream inputStream, OutputStream outputStream) + throws IOException { + int headerLen = dataHeader.length - lengthOffset; + // length field is just before data so do not include in data length + if (headerLen == 2) { + headerLen = 0; + } + byte[] data = new byte[maxChunkLength]; + int numBytesRead = 0; + while ((numBytesRead = inputStream.read(data, 0, maxChunkLength)) > 0) { + byte[] len = BinaryUtils.convert(headerLen + numBytesRead, 2); + dataHeader[lengthOffset] = len[0]; // Length byte 1 + dataHeader[lengthOffset + 1] = len[1]; // Length byte 2 + outputStream.write(dataHeader); + outputStream.write(data, 0, numBytesRead); + } + } + /** * Writes data chunks to a given outputstream * - * @param data the data + * @param data the data byte array * @param dataHeader the header data * @param lengthOffset offset of length field in data chunk * @param maxChunkLength the maximum chunk length diff --git a/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.java index 41fb67384..224b25112 100644 --- a/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/ContainerDataDescriptor.java @@ -45,15 +45,18 @@ public class ContainerDataDescriptor extends AbstractDescriptor { /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[21]; - copySF(data, Type.DESCRIPTOR, Category.IMAGE); + copySF(data, Type.DESCRIPTOR, Category.OBJECT_CONTAINER); // SF length byte[] len = BinaryUtils.convert(data.length - 1, 2); data[1] = len[0]; data[2] = len[1]; - data[9] = 0x00; // XocBase = 10 inches - data[10] = 0x00; // YocBase = 10 inches + // XocBase = 10 inches + data[9] = 0x00; + + // YocBase = 10 inches + data[10] = 0x00; // XocUnits byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2); @@ -66,16 +69,16 @@ public class ContainerDataDescriptor extends AbstractDescriptor { data[14] = ydpi[1]; // XocSize - byte[] x = BinaryUtils.convert(width, 3); - data[15] = x[0]; - data[16] = x[1]; - data[17] = x[2]; + byte[] xsize = BinaryUtils.convert(width, 3); + data[15] = xsize[0]; + data[16] = xsize[1]; + data[17] = xsize[2]; // YocSize - byte[] y = BinaryUtils.convert(height, 3); - data[18] = y[0]; - data[19] = y[1]; - data[20] = y[2]; + byte[] ysize = BinaryUtils.convert(height, 3); + data[18] = ysize[0]; + data[19] = ysize[1]; + data[20] = ysize[2]; } } diff --git a/src/java/org/apache/fop/render/afp/modca/DataStream.java b/src/java/org/apache/fop/render/afp/modca/DataStream.java index 0b1c2e052..aaa18b2fd 100644 --- a/src/java/org/apache/fop/render/afp/modca/DataStream.java +++ b/src/java/org/apache/fop/render/afp/modca/DataStream.java @@ -30,7 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.fop.render.afp.AFPFontAttributes; import org.apache.fop.render.afp.AFPResourceLevel; import org.apache.fop.render.afp.LineDataInfo; -import org.apache.fop.render.afp.TextDataInfo; +import org.apache.fop.render.afp.AFPTextDataInfo; import org.apache.fop.render.afp.fonts.AFPFont; import org.apache.fop.render.afp.modca.triplets.FullyQualifiedNameTriplet; @@ -357,7 +357,7 @@ public class DataStream { * @param textDataInfo * the afp text data */ - public void createText(TextDataInfo textDataInfo) { + public void createText(AFPTextDataInfo textDataInfo) { textDataInfo.setOrientation(orientation); currentPage.createText(textDataInfo); } 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 5879cb081..a14eae6a0 100644 --- a/src/java/org/apache/fop/render/afp/modca/Factory.java +++ b/src/java/org/apache/fop/render/afp/modca/Factory.java @@ -472,19 +472,51 @@ public class Factory { /** * Creates a new MO:DCA {@link ContainerDataDescriptor} * - * @param width the container data width - * @param height the container data height + * @param dataWidth the container data width + * @param dataHeight the container data height * @param widthRes the container data width resolution * @param heightRes the container data height resolution * @return a new {@link ContainerDataDescriptor} */ public ContainerDataDescriptor createContainerDataDescriptor( - int width, int height, int widthRes, int heightRes) { + int dataWidth, int dataHeight, int widthRes, int heightRes) { ContainerDataDescriptor containerDataDescriptor - = new ContainerDataDescriptor(width, height, widthRes, heightRes); + = new ContainerDataDescriptor(dataWidth, dataHeight, widthRes, heightRes); return containerDataDescriptor; } + /** + * Creates a new MO:DCA {@link MapContainerData} + * + * @param optionValue the option value + * @return a new {@link MapContainerData} + */ + public MapContainerData createMapContainerData(byte optionValue) { + MapContainerData mapContainerData = new MapContainerData(optionValue); + return mapContainerData; + } + + /** + * Creates a new MO:DCA {@link MapDataResource} + * + * @return a new {@link MapDataResource} + */ + public MapDataResource createMapDataResource() { + MapDataResource mapDataResource = new MapDataResource(); + return mapDataResource; + } + + /** + * Creates a new MO:DCA {@link PresentationEnvironmentControl} + * + * @return a new {@link PresentationEnvironmentControl} + */ + public PresentationEnvironmentControl createPresentationEnvironmentControl() { + PresentationEnvironmentControl presentationEnvironmentControl + = new PresentationEnvironmentControl(); + return presentationEnvironmentControl; + } + /** * Creates a new IOCA {@link ImageSegment} * @@ -507,7 +539,6 @@ public class Factory { return imageContent; } - /** * Creates a new IOCA {@link ImageRasterData} * diff --git a/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java b/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java index e2b18cc3e..7ee0e07f5 100644 --- a/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java @@ -67,12 +67,17 @@ public class GraphicsDataDescriptor extends AbstractDescriptor { public void writeToStream(OutputStream os) throws IOException { byte[] headerData = new byte[9]; copySF(headerData, Type.DESCRIPTOR, Category.GRAPHICS); + byte[] drawingOrderSubsetData = getDrawingOrderSubset(); + byte[] windowSpecificationData = getWindowSpecification(); - byte[] len = BinaryUtils.convert( - 8 + drawingOrderSubsetData.length + windowSpecificationData.length, 2); + + byte[] len = BinaryUtils.convert(headerData.length + + drawingOrderSubsetData.length + + windowSpecificationData.length - 1, 2); headerData[1] = len[0]; headerData[2] = len[1]; + os.write(headerData); os.write(drawingOrderSubsetData); os.write(windowSpecificationData); @@ -116,19 +121,23 @@ public class GraphicsDataDescriptor extends AbstractDescriptor { byte[] yResol = BinaryUtils.convert(heightRes * 10, 2); byte[] imxyres = xResol; - final byte[] data = new byte[] { // Window specification - (byte) 0xF6, 18, // LENGTH + final byte[] data = new byte[] { + (byte) 0xF6, + 18, // LENGTH (ABS + IMGRES), // FLAGS (ABS) 0x00, // reserved (must be zero) 0x00, // CFORMAT (coordinate format - 16bit high byte first signed) 0x00, // UBASE (unit base - ten inches) + xResol[0], // XRESOL xResol[1], yResol[0], // YRESOL yResol[1], + imxyres[0], // IMXYRES (Number of image points per ten inches imxyres[1], // in X and Y directions) + xlcoord[0], // XLWIND xlcoord[1], xrcoord[0], // XRWIND diff --git a/src/java/org/apache/fop/render/afp/modca/ImageObject.java b/src/java/org/apache/fop/render/afp/modca/ImageObject.java index 1e62446e9..005bae176 100644 --- a/src/java/org/apache/fop/render/afp/modca/ImageObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ImageObject.java @@ -132,14 +132,14 @@ public class ImageObject extends AbstractDataObject { super.writeContent(os); if (imageSegment != null) { + final byte[] dataHeader = new byte[9]; + copySF(dataHeader, SF_CLASS, Type.DATA, Category.IMAGE); + final int lengthOffset = 1; + // TODO save memory! ByteArrayOutputStream baos = new ByteArrayOutputStream(); imageSegment.writeToStream(baos); byte[] data = baos.toByteArray(); - - final byte[] dataHeader = new byte[9]; - copySF(dataHeader, SF_CLASS, Type.DATA, Category.IMAGE); - final int lengthOffset = 1; writeChunksToStream(data, dataHeader, lengthOffset, MAX_DATA_LEN, os); } } 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 fde387d26..0c8afd98e 100644 --- a/src/java/org/apache/fop/render/afp/modca/IncludeObject.java +++ b/src/java/org/apache/fop/render/afp/modca/IncludeObject.java @@ -22,6 +22,7 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; import java.io.OutputStream; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -259,4 +260,13 @@ public class IncludeObject extends AbstractNamedAFPObject { public String toString() { return "IOB: " + this.getName(); } + + /** + * Sets the mapping option + * + * @param optionValue the mapping option value + */ + public void setMappingOption(byte optionValue) { + addTriplet(new MappingOptionTriplet(optionValue)); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java index 12a8c6406..09b18b9a7 100644 --- a/src/java/org/apache/fop/render/afp/modca/MapDataResource.java +++ b/src/java/org/apache/fop/render/afp/modca/MapDataResource.java @@ -30,61 +30,29 @@ import org.apache.fop.render.afp.tools.BinaryUtils; */ public class MapDataResource extends AbstractStructuredAFPObject { - /** - * Static default generated name reference - */ - private static final String DEFAULT_NAME = "MDR00001"; - /** * Main constructor - * - * @param dataObjectAccessor a data object accessor */ public MapDataResource() { -// AbstractNamedAFPObject namedDataObject = dataObjectAccessor.getDataObject(); -// DataObjectInfo dataObjectInfo = dataObjectAccessor.getDataObjectInfo(); -// AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo(); -// AFPResourceLevel resourceLevel = resourceInfo.getLevel(); -// if (resourceLevel.isExternal()) { -// String url = resourceLevel.getExternalFilePath(); -// if (url != null) { -// super.setFullyQualifiedName( -// FullyQualifiedNameTriplet.TYPE_DATA_OBJECT_EXTERNAL_RESOURCE_REF, -// FullyQualifiedNameTriplet.FORMAT_CHARSTR, url); -// } -// } else { -// String fqName = namedDataObject.getFullyQualifiedName(); -// super.setFullyQualifiedName( -// FullyQualifiedNameTriplet.TYPE_BEGIN_RESOURCE_OBJECT_REF, -// FullyQualifiedNameTriplet.FORMAT_CHARSTR, fqName); -// } -// -// // Set object classification -// Registry.ObjectType objectType = dataObjectInfo.getObjectType(); -// super.setObjectClassification( -// ObjectClassificationTriplet.CLASS_TIME_VARIANT_PRESENTATION_OBJECT, -// objectType); } /** {@inheritDoc} */ - public void writeStart(OutputStream os) throws IOException { + public void writeToStream(OutputStream os) throws IOException { super.writeStart(os); - byte[] data = new byte[9]; + byte[] data = new byte[11]; copySF(data, Type.MAP, Category.DATA_RESOURCE); - byte[] len = BinaryUtils.convert(10 + getTripletDataLength(), 2); + int tripletDataLen = getTripletDataLength(); + + byte[] len = BinaryUtils.convert(10 + tripletDataLen, 2); data[1] = len[0]; data[2] = len[1]; - os.write(data); - } - - /** {@inheritDoc} */ - public void writeContent(OutputStream os) throws IOException { - // RGLength - byte[] len = BinaryUtils.convert(2 + getTripletDataLength(), 2); - os.write(len); + len = BinaryUtils.convert(2 + tripletDataLen, 2); + data[9] = len[0]; + data[10] = len[1]; - super.writeTriplets(os); + os.write(data); + os.write(tripletData); } } 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 dedeb3b8f..1aaed4e7d 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectContainer.java @@ -20,9 +20,14 @@ package org.apache.fop.render.afp.modca; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import org.apache.fop.render.afp.AFPDataObjectInfo; +import org.apache.fop.render.afp.AFPObjectAreaInfo; +import org.apache.fop.render.afp.AFPResourceInfo; +import org.apache.fop.render.afp.AFPResourceLevel; +import org.apache.fop.render.afp.modca.triplets.MappingOptionTriplet; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -33,8 +38,7 @@ public class ObjectContainer extends AbstractDataObject { /** the object container data maximum length */ private static final int MAX_DATA_LEN = 32759; - /** the object data */ - protected byte[] objectData; + private InputStream inputStream; /** * Main constructor @@ -44,6 +48,12 @@ public class ObjectContainer extends AbstractDataObject { */ public ObjectContainer(Factory factory, String name) { super(factory, name); + +// PresentationEnvironmentControl presentationEnvironmentControl +// = factory.createPresentationEnvironmentControl(); +// getObjectEnvironmentGroup().setPresentationEnvironmentControl( +// presentationEnvironmentControl); + } /** {@inheritDoc} */ @@ -52,7 +62,8 @@ public class ObjectContainer extends AbstractDataObject { copySF(headerData, Type.BEGIN, Category.OBJECT_CONTAINER); // Set the total record length - byte[] len = BinaryUtils.convert(16 + getTripletDataLength(), 2); + int containerLen = headerData.length + getTripletDataLength() - 1; + byte[] len = BinaryUtils.convert(containerLen, 2); headerData[1] = len[0]; // Length byte 1 headerData[2] = len[1]; // Length byte 2 @@ -61,14 +72,14 @@ public class ObjectContainer extends AbstractDataObject { /** {@inheritDoc} */ protected void writeContent(OutputStream os) throws IOException { - super.writeContent(os); // write OEG + super.writeContent(os); // write triplets and OEG - // write OCD + // write OCDs byte[] dataHeader = new byte[9]; copySF(dataHeader, SF_CLASS, Type.DATA, Category.OBJECT_CONTAINER); final int lengthOffset = 1; - writeChunksToStream(objectData, dataHeader, lengthOffset, - MAX_DATA_LEN, os); + + copyChunks(dataHeader, lengthOffset, MAX_DATA_LEN, inputStream, os); } /** {@inheritDoc} */ @@ -81,23 +92,35 @@ public class ObjectContainer extends AbstractDataObject { /** {@inheritDoc} */ public void setViewport(AFPDataObjectInfo dataObjectInfo) { super.setViewport(dataObjectInfo); -// AFPObjectAreaInfo objectAreaInfo = dataObjectInfo.getObjectAreaInfo(); -// -// int width = objectAreaInfo.getWidth(); -// int height = objectAreaInfo.getHeight(); -// int widthRes = objectAreaInfo.getWidthRes(); -// int heightRes = objectAreaInfo.getHeightRes(); -// ContainerDataDescriptor containerDataDescriptor -// = factory.createContainerDataDescriptor(width, height, widthRes, heightRes); -// getObjectEnvironmentGroup().setDataDescriptor(containerDataDescriptor); + + 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) + if (resourceLevel.isInline()) { + MapContainerData mapContainerData + = factory.createMapContainerData(MappingOptionTriplet.SCALE_TO_FIT); + getObjectEnvironmentGroup().setMapContainerData(mapContainerData); + + int dataWidth = dataObjectInfo.getDataWidth(); + int dataHeight = dataObjectInfo.getDataHeight(); + int widthRes = objectAreaInfo.getWidthRes(); + int heightRes = objectAreaInfo.getHeightRes(); + ContainerDataDescriptor containerDataDescriptor + = factory.createContainerDataDescriptor( + dataWidth, dataHeight, widthRes, heightRes); + getObjectEnvironmentGroup().setDataDescriptor(containerDataDescriptor); + } } /** - * Sets the object container data + * Sets the inputstream for the the object container data * - * @param data the object container data + * @param inputStream the inputstream for the object container data */ - public void setData(byte[] data) { - this.objectData = data; + public void setInputStream(InputStream inputStream) { + this.inputStream = inputStream; } } 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 9c3c5cf27..48aa9aa6c 100644 --- a/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java +++ b/src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.OutputStream; import org.apache.fop.render.afp.AFPObjectAreaInfo; +import org.apache.fop.render.afp.tools.BinaryUtils; /** * An Object Environment Group (OEG) may be associated with an object and is contained @@ -39,15 +40,24 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { private final Factory factory; + /** the PresentationEnvironmentControl for the object environment group */ + private PresentationEnvironmentControl presentationEnvironmentControl = null; + /** the ObjectAreaDescriptor for the object environment group */ private ObjectAreaDescriptor objectAreaDescriptor = null; /** the ObjectAreaPosition for the object environment group */ private ObjectAreaPosition objectAreaPosition = null; - /** the DataDescritpor for the object environment group */ + /** the DataDescriptor for the object environment group */ private AbstractDescriptor dataDescriptor; + /** the MapDataResource for the object environment group */ + private MapDataResource mapDataResource; + + /** the MapContainerData for the object environment group */ + private MapContainerData mapContainerData; + /** * Constructor for the ObjectEnvironmentGroup, this takes a * name parameter which must be 8 characters long. @@ -76,6 +86,12 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { protected void writeStart(OutputStream os) throws IOException { byte[] data = new byte[17]; copySF(data, Type.BEGIN, Category.OBJECT_ENVIRONMENT_GROUP); + + int sfLen = data.length + getTripletDataLength() - 1; + byte[] len = BinaryUtils.convert(sfLen, 2); + data[1] = len[0]; + data[2] = len[1]; + os.write(data); } @@ -83,6 +99,10 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { protected void writeContent(OutputStream os) throws IOException { super.writeContent(os); + if (presentationEnvironmentControl != null) { + presentationEnvironmentControl.writeToStream(os); + } + if (objectAreaDescriptor != null) { objectAreaDescriptor.writeToStream(os); } @@ -91,6 +111,14 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { objectAreaPosition.writeToStream(os); } + if (mapContainerData != null) { + mapContainerData.writeToStream(os); + } + + if (mapDataResource != null) { + mapDataResource.writeToStream(os); + } + if (dataDescriptor != null) { dataDescriptor.writeToStream(os); } @@ -103,6 +131,16 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { os.write(data); } + /** + * Sets the presentation environment control + * + * @param presentationEnvironmentControl the presentation environment control + */ + public void setPresentationEnvironmentControl( + PresentationEnvironmentControl presentationEnvironmentControl) { + this.presentationEnvironmentControl = presentationEnvironmentControl; + } + /** * Sets the data descriptor * @@ -111,4 +149,22 @@ public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject { public void setDataDescriptor(AbstractDescriptor dataDescriptor) { this.dataDescriptor = dataDescriptor; } + + /** + * Sets the map data resource + * + * @param mapDataResource the map data resource + */ + public void setMapDataResource(MapDataResource mapDataResource) { + this.mapDataResource = mapDataResource; + } + + /** + * Sets the map container data + * + * @param mapContainerData the map container data + */ + public void setMapContainerData(MapContainerData mapContainerData) { + this.mapContainerData = mapContainerData; + } } diff --git a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java index 7dc8c15db..8f0d0dfae 100644 --- a/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PageDescriptor.java @@ -36,11 +36,11 @@ public class PageDescriptor extends AbstractDescriptor { * * @param width The page width. * @param height The page height. - * @param widthResolution The page width resolution - * @param heightResolution The page height resolution + * @param widthRes The page width resolution + * @param heightRes The page height resolution */ - public PageDescriptor(int width, int height, int widthResolution, int heightResolution) { - super(width, height, widthResolution, heightResolution); + public PageDescriptor(int width, int height, int widthRes, int heightRes) { + super(width, height, widthRes, heightRes); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java index 10501f396..57a45f99d 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextData.java @@ -25,7 +25,7 @@ import java.io.OutputStream; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.fop.render.afp.LineDataInfo; -import org.apache.fop.render.afp.TextDataInfo; +import org.apache.fop.render.afp.AFPTextDataInfo; import org.apache.fop.render.afp.tools.BinaryUtils; /** @@ -272,7 +272,7 @@ public class PresentationTextData extends AbstractAFPObject { * @throws MaximumSizeExceededException * thrown if the maximum number of text data is exceeded */ - public void createTextData(TextDataInfo textDataInfo) + public void createTextData(AFPTextDataInfo textDataInfo) throws MaximumSizeExceededException { ByteArrayOutputStream afpdata = new ByteArrayOutputStream(); diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java index 685e79891..807aba4d7 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextDescriptor.java @@ -50,21 +50,21 @@ public class PresentationTextDescriptor extends AbstractDescriptor { /** * Constructor a PresentationTextDescriptor for the specified * width and height. - * + * * @param width The width of the page. * @param height The height of the page. - * @param widthResolution The width resolution of the page. - * @param heightResolution The height resolution of the page. + * @param widthRes The width resolution of the page. + * @param heightRes The height resolution of the page. */ public PresentationTextDescriptor(int width, int height, - int widthResolution, int heightResolution) { - super(width, height, widthResolution, heightResolution); + int widthRes, int heightRes) { + super(width, height, widthRes, heightRes); } /** {@inheritDoc} */ public void writeToStream(OutputStream os) throws IOException { byte[] data = new byte[23]; - + copySF(data, Type.MIGRATION, Category.PRESENTATION_TEXT); data[1] = 0x00; // length diff --git a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java index 25a52aefe..cbfad326d 100644 --- a/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java +++ b/src/java/org/apache/fop/render/afp/modca/PresentationTextObject.java @@ -24,7 +24,7 @@ import java.io.OutputStream; import java.util.List; import org.apache.fop.render.afp.LineDataInfo; -import org.apache.fop.render.afp.TextDataInfo; +import org.apache.fop.render.afp.AFPTextDataInfo; /** * The Presentation Text object is the data object used in document processing @@ -69,7 +69,7 @@ public class PresentationTextObject extends AbstractNamedAFPObject { * @param textDataInfo * The afp text data */ - public void createTextData(TextDataInfo textDataInfo) { + public void createTextData(AFPTextDataInfo textDataInfo) { if (currentPresentationTextData == null) { startPresentationTextData(); } 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 01a48f440..a65394c39 100644 --- a/src/java/org/apache/fop/render/afp/modca/ResourceObject.java +++ b/src/java/org/apache/fop/render/afp/modca/ResourceObject.java @@ -51,6 +51,15 @@ public class ResourceObject extends AbstractPreparedAFPObject { this.namedObject = obj; } + /** + * Returns the data object referenced by this resource object + * + * @return the data object referenced by this resource object + */ + public AbstractNamedAFPObject getDataObject() { + return namedObject; + } + /** {@inheritDoc} */ protected void writeStart(OutputStream os) throws IOException { super.writeStart(os); @@ -109,7 +118,9 @@ public class ResourceObject extends AbstractPreparedAFPObject { public static final byte TYPE_IMAGE = 0x06; // private static final byte FONT_CHARACTER_SET = 0x40; + // private static final byte CODE_PAGE = 0x41; + // private static final byte CODED_FONT = 0x42; /** object container type */ @@ -125,6 +136,7 @@ public class ResourceObject extends AbstractPreparedAFPObject { public static final byte TYPE_OVERLAY_OBJECT = (byte) 0xFC; // private static final byte PAGEDEF = (byte) 0xFD; + // private static final byte FORMDEF = (byte) 0xFE; private class ResourceObjectTypeTriplet extends Triplet { @@ -134,8 +146,7 @@ public class ResourceObject extends AbstractPreparedAFPObject { /** * Main constructor * - * @param type - * the resource objec type + * @param type the resource object type */ public ResourceObjectTypeTriplet(byte type) { super(RESOURCE_OBJECT, diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java new file mode 100644 index 000000000..a2d42feb9 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/modca/triplets/ExtendedResourceLocalIdentifierTriplet.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id: $ */ + +package org.apache.fop.render.afp.modca.triplets; + +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * The Extended Resource Local Identifier triplet specifies a resource type and a + * four byte local identifier or LID. The LID usually is associated with a specific + * resource name by a map structured field, such as a Map Data Resource structured + * field, or a Map Media Type structured field. + */ +public class ExtendedResourceLocalIdentifierTriplet extends Triplet { + + /** the image resource type */ + public static final byte TYPE_IMAGE_RESOURCE = 0x10; + + /** the retired value type */ + public static final byte TYPE_RETIRED_VALUE = 0x30; + + /** the retired value type */ + public static final byte TYPE_MEDIA_RESOURCE = 0x40; + + /** + * Main constructor + * + * @param type the resource type + * @param localId the resource local id + */ + public ExtendedResourceLocalIdentifierTriplet(byte type, int localId) { + super(Triplet.EXTENDED_RESOURCE_LOCAL_IDENTIFIER); + byte[] data = new byte[5]; + data[0] = type; + byte[] resLID = BinaryUtils.convert(localId, 4); + System.arraycopy(resLID, 0, data, 1, resLID.length); + super.setData(data); + } +} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java new file mode 100644 index 000000000..b98a46a72 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/modca/triplets/ObjectByteExtentTriplet.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id: $ */ + +package org.apache.fop.render.afp.modca.triplets; + +import org.apache.fop.render.afp.tools.BinaryUtils; + +/** + * The Object Byte Extent triplet is used to specify the number of bytes contained in an object + */ +public class ObjectByteExtentTriplet extends Triplet { + + /** + * Main constructor + * + * @param byteExt the number of bytes contained in the object + */ + public ObjectByteExtentTriplet(int byteExt) { + super(OBJECT_BYTE_EXTENT); + byte[] data = BinaryUtils.convert(byteExt, 4); + super.setData(data); + } +} diff --git a/src/java/org/apache/fop/render/afp/modca/triplets/StrucFlgs.java b/src/java/org/apache/fop/render/afp/modca/triplets/StrucFlgs.java index 12ae5f00b..7a2f38900 100644 --- a/src/java/org/apache/fop/render/afp/modca/triplets/StrucFlgs.java +++ b/src/java/org/apache/fop/render/afp/modca/triplets/StrucFlgs.java @@ -25,29 +25,29 @@ package org.apache.fop.render.afp.modca.triplets; */ public class StrucFlgs { -// private static final int OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER = 1; -// private static final int OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN = 2; -// private static final int OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER = 3; -// -// private static final int OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP = 4; -// private static final int OBJECT_CONTAINER_OBJECT_ENVIRONMENT_GROUP_CONTAINMENT_UNKNOWN = 8; -// private static final int OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP = 12; -// -// private static final int OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA = 16; -// private static final int OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN = 32; -// private static final int OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA = 48; - - private static final int OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER = 48; - private static final int OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN = 32; - private static final int OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER = 16; + private static final int OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER = 1; + private static final int OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN = 2; + private static final int OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER = 3; - private static final int OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP = 12; + private static final int OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP = 4; private static final int OBJECT_CONTAINER_OBJECT_ENVIRONMENT_GROUP_CONTAINMENT_UNKNOWN = 8; - private static final int OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP = 4; + private static final int OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP = 12; - private static final int OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA = 3; - private static final int OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN = 2; - private static final int OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA = 1; + private static final int OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA = 16; + private static final int OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN = 32; + private static final int OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA = 48; + +// private static final int OBJECT_DATA_NOT_CARRIED_IN_OBJECT_CONTAINER = 48; +// private static final int OBJECT_DATA_OBJECT_CONTAINER_STRUCTURE_UNKNOWN = 32; +// private static final int OBJECT_DATA_CARRIED_IN_OBJECT_CONTAINER = 16; +// +// private static final int OBJECT_CONTAINER_NOT_INCLUDE_OBJECT_ENVIRONMENT_GROUP = 12; +// private static final int OBJECT_CONTAINER_OBJECT_ENVIRONMENT_GROUP_CONTAINMENT_UNKNOWN = 8; +// private static final int OBJECT_CONTAINER_INCLUDES_OBJECT_ENVIRONMENT_GROUP = 4; +// +// private static final int OBJECT_CONTAINER_DATA_NOT_CARRIED_IN_OBJECT_DATA = 3; +// private static final int OBJECT_CONTAINER_DATA_OBJECT_DATA_CONTAINMENT_UNKNOWN = 2; +// private static final int OBJECT_CONTAINER_DATA_CARRIES_OBJECT_DATA = 1; /** * the default structured flags setting -- 2.39.5