Index: /Users/dario/Documents/tesi/workspace3/FOP/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
===================================================================
--- /Users/dario/Documents/tesi/workspace3/FOP/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java	(revision 705986)
+++ /Users/dario/Documents/tesi/workspace3/FOP/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java	(working copy)
@@ -310,6 +310,33 @@
             }
             return false;
         }
+        
+        public double computeIdealAdjRatio() {
+            long totalBoxW = 0;
+            long boxCount = 0;
+            KnuthElement thisElement = null;
+  
+            for (int i = 0; i < this.size(); i++) {
+                thisElement = (KnuthElement) this.getElement(i);
+                if (thisElement.isBox()) {
+                    totalBoxW += thisElement.getW();
+                    boxCount++;
+                }
+            }
+            
+            long avgBoxW = totalBoxW / boxCount;
+            int avgWord = (int)avgBoxW + LineLayoutManager.DEFAULT_SPACE_WIDTH;
+            int wordsPerLine = iLineWidth / avgWord;
+            int idealDifference = iLineWidth - (avgWord * (wordsPerLine / 2));
+            double idealRatio = (double) idealDifference
+                    / (3 * LineLayoutManager.DEFAULT_SPACE_WIDTH);
+            if (idealRatio < 1.0) {
+                idealRatio = 1.0;
+            } else if (idealRatio > 20.0) {
+                idealRatio = 20.0;
+            }
+            return idealRatio;
+        }
     }
 
     private class LineBreakingAlgorithm extends BreakingAlgorithm {
@@ -993,7 +1020,9 @@
                               + (hyphenationProperties.hyphenate.getEnum() == EN_TRUE
                                       ? " and hyphenation" : ""));
                 }
-                maxAdjustment = 20;
+                //maxAdjustment = 20;
+                maxAdjustment = currPar.computeIdealAdjRatio();
+                
                 iBPcount
                     = alg.findBreakingPoints(currPar,
                                              maxAdjustment, true, allowedBreaks);
