]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
* Image positioning fix.
authorAdrian Cumiskey <acumiskey@apache.org>
Mon, 8 Sep 2008 13:32:30 +0000 (13:32 +0000)
committerAdrian Cumiskey <acumiskey@apache.org>
Mon, 8 Sep 2008 13:32:30 +0000 (13:32 +0000)
* Grayscaling of IOCA images fix.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@693092 13f79535-47bb-0310-9956-ffa450edef68

29 files changed:
src/java/org/apache/fop/render/afp/AFPDataObjectFactory.java
src/java/org/apache/fop/render/afp/AFPGraphics2D.java
src/java/org/apache/fop/render/afp/AFPGraphicsObjectPainter.java
src/java/org/apache/fop/render/afp/AFPImageObjectInfo.java
src/java/org/apache/fop/render/afp/AFPImageRenderedFactory.java
src/java/org/apache/fop/render/afp/AFPRenderer.java
src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
src/java/org/apache/fop/render/afp/AFPResourceInfo.java
src/java/org/apache/fop/render/afp/AFPResourceManager.java
src/java/org/apache/fop/render/afp/AFPState.java
src/java/org/apache/fop/render/afp/AFPStreamer.java
src/java/org/apache/fop/render/afp/goca/GraphicsArea.java
src/java/org/apache/fop/render/afp/goca/GraphicsChainedSegment.java
src/java/org/apache/fop/render/afp/goca/GraphicsData.java
src/java/org/apache/fop/render/afp/ioca/ImageContent.java
src/java/org/apache/fop/render/afp/ioca/ImageSegment.java
src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java
src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java
src/java/org/apache/fop/render/afp/modca/AbstractPreparedAFPObject.java
src/java/org/apache/fop/render/afp/modca/AbstractPreparedObjectContainer.java
src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java
src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java
src/java/org/apache/fop/render/afp/modca/Factory.java
src/java/org/apache/fop/render/afp/modca/GraphicsObject.java
src/java/org/apache/fop/render/afp/modca/IncludeObject.java
src/java/org/apache/fop/render/afp/modca/ObjectContainer.java
src/java/org/apache/fop/render/afp/modca/ObjectEnvironmentGroup.java
src/java/org/apache/fop/render/afp/modca/PreparedAFPObject.java
src/java/org/apache/fop/render/afp/modca/ResourceObject.java

index cba8bd71eb55ac8bed1c450df00d997a9c6cffed..d31b79cc4ebae332357f4e11ae200b0ee4b7120f 100644 (file)
@@ -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);
index e5049ce076a412fdd9e7a7f2818858be4ad7cd60..cb33e5a5a7033b36f0d4d0c4accf3ce9df9fdd10 100644 (file)
@@ -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();
index 79788b09189a7acdf940c9d14581c58b61d22c14..b794ff93cc59b2f670bd74a1487c02e087053102 100644 (file)
@@ -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
index 23bef01de252b57b5ccb3e65345f74e12b2b64df..c4b901b7c75c3bddc8c76dd911c1ff28d74a1d6c 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.fop.render.afp;
 
 
+
 /**
  * A list of parameters associated with an image
  */
index 15d7a317395a7c67f6198ed1ecbaff9d00728f24..4ce6b27b0b79034f6653ff35afc5e1f83b2b7e97 100644 (file)
@@ -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;
     }
index 056792fdd000290e5639547e98f0da617900df56..9a7fa7515d24a761bd52a30d366bce86c3f803df 100644 (file)
@@ -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);
-    }
-
 }
index 794f5bda8735481cac007bcb7b214a9972a65eb4..85784af55cc4d749620d6c511b549b2a4ea654b0 100644 (file)
@@ -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
index d6d30888333e97f4d8db8097c3ea7d19081ae6e7..cdb7c096171c0ebd3b7957e11df4b29a1c08cafa 100644 (file)
@@ -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} */
index 566834e4bd21d8a640db8d339c1449a5baec93ce..5a28efe266f921b7961675fc1087834fc75c1cc5 100644 (file)
@@ -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);
         }
     }
index 709e151f6b3fc9f393d8d2b205a489287c58b723..2f01e837173a15f962fd86ba4f6312b3d1803905 100644 (file)
@@ -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;
index 25a631aa983a2a28fa746218d0444f521970156b..0759b85fcb3d412b266116f8399ae3be17ae1a01 100644 (file)
@@ -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;
     }
