aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-07-08 12:50:49 +0000
committerJeremias Maerki <jeremias@apache.org>2005-07-08 12:50:49 +0000
commitc14bf42f72bd4053ed7884a9e44463515d47b9f3 (patch)
tree5051b900d6b489cfdaf5adcfbebf9fd72aeb3bd9 /src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
parent519b72f5b5f19640b620b5bbf24d0839fe25e60b (diff)
downloadxmlgraphics-fop-c14bf42f72bd4053ed7884a9e44463515d47b9f3.tar.gz
xmlgraphics-fop-c14bf42f72bd4053ed7884a9e44463515d47b9f3.zip
Column balancing seems to work now.
I had to modify BreakingAlgorithm to add best records for parts which are too short. Furthermore, it took an additional computed value to tweak the balancing. It effectively makes shorter trailing parts preferred. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@209748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java')
-rw-r--r--src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java b/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
index d6a154db1..3a3c343c6 100644
--- a/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
+++ b/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java
@@ -38,33 +38,55 @@ public class BalancingColumnBreakingAlgorithm extends PageBreakingAlgorithm {
super(topLevelLM, pvProvider, alignment, alignmentLast,
fnSeparatorLength, partOverflowRecovery);
this.columnCount = columnCount;
+ this.considerTooShort = true; //This is important!
}
/** @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);
+ if (log.isTraceEnabled()) {
+ log.trace("original demerit=" + dem + " " + totalWidth
+ + " line=" + activeNode.line);
+ }
+ int remParts = columnCount - activeNode.line;
int curPos = par.indexOf(element);
if (fullLen == 0) {
fullLen = ElementListUtils.calcContentLength(par);
}
int partLen = ElementListUtils.calcContentLength(par, activeNode.position, curPos - 1);
+ int restLen = ElementListUtils.calcContentLength(par, curPos - 1, par.size() - 1);
+ int avgRestLen = 0;
+ if (remParts > 0) {
+ avgRestLen = restLen / remParts;
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("remaining parts: " + remParts + " rest len: " + restLen
+ + " avg=" + avgRestLen);
+ }
int meanColumnLen = (fullLen / columnCount);
double balance = (meanColumnLen - partLen) / 1000f;
- log.trace("balance=" + balance);
+ if (log.isTraceEnabled()) {
+ log.trace("balance=" + balance);
+ }
double absBalance = Math.abs(balance);
+ //Step 1: This does the rough balancing
if (balance <= 0) {
- dem = absBalance * absBalance;
+ dem = absBalance;
} else {
//shorter parts are less desired than longer ones
- dem = absBalance * absBalance * 2;
+ dem = absBalance * 1.2f;
}
+ //Step 2: This helps keep the trailing parts shorter than the previous ones
+ dem += (avgRestLen) / 1000f;
+
if (activeNode.line >= columnCount) {
//We don't want more columns than available
dem = Double.MAX_VALUE;
}
- log.trace("effective dem=" + dem + " " + totalWidth);
+ if (log.isTraceEnabled()) {
+ log.trace("effective dem=" + dem + " " + totalWidth);
+ }
return dem;
}
}