diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-06-29 13:14:55 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-06-29 13:14:55 +0000 |
commit | ee677ef43cea0a4aba9f281b92e2a8631a781aa4 (patch) | |
tree | 81c2d10d84cfca071b408b2628de7bb629c75d3f /src/java/org/apache | |
parent | 8c3ee10b15c1aae9c4157fab047672583911f6ed (diff) | |
download | xmlgraphics-fop-ee677ef43cea0a4aba9f281b92e2a8631a781aa4.tar.gz xmlgraphics-fop-ee677ef43cea0a4aba9f281b92e2a8631a781aa4.zip |
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.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@202367 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java new file mode 100644 index 000000000..d6a154db1 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java @@ -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;
+ }
+}
|