index 06cc8451f041cfef675bc265e38693af0258b1d0..7ad6ede2798e8b2a6ac2e55128be7ee55f29909a 100644 (file)
@@ -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))
index 89803507c3075a9bad3dacac37b3cf462bda9497..ba4ccea86483da0278280344ebcf220bda9e5a30 100644 (file)
@@ -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} */
index ad346dfb7504979508dde9f61aa13a4a0858f688..538933a03bcc9a3d48dd2c00116b8895af44eb57 100644 (file)
@@ -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} */
index a0e14e12ef95efc5213b80f7d86efd8bbbcd2b81..7143b986c9e4a66a72bcfb7cc44f49521df4c1af 100644 (file)
@@ -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;
     }
 
     /**
index e5e1bbd23ff34f82f08000d8b31b6c3c14391ad1..8f6e6a59cb2bd6f19164bb65c9376b3119eae0bb 100644 (file)
@@ -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);
     }
 
     /**
index b0d59ced7f1936a49690c7f3b9221e1cc5ced09b..b59af4157c95fe432e71bfbaa126d8111d09deee 100644 (file)
@@ -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);
     }
 
     /**
index 7dcd7ea3587cba67329a886452d08be717da08b8..3ce108bfcab9b5e3e2b751af39089da83c30975f 100644 (file)
@@ -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:
                 }
index 16ed036f2fdd625c35ea9d2a547df0d9e64a5d77..42b729cf0220542b691df8ddf6e6cff39c52e005 100644 (file)
@@ -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) {
index f16d2df81d24faa744a1673f9ad6a43ff8ac04de..5d32a6b9b053225e64f4e47d3b9c847f613a540d 100644 (file)
@@ -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;
index 4c31472bd542be7cb4670391a38930e8ff894633..dee0366cb1ff8671912daf2285f3a56685b801cf 100644 (file)
@@ -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;
@@ -234,26 +232,6 @@ public abstract class AbstractStructuredAFPObject extends AbstractAFPObject {
                         objectClass, objectType, dataInContainer, containerHasOEG, dataInOCD));
     }
 
-    /**
-     * Sets the extent of an object area in the X and Y directions
-     *
-     * @param x the x direction extent
-     * @param y the y direction extent
-     */
-    public void setObjectAreaSize(int x, int y) {
-        addTriplet(new ObjectAreaSizeTriplet(x, y));
-    }
-
-    /**
-     * Sets the measurement units used to specify the units of measure
-     *
-     * @param xRes units per base on the x-axis
-     * @param yRes units per base on the y-axis
-     */
-    public void setMeasurementUnits(int xRes, int yRes) {
-        addTriplet(new MeasurementUnitsTriplet(xRes, xRes));
-    }
-
     /**
      * Sets a comment on this resource
      *
index c254ef17b4960787a426a8d86197ad28e3e30c3f..da418aca6f20529cc4e5bc1c4ce8ebb56f6aed6b 100644 (file)
@@ -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 {
index c8e8669a50e0545cb443a0af5661aa0c080a3a0b..d45684a706ef76decc1d6e26e1802ef7fb54f5fd 100644 (file)
@@ -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;
     }
 
@@ -506,6 +507,19 @@ public class Factory {
         return mapDataResource;
     }
 
+    /**
+     * Creates a new PTOCA {@link PresentationTextDescriptor}
+     *
+     * @return a new {@link PresentationTextDescriptor}
+     */
+    public PresentationTextDescriptor createPresentationTextDataDescriptor(
+            int width, int height, int widthRes, int heightRes) {
+        PresentationTextDescriptor presentationTextDescriptor
+            = new PresentationTextDescriptor(width, height,
+                widthRes, heightRes);
+        return presentationTextDescriptor;
+    }
+
     /**
      * Creates a new MO:DCA {@link PresentationEnvironmentControl}
      *
@@ -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;
+    }
+
 }
index c5be86023cbcc7e85349209a603680a0ca688932..4d33b28def638f912f6ac718848c2c5236127a5e 100644 (file)
@@ -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();
         }
     }
 
index 0c8afd98e29270feefb2debc9709e072c0ca5e83..336f2700f093326044a911e61d8f01cc48cdcee4 100644 (file)
@@ -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
index cb8a85fb3716e83a0182b2fed19e743e087b2edb..d9a7c2895422f4da240565bfd5a1abda3dc29d77 100644 (file)
@@ -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);
index 48aa9aa6c85587e48f6a0e0a35e107771d610ce8..7c44701bffa913f4dc7d63933677384b9f8fdaa0 100644 (file)
@@ -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;
     }
+
 }
index c62577ca6ddfbcab3cdc60e42545cfa35687d81b..6856d32872f1d497ea4ad1b733cd94899babc8b1 100644 (file)
@@ -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
index a65394c39f8a58ffb63924e5692a7e8a2172ac0b..edbe302265fdfa4c8b3d7d625dd97984d5a4e34f 100644 (file)
@@ -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
                 }
             );