]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Implementation of hyphenation-ladder-count.
authorLuca Furini <lfurini@apache.org>
Mon, 21 Nov 2005 14:21:45 +0000 (14:21 +0000)
committerLuca Furini <lfurini@apache.org>
Mon, 21 Nov 2005 14:21:45 +0000 (14:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@345909 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/flow/Block.java
src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
test/java/org/apache/fop/KnuthAlgorithmTestCase.java

index 01f779ea71038cc07b87efdce97a5805758ece96..bfe7ec00883aa0a0ef58a782580fc5754e7782fc 100644 (file)
@@ -218,6 +218,11 @@ public class Block extends FObjMixed {
         return breakBefore;
     }
 
+    /** @return the "hyphenation-ladder-count" property.  */
+    public Numeric getHyphenationLadderCount() {
+        return hyphenationLadderCount;
+    }
+
     /** @return the "keep-with-next" property.  */
     public KeepProperty getKeepWithNext() {
         return keepWithNext;
index ce12aa16169091090421fb5d3488cc29cdcb4375..92d5c08d3d59fed158e6fb86a4ddea02773a4179 100644 (file)
@@ -59,6 +59,9 @@ public abstract class BreakingAlgorithm {
     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 @@ public abstract class BreakingAlgorithm {
     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 @@ public abstract class BreakingAlgorithm {
             && ((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
index a6d912904f273d46f87c102ec09a76a6385a564b..5a9ede6eb11017f208b069589ad228745b22c859 100644 (file)
@@ -68,7 +68,7 @@ class PageBreakingAlgorithm extends BreakingAlgorithm {
                                  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();
index d70a783fb450fc4574798dc9240ec9636af76a47..6fe1bf5f1dcb23675642c8ae05702097c6e30962 100644 (file)
@@ -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.ArrayList;
 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 @@ public class LineLayoutManager extends InlineStackingLayoutManager
         textIndent = fobj.getTextIndent();
         lastLineEndIndent = fobj.getLastLineEndIndent();
         hyphenationProperties = fobj.getCommonHyphenation();
+        hyphenationLadderCount = fobj.getHyphenationLadderCount();
         wrapOption = fobj.getWrapOption();
         //
         effectiveAlignment = getEffectiveAlignment(textAlignment, textAlignmentLast);
@@ -140,6 +140,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager
     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 @@ public class LineLayoutManager extends InlineStackingLayoutManager
                                       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 @@ public class LineLayoutManager extends InlineStackingLayoutManager
                                         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) {
index 4a7047a759905b9623f9d698b5f97d071bedef23..39d4190ffc7a8a7e5e0f74e0e3f102e6dab7f645 100644 (file)
@@ -66,7 +66,7 @@ public class KnuthAlgorithmTestCase extends TestCase {
      * @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 @@ public class KnuthAlgorithmTestCase extends TestCase {
         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() {