diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-01-07 08:21:21 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-01-07 08:21:21 +0000 |
commit | c855f83c16cc41ede11f28e4b52de6aecd622de0 (patch) | |
tree | 79e7c1f8b1e295f7e92590ca4ebb43ed32d2378a | |
parent | 4a96fb5584fd9445fae1a649cee2c911ae050e92 (diff) | |
download | xmlgraphics-fop-c855f83c16cc41ede11f28e4b52de6aecd622de0.tar.gz xmlgraphics-fop-c855f83c16cc41ede11f28e4b52de6aecd622de0.zip |
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.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198247 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 107 insertions, 34 deletions
diff --git a/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java b/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java index 5b7e89bf5..0ce5fcf44 100644 --- a/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java +++ b/src/java/org/apache/fop/fo/properties/CommonMarginBlock.java @@ -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 class CommonMarginBlock { 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 @@ public class CommonMarginBlock { 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"; } + } diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index 9c1f6227f..667ec4c6b 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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 class BlockLayoutManager extends BlockStackingLayoutManager { public ProxyLMiter() { super(BlockLayoutManager.this); - listLMs = new ArrayList(10); + listLMs = new java.util.ArrayList(10); } public boolean hasNext() { @@ -143,7 +148,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { * 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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { 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 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { } } + /** + * @see org.apache.fop.layoutmgr.LayoutManager#resetPosition(org.apache.fop.layoutmgr.Position) + */ public void resetPosition(Position resetPos) { if (resetPos == null) { reset(null); diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index b68861d77..26bd72931 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -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 @@ public class TraitSetter { * 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 @@ public class TraitSetter { * 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 @@ public class TraitSetter { * 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 @@ public class TraitSetter { } if (back.getColor() != null || back.getURL() != null) { - curBlock.addTrait(Trait.BACKGROUND, back); + area.addTrait(Trait.BACKGROUND, back); } } @@ -177,29 +179,38 @@ public class TraitSetter { * 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)); } } |