/*
- * 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.
/** True if this LayoutManager has handled all of its content. */
private boolean bFinished = false;
protected boolean bInited = false;
+
+ /**
+ * Used during addAreas(): signals that a BreakPoss is not generating areas
+ * and therefore doesn't add IDs and markers to the current page.
+ * @see org.apache.fop.layoutmgr.AbstractLayoutManager#isBogus
+ */
+ protected boolean bBogus = false;
/** child LM and child LM iterator during getNextBreakPoss phase */
protected LayoutManager curChildLM = null;
*/
+ /** @see org.apache.fop.layoutmgr.LayoutManager#generatesInlineAreas() */
public boolean generatesInlineAreas() {
return false;
}
+ /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */
+ public boolean isBogus() {
+ if (getParent().isBogus()) {
+ return true;
+ } else {
+ return bBogus;
+ }
+ }
+
/**
* Add a child area to the current area. If this causes the maximum
* dimension of the current area to be exceeded, the parent LM is called
}
+ /**
+ * @see org.apache.fop.layoutmgr.LayoutManager#addAreas(org.apache.fop.layoutmgr.PositionIterator, org.apache.fop.layoutmgr.LayoutContext)
+ */
public void addAreas(PositionIterator posIter, LayoutContext context) {
}
* interface which are declared abstract in AbstractLayoutManager.
* ---------------------------------------------------------*/
+ /**
+ * @see org.apache.fop.layoutmgr.LayoutManager#getParentArea(org.apache.fop.area.Area)
+ */
public Area getParentArea(Area childArea) {
return null;
}
* If the id string is not null then add the id to the current page.
*/
protected void addID(String foID) {
- if (foID != null) {
+ if (foID != null && foID.length() > 0) {
addIDToPage(foID);
}
}
LayoutContext layoutContext) {
getParentArea(null);
+ BreakPoss bp1 = (BreakPoss)parentIter.peekNext();
+ bBogus = !bp1.generatesAreas();
+
// if adjusted space before
double adjust = layoutContext.getSpaceAdjust();
addBlockSpacing(adjust, foBlockSpaceBefore);
foBlockSpaceBefore = null;
- addID(fobj.getId());
- addMarkers(true, true);
+ if (!isBogus()) {
+ addID(fobj.getId());
+ addMarkers(true, true);
+ }
try {
LayoutManager childLM;
}
}
} finally {
- addMarkers(false, true);
+ if (!isBogus()) {
+ addMarkers(false, true);
+ }
flush();
// if adjusted space after
return ((flags & ALL_ARE_SUPPRESS_AT_LB) != 0);
}
+ /**
+ * @return true if the BreakPoss results in an area being created.
+ */
+ public boolean generatesAreas() {
+ return !(nextBreakOverflows() && getStackingSize().opt <= 0);
+ }
+
public SpaceSpecifier getLeadingSpace() {
return spaceSpecLeading;
}
/*
- * 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.
return true;
}
+ /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */
+ public boolean isBogus() {
+ return false;
+ }
+
/** @see org.apache.fop.layoutmgr.LayoutManager */
public Area getParentArea(Area childArea) {
return holder;
int alignment) {
return null;
}
+
}
/*
- * 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.
*/
boolean generatesInlineAreas();
+ /**
+ * This method is used during the stage where addAreas() converts BreakPoss
+ * instances to areas. It is used to skip adding IDs and markers to a page
+ * when the current BreakPoss/area was only generated to signal a break
+ * situation. This avoids adding IDs and markers to the wrong pages.
+ * @todo This is a hack. This should be handled differently in the long term.
+ * @return true if the current BreakPoss/area was only generated to signal
+ * break situations.
+ */
+ boolean isBogus();
+
/**
* Return true if the next area which would be generated by this
* LayoutManager could start a new line (or flow for block-level FO).
--- /dev/null
+/*
+ * Copyright 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.properties.LengthRangeProperty;
+import org.apache.fop.traits.MinOptMax;
+
+/**
+ * Utilities for MinOptMax and LengthRangeProperty.
+ */
+public class MinOptMaxUtil {
+
+ /**
+ * Restricts a MinOptMax using the values from a LengthRangeProperty.
+ * @param mom MinOptMax to restrict
+ * @param lr restricting source
+ */
+ public static void restrict(MinOptMax mom, LengthRangeProperty lr) {
+ if (lr.getEnum() != Constants.EN_AUTO) {
+ if (lr.getMinimum().getEnum() != Constants.EN_AUTO) {
+ int min = lr.getMinimum().getLength().getValue();
+ if (min > mom.min) {
+ mom.min = min;
+ fixAfterMinChanged(mom);
+ }
+ }
+ if (lr.getMaximum().getEnum() != Constants.EN_AUTO) {
+ int max = lr.getMaximum().getLength().getValue();
+ if (max < mom.max) {
+ mom.max = max;
+ if (mom.max < mom.opt) {
+ mom.opt = mom.max;
+ mom.min = mom.opt;
+ }
+ }
+ }
+ if (lr.getOptimum().getEnum() != Constants.EN_AUTO) {
+ int opt = lr.getOptimum().getLength().getValue();
+ if (opt > mom.min) {
+ mom.opt = opt;
+ if (mom.opt > mom.max) {
+ mom.max = mom.opt;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * After a calculation on a MinOptMax, this can be called to set opt to
+ * a new effective value.
+ * @param mom MinOptMax to adjust
+ */
+ public static void fixAfterMinChanged(MinOptMax mom) {
+ if (mom.min > mom.opt) {
+ mom.opt = mom.min;
+ if (mom.opt > mom.max) {
+ mom.max = mom.opt;
+ }
+ }
+ }
+
+}
pageSeq.setCurrentPageNumber(getPageCount());
}
+ /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */
+ public boolean isBogus() {
+ return false;
+ }
+
/**
* Get the next break possibility.
* This finds the next break for a page which is always at the end
RegionViewport rv = curPage.getPage().getRegionViewport(
FO_REGION_BODY);
curBody = (BodyRegion) rv.getRegion();
- flowBPD = (int) curBody.getBPD() -
- rv.getBorderAndPaddingWidthBefore() - rv.getBorderAndPaddingWidthAfter();
+ flowBPD = (int) curBody.getBPD()
+ - rv.getBorderAndPaddingWidthBefore()
+ - rv.getBorderAndPaddingWidthAfter();
return curPage;
}
if (bHasNext) {
Object retObj = getPos(nextObj);
lookAhead();
+ //System.out.println(retObj);
return retObj;
} else {
throw new NoSuchElementException("PosIter");
}
}
- protected Object peekNext() {
+ public Object peekNext() {
return nextObj;
}
package org.apache.fop.layoutmgr.table;
import org.apache.fop.fo.flow.TableCell;
+import org.apache.fop.fo.properties.LengthRangeProperty;
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.LeafPosition;
import org.apache.fop.layoutmgr.BreakPoss;
import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.MinOptMaxUtil;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.BreakPossPosIter;
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
+import org.apache.fop.area.CTM;
import org.apache.fop.area.Trait;
import org.apache.fop.traits.MinOptMax;
private int xoffset;
private int yoffset;
private int cellIPD;
- private int height;
+ private int allocBPD;
+ private int usedBPD;
/**
* Create a new Cell layout manager.
context.getStackLimit(), stackSize));
}
}
+
+ usedBPD = stackSize.opt;
+
+ LengthRangeProperty specifiedBPD = fobj.getBlockProgressionDimension();
+ if (specifiedBPD.getEnum() != EN_AUTO) {
+ if ((specifiedBPD.getMaximum().getEnum() != EN_AUTO)
+ && (specifiedBPD.getMaximum().getLength().getValue() < stackSize.min)) {
+ log.warn("maximum height of cell is smaller than the minimum "
+ + "height of its contents");
+ }
+ MinOptMaxUtil.restrict(stackSize, specifiedBPD);
+ }
+
BreakPoss breakPoss = new BreakPoss(
new LeafPosition(this, childBreaks.size() - 1));
if (over) {
* @param h the height of the row
*/
public void setRowHeight(int h) {
- height = h;
+ allocBPD = h;
}
/**
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
- addID(fobj.getId());
+ BreakPoss bp1 = (BreakPoss)parentIter.peekNext();
+ bBogus = !bp1.generatesAreas();
+
+ if (!isBogus()) {
+ addID(fobj.getId());
+ }
+
+ //Handle display-align
+ if (usedBPD < allocBPD) {
+ if (fobj.getDisplayAlign() == EN_CENTER) {
+ Block space = new Block();
+ space.setBPD((allocBPD - usedBPD) / 2);
+ curBlockArea.addBlock(space);
+ } else if (fobj.getDisplayAlign() == EN_AFTER) {
+ Block space = new Block();
+ space.setBPD((allocBPD - usedBPD));
+ curBlockArea.addBlock(space);
+ }
+ }
LayoutManager childLM;
int iStartPos = 0;
TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground());
TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground());
- curBlockArea.setBPD(height);
+ curBlockArea.setBPD(allocBPD);
flush();
package org.apache.fop.layoutmgr.table;
import org.apache.fop.fo.flow.TableRow;
+import org.apache.fop.fo.properties.LengthRangeProperty;
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.LeafPosition;
import org.apache.fop.layoutmgr.BreakPoss;
import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.MinOptMaxUtil;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.BreakPossPosIter;
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.TraitSetter;
import org.apache.fop.area.Area;
import org.apache.fop.area.Block;
+import org.apache.fop.area.Trait;
import org.apache.fop.traits.MinOptMax;
import java.util.Iterator;
private List cellList = null;
private List columns = null;
+ private int referenceIPD;
private int rowHeight;
private int xoffset;
private int yoffset;
// Set up a LayoutContext
// the ipd is from the current column
- int ipd = context.getRefIPD();
+ referenceIPD = context.getRefIPD();
BreakPoss bp;
LayoutContext childLC = new LayoutContext(0);
breakList.add(childBreaks);
}
- rowHeight = opt;
-
MinOptMax rowSize = new MinOptMax(min, opt, max);
+ LengthRangeProperty specifiedBPD = fobj.getBlockProgressionDimension();
+ if (specifiedBPD.getEnum() != EN_AUTO) {
+ if ((specifiedBPD.getMaximum().getEnum() != EN_AUTO)
+ && (specifiedBPD.getMaximum().getLength().getValue() < rowSize.min)) {
+ log.warn("maximum height of row is smaller than the minimum "
+ + "height of its contents");
+ }
+ MinOptMaxUtil.restrict(rowSize, specifiedBPD);
+ }
+ rowHeight = rowSize.opt;
boolean fin = true;
cellcount = 0;
public void addAreas(PositionIterator parentIter,
LayoutContext layoutContext) {
getParentArea(null);
- addID(fobj.getId());
+ BreakPoss bp1 = (BreakPoss)parentIter.peekNext();
+ bBogus = !bp1.generatesAreas();
+ if (!isBogus()) {
+ addID(fobj.getId());
+ }
Cell childLM;
int iStartPos = 0;
LayoutContext lc = new LayoutContext(0);
while (parentIter.hasNext()) {
RowPosition lfp = (RowPosition) parentIter.next();
- // Add the block areas to Area
+
+ //area exclusively for painting the row background
+ Block rowArea = getRowArea();
+ if (rowArea != null) {
+ rowArea.setBPD(rowHeight);
+ rowArea.setIPD(referenceIPD);
+ rowArea.setXOffset(xoffset);
+ rowArea.setYOffset(yoffset);
+ parentLM.addChild(rowArea);
+ }
int cellcount = 0;
int x = this.xoffset;
}
flush();
-
}
/**
*
* @return the row area
*/
- public Area getRowArea() {
- Area block = new Block();
- TraitSetter.addBackground(block, fobj.getCommonBorderPaddingBackground());
- return block;
+ public Block getRowArea() {
+ if (fobj.getCommonBorderPaddingBackground().hasBackground()) {
+ Block block = new Block();
+ block.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
+ block.setPositioning(Block.ABSOLUTE);
+ TraitSetter.addBackground(block, fobj.getCommonBorderPaddingBackground());
+ return block;
+ } else {
+ return null;
+ }
}
}