Index: src/java/org/apache/fop/fo/flow/MultiCase.java
===================================================================
--- src/java/org/apache/fop/fo/flow/MultiCase.java	(revision 1569004)
+++ src/java/org/apache/fop/fo/flow/MultiCase.java	(working copy)
@@ -33,13 +33,11 @@
  * TODO implement validateChildNode()
  */
 public class MultiCase extends FObj {
-    // The value of properties relevant for fo:multi-case.
+
+    // FO multi-case properties
     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:
     //     private CommonAccessibility commonAccessibility;
     // End of property values
@@ -59,12 +57,6 @@
         startingState = pList.get(PR_STARTING_STATE).getEnum();
         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);
-            }
-        }
     }
 
     /**
@@ -91,14 +83,6 @@
         }
     }
 
-    @Override
-    protected void addChildNode(FONode child) throws FOPException {
-        if (child instanceof MultiCaseHandler) {
-            multiCaseHandler = (MultiCaseHandler) child;
-        }
-        super.addChildNode(child);
-    }
-
     /** @return the "starting-state" property */
     public int getStartingState() {
         return startingState;
@@ -126,12 +110,4 @@
         return caseTitle;
     }
 
-    public boolean hasToggle() {
-        return multiCaseHandler != null;
-    }
-
-    MultiCaseHandler getHandler() {
-        return multiCaseHandler;
-    }
-
 }
Index: src/java/org/apache/fop/fo/flow/MultiCaseHandler.java
===================================================================
--- src/java/org/apache/fop/fo/flow/MultiCaseHandler.java	(revision 1569004)
+++ src/java/org/apache/fop/fo/flow/MultiCaseHandler.java	(working copy)
@@ -1,38 +0,0 @@
-/*
- * 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;
-
-}
Index: src/java/org/apache/fop/fo/flow/MultiSwitch.java
===================================================================
--- src/java/org/apache/fop/fo/flow/MultiSwitch.java	(revision 1569004)
+++ src/java/org/apache/fop/fo/flow/MultiSwitch.java	(working copy)
@@ -68,22 +68,6 @@
         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.hasToggle()) {
-                    multiCase.getHandler().filter(this);
-                }
-            }
-        }
-    }
-
     /**
      * {@inheritDoc}
      * <br>XSL Content Model: (multi-case+)
Index: src/java/org/apache/fop/fo/flow/MultiToggle.java
===================================================================
--- src/java/org/apache/fop/fo/flow/MultiToggle.java	(revision 1569004)
+++ src/java/org/apache/fop/fo/flow/MultiToggle.java	(working copy)
@@ -33,7 +33,7 @@
  * 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 implements MultiCaseHandler {
+public class MultiToggle extends FObj {
     // The value of properties relevant for fo:multi-toggle (commented out for performance).
     //     private CommonAccessibility commonAccessibility;
      public StringProperty prSwitchTo;
@@ -92,39 +92,4 @@
         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);
-    }
 }
Index: src/java/org/apache/fop/layoutmgr/BestFitGlue.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/BestFitGlue.java	(revision 0)
+++ src/java/org/apache/fop/layoutmgr/BestFitGlue.java	(working copy)
@@ -0,0 +1,45 @@
+/*
+ * 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.layoutmgr.BestFitLayoutUtils.BestFitPosition;
+
+public class BestFitGlue extends KnuthGlue {
+
+    private KnuthVariant variant;
+    private final BestFitPosition bestFitPosition;
+
+    public BestFitGlue(BestFitPosition pos) {
+        super(0, 0, 0, pos, false);
+        variant = null;
+        bestFitPosition = pos;
+    }
+
+    public void setKnuthVariant(KnuthVariant variant) {
+        this.variant = variant;
+        bestFitPosition.setKnuthList(variant.knuthList);
+    }
+
+    public int getWidth() {
+        if (variant != null) {
+            return variant.width;
+        }
+        return 0;
+    }
+
+}
Index: src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java	(revision 1569004)
+++ src/java/org/apache/fop/layoutmgr/BestFitLayoutUtils.java	(working copy)
@@ -20,7 +20,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
-/*
+/**
  * Utility class used in {@link MultiSwitchLayoutManager}
  * to handle  the <i>best-fit</i> property value if specified in {@link MultiSwitch}
  */
