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 je...@apache.org on 2005/06/29 15:14:56 UTC

svn commit: r202367 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java

Author: jeremias
Date: Wed Jun 29 06:14:55 2005
New Revision: 202367

URL: http://svn.apache.org/viewcvs?rev=202367&view=rev
Log:
My first laughable attempt at a page breaker for balancing columns. Doesn't work if the element list fits into the first available area and doesn't balance exactly like I would like it to when the balancing actually gets active.
But it's better than nothing to start with.

Added:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java

Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java?rev=202367&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java Wed Jun 29 06:14:55 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import org.apache.fop.traits.MinOptMax;
+
+/**
+ * This is a the breaking algorithm that is responsible for balancing columns in multi-column
+ * layout.
+ */
+public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm {
+
+    private int columnCount;
+    private int fullLen;
+    
+    public BalancingColumnBreakingAlgorithm(LayoutManager topLevelLM,
+            PageSequenceLayoutManager.PageViewportProvider pvProvider,
+            int alignment, int alignmentLast,
+            MinOptMax fnSeparatorLength,
+            boolean partOverflowRecovery,
+            int columnCount) {
+        super(topLevelLM, pvProvider, alignment, alignmentLast, 
+                fnSeparatorLength, partOverflowRecovery);
+        this.columnCount = columnCount;
+    }
+    
+    /** @see org.apache.fop.layoutmgr.BreakingAlgorithm */
+    protected double computeDemerits(KnuthNode activeNode,
+            KnuthElement element, int fitnessClass, double r) {
+        double dem = super.computeDemerits(activeNode, element, fitnessClass, r);
+        log.trace("original demerit=" + dem + " " + totalWidth);
+        int curPos = par.indexOf(element);
+        if (fullLen == 0) {
+            fullLen = ElementListUtils.calcContentLength(par);
+        }
+        int partLen = ElementListUtils.calcContentLength(par, activeNode.position, curPos - 1);
+        int meanColumnLen = (fullLen / columnCount);
+        double balance = (meanColumnLen - partLen) / 1000f;
+        log.trace("balance=" + balance);
+        double absBalance = Math.abs(balance);
+        if (balance <= 0) {
+            dem = absBalance * absBalance;
+        } else {
+            //shorter parts are less desired than longer ones
+            dem = absBalance * absBalance * 2;
+        }
+        if (activeNode.line >= columnCount) {
+            //We don't want more columns than available
+            dem = Double.MAX_VALUE;
+        }
+        log.trace("effective dem=" + dem + " " + totalWidth);
+        return dem;
+    }
+}



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