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 lf...@apache.org on 2005/11/21 15:22:06 UTC
svn commit: r345909 - in /xmlgraphics/fop/trunk:
src/java/org/apache/fop/fo/flow/ src/java/org/apache/fop/layoutmgr/
src/java/org/apache/fop/layoutmgr/inline/ test/java/org/apache/fop/
Author: lfurini
Date: Mon Nov 21 06:21:45 2005
New Revision: 345909
URL: http://svn.apache.org/viewcvs?rev=345909&view=rev
Log:
Implementation of hyphenation-ladder-count.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Block.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Block.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Block.java?rev=345909&r1=345908&r2=345909&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Block.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/Block.java Mon Nov 21 06:21:45 2005
@@ -218,6 +218,11 @@
return breakBefore;
}
+ /** @return the "hyphenation-ladder-count" property. */
+ public Numeric getHyphenationLadderCount() {
+ return hyphenationLadderCount;
+ }
+
/** @return the "keep-with-next" property. */
public KeepProperty getKeepWithNext() {
return keepWithNext;
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java?rev=345909&r1=345908&r2=345909&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java Mon Nov 21 06:21:45 2005
@@ -59,6 +59,9 @@
protected int repeatedFlaggedDemerit = 50;
// demerit for consecutive lines belonging to incompatible fitness classes
protected int incompatibleFitnessDemerit = 50;
+ // maximum number of consecutive lines ending with a flagged penalty
+ // only a value >= 1 is a significant limit
+ protected int maxFlaggedPenaltiesCount;
/**
* The threshold for considering breaks to be acceptable.
@@ -130,12 +133,14 @@
private boolean partOverflowRecoveryActivated = true;
public BreakingAlgorithm(int align, int alignLast,
- boolean first, boolean partOverflowRecovery) {
+ boolean first, boolean partOverflowRecovery,
+ int maxFlagCount) {
alignment = align;
alignmentLast = alignLast;
bFirst = first;
this.partOverflowRecoveryActivated = partOverflowRecovery;
this.best = new BestRecords();
+ maxFlaggedPenaltiesCount = maxFlagCount;
}
@@ -760,6 +765,30 @@
&& ((KnuthPenalty) getElement(activeNode.position)).isFlagged()) {
// add demerit for consecutive breaks at flagged penalties
demerits += repeatedFlaggedDemerit;
+ // there are at least two consecutive lines ending with a flagged penalty;
+ // check if the previous line end with a flagged penalty too,
+ // and if this situation is allowed
+ int flaggedPenaltiesCount = 2;
+ for (KnuthNode prevNode = activeNode.previous;
+ prevNode != null && flaggedPenaltiesCount <= maxFlaggedPenaltiesCount;
+ prevNode = prevNode.previous) {
+ KnuthElement prevElement = getElement(prevNode.position);
+ if (prevElement.isPenalty()
+ && ((KnuthPenalty) prevElement).isFlagged()) {
+ // the previous line ends with a flagged penalty too
+ flaggedPenaltiesCount ++;
+ } else {
+ // the previous line does not end with a flagged penalty,
+ // exit the loop
+ break;
+ }
+ }
+ if (maxFlaggedPenaltiesCount >= 1
+ && flaggedPenaltiesCount > maxFlaggedPenaltiesCount) {
+ // add infinite demerits, so this break will not be chosen
+ // unless there isn't any alternative break
+ demerits += BestRecords.INFINITE_DEMERITS;
+ }
}
if (Math.abs(fitnessClass - activeNode.fitness) > 1) {
// add demerit for consecutive breaks
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=345909&r1=345908&r2=345909&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Mon Nov 21 06:21:45 2005
@@ -68,7 +68,7 @@
int alignment, int alignmentLast,
MinOptMax footnoteSeparatorLength,
boolean partOverflowRecovery) {
- super(alignment, alignmentLast, true, partOverflowRecovery);
+ super(alignment, alignmentLast, true, partOverflowRecovery, 0);
this.topLevelLM = topLevelLM;
this.pageViewportProvider = pageViewportProvider;
best = new BestPageRecords();
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=345909&r1=345908&r2=345909&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Mon Nov 21 06:21:45 2005
@@ -19,6 +19,7 @@
package org.apache.fop.layoutmgr.inline;
import org.apache.fop.datatypes.Length;
+import org.apache.fop.datatypes.Numeric;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.properties.CommonHyphenation;
@@ -52,8 +53,6 @@
import java.util.LinkedList;
import org.apache.fop.area.Trait;
import org.apache.fop.fonts.Font;
-import org.apache.fop.layoutmgr.BreakingAlgorithm.KnuthNode;
-import org.apache.fop.layoutmgr.inline.InlineStackingLayoutManager.StackingIter;
import org.apache.fop.traits.MinOptMax;
@@ -79,6 +78,7 @@
textIndent = fobj.getTextIndent();
lastLineEndIndent = fobj.getLastLineEndIndent();
hyphenationProperties = fobj.getCommonHyphenation();
+ hyphenationLadderCount = fobj.getHyphenationLadderCount();
wrapOption = fobj.getWrapOption();
//
effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
@@ -140,6 +140,7 @@
private Length lastLineEndIndent;
private int iIndents = 0;
private CommonHyphenation hyphenationProperties;
+ private Numeric hyphenationLadderCount;
private int wrapOption = EN_WRAP;
//private LayoutProps layoutProps;
@@ -385,8 +386,8 @@
int textAlign, int textAlignLast,
int indent, int fillerWidth,
int lh, int ld, int fl, boolean first,
- LineLayoutManager llm) {
- super(textAlign, textAlignLast, first, false);
+ int maxFlagCount, LineLayoutManager llm) {
+ super(textAlign, textAlignLast, first, false, maxFlagCount);
pageAlignment = pageAlign;
textIndent = indent;
fillerMinWidth = fillerWidth;
@@ -1045,6 +1046,8 @@
textIndent.getValue(this), currPar.lineFiller.opt,
lineHeight.getValue(this), lead, follow,
(knuthParagraphs.indexOf(currPar) == 0),
+ hyphenationLadderCount.getEnum() == EN_NO_LIMIT ?
+ 0 : hyphenationLadderCount.getValue(),
this);
if (hyphenationProperties.hyphenate == EN_TRUE) {
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/KnuthAlgorithmTestCase.java?rev=345909&r1=345908&r2=345909&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/KnuthAlgorithmTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/KnuthAlgorithmTestCase.java Mon Nov 21 06:21:45 2005
@@ -66,7 +66,7 @@
* @throws Exception if an error occurs
*/
public void test1() throws Exception {
- MyBreakingAlgorithm algo = new MyBreakingAlgorithm(0, 0, true, true);
+ MyBreakingAlgorithm algo = new MyBreakingAlgorithm(0, 0, true, true, 0);
algo.setConstantLineWidth(30000);
KnuthSequence seq = getKnuthSequence1();
algo.findBreakingPoints(seq, 1, true, BreakingAlgorithm.ALL_BREAKS);
@@ -87,8 +87,8 @@
private List parts = new java.util.ArrayList();
public MyBreakingAlgorithm(int align, int alignLast, boolean first,
- boolean partOverflowRecovery) {
- super(align, alignLast, first, partOverflowRecovery);
+ boolean partOverflowRecovery, int maxFlagCount) {
+ super(align, alignLast, first, partOverflowRecovery, maxFlagCount);
}
public Part[] getParts() {
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org