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 sp...@apache.org on 2011/02/11 12:59:35 UTC

svn commit: r1069764 [5/7] - in /xmlgraphics/fop/branches/Temp_ComplexScripts: ./ lib/ lib/build/ src/codegen/java/org/apache/fop/tools/ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/afp/ src/java/org/apache/fop/afp/apps/ src/java/org/...

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java Fri Feb 11 11:59:32 2011
@@ -77,8 +77,6 @@ public class InlineLayoutManager extends
     private boolean areaCreated = false;
     private LayoutManager lastChildLM = null; // Set when return last breakposs;
 
-    private Position auxiliaryPosition;
-
     private Font font;
 
     /** The alignment adjust property */
@@ -113,6 +111,7 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     public void initialize() {
         InlineLevel fobj = (InlineLevel) this.fobj;
 
@@ -150,6 +149,7 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     protected MinOptMax getExtraIPD(boolean isNotFirst, boolean isNotLast) {
         int borderAndPadding = 0;
         if (borderProps != null) {
@@ -167,6 +167,7 @@ public class InlineLayoutManager extends
 
 
     /** {@inheritDoc} */
+    @Override
     protected boolean hasLeadingFence(boolean isNotFirst) {
         return borderProps != null
             && (borderProps.getPadding(CommonBorderPaddingBackground.START, isNotFirst, this) > 0
@@ -175,6 +176,7 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     protected boolean hasTrailingFence(boolean isNotLast) {
         return borderProps != null
             && (borderProps.getPadding(CommonBorderPaddingBackground.END, isNotLast, this) > 0
@@ -183,10 +185,12 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     protected SpaceProperty getSpaceStart() {
         return inlineProps != null ? inlineProps.spaceStart : null;
     }
     /** {@inheritDoc} */
+    @Override
     protected SpaceProperty getSpaceEnd() {
         return inlineProps != null ? inlineProps.spaceEnd : null;
     }
@@ -212,6 +216,7 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void setTraits(boolean isNotFirst, boolean isNotLast) {
         if (borderProps != null) {
             // Add border and padding to current area and set flags (FIRST, LAST ...)
@@ -239,15 +244,16 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
-    public List getNextKnuthElements                            // CSOK: MethodLength
+    @Override                                                   // CSOK: MethodLength
+    public List getNextKnuthElements
         (LayoutContext context, int alignment) {
         LayoutManager curLM;
 
         // the list returned by child LM
-        List returnedList;
+        List<KnuthSequence> returnedList;
 
         // the list which will be returned to the parent LM
-        List returnList = new LinkedList();
+        List<KnuthSequence> returnList = new LinkedList<KnuthSequence>();
         KnuthSequence lastSequence = null;
 
         if (fobj instanceof Title) {
@@ -328,16 +334,16 @@ public class InlineLayoutManager extends
                     sequence.wrapPositions(this);
                 }
                 int insertionStartIndex = 0;
-                if (lastSequence != null && lastSequence.appendSequenceOrClose
-                        ((KnuthSequence) returnedList.get(0))) {
+                if (lastSequence != null
+                        && lastSequence.appendSequenceOrClose(returnedList.get(0))) {
                     insertionStartIndex = 1;
                 }
                 // add border and padding to the first complete sequence of this LM
                 if (!borderAdded && !returnedList.isEmpty()) {
-                    addKnuthElementsForBorderPaddingStart((KnuthSequence) returnedList.get(0));
+                    addKnuthElementsForBorderPaddingStart(returnedList.get(0));
                     borderAdded = true;
                 }
-                for (Iterator iter = returnedList.listIterator(insertionStartIndex);
+                for (Iterator<KnuthSequence> iter = returnedList.listIterator(insertionStartIndex);
                         iter.hasNext();) {
                     returnList.add(iter.next());
                 }
@@ -368,7 +374,7 @@ public class InlineLayoutManager extends
                 context.updateKeepWithNextPending(childLC.getKeepWithNextPending());
                 childLC.clearKeepsPending();
             }
-            lastSequence = (KnuthSequence) ListUtil.getLast(returnList);
+            lastSequence = ListUtil.getLast(returnList);
             lastChildLM = curLM;
         }
 
@@ -408,6 +414,7 @@ public class InlineLayoutManager extends
      * by this LayoutManager.
      * @param context layout context.
      */
+    @Override
     public void addAreas(PositionIterator parentIter,
                          LayoutContext context) {
 
@@ -433,21 +440,18 @@ public class InlineLayoutManager extends
         // set in the layout context, it must be also set in the
         // layout context given to lastLM, but must be cleared in the
         // layout context given to the other LMs.
-        List positionList = new LinkedList();
-        NonLeafPosition pos;
+        List<Position> positionList = new LinkedList<Position>();
+        Position pos;
         LayoutManager lastLM = null; // last child LM in this iterator
         Position lastPos = null;
         while (parentIter.hasNext()) {
-            pos = (NonLeafPosition) parentIter.next();
+            pos = parentIter.next();
             if (pos != null && pos.getPosition() != null) {
                 positionList.add(pos.getPosition());
                 lastLM = pos.getPosition().getLM();
                 lastPos = pos;
             }
         }
-        /*if (pos != null) {
-            lastLM = pos.getPosition().getLM();
-        }*/
 
         addMarkersToPage(
                 true,
@@ -469,8 +473,8 @@ public class InlineLayoutManager extends
         }
         setCurrentArea(parent);
 
-        StackingIter childPosIter
-            = new StackingIter(positionList.listIterator());
+        PositionIterator childPosIter
+            = new PositionIterator(positionList.listIterator());
 
         LayoutManager prevLM = null;
         LayoutManager childLM;
@@ -522,6 +526,7 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     public void addChildArea(Area childArea) {
         Area parent = getCurrentArea();
         if (getContext().resolveLeadingSpace()) {
@@ -532,6 +537,7 @@ public class InlineLayoutManager extends
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getChangedKnuthElements(List oldList, int alignment, int depth) {
         List returnedList = new LinkedList();
         addKnuthElementsForBorderPaddingStart(returnedList);
@@ -546,7 +552,7 @@ public class InlineLayoutManager extends
      */
     protected void addKnuthElementsForBorderPaddingStart(List returnList) {
         //Border and Padding (start)
-        /**
+        /*
          * If the returnlist is a BlockKnuthSequence, the border and padding should be added
          * to the first paragraph inside it, but it is too late to do that now.
          * At least, avoid adding it to the bpd sequence.
@@ -571,7 +577,7 @@ public class InlineLayoutManager extends
      */
     protected void addKnuthElementsForBorderPaddingEnd(List returnList) {
         //Border and Padding (after)
-        /**
+        /*
          * If the returnlist is a BlockKnuthSequence, the border and padding should be added
          * to the last paragraph inside it, but it is too late to do that now.
          * At least, avoid adding it to the bpd sequence.
@@ -590,13 +596,8 @@ public class InlineLayoutManager extends
         }
     }
 
-    /** @return a cached auxiliary Position instance used for things like spaces. */
+    /** @return an auxiliary {@link Position} instance used for things like spaces. */
     protected Position getAuxiliaryPosition() {
-        //if (this.auxiliaryPosition == null) {
-            //this.auxiliaryPosition = new NonLeafPosition(this, new LeafPosition(this, -1));
-            this.auxiliaryPosition = new NonLeafPosition(this, null);
-        //}
-        return this.auxiliaryPosition;
+        return new NonLeafPosition(this, null);
     }
-
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/InlineStackingLayoutManager.java Fri Feb 11 11:59:32 2011
@@ -19,7 +19,6 @@
 
 package org.apache.fop.layoutmgr.inline;
 
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
@@ -31,10 +30,8 @@ import org.apache.fop.fo.properties.Spac
 import org.apache.fop.layoutmgr.AbstractLayoutManager;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.LayoutContext;
-import org.apache.fop.layoutmgr.LayoutManager;
 import org.apache.fop.layoutmgr.NonLeafPosition;
 import org.apache.fop.layoutmgr.Position;
-import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.traits.MinOptMax;
 
 /**
@@ -45,33 +42,6 @@ import org.apache.fop.traits.MinOptMax;
 public abstract class InlineStackingLayoutManager extends AbstractLayoutManager
                                          implements InlineLevelLayoutManager {
 
-
-    /**
-     * A stacking iterator.
-     */
-    protected static class StackingIter extends PositionIterator {
-
-        StackingIter(Iterator parentIter) {
-            super(parentIter);
-        }
-
-        /**
-         * @param nextObj the next object
-         * @return layout manager of next object
-         */
-        protected LayoutManager getLM(Object nextObj) {
-            return ((Position) nextObj).getLM();
-        }
-
-        /**
-         * @param nextObj the next object
-         * @return position of next object
-         */
-        protected Position getPos(Object nextObj) {
-            return ((Position) nextObj);
-        }
-    }
-
     /**
      * Size of border and padding in BPD (ie, before and after).
      */
@@ -296,6 +266,7 @@ public abstract class InlineStackingLayo
             } else {
                 currLM = (InlineLevelLayoutManager) pos.getLM(depth);
             }
+
             // initialize prevLM
             if (prevLM == null) {
                 prevLM = currLM;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LeafNodeLayoutManager.java Fri Feb 11 11:59:32 2011
@@ -48,19 +48,14 @@ import org.apache.fop.traits.MinOptMax;
  * an exception to this rule.)
  * This class can be extended to handle the creation and adding of the
  * inline area.
- * TODO [GA] replace use of hungarian notation with normalized java naming
  */
 public abstract class LeafNodeLayoutManager extends AbstractLayoutManager
                                    implements InlineLevelLayoutManager {
 
-    /**
-     * logging instance
-     */
+    /** logging instance */
     protected static final Log log = LogFactory.getLog(LeafNodeLayoutManager.class);
 
-    /**
-     * The inline area that this leafnode will add.
-     */
+    /** The inline area that this leafnode will add. */
     protected InlineArea curArea = null;
     /** Any border, padding and background properties applying to this area */
     protected CommonBorderPaddingBackground commonBorderPaddingBackground = null;
@@ -68,7 +63,7 @@ public abstract class LeafNodeLayoutMana
     protected AlignmentContext alignmentContext = null;
 
     /** Flag to indicate if something was changed as part of the getChangeKnuthElements sequence */
-    protected boolean isSomethingChanged = false;
+    protected boolean somethingChanged = false;
     /** Our area info for the Knuth elements */
     protected AreaInfo areaInfo = null;
 
@@ -77,32 +72,31 @@ public abstract class LeafNodeLayoutMana
      */
     protected class AreaInfo {
         /** letter space count */
-        protected short iLScount;
+        protected short letterSpaces;
         /** ipd of area */
         protected MinOptMax ipdArea;
         /** true if hyphenated */
-        protected boolean bHyphenated;
+        protected boolean isHyphenated;
         /** alignment context */
         protected AlignmentContext alignmentContext;
 
         /**
          * Construct an area information item.
-         * @param iLS letter space count
+         * @param letterSpaces letter space count
          * @param ipd inline progression dimension
-         * @param bHyph true if hyphenated
+         * @param isHyphenated true if hyphenated
          * @param alignmentContext an alignment context
          */
-        public AreaInfo(short iLS, MinOptMax ipd, boolean bHyph,
+        public AreaInfo(short letterSpaces, MinOptMax ipd, boolean isHyphenated,
                         AlignmentContext alignmentContext) {
-            iLScount = iLS;
-            ipdArea = ipd;
-            bHyphenated = bHyph;
+            this.letterSpaces = letterSpaces;
+            this.ipdArea = ipd;
+            this.isHyphenated = isHyphenated;
             this.alignmentContext = alignmentContext;
         }
 
     }
 
-
     /**
      * Create a Leaf node layout manager.
      * @param node the FObj to attach to this LM.
@@ -145,18 +139,22 @@ public abstract class LeafNodeLayoutMana
     }
 
     /**
-     * This is a leaf-node, so this method is never called.
+     * This is a leaf-node, so this method should never be called.
      * @param childArea the childArea to add
      */
+    @Override
     public void addChildArea(Area childArea) {
+        assert false;
     }
 
     /**
-     * This is a leaf-node, so this method is never called.
+     * This is a leaf-node, so this method should never be called.
      * @param childArea the childArea to get the parent for
      * @return the parent area
      */
+    @Override
     public Area getParentArea(Area childArea) {
+        assert false;
         return null;
     }
 
@@ -185,6 +183,7 @@ public abstract class LeafNodeLayoutMana
      * @param posIter the position iterator
      * @param context the layout context for adding the area
      */
+    @Override
     public void addAreas(PositionIterator posIter, LayoutContext context) {
         addId();
 
@@ -260,6 +259,7 @@ public abstract class LeafNodeLayoutMana
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getNextKnuthElements(LayoutContext context, int alignment) {
         curArea = get(context);
 
@@ -336,6 +336,7 @@ public abstract class LeafNodeLayoutMana
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getChangedKnuthElements(List oldList, int alignment) {
         if (isFinished()) {
             return null;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Fri Feb 11 11:59:32 2011
@@ -878,7 +878,7 @@ public class LineLayoutManager extends I
      */
     private List postProcessLineBreaks(int alignment, LayoutContext context) {
 
-        List returnList = new LinkedList();
+        List<ListElement> returnList = new LinkedList<ListElement>();
 
         int endIndex = -1;
         for (int p = 0; p < knuthParagraphs.size(); p++) {
@@ -896,7 +896,7 @@ public class LineLayoutManager extends I
             KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(p);
 
             if (!seq.isInlineSequence()) {
-                List targetList = new LinkedList();
+                List<ListElement> targetList = new LinkedList<ListElement>();
                 ListIterator listIter = seq.listIterator();
                 while (listIter.hasNext()) {
                     ListElement tempElement;
@@ -936,10 +936,10 @@ public class LineLayoutManager extends I
                     endIndex = ((LineBreakPosition) llPoss.getChosenPosition(i)).getLeafPos();
                     // create a list of the FootnoteBodyLM handling footnotes
                     // whose citations are in this line
-                    List footnoteList = new LinkedList();
-                    ListIterator elementIterator = seq.listIterator(startIndex);
+                    List<LayoutManager> footnoteList = new LinkedList<LayoutManager>();
+                    ListIterator<KnuthElement> elementIterator = seq.listIterator(startIndex);
                     while (elementIterator.nextIndex() <= endIndex) {
-                        KnuthElement element = (KnuthElement) elementIterator.next();
+                        KnuthElement element = elementIterator.next();
                         if (element instanceof KnuthInlineBox
                                 && ((KnuthInlineBox) element).isAnchor()) {
                             footnoteList.add(((KnuthInlineBox) element).getFootnoteBodyLM());
@@ -952,15 +952,6 @@ public class LineLayoutManager extends I
                     returnList.add(new KnuthBlockBox
                                    (lbp.lineHeight + lbp.spaceBefore + lbp.spaceAfter,
                                     footnoteList, lbp, false));
-                    /* // add stretch and shrink to the returnlist
-                    if (!seq.isInlineSequence()
-                            && lbp.availableStretch != 0 || lbp.availableShrink != 0) {
-                        returnList.add(new KnuthPenalty(0, -KnuthElement.INFINITE,
-                                false, new Position(this), false));
-                        returnList.add(new KnuthGlue(0, lbp.availableStretch, lbp.availableShrink,
-                                new Position(this), false));
-                    }
-                    */
                 }
             }
         }
@@ -968,7 +959,7 @@ public class LineLayoutManager extends I
         return returnList;
     }
 
-    private void createElements(List list, LineLayoutPossibilities llPoss,
+    private void createElements(List<ListElement> list, LineLayoutPossibilities llPoss,
                                 Position elementPosition) {
         /* number of normal, inner lines */
         int innerLines = 0;
@@ -987,36 +978,27 @@ public class LineLayoutManager extends I
         /* number of the last unbreakable lines */
         int lastLines = fobj.getWidows();
         /* sub-sequence used to separate the elements representing different lines */
-        List breaker = new LinkedList();
+        List<KnuthElement> breaker = new LinkedList<KnuthElement>();
 
         /* comment out the next lines in order to test particular situations */
         if (fobj.getOrphans() + fobj.getWidows() <= llPoss.getMinLineCount()) {
-            innerLines = llPoss.getMinLineCount()
-                          - (fobj.getOrphans() + fobj.getWidows());
-            optionalLines = llPoss.getMaxLineCount()
-                             - llPoss.getOptLineCount();
-            eliminableLines = llPoss.getOptLineCount()
-                               - llPoss.getMinLineCount();
+            innerLines = llPoss.getMinLineCount() - (fobj.getOrphans() + fobj.getWidows());
+            optionalLines = llPoss.getMaxLineCount() - llPoss.getOptLineCount();
+            eliminableLines = llPoss.getOptLineCount() - llPoss.getMinLineCount();
         } else if (fobj.getOrphans() + fobj.getWidows() <= llPoss.getOptLineCount()) {
-            optionalLines = llPoss.getMaxLineCount()
-                             - llPoss.getOptLineCount();
-            eliminableLines = llPoss.getOptLineCount()
-                               - (fobj.getOrphans() + fobj.getWidows());
-            conditionalEliminableLines = (fobj.getOrphans() + fobj.getWidows())
-                                          - llPoss.getMinLineCount();
+            optionalLines = llPoss.getMaxLineCount() - llPoss.getOptLineCount();
+            eliminableLines = llPoss.getOptLineCount() - (fobj.getOrphans() + fobj.getWidows());
+            conditionalEliminableLines
+                    = (fobj.getOrphans() + fobj.getWidows()) - llPoss.getMinLineCount();
         } else if (fobj.getOrphans() + fobj.getWidows() <= llPoss.getMaxLineCount()) {
-            optionalLines = llPoss.getMaxLineCount()
-                             - (fobj.getOrphans() + fobj.getWidows());
-            conditionalOptionalLines = (fobj.getOrphans() + fobj.getWidows())
-                                        - llPoss.getOptLineCount();
-            conditionalEliminableLines = llPoss.getOptLineCount()
-                                          - llPoss.getMinLineCount();
+            optionalLines = llPoss.getMaxLineCount() - (fobj.getOrphans() + fobj.getWidows());
+            conditionalOptionalLines
+                    = (fobj.getOrphans() + fobj.getWidows()) - llPoss.getOptLineCount();
+            conditionalEliminableLines = llPoss.getOptLineCount() - llPoss.getMinLineCount();
             firstLines -= conditionalOptionalLines;
         } else {
-            conditionalOptionalLines = llPoss.getMaxLineCount()
-                                        - llPoss.getOptLineCount();
-            conditionalEliminableLines = llPoss.getOptLineCount()
-                                          - llPoss.getMinLineCount();
+            conditionalOptionalLines = llPoss.getMaxLineCount() - llPoss.getOptLineCount();
+            conditionalEliminableLines = llPoss.getOptLineCount() - llPoss.getMinLineCount();
             firstLines = llPoss.getOptLineCount();
             lastLines = 0;
         }
@@ -1047,12 +1029,6 @@ public class LineLayoutManager extends I
             breaker.add(new KnuthPenalty(0, 0, false, elementPosition, false));
         }
 
-        //log.debug("first=" + firstLines + " inner=" + innerLines
-        //                   + " optional=" + optionalLines + " eliminable=" + eliminableLines
-        //                   + " last=" + lastLines
-        //                   + " (condOpt=" + conditionalOptionalLines
-        //                   + " condEl=" + conditionalEliminableLines + ")");
-
         // creation of the elements:
         // first group of lines
         list.add(new KnuthBox(firstLines * constantLineHeight, elementPosition,
@@ -1569,7 +1545,7 @@ public class LineLayoutManager extends I
         lc.setAlignmentContext(alignmentContext);
         setChildContext(lc);
 
-        PositionIterator childPosIter = new StackingIter(positionList.listIterator());
+        PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
         LayoutContext blocklc = new LayoutContext(0);
         blocklc.setLeadingSpace(new SpaceSpecifier(true));
         blocklc.setTrailingSpace(new SpaceSpecifier(false));

Copied: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java (from r1069711, xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java)
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java?p2=xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java&p1=xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java&r1=1069711&r2=1069764&rev=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/BasicScaledBaselineTable.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/inline/ScaledBaselineTable.java Fri Feb 11 11:59:32 2011
@@ -19,49 +19,55 @@
 
 package org.apache.fop.layoutmgr.inline;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import org.apache.fop.fo.Constants;
 import org.apache.fop.traits.WritingMode;
 
 
 /**
- * An implementation of the ScaledBaselineTable interface which calculates
- * all baselines given the height above and below the dominant baseline.
+ * The FOP specific incarnation of the XSL-FO scaled baseline table.
+ * All baseline tables are scaled to the font size of the font they
+ * apply to. This class uses a coordinate system with its origin
+ * where the dominant baseline intersects the start edge of the box.
+ * All measurements are in mpt.
  */
-public class BasicScaledBaselineTable implements ScaledBaselineTable, Constants {
+final class ScaledBaselineTable {
+
+    private static final float HANGING_BASELINE_FACTOR = 0.8f;
+
+    private static final float MATHEMATICAL_BASELINE_FACTOR = 0.5f;
+
+    private final int altitude;
+
+    private final int depth;
 
-    /** A logger for this class */
-    protected Log log = LogFactory.getLog(BasicScaledBaselineTable.class);
+    private final int xHeight;
+
+    private final int dominantBaselineIdentifier;
+
+    private final WritingMode writingMode;
+
+    private final int dominantBaselineOffset;
 
-    private int altitude;
-    private int depth;
-    private int xHeight;
-    private int dominantBaselineIdentifier;
-    private WritingMode writingMode;
-    private int dominantBaselineOffset;
     private int beforeEdgeOffset;
+
     private int afterEdgeOffset;
 
-    private static final float HANGING_BASELINE_FACTOR = 0.8f;
-    private static final float MATHEMATICAL_BASELINE_FACTOR = 0.5f;
 
     /**
      *
      * Creates a new instance of BasicScaledBaselineTable for the given
-     * altitude, depth, xHeight, baseline and writingmode.
+     * altitude, depth, xHeight, baseline and writing mode.
      * @param altitude the height of the box or the font ascender
      * @param depth the font descender or 0
      * @param xHeight the font xHeight
      * @param dominantBaselineIdentifier the dominant baseline given as an integer constant
      * @param writingMode the writing mode given as an integer constant
      */
-    public BasicScaledBaselineTable(int altitude
-                                    , int depth
-                                    , int xHeight
-                                    , int dominantBaselineIdentifier
-                                    , WritingMode writingMode) {
+    ScaledBaselineTable(int altitude,
+            int depth,
+            int xHeight,
+            int dominantBaselineIdentifier,
+            WritingMode writingMode) {
         this.altitude = altitude;
         this.depth = depth;
         this.xHeight = xHeight;
@@ -76,7 +82,7 @@ public class BasicScaledBaselineTable im
      * Return the dominant baseline for this baseline table.
      * @return the dominant baseline
      */
-    public int getDominantBaselineIdentifier() {
+    int getDominantBaselineIdentifier() {
         return this.dominantBaselineIdentifier;
     }
 
@@ -84,56 +90,52 @@ public class BasicScaledBaselineTable im
      * Return the writing mode for this baseline table.
      * @return the writing mode
      */
-    public WritingMode getWritingMode() {
+    WritingMode getWritingMode() {
         return this.writingMode;
     }
 
     /**
-     * Return the baseline offset measured from the dominant
-     * baseline for the given baseline.
-     * @param baselineIdentifier the baseline identifier
-     * @return the baseline offset
+     * Return the offset of the given baseline from the dominant baseline.
+     *
+     * @param baselineIdentifier a baseline identifier
+     * @return the offset from the dominant baseline
      */
-    public int getBaseline(int baselineIdentifier) {
-        int offset;
+    int getBaseline(int baselineIdentifier) {
+        int offset = 0;
         if (!isHorizontalWritingMode()) {
             switch (baselineIdentifier) {
-                default:
-                case EN_TOP:
-                case EN_TEXT_TOP:
-                case EN_TEXT_BOTTOM:
-                case EN_BOTTOM:
-                    log.warn("The given baseline is only supported for horizontal"
-                        + " writing modes");
-                    offset = 0;
-            }
-        } else {
-            switch (baselineIdentifier) {
-                case EN_TOP: // fall through
-                case EN_BEFORE_EDGE:
-                    offset = beforeEdgeOffset;
-                    break;
-                case EN_TEXT_TOP:
-                case EN_TEXT_BEFORE_EDGE:
-                case EN_HANGING:
-                case EN_CENTRAL:
-                case EN_MIDDLE:
-                case EN_MATHEMATICAL:
-                case EN_ALPHABETIC:
-                case EN_IDEOGRAPHIC:
-                case EN_TEXT_BOTTOM:
-                case EN_TEXT_AFTER_EDGE:
-                    offset = getBaselineDefaultOffset(baselineIdentifier) - dominantBaselineOffset;
-                    break;
-                case EN_BOTTOM: // fall through
-                case EN_AFTER_EDGE:
-                    offset = afterEdgeOffset;
-                    break;
-                default:
-                    offset = 0;
-                    break;
+                case Constants.EN_TOP:
+                case Constants.EN_TEXT_TOP:
+                case Constants.EN_TEXT_BOTTOM:
+                case Constants.EN_BOTTOM:
+                throw new IllegalArgumentException("Baseline " + baselineIdentifier
+                        + " only supported for horizontal writing modes");
+                default: // TODO
             }
         }
+        switch (baselineIdentifier) {
+            case Constants.EN_TOP: // fall through
+            case Constants.EN_BEFORE_EDGE:
+                offset = beforeEdgeOffset;
+                break;
+            case Constants.EN_TEXT_TOP:
+            case Constants.EN_TEXT_BEFORE_EDGE:
+            case Constants.EN_HANGING:
+            case Constants.EN_CENTRAL:
+            case Constants.EN_MIDDLE:
+            case Constants.EN_MATHEMATICAL:
+            case Constants.EN_ALPHABETIC:
+            case Constants.EN_IDEOGRAPHIC:
+            case Constants.EN_TEXT_BOTTOM:
+            case Constants.EN_TEXT_AFTER_EDGE:
+                offset = getBaselineDefaultOffset(baselineIdentifier) - dominantBaselineOffset;
+                break;
+            case Constants.EN_BOTTOM: // fall through
+            case Constants.EN_AFTER_EDGE:
+                offset = afterEdgeOffset;
+                break;
+            default: throw new IllegalArgumentException(String.valueOf(baselineIdentifier));
+        }
         return offset;
     }
 
@@ -150,49 +152,55 @@ public class BasicScaledBaselineTable im
     private int getBaselineDefaultOffset(int baselineIdentifier) {
         int offset = 0;
         switch (baselineIdentifier) {
-            case EN_TEXT_BEFORE_EDGE:
+            case Constants.EN_TEXT_BEFORE_EDGE:
                 offset = altitude;
                 break;
-            case EN_HANGING:
-                offset = (int)Math.round(altitude * HANGING_BASELINE_FACTOR);
+            case Constants.EN_HANGING:
+                offset = Math.round(altitude * HANGING_BASELINE_FACTOR);
                 break;
-            case EN_CENTRAL:
+            case Constants.EN_CENTRAL:
                 offset = (altitude - depth) / 2 + depth;
                 break;
-            case EN_MIDDLE:
+            case Constants.EN_MIDDLE:
                 offset = xHeight / 2;
                 break;
-            case EN_MATHEMATICAL:
-                offset = (int)Math.round(altitude * MATHEMATICAL_BASELINE_FACTOR);
+            case Constants.EN_MATHEMATICAL:
+                offset = Math.round(altitude * MATHEMATICAL_BASELINE_FACTOR);
                 break;
-            case EN_ALPHABETIC:
+            case Constants.EN_ALPHABETIC:
                 offset = 0;
                 break;
-            case EN_IDEOGRAPHIC: // Fall through
-            case EN_TEXT_AFTER_EDGE:
+            case Constants.EN_IDEOGRAPHIC: // Fall through
+            case Constants.EN_TEXT_AFTER_EDGE:
                 offset = depth;
                 break;
-            default:
-                break;
+            default: throw new IllegalArgumentException(String.valueOf(baselineIdentifier));
         }
         return offset;
     }
 
     /**
-     * {@inheritDoc}
+     * Sets the position of the before and after baselines.
+     * This is usually only done for line areas. For other
+     * areas the position of the before and after baselines
+     * are fixed when the table is constructed.
+     * @param beforeBaseline the offset of the before-edge baseline from the dominant baseline
+     * @param afterBaseline the offset of the after-edge baseline from the dominant baseline
      */
-    public void setBeforeAndAfterBaselines(int beforeBaseline, int afterBaseline) {
+    void setBeforeAndAfterBaselines(int beforeBaseline, int afterBaseline) {
         beforeEdgeOffset = beforeBaseline;
         afterEdgeOffset = afterBaseline;
     }
 
     /**
-     * {@inheritDoc}
-     */
-    public ScaledBaselineTable deriveScaledBaselineTable(int baselineIdentifier) {
-        BasicScaledBaselineTable bac
-            = new BasicScaledBaselineTable(altitude, depth, xHeight
-                                            , baselineIdentifier, this.writingMode);
+     * Return a new baseline table for the given baseline based
+     * on the current baseline table.
+     * @param baselineIdentifier the baseline identifer
+     * @return a new baseline with the new baseline
+     */
+    ScaledBaselineTable deriveScaledBaselineTable(int baselineIdentifier) {
+        ScaledBaselineTable bac = new ScaledBaselineTable(altitude, depth, xHeight,
+                baselineIdentifier, this.writingMode);
         return bac;
     }
 

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java Fri Feb 11 11:59:32 2011
@@ -65,20 +65,6 @@ public class ListBlockLayoutManager exte
     private MinOptMax effSpaceBefore;
     private MinOptMax effSpaceAfter;
 
-    private static class StackingIter extends PositionIterator {
-        StackingIter(Iterator parentIter) {
-            super(parentIter);
-        }
-
-        protected LayoutManager getLM(Object nextObj) {
-            return ((Position) nextObj).getLM();
-        }
-
-        protected Position getPos(Object nextObj) {
-            return ((Position) nextObj);
-        }
-    }
-
     /**
      * Create a new list block layout manager.
      * @param node list-block to create the layout manager for
@@ -96,6 +82,7 @@ public class ListBlockLayoutManager exte
     }
 
     /** {@inheritDoc} */
+    @Override
     public void initialize() {
         foSpaceBefore = new SpaceVal(
                 getListBlockFO().getCommonMarginBlock().spaceBefore, this).getSpace();
@@ -115,6 +102,7 @@ public class ListBlockLayoutManager exte
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getNextKnuthElements(LayoutContext context, int alignment) {
         resetSpaces();
         List returnList = super.getNextKnuthElements(context, alignment);
@@ -135,6 +123,7 @@ public class ListBlockLayoutManager exte
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getChangedKnuthElements(List oldList, int alignment) {
         //log.debug("LBLM.getChangedKnuthElements>");
         return super.getChangedKnuthElements(oldList, alignment);
@@ -147,6 +136,7 @@ public class ListBlockLayoutManager exte
      * @param parentIter the position iterator
      * @param layoutContext the layout context for adding areas
      */
+    @Override
     public void addAreas(PositionIterator parentIter,
                          LayoutContext layoutContext) {
         getParentArea(null);
@@ -170,10 +160,10 @@ public class ListBlockLayoutManager exte
 
         // "unwrap" the NonLeafPositions stored in parentIter
         // and put them in a new list;
-        LinkedList positionList = new LinkedList();
+        LinkedList<Position> positionList = new LinkedList<Position>();
         Position pos;
         while (parentIter.hasNext()) {
-            pos = (Position)parentIter.next();
+            pos = parentIter.next();
             if (pos.getIndex() >= 0) {
                 if (firstPos == null) {
                     firstPos = pos;
@@ -194,7 +184,7 @@ public class ListBlockLayoutManager exte
 
         addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
 
-        StackingIter childPosIter = new StackingIter(positionList.listIterator());
+        PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
         while ((childLM = childPosIter.getNextChildLM()) != null) {
             // Add the block areas to Area
             // set the space adjustment ratio
@@ -235,6 +225,7 @@ public class ListBlockLayoutManager exte
      * @param childArea the child area
      * @return the parent area of the child
      */
+    @Override
     public Area getParentArea(Area childArea) {
         if (curBlockArea == null) {
             curBlockArea = new Block();

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java Fri Feb 11 11:59:32 2011
@@ -19,7 +19,6 @@
 
 package org.apache.fop.layoutmgr.list;
 
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -49,20 +48,6 @@ public class ListItemContentLayoutManage
     private int xoffset;
     private int itemIPD;
 
-    private static class StackingIter extends PositionIterator {
-        StackingIter(Iterator parentIter) {
-            super(parentIter);
-        }
-
-        protected LayoutManager getLM(Object nextObj) {
-            return ((Position) nextObj).getLM();
-        }
-
-        protected Position getPos(Object nextObj) {
-            return ((Position) nextObj);
-        }
-    }
-
     /**
      * Create a new Cell layout manager.
      * @param node list-item-label node
@@ -99,6 +84,7 @@ public class ListItemContentLayoutManage
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getChangedKnuthElements(List oldList, int alignment) {
         //log.debug("  ListItemContentLayoutManager.getChanged>");
         return super.getChangedKnuthElements(oldList, alignment);
@@ -112,6 +98,7 @@ public class ListItemContentLayoutManage
      * @param parentIter the iterator of the break positions
      * @param layoutContext the layout context for adding the areas
      */
+    @Override
     public void addAreas(PositionIterator parentIter,
                          LayoutContext layoutContext) {
         getParentArea(null);
@@ -127,10 +114,10 @@ public class ListItemContentLayoutManage
 
         // "unwrap" the NonLeafPositions stored in parentIter
         // and put them in a new list;
-        LinkedList positionList = new LinkedList();
+        LinkedList<Position> positionList = new LinkedList<Position>();
         Position pos;
         while (parentIter.hasNext()) {
-            pos = (Position)parentIter.next();
+            pos = parentIter.next();
             if (pos == null) {
                 continue;
             }
@@ -156,7 +143,7 @@ public class ListItemContentLayoutManage
 
         addMarkersToPage(true, isFirst(firstPos), isLast(lastPos));
 
-        StackingIter childPosIter = new StackingIter(positionList.listIterator());
+        PositionIterator childPosIter = new PositionIterator(positionList.listIterator());
         while ((childLM = childPosIter.getNextChildLM()) != null) {
             // Add the block areas to Area
             lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM);
@@ -189,6 +176,7 @@ public class ListItemContentLayoutManage
      * @param childArea the child area to get the parent for
      * @return the parent area
      */
+    @Override
     public Area getParentArea(Area childArea) {
         if (curBlockArea == null) {
             curBlockArea = new Block();
@@ -215,6 +203,7 @@ public class ListItemContentLayoutManage
      *
      * @param childArea the child to add to the cell
      */
+    @Override
     public void addChildArea(Area childArea) {
         if (curBlockArea != null) {
             curBlockArea.addBlock((Block) childArea);

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFColor.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFColor.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFColor.java Fri Feb 11 11:59:32 2011
@@ -21,18 +21,17 @@ package org.apache.fop.pdf;
 
 import java.awt.Color;
 import java.awt.color.ColorSpace;
-import java.awt.color.ICC_ColorSpace;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
 
-import org.apache.fop.util.ColorExt;
-
 /**
- * PDF Color object.
- * This is used to output color to a PDF content stream.
+ * PDF Color object. It is currently only used to hold the transparent color of a masked bitmap
+ * image. And in this context, only RGB and Gray values are used.
+ * <p>
+ * Use of this class is discouraged. {@link PDFColorHandler} is now used for in-content color
+ * selection. For masked bitmaps, it may be wiser to switch to {@link Color} in the long run.
  */
 public class PDFColor extends PDFPathPaint {
     // could be 3.0 as well.
@@ -46,14 +45,8 @@ public class PDFColor extends PDFPathPai
     private double yellow = -1.0;
     private double black = -1.0;
 
-    // TODO - It would probably be better to reorganize PDFPathPaint/PDFColor/PDFColorSpace
-    //        class hierarchy. However, at this early stages of my FOP understanding, I can
-    //        not really oversee the consequences of such a switch (nor whether it would be
-    //        appropriate).
-    private ColorExt colorExt = null;
-
     /**
-     * Create a PDF color with double values ranging from 0 to 1
+     * Create a PDF color with double values ranging from 0 to 1.
      *
      * @param theRed the red double value
      * @param theGreen the green double value
@@ -69,81 +62,27 @@ public class PDFColor extends PDFPathPai
     }
 
     /**
-     * Create PDFColor for the given document and based on the java.awt.Color object
-     *
-     * In case the java.awt.Color is an instance of the ColorExt class a PDFICCStream is added to
-     * the PDFDocument that is being created
-     *
-     * @param pdfDoc PDFDocument that is being created
-     * @param col Color object from which to create this PDFColor
-     */
-    public PDFColor(PDFDocument pdfDoc, Color col) {
-        this(col);
-        // TODO - 1) There is a potential conflict when FOP and Batik elements use the same color
-        //           profile name for different profiles.
-        //        2) In case the same color profile is used with different names it will be
-        //           included multiple times in the PDF
-        //
-        if (colorExt != null
-                && pdfDoc.getResources().getColorSpace(colorExt.getIccProfileName()) == null) {
-            PDFICCStream pdfIccStream = new PDFICCStream();
-            ColorSpace ceCs = colorExt.getOrigColorSpace();
-            try {
-                pdfIccStream.setColorSpace(((ICC_ColorSpace)ceCs).getProfile(), null);
-                pdfIccStream.setData(
-                        ((ICC_ColorSpace)colorExt.getColorSpace()).getProfile().getData());
-            } catch (IOException ioe) {
-                log.error("Failed to set profile data for " + colorExt.getIccProfileName());
-            }
-            pdfDoc.registerObject(pdfIccStream);
-            pdfDoc.getFactory().makeICCBasedColorSpace(
-                    null, colorExt.getIccProfileName(), pdfIccStream);
-            if (log.isInfoEnabled()) {
-                log.info("Adding PDFICCStream " + colorExt.getIccProfileName()
-                        + " for " + colorExt.getIccProfileSrc());
-            }
-        }
-    }
-
-    /**
      * Create a PDF color from a java.awt.Color object.
      *
      * Different Color objects are handled differently. Cases recognized are.
      *
      * 1. CMYK color
-     * 2. ColorExt color
-     * 3. 'Normal' java.awt.Color (RGB case assumed)
+     * 3. 'Normal' java.awt.Color (RGB case assumed or implicit conversion to sRGB)
      *
      * @param col the java.awt.Color object for which to create a PDFColor object
      */
     public PDFColor(java.awt.Color col) {
         ColorSpace cs = col.getColorSpace();
-        ColorExt ce = null;
-        if (col instanceof ColorExt) {
-            ce = (ColorExt)col;
-            cs = ce.getOrigColorSpace();
-        }
         if (cs != null && cs instanceof DeviceCMYKColorSpace) {
             // CMYK case
             this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_CMYK);
-            float[] cmyk = (ce == null
-                    ? col.getColorComponents(null)
-                    : ce.getOriginalColorComponents());
+            float[] cmyk = col.getColorComponents(null);
             this.cyan = cmyk[0];
             this.magenta = cmyk[1];
             this.yellow = cmyk[2];
             this.black = cmyk[3];
-        } else if (ce != null) {
-            // ColorExt (ICC) case
-            this.colorExt = ce;
-            float[] rgb = col.getRGBColorComponents(null);
-            this.red = rgb[0];
-            this.green = rgb[1];
-            this.blue = rgb[2];
-            // TODO - See earlier todo
-            this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
         } else {
-            // Default (RGB) Color
+            // Default (RGB) Color (ICC Colors are converted to sRGB, too)
             this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
             float[] comps = new float[3];
             comps = col.getColorComponents(comps);
@@ -163,7 +102,6 @@ public class PDFColor extends PDFPathPai
     public PDFColor(int theRed, int theGreen, int theBlue) {
         this(((double)theRed) / 255d, ((double)theGreen) / 255d,
              ((double)theBlue) / 255d);
-
     }
 
     /**
@@ -176,8 +114,6 @@ public class PDFColor extends PDFPathPai
      */
     public PDFColor(double theCyan, double theMagenta, double theYellow,
                     double theBlack) {
-        // super(theNumber);//?
-
         this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_CMYK);
 
         this.cyan = theCyan;
@@ -351,26 +287,7 @@ public class PDFColor extends PDFPathPai
     public String getColorSpaceOut(boolean fillNotStroke) {
         StringBuffer p = new StringBuffer("");
 
-        if (this.colorExt != null) {
-            if (fillNotStroke)  {
-                p.append("/" + this.colorExt.getIccProfileName() + " cs ");
-            } else {
-                p.append("/" + this.colorExt.getIccProfileName() + " CS ");
-            }
-            float[] colorArgs;
-            colorArgs = this.colorExt.getOriginalColorComponents();
-            if (colorArgs == null) {
-                colorArgs = this.colorExt.getColorComponents(null);
-            }
-            for (int ix = 0; ix < colorArgs.length; ix++) {
-                p.append(colorArgs[ix] + " ");
-            }
-            if (fillNotStroke)  {
-                p.append("sc\n");
-            } else {
-                p.append("SC\n");
-            }
-        } else if (this.colorSpace.getColorSpace()
+        if (this.colorSpace.getColorSpace()
                 == PDFDeviceColorSpace.DEVICE_RGB) {       // colorspace is RGB
             // according to pdfspec 12.1 p.399
             // if the colors are the same then just use the g or G operator

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDeviceColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDeviceColorSpace.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDeviceColorSpace.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDeviceColorSpace.java Fri Feb 11 11:59:32 2011
@@ -19,6 +19,8 @@
 
 package org.apache.fop.pdf;
 
+import java.awt.color.ColorSpace;
+
 /**
  * Represents a device-specific color space. Used for mapping DeviceRGB, DeviceCMYK and DeviceGray.
  */
@@ -137,4 +139,28 @@ public class PDFDeviceColorSpace impleme
         return getColorSpace() == DEVICE_GRAY;
     }
 
+    /**
+     * Returns a suitable {@link PDFDeviceColorSpace} object given a {@link ColorSpace} object.
+     * @param cs ColorSpace instance
+     * @return a PDF-based color space
+     */
+    public static PDFDeviceColorSpace toPDFColorSpace(ColorSpace cs) {
+        if (cs == null) {
+            return null;
+        }
+
+        PDFDeviceColorSpace pdfCS = new PDFDeviceColorSpace(0);
+        switch (cs.getType()) {
+            case ColorSpace.TYPE_CMYK:
+                pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_CMYK);
+            break;
+            case ColorSpace.TYPE_GRAY:
+                pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_GRAY);
+                break;
+            default:
+                pdfCS.setColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
+        }
+        return pdfCS;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDocument.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDocument.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDocument.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFDocument.java Fri Feb 11 11:59:32 2011
@@ -67,7 +67,7 @@ import org.apache.commons.logging.LogFac
  */
 public class PDFDocument {
 
-    private static final Integer LOCATION_PLACEHOLDER = new Integer(0);
+    private static final Long LOCATION_PLACEHOLDER = new Long(0);
 
     /** Integer constant to represent PDF 1.3 */
     public static final int PDF_VERSION_1_3 = 3;
@@ -85,13 +85,13 @@ public class PDFDocument {
     private Log log = LogFactory.getLog("org.apache.fop.pdf");
 
     /** the current character position */
-    private int position = 0;
+    private long position = 0;
 
     /** character position of xref table */
-    private int xref;
+    private long xref;
 
     /** the character position of each object */
-    private List location = new ArrayList();
+    private List<Long> location = new ArrayList<Long>();
 
     /** List of objects to write in the trailer */
     private List trailerObjects = new ArrayList();
@@ -747,6 +747,7 @@ public class PDFDocument {
      * @return the image or PDFXObject for the key if found
      * @deprecated Use getXObject instead (so forms are treated in the same way)
      */
+    @Deprecated
     public PDFImageXObject getImage(String key) {
         return (PDFImageXObject)this.xObjectsMap.get(key);
     }
@@ -911,11 +912,11 @@ public class PDFDocument {
      * @param objidx    the object's index
      * @param position  the position
      */
-    private void setLocation(int objidx, int position) {
+    private void setLocation(int objidx, long position) {
         while (this.location.size() <= objidx) {
             this.location.add(LOCATION_PLACEHOLDER);
         }
-        this.location.set(objidx, new Integer(position));
+        this.location.set(objidx, position);
     }
 
     /**
@@ -1071,6 +1072,9 @@ public class PDFDocument {
         for (int count = 0; count < this.location.size(); count++) {
             final String padding = "0000000000";
             s = this.location.get(count).toString();
+            if (s.length() > 10) {
+                throw new IOException("PDF file too large. PDF cannot grow beyond approx. 9.3GB.");
+            }
 
             /* contruct xref entry for object */
             loc = padding.substring(s.length()) + s;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFFactory.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFFactory.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFFactory.java Fri Feb 11 11:59:32 2011
@@ -20,6 +20,7 @@
 package org.apache.fop.pdf;
 
 // Java
+import java.awt.Color;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.io.FileNotFoundException;
@@ -27,6 +28,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Iterator;
 import java.util.List;
@@ -40,6 +42,8 @@ import org.apache.commons.io.output.Byte
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
 import org.apache.xmlgraphics.xmp.Metadata;
 
 import org.apache.fop.fonts.CIDFont;
@@ -779,23 +783,23 @@ public class PDFFactory {
 
         for (currentPosition = 0; currentPosition < lastPosition;
                 currentPosition++) {    // for every consecutive color pair
-            PDFColor currentColor = (PDFColor)theColors.get(currentPosition);
-            PDFColor nextColor = (PDFColor)theColors.get(currentPosition
-                                 + 1);
-            // colorspace must be consistant
-            if (getDocument().getColorSpace() != currentColor.getColorSpace()) {
-                currentColor.setColorSpace(
-                    getDocument().getColorSpace());
-            }
+            Color currentColor = (Color)theColors.get(currentPosition);
+            Color nextColor = (Color)theColors.get(currentPosition + 1);
 
-            if (getDocument().getColorSpace()
-                    != nextColor.getColorSpace()) {
-                nextColor.setColorSpace(
-                    getDocument().getColorSpace());
+            // colorspace must be consistent, so we simply convert to sRGB where necessary
+            if (!currentColor.getColorSpace().isCS_sRGB()) {
+                //Convert to sRGB
+                currentColor = ColorUtil.toSRGBColor(currentColor);
+                theColors.set(currentPosition, currentColor);
+            }
+            if (!nextColor.getColorSpace().isCS_sRGB()) {
+                //Convert to sRGB
+                nextColor = ColorUtil.toSRGBColor(nextColor);
+                theColors.set(currentPosition + 1, nextColor);
             }
 
-            theCzero = currentColor.getVector();
-            theCone = nextColor.getVector();
+            theCzero = toColorVector(currentColor);
+            theCone = toColorVector(nextColor);
 
             myfunc = makeFunction(2, null, null, theCzero, theCone,
                                        interpolation);
@@ -843,6 +847,15 @@ public class PDFFactory {
         return (myPattern);
     }
 
+    private List toColorVector(Color nextColor) {
+        List vector = new java.util.ArrayList();
+        float[] comps = nextColor.getColorComponents(null);
+        for (int i = 0, c = comps.length; i < c; i++) {
+            vector.add(new Double(comps[i]));
+        }
+        return vector;
+    }
+
     /* ============= named destinations and the name dictionary ============ */
 
     /**
@@ -1782,6 +1795,38 @@ public class PDFFactory {
     }
 
     /**
+     * Create a new Separation color space.
+     * @param res the resource context (may be null)
+     * @param ncs the named color space to map to a separation color space
+     * @return the newly created Separation color space
+     */
+    public PDFSeparationColorSpace makeSeparationColorSpace(PDFResourceContext res,
+            NamedColorSpace ncs) {
+        String colorName = ncs.getColorName();
+        final Double zero = new Double(0d);
+        final Double one = new Double(1d);
+        List theDomain = Arrays.asList(new Double[] {zero, one});
+        List theRange = Arrays.asList(new Double[] {zero, one, zero, one, zero, one});
+        List theCZero = Arrays.asList(new Double[] {one, one, one});
+        List theCOne = new ArrayList();
+        float[] comps = ncs.getRGBColor().getColorComponents(null);
+        for (int i = 0, c = comps.length; i < c; i++) {
+            theCOne.add(new Double(comps[i]));
+        }
+        PDFFunction tintFunction = makeFunction(2, theDomain, theRange,
+                theCZero, theCOne, 1.0d);
+        PDFSeparationColorSpace cs = new PDFSeparationColorSpace(colorName, tintFunction);
+        getDocument().registerObject(cs);
+        if (res != null) {
+            res.getPDFResources().addColorSpace(cs);
+        } else {
+            getDocument().getResources().addColorSpace(cs);
+        }
+
+        return cs;
+    }
+
+    /**
      * Make an Array object (ex. Widths array for a font).
      *
      * @param values the int array values

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFICCBasedColorSpace.java Fri Feb 11 11:59:32 2011
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 
 /**
  * Represents an ICCBased color space in PDF.
@@ -134,21 +135,19 @@ public class PDFICCBasedColorSpace exten
     public static PDFICCStream setupsRGBColorProfile(PDFDocument pdfDoc) {
         ICC_Profile profile;
         PDFICCStream sRGBProfile = pdfDoc.getFactory().makePDFICCStream();
-        synchronized (PDFICCBasedColorSpace.class) {
-            InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
-            if (in != null) {
-                try {
-                    profile = ICC_Profile.getInstance(in);
-                } catch (IOException ioe) {
-                    throw new RuntimeException(
-                            "Unexpected IOException loading the sRGB profile: " + ioe.getMessage());
-                } finally {
-                    IOUtils.closeQuietly(in);
-                }
-            } else {
-                // Fallback: Use the sRGB profile from the JRE (about 140KB)
-                profile = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
+        InputStream in = PDFDocument.class.getResourceAsStream("sRGB Color Space Profile.icm");
+        if (in != null) {
+            try {
+                profile = ColorProfileUtil.getICC_Profile(in);
+            } catch (IOException ioe) {
+                throw new RuntimeException(
+                        "Unexpected IOException loading the sRGB profile: " + ioe.getMessage());
+            } finally {
+                IOUtils.closeQuietly(in);
             }
+        } else {
+            // Fallback: Use the sRGB profile from the JRE (about 140KB)
+            profile = ColorProfileUtil.getICC_Profile(ColorSpace.CS_sRGB);
         }
         sRGBProfile.setColorSpace(profile, null);
         return sRGBProfile;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFName.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFName.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFName.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFName.java Fri Feb 11 11:59:32 2011
@@ -86,6 +86,29 @@ public class PDFName extends PDFObject {
         return this.name;
     }
 
+    /**
+     * Returns the name without the leading slash.
+     * @return the name without the leading slash
+     */
+    public String getName() {
+        return this.name.substring(1);
+    }
+
+    /** {@inheritDoc} */
+    public boolean equals(Object obj) {
+        if (!(obj instanceof PDFName)) {
+            return false;
+        }
+        PDFName other = (PDFName)obj;
+        return this.name.equals(other.name);
+    }
+
+    /** {@inheritDoc} */
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+
     /** {@inheritDoc} */
     protected int output(OutputStream stream) throws IOException {
         CountingOutputStream cout = new CountingOutputStream(stream);

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFPaintingState.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFPaintingState.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFPaintingState.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFPaintingState.java Fri Feb 11 11:59:32 2011
@@ -19,12 +19,15 @@
 
 package org.apache.fop.pdf;
 
+import java.awt.Color;
 import java.awt.Paint;
 import java.awt.Shape;
 import java.awt.geom.Area;
 import java.awt.geom.GeneralPath;
 import java.util.Iterator;
 
+import org.apache.xmlgraphics.java2d.color.ColorUtil;
+
 import org.apache.fop.util.AbstractPaintingState;
 
 /**
@@ -63,13 +66,18 @@ public class PDFPaintingState extends or
      */
     public boolean setPaint(Paint p) {
         PDFData data = getPDFData();
-        Paint paint = data.paint;
-        if (paint == null) {
+        Paint currentPaint = data.paint;
+        if (currentPaint == null) {
             if (p != null) {
                 data.paint = p;
                 return true;
             }
-        } else if (!paint.equals(p)) {
+        } else if (p instanceof Color && currentPaint instanceof Color) {
+            if (!ColorUtil.isSameColor((Color)p, (Color)currentPaint)) {
+                data.paint = p;
+                return true;
+            }
+        } else if (!currentPaint.equals(p)) {
             data.paint = p;
             return true;
         }
@@ -180,11 +188,13 @@ public class PDFPaintingState extends or
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AbstractData instantiateData() {
         return new PDFData();
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AbstractPaintingState instantiate() {
         return new PDFPaintingState();
     }
@@ -194,6 +204,7 @@ public class PDFPaintingState extends or
      * This call should be used when the q operator is used
      * so that the state is known when popped.
      */
+    @Override
     public void save() {
         AbstractData data = getData();
         AbstractData copy = (AbstractData)data.clone();
@@ -222,6 +233,7 @@ public class PDFPaintingState extends or
         private float characterSpacing = 0f;
 
         /** {@inheritDoc} */
+        @Override
         public Object clone() {
             PDFData obj = (PDFData)super.clone();
             obj.paint = this.paint;
@@ -237,6 +249,7 @@ public class PDFPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         public String toString() {
             return super.toString()
                 + ", paint=" + paint
@@ -249,6 +262,7 @@ public class PDFPaintingState extends or
         }
 
         /** {@inheritDoc} */
+        @Override
         protected AbstractData instantiate() {
             return new PDFData();
         }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFResources.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFResources.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFResources.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/pdf/PDFResources.java Fri Feb 11 11:59:32 2011
@@ -19,26 +19,28 @@
 
 package org.apache.fop.pdf;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 import org.apache.fop.fonts.FontDescriptor;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.Typeface;
 import org.apache.fop.fonts.base14.Symbol;
 import org.apache.fop.fonts.base14.ZapfDingbats;
-import org.apache.fop.util.ColorProfileUtil;
 
 /**
- * class representing a /Resources object.
+ * Class representing a /Resources object.
  *
  * /Resources object contain a list of references to the fonts for the
  * document
  */
-public class PDFResources extends PDFObject {
+public class PDFResources extends PDFDictionary {
 
     /**
      * /Font objects keyed by their internal name
@@ -159,11 +161,14 @@ public class PDFResources extends PDFObj
      * Add a ColorSpace dictionary to the resources.
      * @param colorSpace the color space
      */
-    public void addColorSpace(PDFICCBasedColorSpace colorSpace) {
-        this.colorSpaces.put(colorSpace.getName(), colorSpace);
-        String desc = ColorProfileUtil.getICCProfileDescription(
-                colorSpace.getICCStream().getICCProfile());
-        this.iccColorSpaces.put(desc, colorSpace);
+    public void addColorSpace(PDFColorSpace colorSpace) {
+        this.colorSpaces.put(new PDFName(colorSpace.getName()), colorSpace);
+        if (colorSpace instanceof PDFICCBasedColorSpace) {
+            PDFICCBasedColorSpace icc = (PDFICCBasedColorSpace)colorSpace;
+            String desc = ColorProfileUtil.getICCProfileDescription(
+                    icc.getICCStream().getICCProfile());
+            this.iccColorSpaces.put(desc, colorSpace);
+        }
     }
 
     /**
@@ -181,106 +186,80 @@ public class PDFResources extends PDFObj
      * @param name the name of the color space
      * @return the requested color space or null if it wasn't found
      */
-    public PDFICCBasedColorSpace getColorSpace(String name) {
-        PDFICCBasedColorSpace cs = (PDFICCBasedColorSpace)this.colorSpaces.get(name);
+    public PDFColorSpace getColorSpace(PDFName name) {
+        PDFColorSpace cs = (PDFColorSpace)this.colorSpaces.get(name);
         return cs;
     }
 
-    /**
-     * represent the object in PDF
-     * This adds the references to all the objects in the current
-     * resource context.
-     *
-     * @return the PDF
-     * {@inheritDoc}
-     */
-    @Override
-    public String toPDFString() {
-        StringBuffer p = new StringBuffer(128);
-        p.append(getObjectID() + "<<\n");
-        if (!this.fonts.isEmpty()) {
-            p.append("/Font <<\n");
+    /** {@inheritDoc} */
+    protected int output(OutputStream stream) throws IOException {
+        populateDictionary();
+        return super.output(stream);
+    }
 
+    private void populateDictionary() {
+        if (!this.fonts.isEmpty()) {
+            PDFDictionary dict = new PDFDictionary(this);
             /* construct PDF dictionary of font object references */
             Iterator fontIterator = this.fonts.keySet().iterator();
             while (fontIterator.hasNext()) {
                 String fontName = (String)fontIterator.next();
-                p.append("  /" + fontName + " "
-                         + ((PDFFont)this.fonts.get(fontName)).referencePDF()
-                         + "\n");
+                dict.put(fontName, (PDFFont)this.fonts.get(fontName));
             }
-
-            p.append(">>\n");
+            put("Font", dict);
         }
 
-        PDFShading currentShading = null;
         if (!this.shadings.isEmpty()) {
-            p.append("/Shading <<\n");
-
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = shadings.iterator(); iter.hasNext();) {
-                currentShading = (PDFShading)iter.next();
-                p.append("  /" + currentShading.getName() + " "
-                         + currentShading.referencePDF() + " ");    // \n ??????
+                PDFShading currentShading = (PDFShading)iter.next();
+                dict.put(currentShading.getName(), currentShading);
             }
-
-            p.append(">>\n");
+            put("Shading", dict);
         }
-        // "free" the memory. Sorta.
-        currentShading = null;
 
-        PDFPattern currentPattern = null;
         if (!this.patterns.isEmpty()) {
-            p.append("/Pattern <<\n");
-
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = patterns.iterator(); iter.hasNext();) {
-                currentPattern = (PDFPattern)iter.next();
-                p.append("  /" + currentPattern.getName() + " "
-                         + currentPattern.referencePDF() + " ");
+                PDFPattern currentPattern = (PDFPattern)iter.next();
+                dict.put(currentPattern.getName(), currentPattern);
             }
-
-            p.append(">>\n");
+            put("Pattern", dict);
         }
-        // "free" the memory. Sorta.
-        currentPattern = null;
 
-        p.append("/ProcSet [ /PDF /ImageB /ImageC /Text ]\n");
+        PDFArray procset = new PDFArray(this);
+        procset.add(new PDFName("PDF"));
+        procset.add(new PDFName("ImageB"));
+        procset.add(new PDFName("ImageC"));
+        procset.add(new PDFName("Text"));
+        put("ProcSet", procset);
 
         if (this.xObjects != null && !this.xObjects.isEmpty()) {
-            p = p.append("/XObject <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = xObjects.iterator(); iter.hasNext();) {
                 PDFXObject xobj = (PDFXObject)iter.next();
-                p = p.append("  " + xobj.getName() + " "
-                             + xobj.referencePDF()
-                             + "\n");
+                dict.put(xobj.getName().toString(), xobj);
             }
-            p = p.append(">>\n");
+            put("XObject", dict);
         }
 
         if (!this.gstates.isEmpty()) {
-            p = p.append("/ExtGState <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = gstates.iterator(); iter.hasNext();) {
                 PDFGState gs = (PDFGState)iter.next();
-                p = p.append("  /" + gs.getName() + " "
-                             + gs.referencePDF()
-                             + "\n");
+                dict.put(gs.getName(), gs);
             }
-            p = p.append(">>\n");
+            put("ExtGState", dict);
         }
 
         if (!this.colorSpaces.isEmpty()) {
-            p = p.append("/ColorSpace <<\n");
+            PDFDictionary dict = new PDFDictionary(this);
             for (Iterator iter = colorSpaces.values().iterator(); iter.hasNext();) {
-                PDFICCBasedColorSpace colorSpace = (PDFICCBasedColorSpace)iter.next();
-                p = p.append("  /" + colorSpace.getName() + " "
-                             + colorSpace.referencePDF()
-                             + "\n");
+                PDFColorSpace colorSpace = (PDFColorSpace)iter.next();
+                dict.put(colorSpace.getName(), colorSpace);
             }
-            p = p.append(">>\n");
+            put("ColorSpace", dict);
         }
-
-        p = p.append(">>\nendobj\n");
-
-        return p.toString();
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java Fri Feb 11 11:59:32 2011
@@ -77,17 +77,17 @@ public class AFPDocumentHandler extends 
     private DataStream dataStream;
 
     /** the map of page segments */
-    private Map/*<String,PageSegmentDescriptor>*/pageSegmentMap
-        = new java.util.HashMap/*<String,PageSegmentDescriptor>*/();
+    private Map<String, PageSegmentDescriptor> pageSegmentMap
+        = new java.util.HashMap<String, PageSegmentDescriptor>();
 
     /** Medium Map referenced on previous page **/
     private String lastMediumMap;
 
-    private static final int LOC_ELSEWHERE = 0;
-    private static final int LOC_FOLLOWING_PAGE_SEQUENCE = 1;
-    private static final int LOC_IN_PAGE_HEADER = 2;
+    private static enum Location {
+        ELSEWHERE, IN_DOCUMENT_HEADER, FOLLOWING_PAGE_SEQUENCE, IN_PAGE_HEADER
+    }
 
-    private int location = LOC_ELSEWHERE;
+    private Location location = Location.ELSEWHERE;
 
     /** the shading mode for filled rectangles */
     private AFPShadingMode shadingMode = AFPShadingMode.COLOR;
@@ -117,6 +117,7 @@ public class AFPDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    @Override
     public void setDefaultFontInfo(FontInfo fontInfo) {
         FontManager fontManager = getUserAgent().getFactory().getFontManager();
         FontCollection[] fontCollections = new FontCollection[] {
@@ -152,6 +153,7 @@ public class AFPDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startDocument() throws IFException {
         super.startDocument();
         try {
@@ -165,11 +167,23 @@ public class AFPDocumentHandler extends 
         }
     }
 
+
+    /** {@inheritDoc} */
+    @Override
+    public void startDocumentHeader() throws IFException {
+        super.startDocumentHeader();
+        this.location = Location.IN_DOCUMENT_HEADER;
+    }
+
     /** {@inheritDoc} */
+    @Override
     public void endDocumentHeader() throws IFException {
+        super.endDocumentHeader();
+        this.location = Location.ELSEWHERE;
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endDocument() throws IFException {
         try {
             this.dataStream.endDocument();
@@ -189,7 +203,7 @@ public class AFPDocumentHandler extends 
         } catch (IOException ioe) {
             throw new IFException("I/O error in startPageSequence()", ioe);
         }
-        this.location = LOC_FOLLOWING_PAGE_SEQUENCE;
+        this.location = Location.FOLLOWING_PAGE_SEQUENCE;
     }
 
     /** {@inheritDoc} */
@@ -212,7 +226,7 @@ public class AFPDocumentHandler extends 
     /** {@inheritDoc} */
     public void startPage(int index, String name, String pageMasterName, Dimension size)
                 throws IFException {
-        this.location = LOC_ELSEWHERE;
+        this.location = Location.ELSEWHERE;
         paintingState.clear();
 
         AffineTransform baseTransform = getBaseTransform();
@@ -232,14 +246,16 @@ public class AFPDocumentHandler extends 
     }
 
     /** {@inheritDoc} */
+    @Override
     public void startPageHeader() throws IFException {
         super.startPageHeader();
-        this.location = LOC_IN_PAGE_HEADER;
+        this.location = Location.IN_PAGE_HEADER;
     }
 
     /** {@inheritDoc} */
+    @Override
     public void endPageHeader() throws IFException {
-        this.location = LOC_ELSEWHERE;
+        this.location = Location.ELSEWHERE;
         super.endPageHeader();
     }
 
@@ -272,17 +288,36 @@ public class AFPDocumentHandler extends 
             AFPPageSetup aps = (AFPPageSetup)extension;
             String element = aps.getElementName();
             if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(element)) {
-                if (this.location != LOC_IN_PAGE_HEADER
-                        && this.location != LOC_FOLLOWING_PAGE_SEQUENCE) {
+                switch (this.location) {
+                case FOLLOWING_PAGE_SEQUENCE:
+                case IN_PAGE_HEADER:
+                    String name = aps.getName();
+                    String value = aps.getValue();
+                    dataStream.createTagLogicalElement(name, value);
+                    break;
+                default:
                     throw new IFException(
                         "TLE extension must be in the page header or between page-sequence"
                             + " and the first page: " + aps, null);
                 }
-                String name = aps.getName();
-                String value = aps.getValue();
-                dataStream.createTagLogicalElement(name, value);
+            } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
+                switch (this.location) {
+                case IN_DOCUMENT_HEADER:
+                case FOLLOWING_PAGE_SEQUENCE:
+                case IN_PAGE_HEADER:
+                    String content = aps.getContent();
+                    if (content != null) {
+                        dataStream.createNoOperation(content);
+                    }
+                    break;
+                default:
+                    throw new IFException(
+                            "NOP extension must be in the document header, the page header"
+                                + " or between page-sequence"
+                                + " and the first page: " + aps, null);
+                }
             } else {
-                if (this.location != LOC_IN_PAGE_HEADER) {
+                if (this.location != Location.IN_PAGE_HEADER) {
                     throw new IFException(
                         "AFP page setup extension encountered outside the page header: " + aps,
                         null);
@@ -294,16 +329,11 @@ public class AFPDocumentHandler extends 
                     String source = apse.getValue();
                     String uri = apse.getResourceSrc();
                     pageSegmentMap.put(source, new PageSegmentDescriptor(name, uri));
-                } else if (AFPElementMapping.NO_OPERATION.equals(element)) {
-                    String content = aps.getContent();
-                    if (content != null) {
-                        dataStream.createNoOperation(content);
-                    }
                 }
             }
         } else if (extension instanceof AFPPageOverlay) {
             AFPPageOverlay ipo = (AFPPageOverlay)extension;
-            if (this.location != LOC_IN_PAGE_HEADER) {
+            if (this.location != Location.IN_PAGE_HEADER) {
                     throw new IFException(
                         "AFP page overlay extension encountered outside the page header: " + ipo,
                         null);
@@ -313,8 +343,8 @@ public class AFPDocumentHandler extends 
                 dataStream.createIncludePageOverlay(overlay, ipo.getX(), ipo.getY());
             }
         } else if (extension instanceof AFPInvokeMediumMap) {
-            if (this.location != LOC_FOLLOWING_PAGE_SEQUENCE
-                    && this.location != LOC_IN_PAGE_HEADER) {
+            if (this.location != Location.FOLLOWING_PAGE_SEQUENCE
+                    && this.location != Location.IN_PAGE_HEADER) {
 
                 throw new IFException(
                     "AFP IMM extension must be between page-sequence"
@@ -401,7 +431,7 @@ public class AFPDocumentHandler extends 
      * @return the page segment descriptor or null if there's no page segment for the given URI
      */
     PageSegmentDescriptor getPageSegmentNameFor(String uri) {
-        return (PageSegmentDescriptor)pageSegmentMap.get(uri);
+        return pageSegmentMap.get(uri);
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java Fri Feb 11 11:59:32 2011
@@ -24,8 +24,10 @@ import java.awt.Rectangle;
 import java.awt.image.ColorModel;
 import java.awt.image.DataBuffer;
 import java.awt.image.DataBufferByte;
+import java.awt.image.MultiPixelPackedSampleModel;
 import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
+import java.awt.image.SampleModel;
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -254,6 +256,12 @@ public class AFPImageHandlerRenderedImag
         if (tiles > 1) {
             return false;
         }
+        SampleModel sampleModel = renderedImage.getSampleModel();
+        SampleModel expectedSampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+                renderedImage.getWidth(), renderedImage.getHeight(), 1);
+        if (!expectedSampleModel.equals(sampleModel)) {
+            return false; //Pixels are not packed
+        }
 
         imageObjectInfo.setBitsPerPixel(1);
 
@@ -290,6 +298,7 @@ public class AFPImageHandlerRenderedImag
     }
 
     /** {@inheritDoc} */
+    @Override
     protected AFPDataObjectInfo createDataObjectInfo() {
         return new AFPImageObjectInfo();
     }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java?rev=1069764&r1=1069763&r2=1069764&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/extensions/AFPPageSetupElement.java Fri Feb 11 11:59:32 2011
@@ -54,6 +54,7 @@ public class AFPPageSetupElement extends
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void startOfNode() throws FOPException {
         super.startOfNode();
         if (AFPElementMapping.TAG_LOGICAL_ELEMENT.equals(getLocalName())) {
@@ -63,14 +64,17 @@ public class AFPPageSetupElement extends
                     "rule.childOfPageSequenceOrSPM");
             }
         } else {
-            if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER) {
+            if (parent.getNameId() != Constants.FO_SIMPLE_PAGE_MASTER
+                    && parent.getNameId() != Constants.FO_PAGE_SEQUENCE
+                    && parent.getNameId() != Constants.FO_DECLARATIONS) {
                 invalidChildError(getLocator(), parent.getName(), getNamespaceURI(), getName(),
-                    "rule.childOfSPM");
+                    "rule.childOfSPMorPSorDeclarations");
             }
         }
     }
 
     /** {@inheritDoc} */
+    @Override
     protected void characters(char[] data, int start, int length,
                                  PropertyList pList, Locator locator) throws FOPException {
         StringBuffer sb = new StringBuffer();
@@ -83,6 +87,7 @@ public class AFPPageSetupElement extends
     }
 
     /** {@inheritDoc} */
+    @Override
     public void processNode(String elementName, Locator locator,
                             Attributes attlist, PropertyList propertyList)
                                 throws FOPException {
@@ -106,6 +111,7 @@ public class AFPPageSetupElement extends
     }
 
     /** {@inheritDoc} */
+    @Override
     protected ExtensionAttachment instantiateExtensionAttachment() {
         return new AFPPageSetup(getLocalName());
     }



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