@@ -30,32 +30,27 @@
 
     static class BestFitPosition extends Position {
 
-        public List<ListElement> knuthList;
+        private List<ListElement> knuthList;
 
         public BestFitPosition(LayoutManager lm) {
             super(lm);
         }
 
-        public BestFitPosition(LayoutManager lm, List<ListElement> knuthList) {
-            super(lm);
-            this.knuthList = knuthList;
-        }
-
         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());
-                    }
+                    positions.add(elem.getPosition());
                 }
             }
             return positions;
         }
+
         public void setKnuthList(List<ListElement> knuthList) {
             this.knuthList = knuthList;
         }
+
     }
 
     public static List<ListElement> getKnuthList(LayoutManager lm,
@@ -65,14 +60,20 @@
 
         BestFitPenalty bestFitPenalty = new BestFitPenalty(new BestFitPosition(lm));
         for (List<ListElement> childList : childrenLists) {
+            // TODO Doing space resolution here is not correct.
+            // Space elements will simply be nulled.
             SpaceResolver.resolveElementList(childList);
             int contentLength = ElementListUtils.calcContentLength(childList);
-            bestFitPenalty.addVariant(childList, contentLength);
+            bestFitPenalty.addKnuthVariant(new KnuthVariant(childList, contentLength));
         }
-        // TODO Adding the two enclosing boxes is definitely a dirty hack.
-        // Let's leave it like that for now, until I find a proper fix.
+        // TODO Adding two enclosing boxes is definitely a dirty hack.
+        // The first box forces the breaking algorithm to consider the penalty
+        // in case there are no elements preceding it
+        // and the last box prevents the glue and penalty from getting deleted
+        // when they are at the end of the Knuth list.
         knuthList.add(new KnuthBox(0, new Position(lm), false));
         knuthList.add(bestFitPenalty);
+        knuthList.add(new BestFitGlue(new BestFitPosition(lm)));
         knuthList.add(new KnuthBox(0, new Position(lm), false));
         return knuthList;
     }
@@ -82,9 +83,8 @@
         // "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();
