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/09/05 17:07:00 UTC

svn commit: r278765 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: area/ area/inline/ layoutmgr/inline/

Author: lfurini
Date: Mon Sep  5 08:06:39 2005
New Revision: 278765

URL: http://svn.apache.org/viewcvs?rev=278765&view=rev
Log:
Re-adjusting lines after a page-number or a page-number-citation is resolved.
At the moment, only TextAreas are adjusted, the other will be fixed soon!

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/LineArea.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/AbstractTextArea.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/TextArea.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/LineArea.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/LineArea.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/LineArea.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/LineArea.java Mon Sep  5 08:06:39 2005
@@ -19,6 +19,7 @@
 package org.apache.fop.area;
 
 import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.fo.Constants;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -28,6 +29,33 @@
  * This is a line area that contains inline areas.
  */
 public class LineArea extends Area {
+
+    /**
+     * this class stores information about line width and potential adjustments
+     * that can be used in order to re-compute adjustement and / or indents when a
+     * page-number or a page-number-citation is resolved
+     */
+    private class LineAdjustingInfo {
+        private int lineAlignment;
+        private int difference;
+        private int availableStretch;
+        private int availableShrink;
+        private double variationFactor;
+        private boolean bAddedToAreaTree;
+        
+        private LineAdjustingInfo(int alignment, int diff,
+                                  int stretch, int shrink) {
+            lineAlignment = alignment;
+            difference = diff;
+            availableStretch = stretch;
+            availableShrink = shrink;
+            variationFactor = 1.0;
+            bAddedToAreaTree = false;
+        }
+    }
+    
+    private LineAdjustingInfo adjustingInfo = null;
+
     private int stacking = LR;
     // contains inline areas
     // has start indent and length, dominant baseline, height
@@ -42,6 +70,24 @@
     private List inlineAreas = new ArrayList();
 
     /**
+     * default constructor:
+     * nothing to do
+     */
+    public LineArea() {        
+    }
+
+    /**
+     * constructor with extra parameters:
+     * a new LineAdjustingInfo object is created
+     * @param alignment alignment of this line
+     * @param diff      difference between content width and line width
+     */
+    public LineArea(int alignment, int diff,
+                    int stretch, int shrink) {
+        adjustingInfo = new LineAdjustingInfo(alignment, diff, stretch, shrink);
+    }
+
+    /**
      * Add a child area to this line area.
      *
      * @param childArea the inline child area to add
@@ -49,6 +95,8 @@
     public void addChildArea(Area childArea) {
         if (childArea instanceof InlineArea) {
             addInlineArea((InlineArea)childArea);
+            // set the parent area for the child area
+            ((InlineArea) childArea).setParentArea(this);
         }
     }
 
@@ -104,6 +152,83 @@
         }
         setIPD(ipd);
         setBPD(bpd);
+    }
+    
+    /**
+     * receive notification about the ipd variation of a descendant area
+     * and perform the needed adjustment, according to the alignment;
+     * in particular:
+     * <ul>
+     *   <li>left-aligned text needs no adjustement;</li>
+     *   <li>right-aligned text and centered text are handled locally,
+     *       adjusting the indent of this LineArea;</li>
+     *   <li>justified text requires a more complex adjustment, as the 
+     *       variation factor computed on the basis of the total
+     *       stretch and shrink of the line must be applied in every
+     *       descendant leaf areas (text areas and leader areas).</li> 
+     * </ul>
+     * @param ipdVariation the difference between old and new ipd 
+     */
+    public void handleIPDVariation(int ipdVariation) {
+        switch (adjustingInfo.lineAlignment) {
+            case Constants.EN_START:
+                // nothing to do in this case
+                break;
+            case Constants.EN_CENTER:
+                // re-compute indent
+                startIndent -= ipdVariation / 2;
+                break;
+            case Constants.EN_END:
+                // re-compute indent
+                startIndent -= ipdVariation;
+                break;
+            case Constants.EN_JUSTIFY:
+                // compute variation factor
+                adjustingInfo.variationFactor *= (float) (adjustingInfo.difference - ipdVariation) / adjustingInfo.difference;
+                adjustingInfo.difference -= ipdVariation;
+                // if the LineArea has already been added to the area tree,
+                // call finalize(); otherwise, wait for the LineLM to call it
+                if (adjustingInfo.bAddedToAreaTree) {
+                    finalize();
+                }
+                break;
+        }
+    }
+    
+    /**
+     * apply the variation factor to all descendant areas
+     * and destroy the AdjustingInfo object if there are
+     * no UnresolvedAreas left
+     */
+    public void finalize() {
+        if (adjustingInfo.lineAlignment == Constants.EN_JUSTIFY) {
+            // justified line: apply the variation factor
+            boolean bUnresolvedAreasPresent = false;
+            // recursively apply variation factor to descendant areas
+            for (int i = 0, len = inlineAreas.size(); i < len; i++) {
+                bUnresolvedAreasPresent |= ((InlineArea) inlineAreas.get(i))
+                        .applyVariationFactor(adjustingInfo.variationFactor,
+                                adjustingInfo.availableStretch,
+                                adjustingInfo.availableShrink);
+            }
+            if (!bUnresolvedAreasPresent) {
+                // there are no more UnresolvedAreas:
+                // destroy the AdjustingInfo instance
+                adjustingInfo = null;
+            } else {
+                // this method will be called again later:
+                // the first time, it is called by the LineLM,
+                // afterwards it must be called by the LineArea itself
+                if (!adjustingInfo.bAddedToAreaTree) {
+                    adjustingInfo.bAddedToAreaTree = true;
+                }
+                // reset the variation factor
+                adjustingInfo.variationFactor = 1.0;
+            }
+        } else {
+            // the line is not justified: the ipd variation has already
+            // been handled, modifying the line indent
+        }
     }
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/AbstractTextArea.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/AbstractTextArea.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/AbstractTextArea.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/AbstractTextArea.java Mon Sep  5 08:06:39 2005
@@ -23,10 +23,45 @@
  */
 public abstract class AbstractTextArea extends InlineArea {
 
+    /**
+     * this class stores information about spaces and potential adjustments
+     * that can be used in order to re-compute adjustments when a
+     * page-number or a page-number-citation is resolved
+     */
+    protected class TextAdjustingInfo extends InlineAdjustingInfo {
+
+        // difference between the optimal width of a space
+        // and the default width of a space according to the font
+        // (this is equivalent to the property word-spacing.optimum)
+        protected int spaceDifference = 0;
+        
+        protected TextAdjustingInfo(int stretch, int shrink, int adj) {
+            super(stretch, shrink, adj);
+        }
+    }
+
     private int iTextWordSpaceAdjust = 0;
     private int iTextLetterSpaceAdjust = 0;
+    private TextAdjustingInfo adjustingInfo = null;
 
     /**
+     * Default onstructor
+     */
+    public AbstractTextArea() {
+    }
+
+    /**
+     * Constructor with extra parameters:
+     * create a TextAdjustingInfo object
+     * @param stretch  the available stretch of the text
+     * @param shrink   the available shrink of the text
+     * @param adj      the current adjustment of the area
+     */
+    public AbstractTextArea(int stretch, int shrink, int adj) {
+        adjustingInfo = new TextAdjustingInfo(stretch, shrink, adj);
+    }
+    
+    /**
      * Get text word space adjust.
      *
      * @return the text word space adjustment
@@ -59,5 +94,57 @@
      */
     public void setTextLetterSpaceAdjust(int iTLSadjust) {
         iTextLetterSpaceAdjust = iTLSadjust;
+    }
+
+    /**
+     * Set the difference between optimal width of a space and 
+     * default width of a space according to the font; this part
+     * of the space adjustment is fixed and must not be 
+     * multiplied by the variation factor.
+     * @param spaceDiff the space difference
+     */
+    public void setSpaceDifference(int spaceDiff) {
+        adjustingInfo.spaceDifference = spaceDiff;
+    }
+
+    /**
+     * recursively apply the variation factor to all descendant areas
+     * @param variationFactor the variation factor that must be applied to adjustments
+     * @param lineStretch     the total stretch of the line
+     * @param lineShrink      the total shrink of the line
+     * @return true if there is an UnresolvedArea descendant
+     */
+    public boolean applyVariationFactor(double variationFactor,
+                                        int lineStretch, int lineShrink) {
+        if (adjustingInfo != null) {
+            // compute the new adjustments:
+            // if the variation factor is negative, it means that before 
+            // the ipd variation the line had to stretch and now it has
+            // to shrink (or vice versa);
+            // in this case, if the stretch and shrink are not equally 
+            // divided among the inline areas, we must compute a 
+            // balancing factor
+            double balancingFactor = 1.0;
+            if (variationFactor < 0) {
+                if (iTextWordSpaceAdjust < 0) {
+                    // from a negative adjustment to a positive one
+                    balancingFactor = ((double) adjustingInfo.availableStretch / adjustingInfo.availableShrink)
+                            * ((double) lineShrink / lineStretch);
+                } else {
+                    // from a positive adjustment to a negative one
+                    balancingFactor = ((double) adjustingInfo.availableShrink / adjustingInfo.availableStretch)
+                            * ((double) lineStretch / lineShrink);
+                }
+            }
+            iTextWordSpaceAdjust = (int) ((iTextWordSpaceAdjust - adjustingInfo.spaceDifference)
+                    * variationFactor * balancingFactor)
+                    + adjustingInfo.spaceDifference;
+            iTextLetterSpaceAdjust *= variationFactor;
+            // update the ipd of the area
+            int oldAdjustment = adjustingInfo.adjustment;
+            adjustingInfo.adjustment *= balancingFactor * variationFactor;
+            ipd += adjustingInfo.adjustment - oldAdjustment;
+        }
+        return false;
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java Mon Sep  5 08:06:39 2005
@@ -19,6 +19,7 @@
 package org.apache.fop.area.inline;
 
 import org.apache.fop.area.Area;
+import org.apache.fop.area.LineArea;
 import org.apache.fop.area.Trait;
 
 /**
@@ -27,11 +28,45 @@
  * in a line area.
  */
 public class InlineArea extends Area {
+    
+    /**
+     * this class stores information about potential adjustments
+     * that can be used in order to re-compute adjustments when a
+     * page-number or a page-number-citation is resolved
+     */
+    protected class InlineAdjustingInfo {
+        // stretch of the inline area
+        protected int availableStretch;
+        // shrink of the inline area
+        protected int availableShrink;
+        // total adjustment (= ipd - width of fixed elements)
+        protected int adjustment;
+        
+        protected InlineAdjustingInfo(int stretch, int shrink, int adj) {
+            availableStretch = stretch;
+            availableShrink = shrink;
+            adjustment = adj;
+        }
+    }
+    
     /**
      * offset position from top of parent area
      */
     protected int verticalPosition = 0;
-
+    
+    /**
+     * parent area
+     * it is needed in order to recompute adjust ratio and indents
+     * when a page-number or a page-number-citation is resolved
+     */
+    private Area parentArea = null;
+    
+    /**
+     * ipd variation of child areas: if this area has not already
+     * been added and cannot notify its parent area, store the variation
+     * and wait for the parent area to be set
+     */
+    private int storedIPDVariation = 0;
 
     /**
      * Increase the inline progression dimensions of this area.
@@ -66,6 +101,36 @@
     public int getOffset() {
         return verticalPosition;
     }
+
+    /**
+     * @param parentArea The parentArea to set.
+     */
+    public void setParentArea(Area parentArea) {
+        this.parentArea = parentArea;
+        // notify the parent area about ipd variations
+        if (storedIPDVariation > 0) {
+            notifyIPDVariation(storedIPDVariation);
+            storedIPDVariation = 0;
+        }
+    }
+
+    /**
+     * @return Returns the parentArea.
+     */
+    public Area getParentArea() {
+        return parentArea;
+    }
+    
+    /**
+     * Override Area.addChildArea(Area)
+     * set the parent for the child area
+     */
+    public void addChildArea(Area childArea) {
+        super.addChildArea(childArea);
+        if (childArea instanceof InlineArea) {
+            ((InlineArea) childArea).setParentArea(this);
+        }
+    }
     
     /** @return true if the inline area is underlined. */
     public boolean hasUnderline() {
@@ -87,5 +152,43 @@
         return getBooleanTrait(Trait.BLINK);
     }
     
+    /**
+     * set the ipd and notify the parent area about the variation;
+     * this happens when a page-number or a page-number-citation
+     * is resolved to its actual value
+     * @param newIPD the new ipd of the area
+     */
+    public void updateIPD(int newIPD) {
+        // default behaviour: do nothing
+    }
+    
+    /**
+     * recursively apply the variation factor to all descendant areas
+     * @param variationFactor the variation factor that must be applied to adjustments
+     * @param lineStretch     the total stretch of the line
+     * @param lineShrink      the total shrink of the line
+     * @return true if there is an UnresolvedArea descendant
+     */
+    public boolean applyVariationFactor(double variationFactor,
+                                        int lineStretch, int lineShrink) {
+        // default behaviour: simply return false
+        return false;
+    }
+    
+    /**
+     * notify the parent area about the ipd variation of this area
+     * or of a descendant area
+     * @param ipdVariation the difference between new and old ipd
+     */
+    protected void notifyIPDVariation(int ipdVariation) {
+        if (getParentArea() instanceof InlineArea) {
+            ((InlineArea) getParentArea()).notifyIPDVariation(ipdVariation);
+        } else if (getParentArea() instanceof LineArea) {
+            ((LineArea) getParentArea()).handleIPDVariation(ipdVariation);
+        } else if (getParentArea() == null) {
+            // parent area not yet set: store the variations
+            storedIPDVariation += ipdVariation;
+        }
+    }
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java Mon Sep  5 08:06:39 2005
@@ -65,5 +65,22 @@
         return inlines;
     }
 
+    /**
+     * recursively apply the variation factor to all descendant areas
+     * @param variationFactor the variation factor that must be applied to adjustments
+     * @param lineStretch     the total stretch of the line
+     * @param lineShrink      the total shrink of the line
+     * @return true if there is an UnresolvedArea descendant
+     */
+    public boolean applyVariationFactor(double variationFactor,
+                                        int lineStretch, int lineShrink) {
+        boolean bUnresolvedAreasPresent = false;
+        // recursively apply variation factor to descendant areas 
+        for (int i = 0, len = inlines.size(); i < len; i++) {
+            bUnresolvedAreasPresent |= ((InlineArea)inlines.get(i))
+                .applyVariationFactor(variationFactor, lineStretch, lineShrink);
+        }
+        return bUnresolvedAreasPresent;
+    }
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/TextArea.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/TextArea.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/TextArea.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/TextArea.java Mon Sep  5 08:06:39 2005
@@ -35,6 +35,17 @@
     }
 
     /**
+     * Constructor with extra parameters:
+     * create a TextAdjustingInfo object
+     * @param stretch  the available stretch of the text
+     * @param shrink   the available shrink of the text
+     * @param adj      the current total adjustment
+     */
+    public TextArea(int stretch, int shrink, int adj) {
+        super(stretch, shrink, adj);
+    }
+
+    /**
      * Set the text string
      *
      * @param t the text string
@@ -50,6 +61,23 @@
      */
     public String getTextArea() {
         return text;
+    }
+
+    /**
+     * set the ipd and notify the parent area about the variation;
+     * this happens when a page-number or a page-number-citation
+     * is resolved to its actual value
+     * @param newIPD the new ipd of the area
+     */
+    public void updateIPD(int newIPD) {
+        // remember the old ipd
+        int oldIPD = getIPD();
+        // set the new ipd
+        setIPD(newIPD);
+        // check if the line needs to be adjusted because of the ipd variation
+        if (newIPD != oldIPD) {
+            notifyIPDVariation(newIPD - oldIPD);
+        }
     }
 
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java Mon Sep  5 08:06:39 2005
@@ -20,6 +20,7 @@
 
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.area.Resolvable;
+import org.apache.fop.fonts.Font;
 
 import java.util.List;
 
@@ -31,14 +32,17 @@
 public class UnresolvedPageNumber extends TextArea implements Resolvable {
     private boolean resolved = false;
     private String pageIDRef;
+    private Font font;
 
     /**
      * Create a new unresolvable page number.
      *
      * @param id the id reference for resolving this
+     * @param f  the font for formatting the page number
      */
-    public UnresolvedPageNumber(String id) {
+    public UnresolvedPageNumber(String id, Font f) {
         pageIDRef = id;
+        font = f;
         text = "?";
     }
 
@@ -65,8 +69,11 @@
         if (pageIDRef.equals(id) && pages != null) {
             resolved = true;
             PageViewport page = (PageViewport)pages.get(0);
-            text = page.getPageNumberString();
-            /**@todo Update IPD ??? */
+            setTextArea(page.getPageNumberString());
+            // update ipd
+            updateIPD(getStringWidth(text));
+            // set the Font object to null, as we don't need it any more
+            font = null;
         }
     }
 
@@ -77,5 +84,29 @@
      */
     public boolean isResolved() {
        return resolved;
+    }
+
+    /**
+     * recursively apply the variation factor to all descendant areas
+     * @param variationFactor the variation factor that must be applied to adjustment ratios
+     * @param lineStretch     the total stretch of the line
+     * @param lineShrink      the total shrink of the line
+     * @return true if there is an UnresolvedArea descendant
+     */
+    public boolean applyVariationFactor(double variationFactor,
+                                        int lineStretch, int lineShrink) {
+        return true;
+    }
+
+    /**
+     * @param str string to be measured
+     * @return width of the string
+     */
+    private int getStringWidth(String str) {
+        int width = 0;
+        for (int count = 0; count < str.length(); count++) {
+            width += font.getCharWidth(str.charAt(count));
+        }
+        return width;
     }
 }

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=278765&r1=278764&r2=278765&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 Sep  5 08:06:39 2005
@@ -1606,7 +1606,13 @@
                 LayoutManager lastLM = null;
     
                 LineBreakPosition lbp = (LineBreakPosition) pos;
-                LineArea lineArea = new LineArea();
+                iCurrParIndex = lbp.iParIndex;
+                KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex); 
+                iEndElement = lbp.getLeafPos();
+    
+                //LineArea lineArea = new LineArea();
+                LineArea lineArea = new LineArea((lbp.getLeafPos() < seq.size() - 1 ? bTextAlignment : bTextAlignmentLast),
+                                                 lbp.difference, lbp.availableStretch, lbp.availableShrink);
                 lineArea.setStartIndent(lbp.startIndent);
                 lineArea.setBPD(lbp.lineHeight);
                 lineArea.setIPD(lbp.lineWidth);
@@ -1616,10 +1622,6 @@
                 lc.setTopShift(lbp.topShift);
                 lc.setBottomShift(lbp.bottomShift);
 
-                iCurrParIndex = lbp.iParIndex;
-                KnuthSequence seq = (KnuthSequence) knuthParagraphs.get(iCurrParIndex); 
-                iEndElement = lbp.getLeafPos();
-    
                 if (seq instanceof Paragraph) {
                     Paragraph currPar = (Paragraph) seq;
                     // ignore the first elements added by the LineLayoutManager
@@ -1707,6 +1709,7 @@
                     && (!context.isLastArea() || parentIter.hasNext())) {
                     lineArea.setBPD(lineArea.getBPD() + context.getSpaceAfter());
                 }
+                lineArea.finalize();
                 parentLM.addChildArea(lineArea);
             } else if (pos instanceof NonLeafPosition) {
                 // Nested block-level content;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java Mon Sep  5 08:06:39 2005
@@ -97,7 +97,7 @@
             resolved = true;
         } else {
             resolved = false;
-            inline = new UnresolvedPageNumber(fobj.getRefId());
+            inline = new UnresolvedPageNumber(fobj.getRefId(), font);
             String str = "MMM"; // reserve three spaces for page number
             int width = getStringWidth(str);
             inline.setIPD(width);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java Mon Sep  5 08:06:39 2005
@@ -25,6 +25,7 @@
 import org.apache.fop.fonts.Font;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.TraitSetter;
+import org.apache.fop.traits.MinOptMax;
 
 /**
  * LayoutManager for the fo:page-number formatting object
@@ -53,10 +54,7 @@
         // get page string from parent, build area
         TextArea text = new TextArea();
         String str = getCurrentPV().getPageNumberString();
-        int width = 0;
-        for (int count = 0; count < str.length(); count++) {
-            width += font.getCharWidth(str.charAt(count));
-        }
+        int width = getStringWidth(str);
         text.setTextArea(str);
         text.setIPD(width);
         text.setBPD(font.getAscender() - font.getDescender());
@@ -64,7 +62,7 @@
         text.addTrait(Trait.FONT_NAME, font.getFontName());
         text.addTrait(Trait.FONT_SIZE,
                         new Integer(font.getFontSize()));
-        text.addTrait(Trait.COLOR, fobj.getColor());
+        text.addTrait(Trait.COLOR, fobj.getColor());        
 
         TraitSetter.addTextDecoration(text, fobj.getTextDecoration());
 
@@ -98,7 +96,24 @@
     }
     
     private void updateContent(TextArea area) {
+        // get the page number of the page actually being built
         area.setTextArea(getCurrentPV().getPageNumberString());
+        // update the ipd of the area
+        area.updateIPD(getStringWidth(area.getTextArea()));
+        // update the width stored in the AreaInfo object
+        areaInfo.ipdArea = new MinOptMax(area.getIPD());
+    }
+
+    /**
+     * @param str string to be measured
+     * @return width of the string
+     */
+    private int getStringWidth(String str) {
+        int width = 0;
+        for (int count = 0; count < str.length(); count++) {
+            width += font.getCharWidth(str.charAt(count));
+        }
+        return width;
     }
     
     protected void addId() {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java?rev=278765&r1=278764&r2=278765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java Mon Sep  5 08:06:39 2005
@@ -344,8 +344,8 @@
         }
         iTotalAdjust += (iWordSpaceDim - wordSpaceIPD.opt) * iWScount;
 
-        TextArea t = createTextArea(str, realWidth.opt + iTotalAdjust,
-                                    context);
+        TextArea t = createTextArea(str, realWidth, iTotalAdjust, context,
+                                    wordSpaceIPD.opt - spaceCharIPD);
 
         // iWordSpaceDim is computed in relation to wordSpaceIPD.opt
         // but the renderer needs to know the adjustment in relation
@@ -362,7 +362,11 @@
         t.setTextLetterSpaceAdjust(iLetterSpaceDim);
         t.setTextWordSpaceAdjust(iWordSpaceDim - spaceCharIPD
                                  - 2 * t.getTextLetterSpaceAdjust());
-        
+        if (context.getIPDAdjust() != 0) {
+            // add information about space width
+            t.setSpaceDifference(wordSpaceIPD.opt - spaceCharIPD
+                                 - 2 * t.getTextLetterSpaceAdjust());
+        }
         word = t;
         if (word != null) {
             parentLM.addChildArea(word);
@@ -374,13 +378,25 @@
      * This creates a TextArea and sets up the various attributes.
      *
      * @param str the string for the TextArea
-     * @param width the width that the TextArea uses
+     * @param width the MinOptMax width of the content
+     * @param adjust the total ipd adjustment with respect to the optimal width
      * @param base the baseline position
      * @return the new word area
      */
-    protected TextArea createTextArea(String str, int width, LayoutContext context) {
-        TextArea textArea = new TextArea();
-        textArea.setIPD(width);
+    protected TextArea createTextArea(String str, MinOptMax width, int adjust,
+                                      LayoutContext context, int spaceDiff) {
+        TextArea textArea;
+        if (context.getIPDAdjust() == 0.0) {
+            // create just a TextArea
+            textArea = new TextArea();
+        } else {
+            // justified area: create a TextArea with extra info
+            // about potential adjustments
+            textArea = new TextArea(width.max - width.opt,
+                                    width.opt - width.min,
+                                    adjust);
+        }
+        textArea.setIPD(width.opt + adjust);
         textArea.setBPD(fs.getAscender() - fs.getDescender());
         int bpd = textArea.getBPD();
         switch (verticalAlignment) {



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org