jeremias    2005/01/07 00:21:21

  Modified:    src/java/org/apache/fop/fo/properties CommonMarginBlock.java
               src/java/org/apache/fop/layoutmgr TraitSetter.java
                        BlockLayoutManager.java
  Log:
  Bugfix for start-indent calculation for nested blocks. The inherited 
start-indent wasn't taken into account as described in 5.3.2 of the spec.
  Minor style and javadoc improvements on the way.
  
  Revision  Changes    Path
  1.5       +34 -2     
xml-fop/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java
  
  Index: CommonMarginBlock.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CommonMarginBlock.java    28 Oct 2004 10:00:24 -0000      1.4
  +++ CommonMarginBlock.java    7 Jan 2005 08:21:21 -0000       1.5
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -70,6 +70,16 @@
       public Length endIndent;
   
       /**
  +     * The inherited "start-indent" property.
  +     */
  +    public Length inheritedStartIndent;
  +
  +    /**
  +     * The inherited "end-indent" property.
  +     */
  +    public Length inheritedEndIndent;
  +
  +    /**
        * Create a CommonMarginBlock object.
        * @param pList The PropertyList with propery values.
        */
  @@ -84,5 +94,27 @@
   
           startIndent = pList.get(Constants.PR_START_INDENT).getLength();
           endIndent = pList.get(Constants.PR_END_INDENT).getLength();
  +        
  +        if (!pList.getFObj().generatesReferenceAreas()) {
  +            inheritedStartIndent = pList.getParentPropertyList()
  +                    .get(Constants.PR_START_INDENT).getLength();
  +            inheritedEndIndent = pList.getParentPropertyList()
  +                    .get(Constants.PR_END_INDENT).getLength();
  +        }
  +    }
  +    
  +    /** @see java.lang.Object#toString() */
  +    public String toString() {
  +        return "CommonMarginBlock:\n" 
  +            + "Margins (top, bottom, left, right): (" 
  +            + marginTop + ", " + marginBottom + ", " 
  +            + marginLeft + ", " + marginRight + ")\n"
  +            + "Space (before, after): (" 
  +            + spaceBefore + ", " + spaceAfter + ")\n" 
  +            + "Indents (start, end): ("
  +            + startIndent + ", " + endIndent + ")\n"
  +            + "Indents inherited (start, end): (" 
  +            + inheritedStartIndent + ", " + inheritedEndIndent + ")\n";
       }
  +    
   }
  
  
  
  1.11      +33 -22    
xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java
  
  Index: TraitSetter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TraitSetter.java  20 Oct 2004 11:55:32 -0000      1.10
  +++ TraitSetter.java  7 Jan 2005 08:21:21 -0000       1.11
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -33,6 +33,8 @@
        * Sets border and padding traits on areas.
        * @param area area to set the traits on
        * @param bpProps border and padding properties
  +     * @param bNotFirst True if the area is not the first area
  +     * @param bNotLast True if the area is not the last area
        */
       public static void setBorderPaddingTraits(Area area,
               CommonBorderPaddingBackground bpProps, boolean bNotFirst, 
boolean bNotLast) {
  @@ -96,45 +98,45 @@
        * Add borders to an area.
        * Layout managers that create areas with borders can use this to
        * add the borders to the area.
  -     * @param curBlock area to set the traits on
  +     * @param area the area to set the traits on.
        * @param bordProps border properties
        */
  -    public static void addBorders(Area curBlock, 
CommonBorderPaddingBackground bordProps) {
  +    public static void addBorders(Area area, CommonBorderPaddingBackground 
bordProps) {
           BorderProps bps = getBorderProps(bordProps, 
CommonBorderPaddingBackground.BEFORE);
           if (bps.width != 0) {
  -            curBlock.addTrait(Trait.BORDER_BEFORE, bps);
  +            area.addTrait(Trait.BORDER_BEFORE, bps);
           }
           bps = getBorderProps(bordProps, CommonBorderPaddingBackground.AFTER);
           if (bps.width != 0) {
  -            curBlock.addTrait(Trait.BORDER_AFTER, bps);
  +            area.addTrait(Trait.BORDER_AFTER, bps);
           }
           bps = getBorderProps(bordProps, CommonBorderPaddingBackground.START);
           if (bps.width != 0) {
  -            curBlock.addTrait(Trait.BORDER_START, bps);
  +            area.addTrait(Trait.BORDER_START, bps);
           }
           bps = getBorderProps(bordProps, CommonBorderPaddingBackground.END);
           if (bps.width != 0) {
  -            curBlock.addTrait(Trait.BORDER_END, bps);
  +            area.addTrait(Trait.BORDER_END, bps);
           }
   
           int padding = 
bordProps.getPadding(CommonBorderPaddingBackground.START, false);
           if (padding != 0) {
  -            curBlock.addTrait(Trait.PADDING_START, new 
java.lang.Integer(padding));
  +            area.addTrait(Trait.PADDING_START, new 
java.lang.Integer(padding));
           }
   
           padding = bordProps.getPadding(CommonBorderPaddingBackground.END, 
false);
           if (padding != 0) {
  -            curBlock.addTrait(Trait.PADDING_END, new 
java.lang.Integer(padding));
  +            area.addTrait(Trait.PADDING_END, new java.lang.Integer(padding));
           }
   
           padding = bordProps.getPadding(CommonBorderPaddingBackground.BEFORE, 
false);
           if (padding != 0) {
  -            curBlock.addTrait(Trait.PADDING_BEFORE, new 
java.lang.Integer(padding));
  +            area.addTrait(Trait.PADDING_BEFORE, new 
java.lang.Integer(padding));
           }
   
           padding = bordProps.getPadding(CommonBorderPaddingBackground.AFTER, 
false);
           if (padding != 0) {
  -            curBlock.addTrait(Trait.PADDING_AFTER, new 
java.lang.Integer(padding));
  +            area.addTrait(Trait.PADDING_AFTER, new 
java.lang.Integer(padding));
           }
       }
   
  @@ -150,10 +152,10 @@
        * Add background to an area.
        * Layout managers that create areas with a background can use this to
        * add the background to the area.
  -     * @param curBlock the current block
  +     * @param area the area to set the traits on
        * @param backProps the background properties
        */
  -    public static void addBackground(Area curBlock, 
CommonBorderPaddingBackground backProps) {
  +    public static void addBackground(Area area, 
CommonBorderPaddingBackground backProps) {
           Trait.Background back = new Trait.Background();
           back.setColor(backProps.backgroundColor);
   
  @@ -169,7 +171,7 @@
           }
   
           if (back.getColor() != null || back.getURL() != null) {
  -            curBlock.addTrait(Trait.BACKGROUND, back);
  +            area.addTrait(Trait.BACKGROUND, back);
           }
       }
   
  @@ -177,29 +179,38 @@
        * Add space to a block area.
        * Layout managers that create block areas can use this to add space
        * outside of the border rectangle to the area.
  -     * @param curBlock the current block.
  +     * @param area the area to set the traits on.
  +     * @param bpProps the border, padding and background properties
        * @param marginProps the margin properties.
        */
  -    public static void addMargins(Area curBlock,
  +    public static void addMargins(Area area,
                                     CommonBorderPaddingBackground bpProps,
                                     CommonMarginBlock marginProps) {
  -        int spaceStart = marginProps.startIndent.getValue() 
  +        int spaceStart = marginProps.startIndent.getValue()
  +                            - marginProps.inheritedStartIndent.getValue()
                               - bpProps.getBorderStartWidth(false)
                               - bpProps.getPaddingStart(false);
           if (spaceStart != 0) {
  -            curBlock.addTrait(Trait.SPACE_START, new Integer(spaceStart));
  +            area.addTrait(Trait.SPACE_START, new Integer(spaceStart));
           }
   
           int spaceEnd = marginProps.endIndent.getValue()
  +                            - marginProps.inheritedEndIndent.getValue()
                               - bpProps.getBorderEndWidth(false)
                               - bpProps.getPaddingEnd(false);
           if (spaceEnd != 0) {
  -            curBlock.addTrait(Trait.SPACE_END, new Integer(spaceEnd));
  +            area.addTrait(Trait.SPACE_END, new Integer(spaceEnd));
           }
       }
   
  -    public static void addBreaks(Area curArea,  int breakBefore, int 
breakAfter) {
  -        curArea.addTrait(Trait.BREAK_AFTER, new Integer(breakAfter));
  -        curArea.addTrait(Trait.BREAK_BEFORE, new Integer(breakBefore));
  +    /**
  +     * Sets the traits for breaks on an area.
  +     * @param area the area to set the traits on.
  +     * @param breakBefore the value for break-before
  +     * @param breakAfter the value for break-after
  +     */
  +    public static void addBreaks(Area area,  int breakBefore, int 
breakAfter) {
  +        area.addTrait(Trait.BREAK_AFTER, new Integer(breakAfter));
  +        area.addTrait(Trait.BREAK_BEFORE, new Integer(breakBefore));
       }
   }
  
  
  
  1.35      +41 -11    
xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
  
  Index: BlockLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- BlockLayoutManager.java   7 Dec 2004 20:11:21 -0000       1.34
  +++ BlockLayoutManager.java   7 Jan 2005 08:21:21 -0000       1.35
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -19,7 +19,6 @@
   package org.apache.fop.layoutmgr;
   
   import java.util.ListIterator;
  -import java.util.ArrayList;
   import java.util.List;
   
   import org.apache.fop.datatypes.PercentBase;
  @@ -39,6 +38,7 @@
       
       private Block curBlockArea;
   
  +    /** Iterator over the child layout managers. */
       protected ListIterator proxyLMiter;
   
       /* holds the (one-time use) fo:block space-before
  @@ -61,8 +61,13 @@
   
       private int iStartPos = 0;
   
  +    /** The list of child BreakPoss instances. */
       protected List childBreaks = new java.util.ArrayList();
   
  +    /**
  +     * Creates a new BlockLayoutManager.
  +     * @param inBlock the block FO object to create the layout manager for.
  +     */
       public BlockLayoutManager(org.apache.fop.fo.flow.Block inBlock) {
           super(inBlock);
           fobj = inBlock;
  @@ -98,7 +103,7 @@
   
           public ProxyLMiter() {
               super(BlockLayoutManager.this);
  -            listLMs = new ArrayList(10);
  +            listLMs = new java.util.ArrayList(10);
           }
   
           public boolean hasNext() {
  @@ -143,7 +148,7 @@
       private LineLayoutManager createLineManager(LayoutManager firstlm) {
           LineLayoutManager llm;
           llm = new LineLayoutManager(fobj, lineHeight, lead, follow, 
middleShift);
  -        List inlines = new ArrayList();
  +        List inlines = new java.util.ArrayList();
           inlines.add(firstlm);
           while (proxyLMiter.hasNext()) {
               LayoutManager lm = (LayoutManager) proxyLMiter.next();
  @@ -158,12 +163,18 @@
           return llm;
       }
   
  +    /**
  +     * @see 
org.apache.fop.layoutmgr.LayoutManager#getNextBreakPoss(org.apache.fop.layoutmgr.LayoutContext)
  +     */
       public BreakPoss getNextBreakPoss(LayoutContext context) {
           LayoutManager curLM; // currently active LM
   
           int ipd = context.getRefIPD();
  -        int iIndents = fobj.getCommonMarginBlock().startIndent.getValue() + 
fobj.getCommonMarginBlock().endIndent.getValue();
  -        int bIndents = 
fobj.getCommonBorderPaddingBackground().getBPPaddingAndBorder(false);
  +        int iIndents = fobj.getCommonMarginBlock().startIndent.getValue();
  +        iIndents += fobj.getCommonMarginBlock().endIndent.getValue();
  +        iIndents -= 
fobj.getCommonMarginBlock().inheritedStartIndent.getValue();
  +        iIndents -= 
fobj.getCommonMarginBlock().inheritedEndIndent.getValue();
  +        //int bIndents = 
fobj.getCommonBorderPaddingBackground().getBPPaddingAndBorder(false);
           ipd -= iIndents;
   
           MinOptMax stackSize = new MinOptMax();
  @@ -258,6 +269,9 @@
           return breakPoss;
       }
   
  +    /**
  +     * @see 
org.apache.fop.layoutmgr.LayoutManager#addAreas(org.apache.fop.layoutmgr.PositionIterator,
 org.apache.fop.layoutmgr.LayoutContext)
  +     */
       public void addAreas(PositionIterator parentIter,
                            LayoutContext layoutContext) {
           getParentArea(null);
  @@ -309,16 +323,22 @@
        * Finally, based on the dimensions of the parent area, it initializes
        * its own area. This includes setting the content IPD and the maximum
        * BPD.
  +     * @param childArea area to get the parent area for
        */
       public Area getParentArea(Area childArea) {
           if (curBlockArea == null) {
               curBlockArea = new Block();
   
               // set traits
  -            TraitSetter.addBorders(curBlockArea, 
fobj.getCommonBorderPaddingBackground());
  -            TraitSetter.addBackground(curBlockArea, 
fobj.getCommonBorderPaddingBackground());
  -            TraitSetter.addMargins(curBlockArea, 
fobj.getCommonBorderPaddingBackground(), fobj.getCommonMarginBlock());
  -            TraitSetter.addBreaks(curBlockArea, fobj.getBreakBefore(), 
fobj.getBreakAfter());
  +            TraitSetter.addBorders(curBlockArea, 
  +                    fobj.getCommonBorderPaddingBackground());
  +            TraitSetter.addBackground(curBlockArea, 
  +                    fobj.getCommonBorderPaddingBackground());
  +            TraitSetter.addMargins(curBlockArea, 
  +                    fobj.getCommonBorderPaddingBackground(), 
  +                    fobj.getCommonMarginBlock());
  +            TraitSetter.addBreaks(curBlockArea, 
  +                    fobj.getBreakBefore(), fobj.getBreakAfter());
   
               // Set up dimensions
               // Must get dimensions from parent area
  @@ -337,13 +357,20 @@
               if (parentwidth == 0) {
                   parentwidth = referenceIPD;
               }
  -            parentwidth -= 
fobj.getCommonMarginBlock().startIndent.getValue() + 
fobj.getCommonMarginBlock().endIndent.getValue();
  +            parentwidth -= 
fobj.getCommonMarginBlock().startIndent.getValue();
  +            parentwidth -= fobj.getCommonMarginBlock().endIndent.getValue();
  +            parentwidth += 
fobj.getCommonMarginBlock().inheritedStartIndent.getValue();
  +            parentwidth += 
fobj.getCommonMarginBlock().inheritedEndIndent.getValue();
  +            
               curBlockArea.setIPD(parentwidth);
               setCurrentArea(curBlockArea); // ??? for generic operations
           }
           return curBlockArea;
       }
   
  +    /**
  +     * @see 
org.apache.fop.layoutmgr.LayoutManager#addChild(org.apache.fop.area.Area)
  +     */
       public void addChild(Area childArea) {
           if (curBlockArea != null) {
               if (childArea instanceof LineArea) {
  @@ -354,6 +381,9 @@
           }
       }
   
  +    /**
  +     * @see 
org.apache.fop.layoutmgr.LayoutManager#resetPosition(org.apache.fop.layoutmgr.Position)
  +     */
       public void resetPosition(Position resetPos) {
           if (resetPos == null) {
               reset(null);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to