+            Position pos = posIter.next();
             if (pos instanceof BestFitPosition) {
                 positionList.addAll(((BestFitPosition) pos).getPositionList());
             } else {
Index: src/java/org/apache/fop/layoutmgr/BestFitPenalty.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/BestFitPenalty.java	(revision 1569004)
+++ src/java/org/apache/fop/layoutmgr/BestFitPenalty.java	(working copy)
@@ -27,43 +27,28 @@
 /**
  * A type of penalty 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.
+ * less than the remaining BPD on the active page.
  */
 public class BestFitPenalty extends KnuthPenalty {
 
-    public class Variant {
-
-        public final List<ListElement> knuthList;
-        public final int width;
-
-        public Variant(List<ListElement> knuthList, int width) {
-            this.knuthList = knuthList;
-            this.width = width;
-        }
-        public KnuthElement toPenalty() {
-            return new KnuthPenalty(width, 0, false, null, false);
-        }
-    }
-
     private final BestFitPosition bestFitPosition;
+    private final List<KnuthVariant> variantList;
 
-    private final List<Variant> variantList;
-
     public BestFitPenalty(BestFitPosition pos) {
-        super(0, 0, false, pos, false);
+        super(0, -1, false, pos, false);
         this.bestFitPosition = pos;
-        variantList = new ArrayList<Variant>();
+        variantList = new ArrayList<KnuthVariant>();
     }
 
-    public void addVariant(List<ListElement> knuthList, int width) {
-        variantList.add(new Variant(knuthList, width));
+    public void addKnuthVariant(KnuthVariant variant) {
+        variantList.add(variant);
     }
 
-    public void activatePenalty(Variant bestVariant) {
-        bestFitPosition.setKnuthList(bestVariant.knuthList);
+    public void setActiveKnuthVariant(KnuthVariant bestKnuthVariant) {
+        bestFitPosition.setKnuthList(bestKnuthVariant.knuthList);
     }
 
-    public List<Variant> getVariantList() {
+    public List<KnuthVariant> getKnuthVariantsList() {
         return variantList;
     }
 
Index: src/java/org/apache/fop/layoutmgr/KnuthVariant.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/KnuthVariant.java	(revision 0)
+++ src/java/org/apache/fop/layoutmgr/KnuthVariant.java	(working copy)
@@ -0,0 +1,36 @@
+/*
+ * 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.List;
+
+public class KnuthVariant {
+
+    public final List<ListElement> knuthList;
+    public final int width;
+
+    public KnuthVariant(List<ListElement> knuthList, int width) {
+        this.knuthList = knuthList;
+        this.width = width;
+    }
+
+    public KnuthElement toPenalty() {
+        return new KnuthPenalty(width, 0, false, null, false);
+    }
+
+}
Index: src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java	(revision 1569004)
+++ src/java/org/apache/fop/layoutmgr/MultiSwitchLayoutManager.java	(working copy)
@@ -24,10 +24,7 @@
 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;
 
 public class MultiSwitchLayoutManager extends BlockStackingLayoutManager {
 
@@ -41,7 +38,7 @@
     public List<ListElement> getNextKnuthElements(LayoutContext context, int alignment) {
 
         referenceIPD = context.getRefIPD();
-        List<List<ListElement>> childrenLists = new LinkedList<List<ListElement>>();
+        List<List<ListElement>> childrenLists = new ArrayList<List<ListElement>>();
         LayoutManager childLM;
         while ((childLM = getChildLM()) != null) {
             if (!childLM.isFinished()) {
@@ -59,33 +56,6 @@
     }
 
     @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;
     }
@@ -151,6 +121,8 @@
 
         AreaAdditionUtil.addAreas(this, newPosIter, context);
         flush();
+        // TODO removing the following line forces the generated area
+        // to be rendered twice in some cases...
         curBlockArea = null;
     }
 
Index: src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java	(revision 1569004)
+++ src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java	(working copy)
@@ -28,9 +28,10 @@
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.fo.Constants;
+
 import org.apache.fop.fo.FObj;
 import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
-import org.apache.fop.layoutmgr.BestFitPenalty.Variant;
+import org.apache.fop.layoutmgr.BreakingAlgorithm.KnuthNode;
 import org.apache.fop.traits.MinOptMax;
 import org.apache.fop.util.ListUtil;
 
@@ -99,8 +100,8 @@
     private int currentKeepContext = Constants.EN_AUTO;
     private KnuthNode lastBeforeKeepContextSwitch;
 
-    /** Holds the variant that should be assigned to the next node to be created */
-    private Variant variant;
+    /** Holds the variant of a dynamic content that must be attached to the next page node */
+    private KnuthVariant variant;
 
     /**
      * Construct a page breaking algorithm.
@@ -156,7 +157,7 @@
         /** Index of the last inserted element of the last inserted footnote. */
         public int footnoteElementIndex;
 
-        public final Variant variant;
+        public final KnuthVariant variant;
 
         public KnuthPageNode(int position,
                              int line, int fitness,
@@ -164,7 +165,7 @@
                              int insertedFootnotes, int totalFootnotes,
                              int footnoteListIndex, int footnoteElementIndex,
                              double adjustRatio, int availableShrink, int availableStretch,
-                             int difference, double totalDemerits, KnuthNode previous, Variant variant) {
+                             int difference, double totalDemerits, KnuthNode previous, KnuthVariant variant) {
             super(position, line, fitness,
                   totalWidth, totalStretch, totalShrink,
                   adjustRatio, availableShrink, availableStretch,
@@ -188,7 +189,7 @@
         private final int[] bestTotalFootnotesLength = new int[4];
         private final int[] bestFootnoteListIndex = new int[4];
         private final int[] bestFootnoteElementIndex = new int[4];
-        private final Variant[] bestVariant = new Variant[4];
+        private final KnuthVariant[] bestKnuthVariant = new KnuthVariant[4];
 
         @Override
         public void addRecord(double demerits, KnuthNode node, double adjust,
@@ -201,7 +202,7 @@
             bestTotalFootnotesLength[fitness] = totalFootnotesLength;
             bestFootnoteListIndex[fitness] = footnoteListIndex;
             bestFootnoteElementIndex[fitness] = footnoteElementIndex;
-            bestVariant[fitness] = variant;
+            bestKnuthVariant[fitness] = variant;
         }
 
         public int getInsertedFootnotesLength(int fitness) {
@@ -220,8 +221,8 @@
             return bestFootnoteElementIndex[fitness];
         }
 
-        public Variant getVariant(int fitness) {
-            return bestVariant[fitness];
+        public KnuthVariant getKnuthVariant(int fitness) {
+            return bestKnuthVariant[fitness];
         }
     }
 
@@ -331,7 +332,7 @@
                                  best.getAdjust(fitness), best.getAvailableShrink(fitness),
                                  best.getAvailableStretch(fitness), best.getDifference(fitness),
                                  best.getDemerits(fitness), best.getNode(fitness),
-                                 ((BestPageRecords) best).getVariant(fitness));
+                                 ((BestPageRecords) best).getKnuthVariant(fitness));
     }
 
     /**
@@ -352,6 +353,33 @@
         }
     }
 
+    /** {@inheritDoc} */
+    protected void handleGlueAt(KnuthGlue glue, int position,
+            boolean previousIsBox, int allowedBreaks) {
+        if (glue instanceof BestFitGlue) {
+            if (variant != null) {
+                // This solves the problem where a break occurs
+                // at a zero-width BestFitPenalty which causes the BestFitGlue
+                // to be moved to the beginning of the next page.
+                boolean ignoreGlue = false;
+                for (KnuthNode node = getNode(endLine - 1); node != null; node = node.next) {
+                    KnuthPageNode pageNode = (KnuthPageNode) node;
+                    if (pageNode.variant == null && pageNode.position == position - 1) {
+                        ignoreGlue = true;
+                        break;
+                    }
+                }
+                if (!ignoreGlue) {
+                    // variant should have an adjustment ratio >= -1
+                    // Activate the glue anyway, it will be ignored
+                    // if the previous penalty led to an accepted KnuthPageNode
+                    ((BestFitGlue)glue).setKnuthVariant(variant);
+                }
+            }
+        }
+        super.handleGlueAt(glue, position, previousIsBox, allowedBreaks);
+    }
+
     /**
      * Overridden to consider penalties with value {@link KnuthElement#INFINITE}
      * as legal break-points, if the current keep-context allows this
@@ -458,7 +486,6 @@
     /** {@inheritDoc} */
     @Override
     protected void considerLegalBreak(KnuthElement element, int elementIdx) {
-        variant = null;
         if (element.isPenalty()) {
             int breakClass = ((KnuthPenalty) element).getBreakClass();
             switch (breakClass) {
@@ -526,6 +553,7 @@
         int actualWidth = totalWidth - pageNode.totalWidth;
         int footnoteSplit;
         boolean canDeferOldFN;
+        variant = null;
         if (element.isPenalty()) {
             if (element instanceof BestFitPenalty) {
                 actualWidth += handleBestFitPenalty(activeNode, (BestFitPenalty) element, elementIndex);
@@ -592,7 +620,7 @@
     }
 
     private int handleBestFitPenalty(KnuthNode activeNode, BestFitPenalty penalty, int elementIndex) {
-        for (Variant var : penalty.getVariantList()) {
+        for (KnuthVariant var : penalty.getKnuthVariantsList()) {
             int difference = computeDifference(activeNode, var.toPenalty(), elementIndex);
             double r = computeAdjustmentRatio(activeNode, difference);
             if (r >= -1.0) {
@@ -1015,11 +1043,11 @@
                             int total) {
         //int difference = (bestActiveNode.line < total)
         //      ? bestActiveNode.difference : bestActiveNode.difference + fillerMinWidth;
-        // Check if the given node has an attached dynamic content
+        // Check if the given node has an attached variant of a dynamic content
         KnuthPageNode pageNode = (KnuthPageNode) bestActiveNode;
         if (pageNode.variant != null) {
             BestFitPenalty penalty = (BestFitPenalty) par.get(pageNode.position);
-            penalty.activatePenalty(pageNode.variant);
+            penalty.setActiveKnuthVariant(pageNode.variant);
         }
         int difference = bestActiveNode.difference;
         if (difference + bestActiveNode.availableShrink < 0) {
