You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ac...@apache.org on 2007/12/12 13:24:16 UTC

svn commit: r603590 [3/5] - in /xmlgraphics/fop/trunk: lib/ src/java/org/apache/fop/render/afp/ src/java/org/apache/fop/render/afp/modca/ src/java/org/apache/fop/render/afp/modca/goca/ src/java/org/apache/fop/render/ps/

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPTextPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPTextPainter.java?rev=603590&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPTextPainter.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPTextPainter.java Wed Dec 12 04:24:10 2007
@@ -0,0 +1,516 @@
+/*
+ * 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: PSTextPainter.java 542237 2007-05-28 14:31:24Z jeremias $ */
+
+package org.apache.fop.render.afp;
+
+import java.awt.Graphics2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.text.AttributedCharacterIterator;
+import java.text.CharacterIterator;
+import java.awt.font.TextAttribute;
+import java.awt.Shape;
+import java.awt.Paint;
+import java.awt.Color;
+import java.io.IOException;
+import java.util.List;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.batik.dom.svg.SVGOMTextElement;
+import org.apache.batik.gvt.text.Mark;
+import org.apache.batik.gvt.TextPainter;
+import org.apache.batik.gvt.TextNode;
+import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
+import org.apache.batik.gvt.text.TextPaintInfo;
+import org.apache.batik.gvt.font.GVTFontFamily;
+import org.apache.batik.gvt.renderer.StrokingTextPainter;
+
+import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
+
+/**
+ * Renders the attributed character iterator of a <tt>TextNode</tt>.
+ * This class draws the text directly into the AFPGraphics2D so that
+ * the text is not drawn using shapes.
+ * If the text is simple enough to draw then it sets the font and calls
+ * drawString. If the text is complex or the cannot be translated
+ * into a simple drawString the StrokingTextPainter is used instead.
+ */
+public class AFPTextPainter implements TextPainter {
+    
+    /** the logger for this class */
+    protected Log log = LogFactory.getLog(AFPTextPainter.class);
+    
+    private AFPTextHandler nativeTextHandler;
+    //private FontInfo fontInfo;
+
+    /**
+     * Use the stroking text painter to get the bounds and shape.
+     * Also used as a fallback to draw the string with strokes.
+     */
+    protected static final TextPainter 
+        PROXY_PAINTER = StrokingTextPainter.getInstance();
+
+    /**
+     * Create a new PS text painter with the given font information.
+     * @param nativeTextHandler the NativeTextHandler instance used for text painting
+     */
+    public AFPTextPainter(AFPTextHandler nativeTextHandler) {
+        this.nativeTextHandler = nativeTextHandler;
+    }
+
+    /**
+     * Paints the specified attributed character iterator using the
+     * specified Graphics2D and context and font context.
+     * @param node the TextNode to paint
+     * @param g2d the Graphics2D to use
+     */
+    public void paint(TextNode node, Graphics2D g2d) {
+        Point2D loc = node.getLocation();
+        log.debug("painting text node " + node);
+        if (hasUnsupportedAttributes(node)) {
+            log.debug("hasunsuportedattributes");
+            PROXY_PAINTER.paint(node, g2d);
+        } else {
+            log.debug("allattributessupported");
+            paintTextRuns(node.getTextRuns(), g2d, loc);
+        }
+    }
+    
+    private boolean hasUnsupportedAttributes(TextNode node) {
+        Iterator iter = node.getTextRuns().iterator();
+        while (iter.hasNext()) {
+            StrokingTextPainter.TextRun 
+                    run = (StrokingTextPainter.TextRun)iter.next();
+            AttributedCharacterIterator aci = run.getACI();
+            boolean hasUnsupported = hasUnsupportedAttributes(aci);
+            if (hasUnsupported) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean hasUnsupportedAttributes(AttributedCharacterIterator aci) {
+        boolean hasunsupported = false;
+        
+        String text = getText(aci);
+        Font font = makeFont(aci);
+        if (hasUnsupportedGlyphs(text, font)) {
+            log.trace("-> Unsupported glyphs found");
+            hasunsupported = true;
+        }
+        
+        TextPaintInfo tpi = (TextPaintInfo) aci.getAttribute(
+            GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
+        if ((tpi != null) 
+                && ((tpi.strokeStroke != null && tpi.strokePaint != null)
+                    || (tpi.strikethroughStroke != null)
+                    || (tpi.underlineStroke != null)
+                    || (tpi.overlineStroke != null))) {
+                        log.trace("-> under/overlines etc. found");
+            hasunsupported = true;
+        }
+
+        //Alpha is not supported
+        Paint foreground = (Paint) aci.getAttribute(TextAttribute.FOREGROUND);
+        if (foreground instanceof Color) {
+            Color col = (Color)foreground;
+            if (col.getAlpha() != 255) {
+                log.trace("-> transparency found");
+                hasunsupported = true;
+            }
+        }
+
+        Object letSpace = aci.getAttribute(
+                            GVTAttributedCharacterIterator.TextAttribute.LETTER_SPACING);
+        if (letSpace != null) {
+            log.trace("-> letter spacing found");
+            hasunsupported = true;
+        }
+
+        Object wordSpace = aci.getAttribute(
+                             GVTAttributedCharacterIterator.TextAttribute.WORD_SPACING);
+        if (wordSpace != null) {
+            log.trace("-> word spacing found");
+            hasunsupported = true;
+        }
+        
+        Object lengthAdjust = aci.getAttribute(
+                            GVTAttributedCharacterIterator.TextAttribute.LENGTH_ADJUST);
+        if (lengthAdjust != null) {
+            log.trace("-> length adjustments found");
+            hasunsupported = true;
+        }
+
+        Object writeMod = aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE);
+        if (writeMod != null 
+            && !GVTAttributedCharacterIterator.TextAttribute.WRITING_MODE_LTR.equals(
+                  writeMod)) {
+            log.trace("-> Unsupported writing modes found");
+            hasunsupported = true;
+        }
+
+        Object vertOr = aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.VERTICAL_ORIENTATION);
+        if (GVTAttributedCharacterIterator.TextAttribute.ORIENTATION_ANGLE.equals(
+                  vertOr)) {
+            log.trace("-> vertical orientation found");
+            hasunsupported = true;
+        }
+        
+        Object rcDel = aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
+        //Batik 1.6 returns null here which makes it impossible to determine whether this can
+        //be painted or not, i.e. fall back to stroking. :-(
+        if (rcDel != null && !(rcDel instanceof SVGOMTextElement)) {
+            log.trace("-> spans found");
+            hasunsupported = true; //Filter spans
+        }
+        
+        if (hasunsupported) {
+            log.trace("Unsupported attributes found in ACI, using StrokingTextPainter");
+        }
+        return hasunsupported;
+    }
+
+    /**
+     * Paint a list of text runs on the Graphics2D at a given location.
+     * @param textRuns the list of text runs
+     * @param g2d the Graphics2D to paint to
+     * @param loc the current location of the "cursor"
+     */
+    protected void paintTextRuns(List textRuns, Graphics2D g2d, Point2D loc) {
+        Point2D currentloc = loc;
+        Iterator i = textRuns.iterator();
+        while (i.hasNext()) {
+            StrokingTextPainter.TextRun 
+                    run = (StrokingTextPainter.TextRun)i.next();
+            currentloc = paintTextRun(run, g2d, currentloc);
+        }
+    }
+
+    /**
+     * Paint a single text run on the Graphics2D at a given location.
+     * @param run the text run to paint
+     * @param g2d the Graphics2D to paint to
+     * @param loc the current location of the "cursor"
+     * @return the new location of the "cursor" after painting the text run
+     */
+    protected Point2D paintTextRun(StrokingTextPainter.TextRun run, Graphics2D g2d, Point2D loc) {
+        AttributedCharacterIterator aci = run.getACI();
+        aci.first();
+
+        updateLocationFromACI(aci, loc);
+        loc = g2d.getTransform().transform(loc, null);
+
+        // font
+        Font font = makeFont(aci);
+        nativeTextHandler.setOverrideFont(font);
+        
+        // color
+        TextPaintInfo tpi = (TextPaintInfo) aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
+        if (tpi == null) {
+            return loc;
+        }
+        Paint foreground = tpi.fillPaint;
+        if (foreground instanceof Color) {
+            Color col = (Color)foreground;
+            g2d.setColor(col);
+        }
+        g2d.setPaint(foreground);
+        
+        String txt = getText(aci);
+        float advance = getStringWidth(txt, font);
+        float tx = 0;
+        TextNode.Anchor anchor = (TextNode.Anchor)aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
+        if (anchor != null) {
+            switch (anchor.getType()) {
+            case TextNode.Anchor.ANCHOR_MIDDLE:
+                tx = -advance / 2;
+                break;
+            case TextNode.Anchor.ANCHOR_END:
+                tx = -advance;
+                break;
+            default: //nop
+            }
+        }
+
+        // draw string
+        try {
+            try {
+                nativeTextHandler.drawString(txt, (float)(loc.getX() + tx), (float)(loc.getY()));
+            } catch (IOException ioe) {
+                if (g2d instanceof AFPGraphics2D) {
+                    ((AFPGraphics2D)g2d).handleIOException(ioe);
+                }
+            }
+        } finally {
+            nativeTextHandler.setOverrideFont(null);
+        }
+        loc.setLocation(loc.getX() + (double)advance, loc.getY());
+        return loc;
+    }
+
+    /**
+     * Extract the raw text from an ACI.
+     * @param aci ACI to inspect
+     * @return the extracted text
+     */
+    protected String getText(AttributedCharacterIterator aci) {
+        StringBuffer sb = new StringBuffer(aci.getEndIndex() - aci.getBeginIndex());
+        for (char c = aci.first(); c != CharacterIterator.DONE; c = aci.next()) {
+            sb.append(c);
+        }
+        return sb.toString();
+    }
+
+    private void updateLocationFromACI(
+                AttributedCharacterIterator aci,
+                Point2D loc) {
+        //Adjust position of span
+        Float xpos = (Float)aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.X);
+        Float ypos = (Float)aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.Y);
+        Float dxpos = (Float)aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.DX);
+        Float dypos = (Float)aci.getAttribute(
+                GVTAttributedCharacterIterator.TextAttribute.DY);
+        if (xpos != null) {
+            loc.setLocation(xpos.doubleValue(), loc.getY());
+        }
+        if (ypos != null) {
+            loc.setLocation(loc.getX(), ypos.doubleValue());
+        } 
+        if (dxpos != null) {
+            loc.setLocation(loc.getX() + dxpos.doubleValue(), loc.getY());
+        } 
+        if (dypos != null) {
+            loc.setLocation(loc.getX(), loc.getY() + dypos.doubleValue());
+        } 
+    }
+
+    private String getStyle(AttributedCharacterIterator aci) {
+        Float posture = (Float)aci.getAttribute(TextAttribute.POSTURE);
+        return ((posture != null) && (posture.floatValue() > 0.0))
+                       ? "italic" 
+                       : "normal";
+    }
+
+    private int getWeight(AttributedCharacterIterator aci) {
+        Float taWeight = (Float)aci.getAttribute(TextAttribute.WEIGHT);
+        return ((taWeight != null) &&  (taWeight.floatValue() > 1.0)) 
+                       ? Font.WEIGHT_BOLD
+                       : Font.WEIGHT_NORMAL;
+    }
+
+    private Font makeFont(AttributedCharacterIterator aci) {
+        Float fontSize = (Float)aci.getAttribute(TextAttribute.SIZE);
+        if (fontSize == null) {
+            fontSize = new Float(10.0f);
+        }
+        String style = getStyle(aci);
+        int weight = getWeight(aci);
+
+        FontInfo fontInfo = nativeTextHandler.getFontInfo();
+        String fontFamily = null;
+        List gvtFonts = (List) aci.getAttribute(
+                      GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
+        if (gvtFonts != null) {
+            Iterator i = gvtFonts.iterator();
+            while (i.hasNext()) {
+                GVTFontFamily fam = (GVTFontFamily) i.next();
+                /* (todo) Enable SVG Font painting
+                if (fam instanceof SVGFontFamily) {
+                    PROXY_PAINTER.paint(node, g2d);
+                    return;
+                }*/
+                fontFamily = fam.getFamilyName();
+                if (fontInfo.hasFont(fontFamily, style, weight)) {
+                    FontTriplet triplet = fontInfo.fontLookup(
+                            fontFamily, style, weight);
+                    int fsize = (int)(fontSize.floatValue() * 1000);
+                    return fontInfo.getFontInstance(triplet, fsize);
+                }
+            }
+        }
+        FontTriplet triplet = fontInfo.fontLookup("any", style, Font.WEIGHT_NORMAL);
+        int fsize = (int)(fontSize.floatValue() * 1000);
+        return fontInfo.getFontInstance(triplet, fsize);
+    }
+
+    private float getStringWidth(String str, Font font) {
+        float wordWidth = 0;
+        float whitespaceWidth = font.getWidth(font.mapChar(' '));
+
+        for (int i = 0; i < str.length(); i++) {
+            float charWidth;
+            char c = str.charAt(i);
+            if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
+                charWidth = font.getWidth(font.mapChar(c));
+                if (charWidth <= 0) {
+                    charWidth = whitespaceWidth;
+                }
+            } else {
+                charWidth = whitespaceWidth;
+            }
+            wordWidth += charWidth;
+        }
+        return wordWidth / 1000f;
+    }
+
+    private boolean hasUnsupportedGlyphs(String str, Font font) {
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            if (!((c == ' ') || (c == '\n') || (c == '\r') || (c == '\t'))) {
+                if (!font.hasChar(c)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Get the outline shape of the text characters.
+     * This uses the StrokingTextPainter to get the outline
+     * shape since in theory it should be the same.
+     *
+     * @param node the text node
+     * @return the outline shape of the text characters
+     */
+    public Shape getOutline(TextNode node) {
+        return PROXY_PAINTER.getOutline(node);
+    }
+
+    /**
+     * Get the bounds.
+     * This uses the StrokingTextPainter to get the bounds
+     * since in theory it should be the same.
+     *
+     * @param node the text node
+     * @return the bounds of the text
+     */
+    public Rectangle2D getBounds2D(TextNode node) {
+        /* (todo) getBounds2D() is too slow 
+         * because it uses the StrokingTextPainter. We should implement this 
+         * method ourselves. */
+        return PROXY_PAINTER.getBounds2D(node);
+    }
+
+    /**
+     * Get the geometry bounds.
+     * This uses the StrokingTextPainter to get the bounds
+     * since in theory it should be the same.
+     * @param node the text node
+     * @return the bounds of the text
+     */
+    public Rectangle2D getGeometryBounds(TextNode node) {
+        return PROXY_PAINTER.getGeometryBounds(node);
+    }
+
+    // Methods that have no purpose for PS
+
+    /**
+     * Get the mark.
+     * This does nothing since the output is pdf and not interactive.
+     * @param node the text node
+     * @param pos the position
+     * @param all select all
+     * @return null
+     */
+    public Mark getMark(TextNode node, int pos, boolean all) {
+        return null;
+    }
+
+    /**
+     * Select at.
+     * This does nothing since the output is pdf and not interactive.
+     * @param x the x position
+     * @param y the y position
+     * @param node the text node
+     * @return null
+     */
+    public Mark selectAt(double x, double y, TextNode node) {
+        return null;
+    }
+
+    /**
+     * Select to.
+     * This does nothing since the output is pdf and not interactive.
+     * @param x the x position
+     * @param y the y position
+     * @param beginMark the start mark
+     * @return null
+     */
+    public Mark selectTo(double x, double y, Mark beginMark) {
+        return null;
+    }
+
+    /**
+     * Selec first.
+     * This does nothing since the output is pdf and not interactive.
+     * @param node the text node
+     * @return null
+     */
+    public Mark selectFirst(TextNode node) {
+        return null;
+    }
+
+    /**
+     * Select last.
+     * This does nothing since the output is pdf and not interactive.
+     * @param node the text node
+     * @return null
+     */
+    public Mark selectLast(TextNode node) {
+        return null;
+    }
+
+    /**
+     * Get selected.
+     * This does nothing since the output is pdf and not interactive.
+     * @param start the start mark
+     * @param finish the finish mark
+     * @return null
+     */
+    public int[] getSelected(Mark start, Mark finish) {
+        return null;
+    }
+
+    /**
+     * Get the highlighted shape.
+     * This does nothing since the output is pdf and not interactive.
+     * @param beginMark the start mark
+     * @param endMark the end mark
+     * @return null
+     */
+    public Shape getHighlightShape(Mark beginMark, Mark endMark) {
+        return null;
+    }
+
+}

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AFPDataStream.java Wed Dec 12 04:24:10 2007
@@ -22,9 +22,12 @@
 import java.awt.Color;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.fop.render.afp.AFPFontAttributes;
 import org.apache.fop.render.afp.fonts.AFPFont;
 import org.apache.fop.render.afp.tools.StringUtils;
 
@@ -132,7 +135,7 @@
      * The outputstream for the data stream
      */
     private OutputStream outputStream = null;
-
+    
     /**
      * Default constructor for the AFPDataStream.
      */
@@ -147,7 +150,6 @@
      *            the outputStream which the document is written to.
      */
     public void startDocument(OutputStream docOutputStream) {
-
         if (document != null) {
             String msg = "Invalid state - document already started.";
             log.warn("startDocument():: " + msg);
@@ -156,7 +158,6 @@
 
         this.document = new Document();
         this.outputStream = docOutputStream;
-
     }
 
     /**
@@ -168,7 +169,6 @@
      *             throws an I/O exception of some sort has occurred
      */
     public void endDocument() throws IOException {
-
         if (complete) {
             String msg = "Invalid state - document already ended.";
             log.warn("endDocument():: " + msg);
@@ -206,19 +206,19 @@
      *            the height of the page
      * @param pageRotation
      *            the rotation of the page
-     * @param pageWidthResolution
+     * @param pageWidthRes
      *            the width resolution of the page
-     * @param pageHeightResolution
+     * @param pageHeightRes
      *            the height resolution of the page
      */
     public void startPage(int pageWidth, int pageHeight, int pageRotation,
-            int pageWidthResolution, int pageHeightResolution) {
+            int pageWidthRes, int pageHeightRes) {
 
         String pageName = "PGN"
                 + StringUtils.lpad(String.valueOf(pageCount++), '0', 5);
 
         currentPageObject = new PageObject(pageName, pageWidth, pageHeight,
-                pageRotation, pageWidthResolution, pageHeightResolution);
+                pageRotation, pageWidthRes, pageHeightRes);
         currentPage = currentPageObject;
         currentOverlay = null;
         setOffsets(0, 0, 0);
@@ -265,11 +265,9 @@
      * Helper method to mark the end of the current overlay.
      */
     public void endOverlay() {
-
         currentOverlay.endPage();
         currentOverlay = null;
         currentPage = currentPageObject;
-
     }
 
     /**
@@ -278,7 +276,6 @@
      * @return current page object that was saved
      */
     public PageObject savePage() {
-
         PageObject pageObject = currentPageObject;
         if (currentPageGroup != null) {
             currentPageGroup.addPage(currentPageObject);
@@ -288,7 +285,6 @@
         currentPageObject = null;
         currentPage = null;
         return pageObject;
-
     }
 
     /**
@@ -298,10 +294,8 @@
      *            page object
      */
     public void restorePage(PageObject pageObject) {
-
         currentPageObject = pageObject;
         currentPage = pageObject;
-
     }
 
     /**
@@ -311,7 +305,6 @@
      *             thrown when an I/O exception of some sort has occurred
      */
     public void endPage() throws IOException {
-
         currentPageObject.endPage();
         if (currentPageGroup != null) {
             currentPageGroup.addPage(currentPageObject);
@@ -319,10 +312,8 @@
             document.addPage(currentPageObject);
             document.writeDataStream(this.outputStream);
         }
-
         currentPageObject = null;
         currentPage = null;
-
     }
 
     /**
@@ -342,6 +333,21 @@
     }
 
     /**
+     * Creates the given page fonts in the current page
+     * @param pageFonts a collection of AFP font attributes
+     */
+    public void addFontsToCurrentPage(Map pageFonts) {
+        Iterator iter = pageFonts.values().iterator();
+        while (iter.hasNext()) {
+            AFPFontAttributes afpFontAttributes = (AFPFontAttributes)iter.next();
+            createFont(
+                afpFontAttributes.getFontReference(),
+                afpFontAttributes.getFont(),
+                afpFontAttributes.getPointSize());
+        }
+    }
+
+    /**
      * Helper method to create a map coded font object on the current page, this
      * method delegates the construction of the map coded font object to the
      * active environment group on the current page.
@@ -353,18 +359,17 @@
      * @param size
      *            the point size of the font
      */
-    public void createFont(byte fontReference, AFPFont font, int size) {
-
+    public void createFont(int fontReference, AFPFont font, int size) {
         currentPage.createFont(fontReference, font, size);
-
     }
 
+
     /**
      * Helper method to create text on the current page, this method delegates
      * to the current presentation text object in order to construct the text.
      * 
-     * @param fontNumber
-     *            the font number used as the resource identifier
+     * @param fontReference
+     *            the font reference used as the resource identifier
      * @param x
      *            the x coordinate of the text
      * @param y
@@ -378,81 +383,125 @@
      * @param data
      *            the text data to create
      */
-    public void createText(int fontNumber, int x, int y, Color col, int vsci,
+    public void createText(int fontReference, int x, int y, Color col, int vsci,
             int ica, byte[] data) {
-
-        currentPage.createText(fontNumber, x + xOffset, y + yOffset, rotation,
+        currentPage.createText(fontReference, x + xOffset, y + yOffset, rotation,
                 col, vsci, ica, data);
-
     }
 
     /**
      * Returns an ImageObject used to create an image in the datastream.
-     * 
+     *
      * @param x
      *            the x position of the image
      * @param y
      *            the y position of the image
-     * @param w
+     * @param width
      *            the width of the image
-     * @param h
+     * @param height
      *            the height of the image
+     * @param widthRes
+     *            the resolution width of the image
+     * @param heightRes
+     *            the resolution height of the image
+     * @return
+     *            a new image object
+     */
+    public ImageObject getImageObject(int x, int y, int width, int height,
+            int widthRes, int heightRes) {
+        ImageObject imageObj = currentPage.getImageObject();
+        setObjectViewPort(imageObj, x, y, width, height, widthRes, heightRes);
+        return imageObj;
+    }
+
+    /**
+     * Returns an GraphicObject used to create an graphic in the datastream.
+     *
+     * @param x
+     *            the x position of the graphic
+     * @param y
+     *            the y position of the graphic
+     * @param width
+     *            the width of the graphic
+     * @param height
+     *            the height of the graphic
+     * @param widthRes
+     *            the resolution width of the graphic
+     * @param heightRes
+     *            the resolution height of the graphic
+     * @return
+     *            a new graphics object
+     */
+    public GraphicsObject getGraphicsObject(int x, int y, int width, int height,
+            int widthRes, int heightRes) {
+        GraphicsObject graphicsObj = currentPage.getGraphicsObject();
+        setObjectViewPort(graphicsObj, x, y, width, height, widthRes, heightRes);
+        return graphicsObj;
+    }
+
+    /**
+     * Sets the object view port taking into account rotation.
+     *
+     * @param x
+     *            the x position of the object
+     * @param y
+     *            the y position of the object
+     * @param w
+     *            the width of the object
+     * @param h
+     *            the height of the object
      * @param wr
-     *            the width resolution of the image
+     *            the resolution width of the object
      * @param hr
-     *            the height resolution of the image
-     * @return ImageObject used to create an image in the datastream
+     *            the resolution height of the object
+     * @return
+     *            a new graphics object
      */
-    public ImageObject getImageObject(int x, int y, int w, int h, int wr, int hr) {
-
+    private void setObjectViewPort(AbstractDataObject dataObj,
+            int x, int y, int w, int h, int wr, int hr) {
         int xOrigin;
         int yOrigin;
         int width;
         int height;
-        int widthResolution;
-        int heightResolution;
-
-        switch (rotation) {
+        int widthRes;
+        int heightRes;
+        switch (this.rotation) {
         case 90:
             xOrigin = currentPage.getWidth() - y - yOffset;
             yOrigin = x + xOffset;
             width = h;
             height = w;
-            widthResolution = hr;
-            heightResolution = wr;
+            widthRes = hr;
+            heightRes = wr;
             break;
         case 180:
             xOrigin = currentPage.getWidth() - x - xOffset;
             yOrigin = currentPage.getHeight() - y - yOffset;
             width = w;
             height = h;
-            widthResolution = wr;
-            heightResolution = hr;
+            widthRes = wr;
+            heightRes = hr;
             break;
         case 270:
             xOrigin = y + yOffset;
             yOrigin = currentPage.getHeight() - x - xOffset;
             width = h;
             height = w;
-            widthResolution = hr;
-            heightResolution = wr;
+            widthRes = hr;
+            heightRes = wr;
             break;
         default:
             xOrigin = x + xOffset;
             yOrigin = y + yOffset;
             width = w;
             height = h;
-            widthResolution = wr;
-            heightResolution = hr;
+            widthRes = wr;
+            heightRes = hr;
             break;
         }
-        ImageObject io = currentPage.getImageObject();
-        io.setImageViewport(xOrigin, yOrigin, width, height, rotation,
-                widthResolution, heightResolution);
-        return io;
-
+        dataObj.setViewport(xOrigin, yOrigin, width, height, widthRes, heightRes, rotation);
     }
-
+        
     /**
      * Method to create a line on the current page.
      * 
@@ -471,10 +520,8 @@
      */
     public void createLine(int x1, int y1, int x2, int y2, int thickness,
             Color col) {
-
         currentPage.createLine(x1 + xOffset, y1 + yOffset, x2 + xOffset, y2
                 + yOffset, thickness, rotation, col);
-
     }
 
     /**
@@ -499,10 +546,8 @@
      */
     public void createShading(int x, int y, int w, int h, int red, int green,
             int blue) {
-
         currentPage.createShading(x + xOffset, y + xOffset, w, h, red, green,
                 blue);
-
     }
 
     /**
@@ -513,12 +558,10 @@
      *            the name of the static overlay
      */
     public void createIncludePageOverlay(String name) {
-
         currentPageObject.createIncludePageOverlay(name, 0, 0, rotation);
         ActiveEnvironmentGroup aeg = currentPageObject
                 .getActiveEnvironmentGroup();
         aeg.createOverlay(name);
-
     }
 
     /**
@@ -528,12 +571,10 @@
      *            the name of the medium map
      */
     public void createInvokeMediumMap(String name) {
-
         if (currentPageGroup == null) {
             startPageGroup();
         }
         currentPageGroup.createInvokeMediumMap(name);
-
     }
 
     /**
@@ -547,7 +588,6 @@
      *            the y coordinate for the overlay
      */
     public void createIncludePageSegment(String name, int x, int y) {
-
         int xOrigin;
         int yOrigin;
         switch (rotation) {
@@ -569,7 +609,6 @@
             break;
         }
         currentPage.createIncludePageSegment(name, xOrigin, yOrigin);
-
     }
 
     /**
@@ -579,13 +618,11 @@
      *            the array of key value pairs.
      */
     public void createPageTagLogicalElement(TagLogicalElementBean[] attributes) {
-
         for (int i = 0; i < attributes.length; i++) {
             String name = (String) attributes[i].getKey();
             String value = (String) attributes[i].getValue();
             currentPage.createTagLogicalElement(name, value);
         }
-
     }
 
     /**
@@ -594,15 +631,12 @@
      * @param attributes
      *            the array of key value pairs.
      */
-    public void createPageGroupTagLogicalElement(
-            TagLogicalElementBean[] attributes) {
-
+    public void createPageGroupTagLogicalElement(TagLogicalElementBean[] attributes) {
         for (int i = 0; i < attributes.length; i++) {
             String name = (String) attributes[i].getKey();
             String value = (String) attributes[i].getValue();
             currentPageGroup.createTagLogicalElement(name, value);
         }
-
     }
 
     /**
@@ -614,13 +648,11 @@
      *            The tag value
      */
     public void createTagLogicalElement(String name, String value) {
-
         if (currentPageGroup != null) {
             currentPageGroup.createTagLogicalElement(name, value);
         } else {
             currentPage.createTagLogicalElement(name, value);
         }
-
     }
 
     /**
@@ -697,5 +729,4 @@
         }
 
     }
-
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractAFPObject.java Wed Dec 12 04:24:10 2007
@@ -44,7 +44,7 @@
      * DataStream objects must implement the writeDataStream()
      * method to write its data to the given OutputStream
      * @param os The outputsteam stream
-     * @throws java.io.IOException
+     * @throws java.io.IOException in the event that an I/O exception occurred
      */
     public abstract void writeDataStream(OutputStream os) throws IOException;
 
@@ -52,15 +52,14 @@
      * Help method to write a set of AFPObjects to the AFP datastream.
      * @param afpObjects a list of AFPObjects
      * @param os The stream to write to
-     * @throws java.io.IOException
+     * @throws java.io.IOException in the event that an I/O exception occurred
      */
     protected void writeObjectList(List afpObjects, OutputStream os)
-        throws IOException {
+    throws IOException {
 
-        for (Iterator it = afpObjects.iterator(); it.hasNext(); ) {
+        Iterator it = afpObjects.iterator();
+        while (it.hasNext()) {
             ((AbstractAFPObject)it.next()).writeDataStream(os);
         }
-
     }
-
 }

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java?rev=603590&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDataObject.java Wed Dec 12 04:24:10 2007
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.render.afp.modca.goca.AbstractGraphicsContainer;
+
+/**
+ * Abstract base class used by the ImageObject and GraphicsObject which both
+ * have define an ObjectEnvironmentGroup
+ */
+public abstract class AbstractDataObject extends AbstractGraphicsContainer {
+
+    /**
+     * The object environment group
+     */
+    protected ObjectEnvironmentGroup objectEnvironmentGroup = null;
+
+    /**
+     * Named constructor
+     * @param name data object name
+     */
+    public AbstractDataObject(String name) {
+        super(name);
+    }
+    
+    /**
+     * Sets the object display area position and size.
+     *
+     * @param x
+     *            the x position of the object
+     * @param y
+     *            the y position of the object
+     * @param width
+     *            the width of the object
+     * @param height
+     *            the height of the object
+     * @param widthRes 
+     *            the resolution width 
+     * @param heightRes
+     *            the resolution height 
+     * @param rotation
+     *            the rotation of the object
+     */
+    public void setViewport(int x, int y, int width, int height,
+            int widthRes, int heightRes, int rotation) {
+        if (objectEnvironmentGroup == null) {
+            objectEnvironmentGroup = new ObjectEnvironmentGroup();
+        }
+        objectEnvironmentGroup.setObjectArea(x, y, width, height,
+                widthRes, heightRes, rotation);
+    }
+    
+    /**
+     * Sets the ObjectEnvironmentGroup.
+     * @param objectEnvironmentGroup The objectEnvironmentGroup to set
+     */
+    public void setObjectEnvironmentGroup(ObjectEnvironmentGroup objectEnvironmentGroup) {
+        this.objectEnvironmentGroup = objectEnvironmentGroup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void writeContent(OutputStream os) throws IOException {
+        if (objectEnvironmentGroup != null) {
+            objectEnvironmentGroup.writeDataStream(os);
+        }
+        super.writeContent(os);
+    }
+}

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractDescriptor.java Wed Dec 12 04:24:10 2007
@@ -28,22 +28,22 @@
     /** height of this descriptor */
     protected int height = 0;
     /** width resolution of this descriptor */
-    protected int widthResolution = 0;
+    protected int widthRes = 0;
     /** height resolution of this descriptor */
-    protected int heightResolution = 0;
+    protected int heightRes = 0;
 
     /**
      * 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 AbstractDescriptor(int width, int height, int widthResolution, int heightResolution) {
+    public AbstractDescriptor(int width, int height, int widthRes, int heightRes) {
         this.width = width;
         this.height = height;
-        this.widthResolution = widthResolution;
-        this.heightResolution = heightResolution;
+        this.widthRes = widthRes;
+        this.heightRes = heightRes;
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractNamedAFPObject.java Wed Dec 12 04:24:10 2007
@@ -25,7 +25,7 @@
  * A named data stream object has an 8 byte EBCIDIC name.
  */
 public abstract class AbstractNamedAFPObject extends AbstractAFPObject {
-    
+        
     /**
      * The actual name of the object
      */
@@ -35,35 +35,50 @@
      * The name of the object in EBCIDIC bytes
      */
     protected byte[] nameBytes;
-    
+
+    /**
+     * Default constructor
+     */
+    protected AbstractNamedAFPObject() {
+    }
+
+    private static final int DEFAULT_NAME_LENGTH = 8;
+
+    /**
+     * @return the name length of this object
+     */
+    protected int getNameLength() {
+        return DEFAULT_NAME_LENGTH;
+    }
+
     /**
      * Constructor for the ActiveEnvironmentGroup, this takes a
      * name parameter which should be 8 characters long.
      * @param name the object name
      */
     public AbstractNamedAFPObject(String name) {
-        
-        this.name = name;
-        if (name.length() < 8) {
-            name = (name + "       ").substring(0, 8);
-        } else if (name.length() > 8) {
-            log.warn("Constructor:: name truncated to 8 chars" + name);
-            name = name.substring(0, 8);
+        int nameLen = getNameLength();
+        if (name.length() < nameLen) {
+            this.name = (name + "       ").substring(0, nameLen);
+        } else if (name.length() > nameLen) {
+            log.warn("Constructor:: name truncated to " + nameLen + " chars: " + name);
+            this.name = name.substring(0, nameLen);
+        } else {
+            this.name = name;            
         }
         
         try {
             
-            nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING);
+            this.nameBytes = name.getBytes(AFPConstants.EBCIDIC_ENCODING);
             
         } catch (UnsupportedEncodingException usee) {
             
-            nameBytes = name.getBytes();
+            this.nameBytes = name.getBytes();
             log.warn(
                 "Constructor:: UnsupportedEncodingException translating the name "
                 + name);
             
         }
         
-    }
-    
+    }    
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractPageObject.java Wed Dec 12 04:24:10 2007
@@ -105,13 +105,13 @@
      *            the height of the page.
      * @param rotation
      *            the rotation of the page.
-     * @param widthResolution
+     * @param widthRes
      *            the width resolution of the page.
-     * @param heightResolution
+     * @param heightRes
      *            the height resolution of the page.
      */
     public AbstractPageObject(String name, int width, int height, int rotation,
-            int widthResolution, int heightResolution) {
+            int widthRes, int heightRes) {
 
         super(name);
         this.width = width;
@@ -121,8 +121,7 @@
         /**
          * Every page object must have an ActiveEnvironmentGroup
          */
-        activeEnvironmentGroup = new ActiveEnvironmentGroup(width, height,
-                widthResolution, heightResolution);
+        activeEnvironmentGroup = new ActiveEnvironmentGroup(width, height, widthRes, heightRes);
 
         if (rotation != 0) {
             switch (rotation) {
@@ -138,13 +137,6 @@
                 default:
             }
         }
-
-        /**
-         * We have a presentation text object per page
-         */
-        presentationTextObject = new PresentationTextObject();
-        objects.add(presentationTextObject);
-
     }
 
     /**
@@ -159,10 +151,8 @@
      * @param size
      *            the point size of the font
      */
-    public void createFont(byte fontReference, AFPFont font, int size) {
-
+    public void createFont(int fontReference, AFPFont font, int size) {
         activeEnvironmentGroup.createFont(fontReference, font, size, 0);
-
     }
 
     /**
@@ -186,20 +176,14 @@
      */
     public void createLine(int x1, int y1, int x2, int y2, int thickness,
             int lineRotation, Color col) {
-
-        if (presentationTextObject == null) {
-            presentationTextObject = new PresentationTextObject();
-            objects.add(presentationTextObject);
-        }
-        presentationTextObject.createLineData(x1, y1, x2, y2, thickness, lineRotation, col);
-
+        getPresentationTextObject().createLineData(x1, y1, x2, y2, thickness, lineRotation, col);
     }
 
     /**
      * Helper method to create text on the current page, this method delegates
      * to the presentation text object in order to construct the text.
      *
-     * @param fontNumber
+     * @param fontReference
      *            the font number used as the resource identifier
      * @param x
      *            the x coordinate of the text data
@@ -216,15 +200,10 @@
      * @param data
      *            the text data to create
      */
-    public void createText(int fontNumber, int x, int y, int textRotation, Color col,
+    public void createText(int fontReference, int x, int y, int textRotation, Color col,
             int vsci, int ica, byte[] data) {
-
-        if (presentationTextObject == null) {
-            presentationTextObject = new PresentationTextObject();
-            objects.add(presentationTextObject);
-        }
-        presentationTextObject.createTextData(fontNumber, x, y, textRotation, col, vsci, ica, data);
-
+        getPresentationTextObject().createTextData(
+                fontReference, x, y, textRotation, col, vsci, ica, data);
     }
 
     /**
@@ -232,13 +211,10 @@
      * sequence on the current presenation text object.
      */
     public void endPage() {
-
         if (presentationTextObject != null) {
             presentationTextObject.endControlSequence();
         }
-
         complete = true;
-
     }
 
     /**
@@ -327,6 +303,19 @@
     }
 
     /**
+     * Helper method to create a presentation text object
+     * on the current page and to return the object.
+     * @return the presentation text object
+     */
+    private PresentationTextObject getPresentationTextObject() {
+        if (presentationTextObject == null) {
+            this.presentationTextObject = new PresentationTextObject();
+            objects.add(this.presentationTextObject);
+        }
+        return presentationTextObject;
+    }
+    
+    /**
      * Helper method to create an image on the current page and to return
      * the object.
      * @return the image object
@@ -335,16 +324,32 @@
 
         if (presentationTextObject != null) {
             presentationTextObject.endControlSequence();
+            presentationTextObject = null;
         }
-        presentationTextObject = null;
-
         String imageName = "IMG"
             + StringUtils.lpad(String.valueOf(objects.size() + 1),
             '0', 5);
+        ImageObject imageObj = new ImageObject(imageName);
+        objects.add(imageObj);
+        return imageObj;
+    }
 
-        ImageObject io = new ImageObject(imageName);
-        objects.add(io);
-        return io;
+    /**
+     * Helper method to create a graphic on the current page and to return
+     * the object.
+     * @return the graphics object
+     */
+    public GraphicsObject getGraphicsObject() {
+        if (presentationTextObject != null) {
+            presentationTextObject.endControlSequence();
+            presentationTextObject = null;
+        }
+        String graphicName = "GRA"
+            + StringUtils.lpad(String.valueOf(objects.size() + 1),
+            '0', 5);
+        GraphicsObject graphicsObj = new GraphicsObject(graphicName);
+        objects.add(graphicsObj);
+        return graphicsObj;
     }
 
     /**
@@ -356,10 +361,8 @@
      *            the value of the tag
      */
     public void createTagLogicalElement(String name, String value) {
-
         TagLogicalElement tle = new TagLogicalElement(name, value);
         tagLogicalElements.add(tle);
-
     }
 
     /**
@@ -368,10 +371,8 @@
      * @param content the byte data
      */
     public void createNoOperation(String content) {
-
         NoOperation noOp = new NoOperation(content);
         objects.add(noOp);
-
     }
 
     /**
@@ -380,15 +381,13 @@
      * @param name
      *            the name of the page segment
      * @param xCoor
-     *            the x cooridinate of the page segment.
+     *            the x coordinate of the page segment.
      * @param yCoor
-     *            the y cooridinate of the page segment.
+     *            the y coordinate of the page segment.
      */
     public void createIncludePageSegment(String name, int xCoor, int yCoor) {
-
         IncludePageSegment ips = new IncludePageSegment(name, xCoor, yCoor);
         segments.add(ips);
-
     }
 
     /**
@@ -431,5 +430,4 @@
     public int getRotation() {
         return rotation;
     }
-
 }

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java?rev=603590&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/AbstractStructuredAFPObject.java Wed Dec 12 04:24:10 2007
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * An abstract class encapsulating an MODCA structured object
+ */
+public abstract class AbstractStructuredAFPObject extends AbstractNamedAFPObject {
+   
+    /**
+     * Default constructor
+     */
+    public AbstractStructuredAFPObject() {
+        super();
+    }
+    
+    /**
+     * Named constructor
+     * @param name name of structured object
+     */
+    public AbstractStructuredAFPObject(String name) {
+        super(name);
+    }
+
+    /**
+     * Helper method to write the start of the Object.
+     * @param os The stream to write to
+     * @throws an I/O exception if one occurred
+     */
+    protected void writeStart(OutputStream os) throws IOException {
+    }
+
+    /**
+     * Helper method to write the contents of the Object.
+     * @param os The stream to write to
+     * @throws an I/O exception if one occurred
+     */
+    protected void writeContent(OutputStream os) throws IOException {
+    }
+
+    /**
+     * Helper method to write the end of the Object.
+     * @param os The stream to write to
+     * @throws an I/O exception if one occurred
+     */
+    protected void writeEnd(OutputStream os) throws IOException {
+    }    
+
+    /**
+     * Accessor method to write the AFP datastream for the Image Object
+     * @param os The stream to write to
+     * @throws java.io.IOException in the event that an I/O exception occurred
+     */
+    public void writeDataStream(OutputStream os)
+        throws IOException {
+
+        writeStart(os);
+
+        writeContent(os);
+
+        writeEnd(os);
+    }    
+}

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ActiveEnvironmentGroup.java Wed Dec 12 04:24:10 2007
@@ -20,7 +20,7 @@
 package org.apache.fop.render.afp.modca;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.fop.render.afp.fonts.AFPFont;
 
@@ -47,7 +47,7 @@
     /**
      * The collection of MapCodedFont objects
      */
-    private ArrayList mapCodedFonts = new ArrayList();
+    private List mapCodedFonts = new java.util.ArrayList();
 
     /**
      * The Object Area Descriptor for the active environment group
@@ -72,19 +72,19 @@
     /**
      * The collection of MapPageOverlay objects
      */
-    private ArrayList mapPageOverlays = new ArrayList();
+    private List mapPageOverlays = new java.util.ArrayList();
 
     /**
      * Default constructor for the ActiveEnvironmentGroup.
      * @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 ActiveEnvironmentGroup(int width, int height,
-            int widthResolution, int heightResolution) {
+            int widthRes, int heightRes) {
 
-        this(DEFAULT_NAME, width, height, widthResolution, heightResolution);
+        this(DEFAULT_NAME, width, height, widthRes, heightRes);
 
     }
 
@@ -94,24 +94,24 @@
      * @param name the active environment group name
      * @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 ActiveEnvironmentGroup(String name, int width, int height,
-            int widthResolution, int heightResolution) {
+            int widthRes, int heightRes) {
 
         super(name);
 
         // Create PageDescriptor
-        pageDescriptor = new PageDescriptor(width, height, widthResolution, heightResolution);
+        pageDescriptor = new PageDescriptor(width, height, widthRes, heightRes);
 
         // Create ObjectAreaDescriptor
         objectAreaDescriptor = new ObjectAreaDescriptor(width, height,
-                widthResolution, heightResolution);
+                widthRes, heightRes);
 
         // Create PresentationTextDataDescriptor
         presentationTextDataDescriptor = new PresentationTextDescriptor(width, height,
-                    widthResolution, heightResolution);
+                    widthRes, heightRes);
 
     }
 
@@ -243,7 +243,7 @@
      * @param orientation the orientation of the font (e.g. 0, 90, 180, 270)
      */
     public void createFont(
-        byte fontReference,
+        int fontReference,
         AFPFont font,
         int size,
         int orientation) {
@@ -256,7 +256,7 @@
         }
 
         try {
-
+            
             mcf.addFont(
                 fontReference,
                 font,

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java?rev=603590&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsDataDescriptor.java Wed Dec 12 04:24:10 2007
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.render.afp.tools.BinaryUtils;
+
+/**
+ * GOCA Graphics Data Descriptor
+ */
+public class GraphicsDataDescriptor extends AbstractAFPObject {
+
+    private int xlwind;
+    private int xrwind;
+    private int ybwind;
+    private int ytwind;
+    private int xresol;
+    private int yresol;
+    
+    /**
+     * Main constructor
+     * @param xresol the x resolution of the graphics window
+     * @param yresol the y resolution of the graphics window
+     * @param xlwind the left edge of the graphics window 
+     * @param xrwind the right edge of the graphics window
+     * @param ybwind the top edge of the graphics window
+     * @param ytwind the bottom edge of the graphics window
+     */
+    protected GraphicsDataDescriptor(int xresol, int yresol,
+            int xlwind, int xrwind, int ybwind, int ytwind) {
+        this.xresol = xresol;
+        this.yresol = yresol;
+        this.xlwind = xlwind;
+        this.xrwind = xrwind;
+        this.ybwind = ybwind;
+        this.ytwind = ytwind;
+    }    
+
+    private static final int ABS = 2;
+    private static final int IMGRES = 8;
+
+    /**
+     * {@inheritDoc}
+     */
+    public void writeDataStream(OutputStream os) throws IOException {
+        byte[] xreswind = BinaryUtils.convert(xresol * 10, 2);
+        byte[] yreswind = BinaryUtils.convert(yresol * 10, 2);
+        byte[] xlcoord = BinaryUtils.convert(xlwind, 2);
+        byte[] xrcoord = BinaryUtils.convert(xrwind, 2);
+        byte[] xbcoord = BinaryUtils.convert(ybwind, 2);
+        byte[] ytcoord = BinaryUtils.convert(ytwind, 2);
+        byte[] imxyres = xreswind;      
+        byte[] data = new byte[] {
+            0x5A,
+            0x00,
+            0x25,
+            (byte) 0xD3,
+            (byte) 0xA6,
+            (byte) 0xBB,
+            0x00, // Flags
+            0x00, // Reserved
+            0x00, // Reserved
+            
+            // Drawing order subset
+            (byte) 0xF7,
+            7, // LENGTH
+            (byte) 0xB0, // drawing order subset
+            0x00, // reserved (must be zero)
+            0x00, // reserved (must be zero)
+            0x02, // SUBLEV
+            0x00, // VERSION 0
+            0x01, // LENGTH (of following field)
+            0x00,  // GEOM
+
+            // Window specification
+            (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)
+            xreswind[0], // XRESOL
+            xreswind[1], 
+            yreswind[0], // YRESOL
+            yreswind[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
+            xrcoord[1],
+            xbcoord[0], // YBWIND
+            xbcoord[1],
+            ytcoord[0], // YTWIND
+            ytcoord[1]
+        };
+        os.write(data);    
+    }
+}

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java?rev=603590&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/GraphicsObject.java Wed Dec 12 04:24:10 2007
@@ -0,0 +1,321 @@
+/*
+ * 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;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.render.afp.modca.goca.GraphicsBox;
+import org.apache.fop.render.afp.modca.goca.GraphicsData;
+import org.apache.fop.render.afp.modca.goca.GraphicsFillet;
+import org.apache.fop.render.afp.modca.goca.GraphicsFullArc;
+import org.apache.fop.render.afp.modca.goca.GraphicsImageBegin;
+import org.apache.fop.render.afp.modca.goca.GraphicsImageData;
+import org.apache.fop.render.afp.modca.goca.GraphicsImageEnd;
+import org.apache.fop.render.afp.modca.goca.GraphicsLine;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetArcParameters;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetCharacterSet;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetCurrentPosition;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetLineType;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetLineWidth;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetPatternSymbol;
+import org.apache.fop.render.afp.modca.goca.GraphicsSetProcessColor;
+import org.apache.fop.render.afp.modca.goca.GraphicsString;
+
+/**
+ * Top-level GOCA graphics object.
+ * 
+ * Acts as container and factory of all other graphic objects
+ */
+public class GraphicsObject extends AbstractDataObject {
+        
+    /**
+     * The graphics data
+     */
+    private GraphicsData graphicsData = null;
+
+    /**
+     * Default constructor
+     * 
+     * @param name the name of graphics object
+     */
+    public GraphicsObject(String name) {
+        super(name);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setViewport(int x, int y, int width, int height,
+            int widthRes, int heightRes, int rotation) {
+        super.setViewport(x, y, width, height, widthRes, heightRes, rotation);
+        objectEnvironmentGroup.setGraphicsData(
+                widthRes, heightRes, 0, x + width, 0, y + height);        
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void writeStart(OutputStream os) throws IOException {
+        super.writeStart(os);
+        byte[] data = new byte[] {
+            0x5A, // Structured field identifier
+            0x00, //sfLen[0], // Length byte 1
+            0x10, //sfLen[1], // Length byte 2
+            (byte) 0xD3, // Structured field id byte 1
+            (byte) 0xA8, // Structured field id byte 2
+            (byte) 0xBB, // Structured field id byte 3
+            0x00, // Flags
+            0x00, // Reserved
+            0x00, // Reserved
+            super.nameBytes[0], // gdoName
+            super.nameBytes[1],
+            super.nameBytes[2],
+            super.nameBytes[3],
+            super.nameBytes[4],
+            super.nameBytes[5],
+            super.nameBytes[6],
+            super.nameBytes[7]
+        };
+        os.write(data);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void writeEnd(OutputStream os) throws IOException {
+        byte[] data = new byte[] {
+            0x5A, // Structured field identifier
+            0x00, // sfLen[0], // Length byte 1
+            0x10, // sfLen[1], // Length byte 2
+            (byte) 0xD3, // Structured field id byte 1
+            (byte) 0xA9, // Structured field id byte 2
+            (byte) 0xBB, // Structured field id byte 3
+            0x00, // Flags
+            0x00, // Reserved
+            0x00, // Reserved
+            super.nameBytes[0], // gdoName
+            super.nameBytes[1],
+            super.nameBytes[2],
+            super.nameBytes[3],
+            super.nameBytes[4],
+            super.nameBytes[5],
+            super.nameBytes[6],
+            super.nameBytes[7]
+        };
+        os.write(data);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected PreparedAFPObject addDrawingOrder(PreparedAFPObject drawingOrder) {
+        if (graphicsData == null
+                || (graphicsData.getDataLength() + drawingOrder.getDataLength())
+                >= GraphicsData.MAX_DATA_LEN) {
+            newData();
+        }
+        graphicsData.addDrawingOrder(drawingOrder);
+        return drawingOrder;
+    }
+    
+    /**
+     * Gets the current graphics data, creating a new one if necessary
+     * @return the current graphics data
+     */
+    private GraphicsData getData() {
+        if (this.graphicsData == null) {
+            return newData();
+        }
+        return this.graphicsData;
+    }
+    
+    /**
+     * Creates a new graphics data
+     * @return a newly created graphics data
+     */
+    private GraphicsData newData() {
+        this.graphicsData = new GraphicsData();            
+        super.addDrawingOrder(graphicsData);
+        return graphicsData;
+    }
+    
+    /**
+     * Sets the current color
+     * @param col the active color to use
+     */
+    public void setColor(Color col) {
+        addDrawingOrder(new GraphicsSetProcessColor(col));
+    }
+
+    /**
+     * Sets the current position
+     * @param coords the x and y coordinates of the current position
+     */
+    public void setCurrentPosition(int[] coords) {
+        addDrawingOrder(new GraphicsSetCurrentPosition(coords));
+    }
+
+    /**
+     * Sets the line width
+     * @param multiplier the line width multiplier
+     */
+    public void setLineWidth(int multiplier) {
+        GraphicsSetLineWidth lw = new GraphicsSetLineWidth(multiplier);
+        addDrawingOrder(lw);
+    }
+
+    /**
+     * Sets the line type
+     * @param type the line type
+     */
+    public void setLineType(byte type) {
+        GraphicsSetLineType lt = new GraphicsSetLineType(type);
+        addDrawingOrder(lt);
+    }    
+
+    /**
+     * Sets whether to fill the next shape
+     * @param fill whether to fill the next shape
+     */
+    public void setFill(boolean fill) {
+        GraphicsSetPatternSymbol pat = new GraphicsSetPatternSymbol(
+                fill ? GraphicsSetPatternSymbol.SOLID_FILL
+                     : GraphicsSetPatternSymbol.NO_FILL
+        );
+        addDrawingOrder(pat);
+    }
+    
+    /**
+     * Sets the character set to use
+     * @param fontReference the character set (font) reference
+     */
+    public void setCharacterSet(int fontReference) {
+        addDrawingOrder(new GraphicsSetCharacterSet(fontReference));
+    }
+
+    /**
+     * Adds a line at the given x/y coordinates
+     * @param coords the x/y coordinates (can be a series)
+     */
+    public void addLine(int[] coords) {
+        addDrawingOrder(new GraphicsLine(coords));
+    }
+
+    /**
+     * Adds a box at the given coordinates
+     * @param coords the x/y coordinates
+     */
+    public void addBox(int[] coords) {
+        addDrawingOrder(new GraphicsBox(coords));
+    }
+
+    /**
+     * Adds a fillet (curve) at the given coordinates
+     * @param coords the x/y coordinates
+     */
+    public void addFillet(int[] coords) {
+        addDrawingOrder(new GraphicsFillet(coords));
+    }
+
+    /**
+     * Sets the arc parameters 
+     * @param xmaj the maximum value of the x coordinate
+     * @param ymin the minimum value of the y coordinate
+     * @param xmin the minimum value of the x coordinate
+     * @param ymaj the maximum value of the y coordinate
+     */
+    public void setArcParams(int xmaj, int ymin, int xmin, int ymaj) {
+        addDrawingOrder(new GraphicsSetArcParameters(xmaj, ymin, xmin, ymaj));
+    }
+
+    /**
+     * Adds an arc
+     * @param x the x coordinate
+     * @param y the y coordinate
+     * @param mh the integer portion of the multiplier
+     * @param mhr the fractional portion of the multiplier
+     */
+    public void addFullArc(int x, int y, int mh, int mhr) {
+        addDrawingOrder(new GraphicsFullArc(x, y, mh, mhr));
+    }
+
+    /**
+     * Adds an image
+     * @param x the x coordinate
+     * @param y the y coordinate
+     * @param width the image width
+     * @param height the image height
+     * @param rawData the image data
+     */
+    public void addImage(int x, int y, int width, int height, byte[] rawData) {
+        addDrawingOrder(new GraphicsImageBegin(x, y, width, height));
+        for (int startIndex = 0;
+            startIndex <= rawData.length;
+            startIndex += GraphicsImageData.MAX_DATA_LEN) {
+            addDrawingOrder(new GraphicsImageData(rawData, startIndex));
+        }
+        addDrawingOrder(new GraphicsImageEnd());
+    }
+
+    /**
+     * Adds a string
+     * @param str the string
+     * @param x the x coordinate
+     * @param y the y coordinate
+     */
+    public void addString(String str, int x, int y) {
+        addDrawingOrder(new GraphicsString(str, x, y));
+    }
+    
+    /**
+     * Begins a graphics area (start of fill)
+     */
+    public void beginArea() {
+        if (graphicsData == null) {
+            newData();
+        }
+        graphicsData.beginArea();
+    }
+
+    /**
+     * Ends a graphics area (end of fill)
+     */
+    public void endArea() {
+        if (graphicsData != null) {
+            graphicsData.endArea();
+        }
+    }
+        
+    /**
+     * {@inheritDoc}
+     */
+    public String toString() {
+        return "GraphicsObject";
+    }
+
+    /**
+     * Creates a new graphics segment
+     */
+    public void newSegment() {
+        getData().newSegment();
+    }
+}
\ No newline at end of file

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageContent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageContent.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageContent.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageContent.java Wed Dec 12 04:24:10 2007
@@ -18,43 +18,45 @@
 /* $Id$ */
 
 package org.apache.fop.render.afp.modca;
+
 import java.io.IOException;
 import java.io.OutputStream;
 import org.apache.fop.render.afp.tools.BinaryUtils;
 
 /**
+ * Image content IOCA object
  */
 public class ImageContent extends AbstractAFPObject {
 
     /**
      * The image size parameter
      */
-    private ImageSizeParameter _imageSizeParameter = null;
+    private ImageSizeParameter imageSizeParam = null;
 
     /**
      * The image encoding
      */
-    private byte _encoding = 0x03;
+    private byte encoding = 0x03;
 
     /**
      * The image ide size
      */
-    private byte _size = 1;
+    private byte size = 1;
 
     /**
      * The image compression
      */
-    private byte _compression = (byte)0xC0;
+    private byte compression = (byte)0xC0;
 
     /**
      * The image color model
      */
-    private byte _colorModel = 0x01;
+    private byte colorModel = 0x01;
 
     /**
      * The image data
      */
-    private byte _data[] = null;
+    private byte[] data = null;
 
     /**
      * Constructor for the image content
@@ -72,60 +74,60 @@
      * @param vsize The vertival size of the image.
      */
     public void setImageSize(int hresol, int vresol, int hsize, int vsize) {
-        _imageSizeParameter = new ImageSizeParameter(hresol, vresol, hsize, vsize);
+        this.imageSizeParam = new ImageSizeParameter(hresol, vresol, hsize, vsize);
     }
 
     /**
      * Sets the image encoding.
-     * @param encoding The image encoding.
+     * @param enc The image encoding.
      */
-    public void setImageEncoding(byte encoding) {
-        _encoding = encoding;
+    public void setImageEncoding(byte enc) {
+        this.encoding = enc;
     }
 
     /**
      * Sets the image compression.
-     * @param compression The image compression.
+     * @param comp The image compression.
      */
-    public void setImageCompression(byte compression) {
-        _compression = compression;
+    public void setImageCompression(byte comp) {
+        this.compression = comp;
     }
 
     /**
      * Sets the image IDE size.
-     * @param size The IDE size.
+     * @param siz The IDE size.
      */
-    public void setImageIDESize(byte size) {
-        _size = size;
+    public void setImageIDESize(byte siz) {
+        this.size = siz;
     }
 
     /**
      * Sets the image IDE color model.
-     * @param colorModel    the IDE color model.
+     * @param model    the IDE color model.
      */
-    public void setImageIDEColorModel(byte colorModel) {
-        _colorModel = colorModel;
+    public void setImageIDEColorModel(byte model) {
+        this.colorModel = model;
     }
 
     /**
      * Set the data of the image.
+     * @param dat the image data
      */
-    public void setImageData(byte data[]) {
-        _data = data;
+    public void setImageData(byte[] dat) {
+        this.data = dat;
     }
 
     /**
      * Accessor method to write the AFP datastream for the Image Content
      * @param os The stream to write to
-     * @throws java.io.IOException
+     * @throws java.io.IOException if an I/O exception occurs
      */
-    public void writeDataStream(OutputStream os)
-        throws IOException {
+    public void writeDataStream(OutputStream os) throws IOException {
 
         writeStart(os);
 
-        if (_imageSizeParameter != null) {
-            _imageSizeParameter.writeDataStream(os);
+        if (imageSizeParam != null) {
+            imageSizeParam.writeDataStream(os);
         }
 
         os.write(getImageEncodingParameter());
@@ -136,12 +138,12 @@
 
         os.write(getExternalAlgorithmParameter());
 
-        if (_data != null) {
+        if (data != null) {
             int off = 0;
-            while (off < _data.length) {
-                int len = Math.min(30000, _data.length - off);
+            while (off < data.length) {
+                int len = Math.min(30000, data.length - off);
                 os.write(getImageDataStart(len));
-                os.write(_data, off, len);
+                os.write(data, off, len);
                 off += len;
             }
         }
@@ -154,33 +156,25 @@
      * Helper method to write the start of the Image Content.
      * @param os The stream to write to
      */
-    private void writeStart(OutputStream os)
-        throws IOException {
-
-        byte[] data = new byte[] {
+    private void writeStart(OutputStream os) throws IOException {
+        byte[] startData = new byte[] {
             (byte)0x91, // ID
                   0x01, // Length
             (byte)0xff, // Object Type = IOCA Image Object
         };
-
-        os.write(data);
-
+        os.write(startData);
     }
 
     /**
      * Helper method to write the end of the Image Content.
      * @param os The stream to write to
      */
-    private void writeEnd(OutputStream os)
-        throws IOException {
-
-        byte[] data = new byte[] {
+    private void writeEnd(OutputStream os) throws IOException {
+        byte[] endData = new byte[] {
             (byte)0x93, // ID
                   0x00, // Length
         };
-
-        os.write(data);
-
+        os.write(endData);
     }
 
     /**
@@ -188,21 +182,16 @@
      * @return byte[] The data stream.
      */
     private byte[] getImageDataStart(int len) {
-
-        byte[] data = new byte[] {
+        byte[] imageDataStartData = new byte[] {
             (byte)0xFE, // ID
             (byte)0x92, // ID
                   0x00, // Length
                   0x00, // Length
         };
-
         byte[] l = BinaryUtils.convert(len, 2);
-        data[2] = l[0];
-        data[3] = l[1];
-
-
-        return data;
-
+        imageDataStartData[2] = l[0];
+        imageDataStartData[3] = l[1];
+        return imageDataStartData;
     }
 
     /**
@@ -210,16 +199,13 @@
      * @return byte[] The data stream.
      */
     private byte[] getImageEncodingParameter() {
-
-        byte[] data = new byte[] {
+        byte[] imageEncParamData = new byte[] {
             (byte)0x95, // ID
                   0x02, // Length
-                  _encoding,
+                  encoding,
                   0x01, // RECID
         };
-
-        return data;
-
+        return imageEncParamData;
     }
 
     /**
@@ -227,9 +213,8 @@
      * @return byte[] The data stream.
      */
     private byte[] getExternalAlgorithmParameter() {
-
-        if (_encoding == (byte)0x83 && _compression != 0) {
-            byte[] data = new byte[] {
+        if (encoding == (byte)0x83 && compression != 0) {
+            byte[] extAlgParamData = new byte[] {
                 (byte)0x95, // ID
                       0x00, // Length
                       0x10, // ALGTYPE = Compression Algorithm
@@ -238,13 +223,13 @@
                       0x00, // Reserved
                       0x00, // Reserved
                       0x00, // Reserved
-              _compression, // MARKER
+              compression, // MARKER
                       0x00, // Reserved
                       0x00, // Reserved
                       0x00, // Reserved
             };
-            data[1] = (byte)(data.length - 2);
-            return data;
+            extAlgParamData[1] = (byte)(extAlgParamData.length - 2);
+            return extAlgParamData;
         }
         return new byte[0];
     }
@@ -254,15 +239,12 @@
      * @return byte[] The data stream.
      */
     private byte[] getImageIDESizeParameter() {
-
-        byte[] data = new byte[] {
+        byte[] imageIDESizeParamData = new byte[] {
             (byte)0x96, // ID
                   0x01, // Length
-                  _size,
+                  size,
         };
-
-        return data;
-
+        return imageIDESizeParamData;
     }
 
     /**
@@ -270,15 +252,14 @@
      * @return byte[] The data stream.
      */
     private byte[] getIDEStructureParameter() {
-
-        if (_colorModel != 0 && _size == 24) {
-            byte bits = (byte)(_size / 3);
-            byte[] data = new byte[] {
+        if (colorModel != 0 && size == 24) {
+            byte bits = (byte)(size / 3);
+            byte[] ideStructParamData = new byte[] {
                 (byte)0x9B, // ID
                       0x00, // Length
                       0x00, // FLAGS
                       0x00, // Reserved
-               _colorModel, // COLOR MODEL
+               colorModel, // COLOR MODEL
                       0x00, // Reserved
                       0x00, // Reserved
                       0x00, // Reserved
@@ -286,10 +267,9 @@
                       bits,
                       bits,
             };
-            data[1] = (byte)(data.length - 2);
-            return data;
+            ideStructParamData[1] = (byte)(ideStructParamData.length - 2);
+            return ideStructParamData;
         }
         return new byte[0];
     }
-
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java?rev=603590&r1=603589&r2=603590&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/modca/ImageDataDescriptor.java Wed Dec 12 04:24:10 2007
@@ -27,10 +27,17 @@
  */
 public class ImageDataDescriptor extends AbstractAFPObject {
 
-    private int _xresol = 0;
-    private int _yresol = 0;
-    private int _width = 0;
-    private int _height = 0;
+    /** x resolution */
+    private int xresol = 0;
+    
+    /** y resolution */
+    private int yresol = 0;
+    
+    /** width */
+    private int width = 0;
+    
+    /** height */
+    private int height = 0;
 
     /**
      * Constructor for a ImageDataDescriptor for the specified
@@ -41,26 +48,25 @@
      * @param height The height of the height.
      */
     public ImageDataDescriptor(int xresol, int yresol, int width, int height) {
-
-        _xresol = xresol;
-        _yresol = yresol;
-        _width = width;
-        _height = height;
-
+        this.xresol = xresol;
+        this.yresol = yresol;
+        this.width = width;
+        this.height = height;
     }
 
     /**
-     * Accessor method to write the AFP datastream for the Image Data Descriptor
-     * @param os The stream to write to
-     * @throws java.io.IOException
+     * {@inheritDoc}
      */
-    public void writeDataStream(OutputStream os)
-        throws IOException {
-
+    public void writeDataStream(OutputStream os) throws IOException {
+        byte[] len = BinaryUtils.convert(21, 2);
+        byte[] xres = BinaryUtils.convert(xresol, 2);
+        byte[] yres = BinaryUtils.convert(yresol, 2);
+        byte[] w = BinaryUtils.convert(width, 2);
+        byte[] h = BinaryUtils.convert(height, 2);
         byte[] data = new byte[] {
             0x5A,
-            0x00,
-            0x20,
+            len[0],
+            len[1],
             (byte) 0xD3,
             (byte) 0xA6,
             (byte) 0xFB,
@@ -68,42 +74,19 @@
             0x00, // Reserved
             0x00, // Reserved
             0x00, // Unit base - 10 Inches
-            0x00, // XRESOL
-            0x00, //
-            0x00, // YRESOL
-            0x00, //
-            0x00, // XSIZE
-            0x00, //
-            0x00, // YSIZE
-            0x00, //
+            xres[0], // XRESOL
+            xres[1], //
+            yres[0], // YRESOL
+            yres[1], //
+            w[0], // XSIZE
+            w[1], //
+            h[0], // YSIZE
+            h[1], //
             (byte)0xF7, // ID = Set IOCA Function Set
             0x02, // Length
             0x01, // Category = Function set identifier
             0x0B, // FCNSET = IOCA FS 11
         };
-
-        byte[] l = BinaryUtils.convert(data.length - 1, 2);
-        data[1] = l[0];
-        data[2] = l[1];
-
-        byte[] x = BinaryUtils.convert(_xresol, 2);
-        data[10] = x[0];
-        data[11] = x[1];
-
-        byte[] y = BinaryUtils.convert(_yresol, 2);
-        data[12] = y[0];
-        data[13] = y[1];
-
-        byte[] w = BinaryUtils.convert(_width, 2);
-        data[14] = w[0];
-        data[15] = w[1];
-
-        byte[] h = BinaryUtils.convert(_height, 2);
-        data[16] = h[0];
-        data[17] = h[1];
-
         os.write(data);
-
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org