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 vh...@apache.org on 2013/11/07 21:49:18 UTC

svn commit: r1539809 - in /xmlgraphics/fop/branches/Temp_WhitespaceManagement: src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/extensions/ src/java/org/apache/fop/fo/flow/ src/java/org/apache/fop/layoutmgr/ test/java/org/apache/fop/

Author: vhennebert
Date: Thu Nov  7 20:49:18 2013
New Revision: 1539809

URL: http://svn.apache.org/r1539809
Log:
Implement whitespace management extension using fo:multi-switch
Patch from 13/10/28 by Seifeddine Dridi, applied with some modifications.

Added:
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java   (with props)
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java   (with props)
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java   (with props)
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java   (with props)
Removed:
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/AlternativeBlock.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeBlockLayoutManager.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutManager.java
Modified:
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCase.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiSwitch.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiToggle.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java Thu Nov  7 20:49:18 2013
@@ -816,11 +816,14 @@ public interface Constants {
     /** Scope for table header */
     int PR_X_HEADER_COLUMN = 290;
 
-    /** Property constant - FOP proprietary*/
+    /** Property constant */
     int PR_X_FITTING_STRATEGY = 291;
 
+    /** Property constant */
+    int PR_X_AUTO_TOGGLE = 292;
+
     /** Number of property constants defined */
-    int PROPERTY_COUNT = 291;
+    int PROPERTY_COUNT = 292;
 
     // compound property constants
 

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java Thu Nov  7 20:49:18 2013
@@ -2128,7 +2128,7 @@ public final class FOPropertyMapping imp
         addPropertyMaker("starting-state", m);
 
         // switch-to
-        m  = new ToBeImplementedProperty.Maker(PR_SWITCH_TO);
+        m  = new StringProperty.Maker(PR_SWITCH_TO);
         m.setInherited(false);
         m.setDefault("xsl-any");
         addPropertyMaker("switch-to", m);
@@ -2617,12 +2617,18 @@ public final class FOPropertyMapping imp
         m.setDefault("");
         addPropertyMaker("fox:alt-text", m);
 
-        //fox:fitting-strategy, used only in fox:best-fit
+        // fox:fitting-strategy, used only in fox:best-fit
         m = new StringProperty.Maker(PR_X_FITTING_STRATEGY);
         m.setInherited(false);
         m.setDefault("first-fit");
         addPropertyMaker("fox:fitting-strategy", m);
 
+        // fox:auto-toggle, used only in fo:multi-switch
+        m = new StringProperty.Maker(PR_X_AUTO_TOGGLE);
+        m.setInherited(false);
+        m.setDefault("");
+        addPropertyMaker("fox:auto-toggle", m);
+
         // fox:border-*-radius-*
         m = new CondLengthProperty.Maker(PR_X_BORDER_BEFORE_RADIUS_START);
         m.useGeneric(genericCondCornerRadius);

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java Thu Nov  7 20:49:18 2013
@@ -15,8 +15,6 @@
  * limitations under the License.
  */
 
-/* $Id$ */
-
 package org.apache.fop.fo.extensions;
 
 import org.xml.sax.Locator;
@@ -24,72 +22,36 @@ import org.xml.sax.Locator;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.flow.MultiCaseHandler;
+import org.apache.fop.fo.flow.MultiSwitch;
 import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
 
-/**
- *  A class that holds a set of <fox:alternative-block> blocks where each one is examined,
- *  and the one that best matches the fitting strategy is selected.
- *  The selected alternative should have an occupied BPD that is less than
- *  the remaining BPD of the current page.
- */
-public class BestFit extends FObj {
+public class BestFit extends FObj implements MultiCaseHandler {
 
     public static final String OBJECT_NAME = "best-fit";
-    private FittingStrategy strategy = FittingStrategy.FIRST_FIT;
+    private FittingStrategy strategy;
 
     public BestFit(FONode parent) {
         super(parent);
-
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public void bind(PropertyList pList) throws FOPException {
-        super.bind(pList);
-        String strategyName = pList.get(PR_X_FITTING_STRATEGY).getString();
-        for (FittingStrategy fs : FittingStrategy.values()) {
-            if (fs.getStrategyName().equals(strategyName)) {
-                strategy = fs;
-                return;
+    public void setFittingStrategy(String strategyName) {
+        strategy = FittingStrategy.make(strategyName);
+        if (strategy == null) {
+            strategy = FittingStrategy.FIRST_FIT;
+            if (log.isWarnEnabled()) {
+                log.warn("Unrecognized strategy name => " + strategyName + ". Using default strategy (first-fit");
             }
         }
-        if (log.isWarnEnabled()) {
-            log.warn("Unrecognized strategy name => " + strategyName + ". Using default strategy (first-fit");
-        }
-    }
-
-    @Override
-    public void startOfNode() throws FOPException {
-        super.startOfNode();
-        if (log.isDebugEnabled()) {
-            log.debug("BestFit.startOfNode()");
-        }
-    }
-
-    @Override
-    public void endOfNode() throws FOPException {
-        super.endOfNode();
-        if (log.isDebugEnabled()) {
-            log.debug("BestFit.endOfNode()");
-        }
     }
 
     /**
      * {@inheritDoc}
-     * Content model: (fox:alternative-block)+
      */
     @Override
     protected void validateChildNode(Locator loc, String nsURI, String localName)
             throws ValidationException {
-        if (FOX_URI.equals(nsURI)) {
-            if (!"alternative-block".equals(localName)) {
-                invalidChildError(loc, FOX_URI, localName);
-            }
-        } else {
-            invalidChildError(loc, nsURI, localName);
-        }
     }
 
     @Override
@@ -107,8 +69,19 @@ public class BestFit extends FObj {
         return ExtensionElementMapping.URI;
     }
 
+    public void filter(MultiSwitch multiSwitch) throws FOPException {
+        // Modifying the FO tree is not advised...
+//        FONodeIterator nodeIter = multiSwitch.getChildNodes();
+//        while (nodeIter.hasNext()) {
+//            FONode childNode = (FONode) nodeIter.next();
+//            this.addChildNode(childNode);
+//        }
+//        multiSwitch.clearChildNodes();
+    }
+
     public FittingStrategy getStrategy() {
         return strategy;
     }
 
 }
+

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java Thu Nov  7 20:49:18 2013
@@ -50,6 +50,7 @@ public class ExtensionElementMapping ext
         PROPERTY_ATTRIBUTES.add("internal-destination");
         PROPERTY_ATTRIBUTES.add("disable-column-balancing");
         PROPERTY_ATTRIBUTES.add("fitting-strategy");
+        PROPERTY_ATTRIBUTES.add("auto-toggle");
         //These are FOP's extension properties for accessibility
         PROPERTY_ATTRIBUTES.add("alt-text");
         PROPERTY_ATTRIBUTES.add("header");
@@ -87,8 +88,6 @@ public class ExtensionElementMapping ext
             foObjs.put("label", new UnknownXMLObj.Maker(URI));
             foObjs.put("destination", new DestinationMaker());
             foObjs.put("external-document", new ExternalDocumentMaker());
-            foObjs.put("best-fit", new BestFitMaker());
-            foObjs.put("alternative-block", new AlternativeBlockMaker());
         }
     }
 
@@ -106,20 +105,6 @@ public class ExtensionElementMapping ext
         }
     }
 
-    static class BestFitMaker extends ElementMapping.Maker {
-        @Override
-        public FONode make(FONode parent) {
-            return new BestFit(parent);
-        }
-    }
-
-    static class AlternativeBlockMaker extends ElementMapping.Maker {
-        @Override
-        public FONode make(FONode parent) {
-            return new AlternativeBlock(parent);
-        }
-    }
-
     /** {@inheritDoc} */
     @Override
     public String getStandardPrefix() {

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCase.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCase.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCase.java Thu Nov  7 20:49:18 2013
@@ -19,10 +19,13 @@
 
 package org.apache.fop.fo.flow;
 
+import org.xml.sax.Locator;
+
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.PropertyList;
+import org.apache.fop.fo.ValidationException;
 
 /**
  * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_multi-case">
@@ -32,6 +35,9 @@ import org.apache.fop.fo.PropertyList;
 public class MultiCase extends FObj {
     // The value of properties relevant for fo:multi-case.
     private int startingState;
+    private String caseName;
+    private String caseTitle;
+    private MultiCaseHandler multiCaseHandler;
     // private ToBeImplementedProperty caseName;
     // private ToBeImplementedProperty caseTitle;
     // Unused but valid items, commented out for performance:
@@ -55,12 +61,50 @@ public class MultiCase extends FObj {
         }
     }
 
-    /** {@inheritDoc} */
+    @Override
     public void bind(PropertyList pList) throws FOPException {
         super.bind(pList);
         startingState = pList.get(PR_STARTING_STATE).getEnum();
-        // caseName = pList.get(PR_CASE_NAME);
-        // caseTitle = pList.get(PR_CASE_TITLE);
+        caseName = pList.get(PR_CASE_NAME).getString();
+        caseTitle = pList.get(PR_CASE_TITLE).getString();
+        if (startingState == EN_SHOW) {
+            MultiSwitch multiSwitch = (MultiSwitch) parent;
+            if (multiSwitch.getCurrentlyVisibleNode() == null) {
+                multiSwitch.setCurrentlyVisibleNode(this);
+            }
+        }
+    }
+
+    /**
+     * Content Model: (#PCDATA|%inline;|%block)*
+     */
+    @Override
+    protected void validateChildNode(Locator loc, String nsURI, String localName)
+            throws ValidationException {
+        if (FO_URI.equals(nsURI)) {
+            if (!isBlockOrInlineItem(nsURI, localName) || "marker".equals(localName)) {
+                invalidChildError(loc, nsURI, localName);
+            }
+            if (!"multi-toggle".equals(localName)) {
+                // Validate against parent of fo:multi-switch
+                FONode.validateChildNode(getParent().getParent(), loc, nsURI, localName);
+            }
+        }
+    }
+
+    @Override
+    public void endOfNode() throws FOPException {
+        if (firstChild == null) {
+            missingChildElementError("(#PCDATA|%inline;|%block)*");
+        }
+    }
+
+    @Override
+    protected void addChildNode(FONode child) throws FOPException {
+        if (child instanceof MultiCaseHandler) {
+            multiCaseHandler = (MultiCaseHandler) child;
+        }
+        super.addChildNode(child);
     }
 
     /** @return the "starting-state" property */
@@ -68,7 +112,7 @@ public class MultiCase extends FObj {
         return startingState;
     }
 
-    /** {@inheritDoc} */
+    @Override
     public String getLocalName() {
         return "multi-case";
     }
@@ -77,7 +121,25 @@ public class MultiCase extends FObj {
      * {@inheritDoc}
      * @return {@link org.apache.fop.fo.Constants#FO_MULTI_CASE}
      */
+    @Override
     public int getNameId() {
         return FO_MULTI_CASE;
     }
+
+    public String getCaseName() {
+        return caseName;
+    }
+
+    public String getCaseTitle() {
+        return caseTitle;
+    }
+
+    public boolean isActuated() {
+        return multiCaseHandler != null;
+    }
+
+    MultiCaseHandler getHandler() {
+        return multiCaseHandler;
+    }
+
 }

Added: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java?rev=1539809&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java (added)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java Thu Nov  7 20:49:18 2013
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.fo.flow;
+
+import org.apache.fop.apps.FOPException;
+
+/**
+ * This interface is used in conjunction with {@link MultiSwitch}
+ * to implement a callback system for handling fo:multi-case elements.
+ */
+
+public interface MultiCaseHandler {
+
+    /**
+     * A filtering function used to select one or more fo:multi-case
+     * elements, children of {@link MultiSwitch}.
+     *
+     * @param multiSwitch parent of the fo:multi-case elements to filter
+     * @throws FOPException
+     */
+    void filter(MultiSwitch multiSwitch) throws FOPException;
+
+}

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiCaseHandler.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiSwitch.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiSwitch.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiSwitch.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiSwitch.java Thu Nov  7 20:49:18 2013
@@ -19,7 +19,6 @@
 
 package org.apache.fop.fo.flow;
 
-// XML
 import org.xml.sax.Locator;
 
 import org.apache.fop.apps.FOPException;
@@ -39,7 +38,10 @@ public class MultiSwitch extends FObj {
     //     private CommonAccessibility commonAccessibility;
     // End of property values
 
-    private static boolean notImplementedWarningGiven = false;
+    private static boolean notImplementedWarningGiven;
+    private FONode currentlyVisibleMultiCase;
+    private String autoToggle;
+    private String fittingStrategy;
 
     /**
      * Base constructor
@@ -57,23 +59,44 @@ public class MultiSwitch extends FObj {
     }
 
     /** {@inheritDoc} */
+    @Override
     public void bind(PropertyList pList) throws FOPException {
         super.bind(pList);
+        autoToggle = pList.get(PR_X_AUTO_TOGGLE).getString();
+        fittingStrategy = pList.get(PR_X_FITTING_STRATEGY).getString();
         // autoRestore = pList.get(PR_AUTO_RESTORE);
     }
 
-
     /** {@inheritDoc} */
+    @Override
     public void endOfNode() throws FOPException {
         if (firstChild == null) {
             missingChildElementError("(multi-case+)");
         }
+        super.endOfNode();
+    }
+
+    @Override
+    public void finalizeNode() throws FOPException {
+        if (autoToggle.equals("best-fit")) {
+            // Nothing to do in this case
+            setCurrentlyVisibleNode(null);
+        } else {
+            FONodeIterator nodeIter = getChildNodes();
+            while (nodeIter.hasNext()) {
+                MultiCase multiCase = (MultiCase) nodeIter.next();
+                if (multiCase.isActuated()) {
+                    multiCase.getHandler().filter(this);
+                }
+            }
+        }
     }
 
     /**
      * {@inheritDoc}
      * <br>XSL Content Model: (multi-case+)
      */
+    @Override
     protected void validateChildNode(Locator loc, String nsURI, String localName)
                 throws ValidationException {
         if (FO_URI.equals(nsURI)) {
@@ -84,6 +107,7 @@ public class MultiSwitch extends FObj {
     }
 
     /** {@inheritDoc} */
+    @Override
     public String getLocalName() {
         return "multi-switch";
     }
@@ -92,7 +116,25 @@ public class MultiSwitch extends FObj {
      * {@inheritDoc}
      * @return {@link org.apache.fop.fo.Constants#FO_MULTI_SWITCH}
      */
+    @Override
     public int getNameId() {
         return FO_MULTI_SWITCH;
     }
+
+    public void setCurrentlyVisibleNode(FONode node) {
+        currentlyVisibleMultiCase = node;
+    }
+
+    public FONode getCurrentlyVisibleNode() {
+        return currentlyVisibleMultiCase;
+    }
+
+    public String getFittingStrategy() {
+        return fittingStrategy;
+    }
+
+    public String getAutoToggle() {
+        return autoToggle;
+    }
+
 }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiToggle.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiToggle.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiToggle.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/flow/MultiToggle.java Thu Nov  7 20:49:18 2013
@@ -19,7 +19,6 @@
 
 package org.apache.fop.fo.flow;
 
-// FOP
 import org.xml.sax.Locator;
 
 import org.apache.fop.apps.FOPException;
@@ -27,16 +26,17 @@ import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
+import org.apache.fop.fo.properties.StringProperty;
 
 
 /**
  * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_multi-toggle">
  * <code>fo:multi-toggle<code></a> property.
  */
-public class MultiToggle extends FObj {
+public class MultiToggle extends FObj implements MultiCaseHandler {
     // The value of properties relevant for fo:multi-toggle (commented out for performance).
     //     private CommonAccessibility commonAccessibility;
-    // public ToBeImplementedProperty prSwitchTo;
+     public StringProperty prSwitchTo;
     // End of property values
 
     private static boolean notImplementedWarningGiven = false;
@@ -57,15 +57,17 @@ public class MultiToggle extends FObj {
     }
 
     /** {@inheritDoc} */
+    @Override
     public void bind(PropertyList pList) throws FOPException {
-        // prSwitchTo = pList.get(PR_SWITCH_TO);
-
+        super.bind(pList);
+        prSwitchTo = (StringProperty) pList.get(PR_SWITCH_TO);
     }
 
     /**
      * {@inheritDoc}
      * <br>XSL Content Model: (#PCDATA|%inline;|%block;)*
      */
+    @Override
     protected void validateChildNode(Locator loc, String nsURI, String localName)
                 throws ValidationException {
         if (FO_URI.equals(nsURI)) {
@@ -76,6 +78,7 @@ public class MultiToggle extends FObj {
     }
 
     /** {@inheritDoc} */
+    @Override
     public String getLocalName() {
         return "multi-toggle";
     }
@@ -84,7 +87,44 @@ public class MultiToggle extends FObj {
      * {@inheritDoc}
      * @return {@link org.apache.fop.fo.Constants#FO_MULTI_TOGGLE}
      */
+    @Override
     public int getNameId() {
         return FO_MULTI_TOGGLE;
     }
+
+    public void filter(MultiSwitch multiSwitch) throws FOPException {
+        if (multiSwitch.getCurrentlyVisibleNode() == null) {
+            multiSwitch.setCurrentlyVisibleNode(parent);
+        }
+
+        FONode currentlyVisibleMultiCase = multiSwitch.getCurrentlyVisibleNode();
+
+        if (prSwitchTo.getString().equals("xsl-any")) {
+//            NoOp
+        } else if (prSwitchTo.getString().equals("xsl-preceding")) {
+            FONodeIterator nodeIter = multiSwitch.getChildNodes(currentlyVisibleMultiCase);
+            if (nodeIter != null) {
+                if (!nodeIter.hasPrevious()) {
+                    currentlyVisibleMultiCase = nodeIter.lastNode();
+                } else {
+                    currentlyVisibleMultiCase = nodeIter.previousNode();
+                }
+            }
+        } else if (prSwitchTo.getString().equals("xsl-following")) {
+            FONodeIterator nodeIter = multiSwitch.getChildNodes(currentlyVisibleMultiCase);
+            if (nodeIter != null) {
+                //Ignore the first node
+                nodeIter.next();
+                if (!nodeIter.hasNext()) {
+                    currentlyVisibleMultiCase = nodeIter.firstNode();
+                } else {
+                    currentlyVisibleMultiCase = nodeIter.nextNode();
+                }
+            }
+        } else {
+            // Pick an fo:multi-case that matches a case-name...
+        }
+
+        multiSwitch.setCurrentlyVisibleNode(currentlyVisibleMultiCase);
+    }
 }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java Thu Nov  7 20:49:18 2013
@@ -19,24 +19,27 @@
 
 package org.apache.fop.layoutmgr;
 
+import java.util.LinkedList;
 import java.util.List;
 
+/**
+ * An alternative has a set of fitness traits (e.g. occupied bpd and ipd,
+ * adjustment ratio, remaining size, etc.) that determine how good its
+ * eligibility is when evaluated by a fitting strategy.
+ */
 public class Alternative {
 
-    /** remaining BPD after inserting the alternative */
+    /** Remaining BPD after inserting the alternative. */
     private int remainingBPD;
-    /** width of the alternative in block-progressing-dimension */
-    private final int width;
-    /** Knuth element list */
+    /** Size of the alternative in block-progression-direction. */
+    private final int length;
     private final List<ListElement> knuthList;
-    /** Indicates whether we should consider the alternative or not */
-    private boolean enabled;
+    private boolean enabled = true;
 
-    public Alternative(List<ListElement> knuthList, int width) {
+    public Alternative(List<ListElement> knuthList, int length) {
         this.knuthList = knuthList;
-        this.width = width;
+        this.length = length;
         this.remainingBPD = 0;
-        this.enabled = false;
     }
 
     public List<ListElement> getKnuthList() {
@@ -47,8 +50,8 @@ public class Alternative {
         return remainingBPD;
     }
 
-    public int getWidth() {
-        return width;
+    public int getLength() {
+        return length;
     }
 
     public void setRemainingBPD(int remainingBPD) {
@@ -68,20 +71,22 @@ public class Alternative {
         FIRST_FIT("first-fit") {
 
             @Override
-            public Alternative filter(List<Alternative> alternatives) {
+            public List<Alternative> filter(List<Alternative> alternatives) {
+                List<Alternative> alts = new LinkedList<Alternative>();
                 for (Alternative alt : alternatives) {
                     if (alt.isEnabled()) {
-                        return alt;
+                        alts.add(alt);
+                        break;
                     }
                 }
-                return null;
+                return alts;
             }
         },
 
         SMALLEST_FIT("smallest-fit") {
 
             @Override
-            public Alternative filter(List<Alternative> alternatives) {
+            public List<Alternative> filter(List<Alternative> alternatives) {
                 int biggestDiff = -Integer.MAX_VALUE;
                 Alternative bestAlt = null;
 
@@ -91,14 +96,16 @@ public class Alternative {
                         bestAlt = alt;
                     }
                 }
-                return bestAlt;
+                List<Alternative> alts = new LinkedList<Alternative>();
+                alts.add(bestAlt);
+                return alts;
             }
         },
 
         BIGGEST_FIT("biggest-fit") {
 
             @Override
-            public Alternative filter(List<Alternative> alternatives) {
+            public List<Alternative> filter(List<Alternative> alternatives) {
                 int smallestDiff = Integer.MAX_VALUE;
                 Alternative bestAlt = null;
 
@@ -108,7 +115,26 @@ public class Alternative {
                         bestAlt = alt;
                     }
                 }
-                return bestAlt;
+                List<Alternative> alts = new LinkedList<Alternative>();
+                alts.add(bestAlt);
+                return alts;
+            }
+        },
+
+        ANY("any") {
+
+            @Override
+            public List<Alternative> filter(List<Alternative> alternatives) {
+                List<Alternative> alts = new LinkedList<Alternative>();
+
+                int remainingSpace = Integer.MAX_VALUE;
+                for (Alternative alt : alternatives) {
+                    if (alt.isEnabled() && alt.getLength() <= remainingSpace) {
+                        alts.add(alt);
+                        remainingSpace = alt.getRemainingBPD();
+                    }
+                }
+                return alts;
             }
         };
 
@@ -122,11 +148,20 @@ public class Alternative {
             return strategyName;
         }
 
+        public static FittingStrategy make(String strategyName) {
+            for (FittingStrategy fs : FittingStrategy.values()) {
+                if (fs.getStrategyName().equals(strategyName)) {
+                    return fs;
+                }
+            }
+            return null;
+        }
+
         /**
          * @param alternatives the list of potential candidate {@link Alternative}
          * @return the best alternative according to the strategy being employed
          */
-        public abstract Alternative filter(List<Alternative> alternatives);
+        public abstract List<Alternative> filter(List<Alternative> alternatives);
 
     }
 }

Added: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java?rev=1539809&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java (added)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java Thu Nov  7 20:49:18 2013
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.layoutmgr;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
+
+/*
+ * Utility class used in {@link MultiSwitchLayoutManager}
+ * to handle  the <i>best-fit</i> property value if specified in {@link MultiSwitch}
+ */
+public final class BestFitLayoutUtils {
+
+    private BestFitLayoutUtils() { }
+
+    static class BestFitPosition extends Position {
+
+        public List<ListElement> knuthList;
+
+        public BestFitPosition(LayoutManager lm) {
+            super(lm);
+        }
+
+        public List<Position> getPositionList() {
+            List<Position> positions = new LinkedList<Position>();
+            if (knuthList != null) {
+
+                SpaceResolver.performConditionalsNotification(knuthList, 0, knuthList.size() - 1, -1);
+
+                for (ListElement elem : knuthList) {
+                    if (elem.getPosition() != null && elem.getLayoutManager() != null) {
+                        positions.add(elem.getPosition());
+                    }
+                }
+            }
+            return positions;
+        }
+
+        public void setKnuthList(List<ListElement> knuthList) {
+            this.knuthList = knuthList;
+        }
+
+        public List<ListElement> getKnuthList() {
+            return knuthList;
+        }
+
+    }
+
+    public static Alternative makeAlternative(List<ListElement> childList) {
+        // Add a zero penalty to make the SpaceResolver
+        // transform Space elements into Knuth glues.
+        childList.add(KnuthPenalty.DUMMY_ZERO_PENALTY);
+        SpaceResolver.resolveElementList(childList);
+        int contentLength = ElementListUtils.calcContentLength(childList);
+        return new Alternative(childList, contentLength);
+    }
+
+    public static List<ListElement> getKnuthList(LayoutManager lm,
+            List<List<ListElement>> childrenLists,
+            FittingStrategy strategy) {
+        List<ListElement> knuthList = new LinkedList<ListElement>();
+        Iterator<List<ListElement>> iter = childrenLists.iterator();
+        BestFitPenalty bestFitPenalty = new BestFitPenalty(strategy, new BestFitPosition(lm));
+        while (iter.hasNext()) {
+            List<ListElement> childList = iter.next();
+            bestFitPenalty.addAlternative(makeAlternative(childList));
+        }
+        // A penalty must always be preceded by a box
+        // to be considered as a valid breakpoint.
+        addKnuthPenalty(lm, knuthList, bestFitPenalty);
+        return knuthList;
+    }
+
+    public static void addKnuthPenalty(LayoutManager lm, List<ListElement> list,
+            KnuthPenalty bestFitPenalty) {
+
+        list.add(0, new KnuthBox(0, new Position(lm), false));
+        list.add(bestFitPenalty);
+        list.add(new KnuthBox(0, new Position(lm), false));
+    }
+
+    public static List<Position> getPositionList(LayoutManager lm, PositionIterator posIter) {
+
+        // "unwrap" the NonLeafPositions stored in parentIter
+        // and put them in a new list;
+        LinkedList<Position> positionList = new LinkedList<Position>();
+        Position pos;
+        while (posIter.hasNext()) {
+            pos = posIter.next();
+            if (pos instanceof BestFitPosition) {
+                positionList.addAll(((BestFitPosition) pos).getPositionList());
+            } else {
+                positionList.add(pos);
+            }
+        }
+        return positionList;
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java Thu Nov  7 20:49:18 2013
@@ -23,17 +23,20 @@ import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
+import org.apache.fop.layoutmgr.BestFitLayoutUtils.BestFitPosition;
 
 /**
- * A dummy penalty used in {@link BestFitLayoutManager} to store
- * the different alternatives in {@link fox:best-fit}
+ * A penalty class used to specify a set of alternatives for the layout engine
+ * to choose from. The chosen alternative must have an occupied size
+ * that is less than the available BPD of the current page
+ * and it must also be the best match when it is evaluated by {@link FittingStrategy}.
  */
-
 public class BestFitPenalty extends KnuthPenalty {
 
     private final LinkedList<Alternative> alternatives;
     private final FittingStrategy strategy;
-    private Alternative bestAlternative = null;
+    public boolean canFit = true;
+    private int currentAltIndex;
 
     public BestFitPenalty(FittingStrategy strategy, Position pos) {
         super(0, 0, false, pos, false);
@@ -49,30 +52,59 @@ public class BestFitPenalty extends Knut
         return alternatives;
     }
 
-    public FittingStrategy getStrategyType() {
+    public FittingStrategy getFittingStrategy() {
         return strategy;
     }
 
-    public Alternative getBestAlternative() {
-        if (bestAlternative != null) {
-            return bestAlternative;
+    @Override
+    public int getWidth() {
+        if (currentAltIndex == -1) {
+            return 0;
+        }
+        return alternatives.get(currentAltIndex).getLength();
+    }
+
+    public boolean hasMoreAlternatives() {
+        return currentAltIndex != -1;
+    }
+
+    public void considerNextAlternative() {
+        if (currentAltIndex < alternatives.size() - 1) {
+            currentAltIndex++;
         } else {
-            bestAlternative = strategy.filter(alternatives);
-            return bestAlternative;
+            currentAltIndex = -1;
         }
     }
 
-//    public void setBestAlternative(Alternative bestAlternative) {
-//        this.bestAlternative = bestAlternative;
-//    }
+    @Override
+    public Position getPosition() {
+        if (currentAltIndex != -1) {
+            Position pos = super.getPosition();
+            if (alternatives.size() > 0) {
+                getBestFitPosition().setKnuthList(alternatives.get(currentAltIndex).getKnuthList());
+            }
+            return pos;
+        }
+        return null;
+    }
+
+    public BestFitPosition getBestFitPosition() {
+        Position pos = super.getPosition();
+        while (pos != null) {
+            if (pos instanceof BestFitPosition) {
+                return (BestFitPosition) pos;
+            }
+            pos = pos.getPosition();
+        }
+        return null;
+    }
 
-    /** {@inheritDoc} */
     @Override
     public String toString() {
         String str = super.toString();
         StringBuffer buffer = new StringBuffer(64);
         buffer.append(" number of alternatives = " + getAlternatives().size());
-        buffer.append(" fitting-strategy = " + strategy);
+        buffer.append(" fitting-strategy = " + strategy.getStrategyName());
         return str + buffer.toString();
     }
 

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java Thu Nov  7 20:49:18 2013
@@ -304,7 +304,6 @@ public abstract class BreakingAlgorithm 
         }
 
         /** {@inheritDoc} */
-        @Override
         public String toString() {
             return "<KnuthNode at " + position + " "
                     + totalWidth + "+" + totalStretch + "-" + totalShrink
@@ -931,13 +930,7 @@ public abstract class BreakingAlgorithm 
                 if (node.position == elementIdx) {
                     continue;
                 }
-                int difference;
-                if (element instanceof BestFitPenalty) {
-                    BestFitPenalty penalty = (BestFitPenalty)element;
-                    difference = handleBestFitPenalty(penalty, node, elementIdx);
-                } else {
-                    difference = computeDifference(node, element, elementIdx);
-                }
+                int difference = computeDifference(node, element, elementIdx);
                 if (!elementCanEndLine(element, endLine, difference)) {
                     log.trace("Skipping legal break");
                     break;
@@ -976,33 +969,6 @@ public abstract class BreakingAlgorithm 
         }
     }
 
-    private int handleBestFitPenalty(BestFitPenalty penalty, KnuthNode node,
-            int elementIdx) {
-        // Find the alternatives that can be fitted inside the remaining space
-        for (int i = 0; i < penalty.getAlternatives().size(); ++i) {
-            Alternative alt = penalty.getAlternatives().get(i);
-            int difference = computeDifference(node, new KnuthPenalty(alt.getWidth(),
-                    0, false, null, false), elementIdx);
-            double r = computeAdjustmentRatio(node, difference);
-            //if (r >= -1) {
-                alt.setRemainingBPD(difference);
-                alt.setEnabled(r >= -1);
-                //altManager.addAlternative(alt);
-            //}
-        }
-        Alternative bestAlt = penalty.getBestAlternative();
-        if (bestAlt != null) {
-            //penalty.setBestAlternative(bestAlt);
-            // Add an empty KnuthBox to represent the chosen alternative
-            par.add(elementIdx + 1, new KnuthBox(bestAlt.getWidth(), null, false));
-            return bestAlt.getRemainingBPD();
-        } else {
-            // No "good" alternative was found
-            return computeDifference(node, new KnuthPenalty(0,
-                    0, false, null, false), elementIdx);
-        }
-    }
-
     /**
      * Check if the given {@link KnuthElement} can end the line with the given
      * number.

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java Thu Nov  7 20:49:18 2013
@@ -163,37 +163,6 @@ public final class ElementListUtils {
     }
 
     /**
-     * Calculates the full content length of the given element list. Warning: It doesn't take any
-     * stretch and shrink possibilities into account.
-     * @param elems the element list
-     * @return the content length
-     */
-    public static int calcFullContentLength(List elems) {
-        ListIterator iter = elems.listIterator(0);
-        int count = elems.size();
-        int len = 0;
-        while (iter.hasNext()) {
-            ListElement el = (ListElement)iter.next();
-            if (el.isBox()) {
-                len += ((KnuthElement)el).getWidth();
-            } else if (el.isGlue()) {
-                len += ((KnuthElement)el).getWidth();
-            } else if (el.isUnresolvedElement() && !(el instanceof BreakElement)) {
-                // Handle properties space-before and space-after
-                UnresolvedListElementWithLength uresolvedEl = (UnresolvedListElementWithLength)el;
-                if (uresolvedEl.isLast() || uresolvedEl.isFirst()) {
-                    len += uresolvedEl.getLength().getOpt();
-                }
-            }
-            count--;
-            if (count == 0) {
-                break;
-            }
-        }
-        return len;
-    }
-
-    /**
      * Calculates the content length of the given element list. Warning: It doesn't take any
      * stretch and shrink possibilities into account.
      * @param elems the element list

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java Thu Nov  7 20:49:18 2013
@@ -34,8 +34,6 @@ import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FONode.FONodeIterator;
 import org.apache.fop.fo.FOText;
 import org.apache.fop.fo.FObjMixed;
-import org.apache.fop.fo.extensions.AlternativeBlock;
-import org.apache.fop.fo.extensions.BestFit;
 import org.apache.fop.fo.extensions.ExternalDocument;
 import org.apache.fop.fo.flow.BasicLink;
 import org.apache.fop.fo.flow.BidiOverride;
@@ -51,6 +49,8 @@ import org.apache.fop.fo.flow.InstreamFo
 import org.apache.fop.fo.flow.Leader;
 import org.apache.fop.fo.flow.ListBlock;
 import org.apache.fop.fo.flow.ListItem;
+import org.apache.fop.fo.flow.MultiCase;
+import org.apache.fop.fo.flow.MultiSwitch;
 import org.apache.fop.fo.flow.PageNumber;
 import org.apache.fop.fo.flow.PageNumberCitation;
 import org.apache.fop.fo.flow.PageNumberCitationLast;
@@ -98,7 +98,7 @@ public class LayoutManagerMapping implem
     private static final Log LOG = LogFactory.getLog(LayoutManagerMapping.class);
 
     /** The map of LayoutManagerMakers */
-    private Map makers = new HashMap();
+    private final Map makers = new HashMap();
 
     /** default constructor */
     public LayoutManagerMapping() {
@@ -144,8 +144,8 @@ public class LayoutManagerMapping implem
         registerMaker(TableHeader.class, new Maker());
         registerMaker(Wrapper.class, new WrapperLayoutManagerMaker());
         registerMaker(Title.class, new InlineLayoutManagerMaker());
-        registerMaker(BestFit.class, new BestFitLayoutManagerMaker());
-        registerMaker(AlternativeBlock.class, new AlternativeBlockLayoutManagerMaker());
+        registerMaker(MultiCase.class, new MultiCaseLayoutManagerMaker());
+        registerMaker(MultiSwitch.class, new MultiSwitchLayoutManagerMaker());
     }
 
     /**
@@ -449,19 +449,30 @@ public class LayoutManagerMapping implem
         }
     }
 
-    /** a layout manager maker */
-    public class BestFitLayoutManagerMaker extends Maker {
-        /** {@inheritDoc} */
+    public class MultiSwitchLayoutManagerMaker extends Maker {
+
+        @Override
         public void make(FONode node, List lms) {
-            lms.add(new BestFitLayoutManager((BestFit) node));
+            MultiSwitch multiSwitch = (MultiSwitch) node;
+            MultiSwitchLayoutManager mslm = new MultiSwitchLayoutManager(multiSwitch);
+            FONode multiCase = multiSwitch.getCurrentlyVisibleNode();
+            if (multiCase != null) {
+                FONodeIterator childIter = multiCase.getChildNodes();
+                while (childIter.hasNext()) {
+                    FONode child = (FONode) childIter.next();
+                    makeLayoutManagers(child, lms);
+                }
+            } else {
+                lms.add(mslm);
+            }
         }
     }
 
-    /** a layout manager maker */
-    public class AlternativeBlockLayoutManagerMaker extends Maker {
-        /** {@inheritDoc} */
+    public class MultiCaseLayoutManagerMaker extends Maker {
+
+        @Override
         public void make(FONode node, List lms) {
-            lms.add(new AlternativeBlockLayoutManager((AlternativeBlock) node));
+            lms.add(new MultiCaseLayoutManager((MultiCase) node));
         }
     }
 

Added: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java?rev=1539809&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java (added)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java Thu Nov  7 20:49:18 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.layoutmgr;
+
+import org.apache.fop.area.Area;
+import org.apache.fop.area.Block;
+import org.apache.fop.area.LineArea;
+import org.apache.fop.fo.FObj;
+
+public class MultiCaseLayoutManager extends BlockStackingLayoutManager {
+
+    private Block curBlockArea;
+
+    public MultiCaseLayoutManager(FObj node) {
+        super(node);
+    }
+
+    @Override
+    public Keep getKeepTogether() {
+        return Keep.KEEP_AUTO;
+    }
+
+    @Override
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO;
+    }
+
+    @Override
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO;
+    }
+
+    @Override
+    public Area getParentArea(Area childArea) {
+        if (curBlockArea == null) {
+            curBlockArea = new Block();
+            curBlockArea.setIPD(super.getContentAreaIPD());
+            // Set up dimensions
+            // Must get dimensions from parent area
+            /*Area parentArea = */parentLayoutManager.getParentArea(curBlockArea);
+            setCurrentArea(curBlockArea);
+        }
+        return curBlockArea;
+    }
+
+    @Override
+    public void addChildArea(Area childArea) {
+        if (curBlockArea != null) {
+            if (childArea instanceof LineArea) {
+                curBlockArea.addLineArea((LineArea) childArea);
+            } else {
+                curBlockArea.addBlock((Block) childArea);
+            }
+        }
+    }
+
+    /**
+     * Force current area to be added to parent area.
+     */
+    @Override
+    protected void flush() {
+        if (getCurrentArea() != null) {
+            super.flush();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void addAreas(PositionIterator posIter, LayoutContext context) {
+        AreaAdditionUtil.addAreas(this, posIter, context);
+        flush();
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiCaseLayoutManager.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Added: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java?rev=1539809&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java (added)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java Thu Nov  7 20:49:18 2013
@@ -0,0 +1,157 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.layoutmgr;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.fop.area.Area;
+import org.apache.fop.area.Block;
+import org.apache.fop.area.LineArea;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.FONode.FONodeIterator;
+import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.flow.MultiSwitch;
+import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
+
+public class MultiSwitchLayoutManager extends BlockStackingLayoutManager {
+
+    private Block curBlockArea;
+
+    public MultiSwitchLayoutManager(FObj node) {
+        super(node);
+    }
+
+    @Override
+    public List<ListElement> getNextKnuthElements(LayoutContext context, int alignment) {
+
+        referenceIPD = context.getRefIPD();
+        List<List<ListElement>> childrenLists = new LinkedList<List<ListElement>>();
+        LayoutManager childLM;
+        while ((childLM = getChildLM()) != null) {
+            if (!childLM.isFinished()) {
+                LayoutContext childLC = makeChildLayoutContext(context);
+                List childElements = childLM.getNextKnuthElements(childLC, alignment);
+                if (childElements != null) {
+                    List<ListElement> newList = new LinkedList<ListElement>();
+                    wrapPositionElements(childElements, newList);
+                    childrenLists.add(newList);
+                }
+            }
+        }
+        setFinished(true);
+        return BestFitLayoutUtils.getKnuthList(this, childrenLists, FittingStrategy.FIRST_FIT);
+    }
+
+    @Override
+    protected List<LayoutManager> createChildLMs(int size) {
+        MultiSwitch multiSwitch = (MultiSwitch) getFObj();
+        if (multiSwitch.getCurrentlyVisibleNode() != null) {
+            List<LayoutManager> newLMs = new ArrayList<LayoutManager>(size);
+            if (childLMs.size() == 0) {
+                createMultiCaseLM(multiSwitch.getCurrentlyVisibleNode());
+                return new ArrayList<LayoutManager>(size);
+            }
+            return newLMs;
+        } else {
+            return super.createChildLMs(size);
+        }
+    }
+
+    private void createMultiCaseLM(FONode multiCase) {
+        FONodeIterator childIter = multiCase.getChildNodes();
+        while (childIter.hasNext()) {
+            List<LayoutManager> newLMs = new ArrayList<LayoutManager>(1);
+            getPSLM().getLayoutManagerMaker()
+            .makeLayoutManagers((childIter.nextNode()), newLMs);
+            if (!newLMs.isEmpty()) {
+                this.getParent().addChildLM(newLMs.get(0));
+            }
+        }
+    }
+
+    @Override
+    public Keep getKeepTogether() {
+        return Keep.KEEP_AUTO;
+    }
+
+    @Override
+    public Keep getKeepWithNext() {
+        return Keep.KEEP_AUTO;
+    }
+
+    @Override
+    public Keep getKeepWithPrevious() {
+        return Keep.KEEP_AUTO;
+    }
+
+    @Override
+    public int getContentAreaIPD() {
+        if (curBlockArea != null) {
+            return curBlockArea.getIPD();
+        }
+        return super.getContentAreaIPD();
+    }
+
+    @Override
+    public Area getParentArea(Area childArea) {
+        if (curBlockArea == null) {
+            curBlockArea = new Block();
+            curBlockArea.setIPD(super.getContentAreaIPD());
+            setCurrentArea(curBlockArea);
+            // Set up dimensions
+            // Must get dimensions from parent area
+            /*Area parentArea = */parentLayoutManager.getParentArea(curBlockArea);
+        }
+        return curBlockArea;
+    }
+
+    @Override
+    public void addChildArea(Area childArea) {
+        if (curBlockArea != null) {
+            if (childArea instanceof LineArea) {
+                curBlockArea.addLineArea((LineArea) childArea);
+            } else {
+                curBlockArea.addBlock((Block) childArea);
+            }
+        }
+    }
+
+    /**
+     * Force current area to be added to parent area.
+     */
+    @Override
+    protected void flush() {
+        if (getCurrentArea() != null) {
+            parentLayoutManager.addChildArea(getCurrentArea());
+        }
+    }
+
+    @Override
+    public void addAreas(PositionIterator posIter, LayoutContext context) {
+
+        List<Position> positionList = BestFitLayoutUtils.getPositionList(this, posIter);
+        PositionIterator newPosIter = new PositionIterator(
+                positionList.listIterator());
+
+        AreaAdditionUtil.addAreas(this, newPosIter, context);
+        flush();
+    }
+
+}

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Thu Nov  7 20:49:18 2013
@@ -149,6 +149,9 @@ class PageBreakingAlgorithm extends Brea
         /** Index of the last inserted element of the last inserted footnote. */
         public int footnoteElementIndex;
 
+        public boolean bestFitNode = false;
+        public boolean skipNode = false;
+
         public KnuthPageNode(int position,
                              int line, int fitness,
                              int totalWidth, int totalStretch, int totalShrink,
@@ -162,6 +165,12 @@ class PageBreakingAlgorithm extends Brea
             this.totalFootnotes = totalFootnotes;
             this.footnoteListIndex = footnoteListIndex;
             this.footnoteElementIndex = footnoteElementIndex;
+            if (getElement(position) instanceof BestFitPenalty) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Creating a KnuthPageNode for a BestFitPenalty.");
+                }
+                bestFitNode = true;
+            }
         }
 
     }
@@ -394,6 +403,25 @@ class PageBreakingAlgorithm extends Brea
     /** {@inheritDoc} */
     @Override
     protected int restartFrom(KnuthNode restartingNode, int currentIndex) {
+        if (getLastTooLong() != null) {
+            KnuthPageNode lastTooLong = (KnuthPageNode) getLastTooLong();
+            if (lastTooLong.skipNode) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Alternative does not fit in the current page. "
+                            + "Switching to the next one in the list");
+                }
+                int penaltyIndex = currentIndex;
+                // In case the paragraph has changed...
+                if (lastTooLong.previous.previous == null) {
+                    if (par.get(0) == KnuthPenalty.DUMMY_ZERO_PENALTY) {
+                        ++penaltyIndex;
+                    }
+                }
+                BestFitPenalty bestFitPenalty = (BestFitPenalty) getElement(penaltyIndex);
+                bestFitPenalty.considerNextAlternative();
+                restartingNode = restartingNode.previous;
+            }
+        }
         int returnValue = super.restartFrom(restartingNode, currentIndex);
         newFootnotes = false;
         if (footnotesPending) {
@@ -491,6 +519,22 @@ class PageBreakingAlgorithm extends Brea
     }
 
     /** {@inheritDoc} */
+    protected void forceNode(KnuthNode node, int line, int elementIdx,
+            int difference, double r, double demerits, int fitnessClass,
+            int availableShrink, int availableStretch) {
+
+        super.forceNode(node, line, elementIdx, difference, r, demerits,
+                fitnessClass, availableShrink, availableStretch);
+
+        KnuthPageNode lastTooLong = (KnuthPageNode) getLastTooLong();
+        if (lastTooLong != null) {
+            if (lastTooLong.bestFitNode) {
+                lastTooLong.skipNode = true;
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override
     protected int computeDifference(KnuthNode activeNode, KnuthElement element,
                                     int elementIndex) {

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java?rev=1539809&r1=1539808&r2=1539809&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java Thu Nov  7 20:49:18 2013
@@ -19,13 +19,12 @@
 
 package org.apache.fop;
 
-import static org.junit.Assert.assertEquals;
-
 import java.util.List;
 
-import org.apache.fop.layoutmgr.Alternative;
-import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
-import org.apache.fop.layoutmgr.BestFitPenalty;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
 import org.apache.fop.layoutmgr.BlockKnuthSequence;
 import org.apache.fop.layoutmgr.BreakingAlgorithm;
 import org.apache.fop.layoutmgr.ElementListObserver;
@@ -33,8 +32,6 @@ import org.apache.fop.layoutmgr.KnuthBox
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.KnuthSequence;
-import org.junit.Before;
-import org.junit.Test;
 
 /**
  * Tests the Knuth algorithm implementation.
@@ -66,23 +63,6 @@ public class KnuthAlgorithmTestCase {
         return seq;
     }
 
-    private static KnuthSequence getKnuthSequence2() {
-        KnuthSequence seq = new BlockKnuthSequence();
-        FittingStrategy[] strategies = {FittingStrategy.FIRST_FIT,
-                FittingStrategy.SMALLEST_FIT,
-                FittingStrategy.BIGGEST_FIT};
-        for (int i = 0; i < 3; ++i) {
-            BestFitPenalty bestFitPenalty = new BestFitPenalty(strategies[i], null);
-            bestFitPenalty.addAlternative(new Alternative(null, 25000));
-            bestFitPenalty.addAlternative(new Alternative(null, 5000));
-            bestFitPenalty.addAlternative(new Alternative(null, 29000));
-            seq.add(new KnuthBox(0, null, false));
-            seq.add(bestFitPenalty);
-            seq.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, false, null, false));
-        }
-        return seq;
-    }
-
     /**
      * Tests a special condition where a negative-length glue occurs directly after a break
      * possibility.
@@ -99,22 +79,6 @@ public class KnuthAlgorithmTestCase {
         assertEquals(5000, parts[0].difference);
         assertEquals(5000, parts[1].difference);
     }
-    /**
-     * Testcase for BestFitPenalty
-     * @throws Exception if an error occurs
-     */
-    @Test
-    public void test2() throws Exception {
-        MyBreakingAlgorithm algo = new MyBreakingAlgorithm(0, 0, true, true, 0);
-        algo.setConstantLineWidth(30000);
-        KnuthSequence seq = getKnuthSequence2();
-        algo.findBreakingPoints(seq, 1, true, BreakingAlgorithm.ALL_BREAKS);
-        Part[] parts = algo.getParts();
-        assertEquals("Sequence must produce 3 parts", 3, parts.length);
-        assertEquals(5000, parts[0].difference);
-        assertEquals(25000, parts[1].difference);
-        assertEquals(1000, parts[2].difference);
-    }
 
     private class Part {
         private int difference;



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