+++ /dev/null
-/*
- * 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.
- * 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.table;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.fop.fo.flow.TableBody;
-import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
-import org.apache.fop.layoutmgr.KnuthElement;
-import org.apache.fop.layoutmgr.KnuthGlue;
-import org.apache.fop.layoutmgr.KnuthPenalty;
-import org.apache.fop.layoutmgr.LayoutManager;
-import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
-import org.apache.fop.layoutmgr.LeafPosition;
-import org.apache.fop.layoutmgr.BreakPoss;
-import org.apache.fop.layoutmgr.LayoutContext;
-import org.apache.fop.layoutmgr.NonLeafPosition;
-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.traits.MinOptMax;
-
-/**
- * LayoutManager for a table-header, table-footer and table body FO.
- * These fo objects have either rows or cells underneath.
- * Cells are organised into rows.
- */
-public class Body extends BlockStackingLayoutManager implements BlockLevelLayoutManager {
- private TableBody fobj;
-
- private List columns;
-
- private int xoffset;
- private int yoffset;
- private int bodyHeight;
-
- //private Block curBlockArea;
-
- private List childBreaks = new java.util.ArrayList();
-
- /**
- * Create a new body layout manager.
- * @param node the table-body FO
- */
- public Body(TableBody node) {
- super(node);
- fobj = node;
- }
-
- /** @return the table-body|header|footer FO */
- public TableBody getFObj() {
- return this.fobj;
- }
-
- /**
- * Set the columns from the table.
- *
- * @param cols the list of columns used for this body
- */
- public void setColumns(List cols) {
- columns = cols;
- }
-
- /**
- * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(org.apache.fop.layoutmgr.LayoutContext, int)
- */
- public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(context.getStackLimit());
- childLC.setRefIPD(context.getRefIPD());
-
- LinkedList returnedList = null;
- LinkedList contentList = new LinkedList();
- LinkedList returnList = new LinkedList();
- Position returnPosition = new NonLeafPosition(this, null);
-
- Row curLM; // currently active LM
- Row prevLM = null; // previously active LM
- while ((curLM = (Row)getChildLM()) != null) {
-
- // get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment);
- /*
- if (returnedList.size() == 1
- && ((KnuthElement) returnedList.getFirst()).isPenalty()
- && ((KnuthPenalty) returnedList.getFirst()).getP() == -KnuthElement.INFINITE) {
- // a descendant of this block has break-before
- if (returnList.size() == 0) {
- // the first child (or its first child ...) has
- // break-before;
- // all this block, including space before, will be put in
- // the
- // following page
- bSpaceBeforeServed = false;
- }
- contentList.addAll(returnedList);
-
- // "wrap" the Position inside each element
- // moving the elements from contentList to returnList
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- } else*/ {
- if (prevLM != null) {
- // there is a block handled by prevLM
- // before the one handled by curLM
- if (mustKeepTogether()
- || prevLM.mustKeepWithNext()
- || curLM.mustKeepWithPrevious()) {
- // add an infinite penalty to forbid a break between
- // blocks
- contentList.add(new KnuthPenalty(0,
- KnuthElement.INFINITE, false,
- new Position(this), false));
- } else if (!((KnuthElement) contentList.getLast()).isGlue()) {
- // add a null penalty to allow a break between blocks
- contentList.add(new KnuthPenalty(0, 0, false,
- new Position(this), false));
- } else {
- // the last element in contentList is a glue;
- // it is a feasible breakpoint, there is no need to add
- // a penalty
- }
- }
- contentList.addAll(returnedList);
- if (returnedList.size() == 0) {
- //Avoid NoSuchElementException below (happens with empty blocks)
- continue;
- }
- if (((KnuthElement) returnedList.getLast()).isPenalty()
- && ((KnuthPenalty) returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
- // a descendant of this block has break-after
- if (curLM.isFinished()) {
- // there is no other content in this block;
- // it's useless to add space after before a page break
- setFinished(true);
- }
-
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- }
- }
- prevLM = curLM;
- }
-
- setFinished(true);
- if (returnList.size() > 0) {
- return returnList;
- } else {
- return null;
- }
- }
-
- /**
- * Breaks for this layout manager are of the form of before
- * or after a row and inside a row.
- *
- * @param context the layout context for finding the breaks
- * @return the next break possibility
- */
- public BreakPoss getNextBreakPossOLDOLDOLD(LayoutContext context) {
- Row curLM; // currently active LM
-
- MinOptMax stackSize = new MinOptMax();
- BreakPoss lastPos = null;
-
- while ((curLM = (Row)getChildLM()) != null) {
- // Make break positions
- // Set up a LayoutContext
- int ipd = context.getRefIPD();
- BreakPoss bp;
-
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(
- MinOptMax.subtract(context.getStackLimit(),
- stackSize));
- childLC.setRefIPD(ipd);
-
- curLM.setColumns(columns);
-
- boolean over = false;
-
- while (!curLM.isFinished()) {
- if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
- if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) {
- // reset to last break
- if (lastPos != null) {
- LayoutManager lm = lastPos.getLayoutManager();
- lm.resetPosition(lastPos.getPosition());
- if (lm != curLM) {
- curLM.resetPosition(null);
- }
- } else {
- curLM.resetPosition(null);
- }
- over = true;
- break;
- }
- stackSize.add(bp.getStackingSize());
- lastPos = bp;
- childBreaks.add(bp);
-
- if (bp.nextBreakOverflows()) {
- over = true;
- break;
- }
-
- childLC.setStackLimit(MinOptMax.subtract(
- context.getStackLimit(), stackSize));
- }
- }
- BreakPoss breakPoss = new BreakPoss(
- new LeafPosition(this, childBreaks.size() - 1));
- if (over) {
- breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
- }
- breakPoss.setStackingSize(stackSize);
- return breakPoss;
- }
-
- setFinished(true);
- return null;
- }
-
- /**
- * Set the x offset of this body within the table.
- * This is used to set the row offsets.
- * @param off the x offset
- */
- public void setXOffset(int off) {
- xoffset = off;
- }
-
- /**
- * Set the y offset of this body within the table.
- * This is used to set the row offsets.
- *
- * @param off the y offset position
- */
- public void setYOffset(int off) {
- yoffset = off;
- }
-
- /**
- * Add the areas for the break points.
- * This sets the offset of each row as it is added.
- *
- * @param parentIter the position iterator
- * @param layoutContext the layout context for adding areas
- */
- public void addAreas(PositionIterator parentIter,
- LayoutContext layoutContext) {
- getParentArea(null);
-
- Row childLM;
- int iStartPos = 0;
- LayoutContext lc = new LayoutContext(0);
- int rowoffset = 0;
- while (parentIter.hasNext()) {
- LeafPosition lfp = (LeafPosition) parentIter.next();
- // Add the block areas to Area
- PositionIterator breakPosIter
- = new BreakPossPosIter(childBreaks, iStartPos,
- lfp.getLeafPos() + 1);
- iStartPos = lfp.getLeafPos() + 1;
- int lastheight = 0;
- while ((childLM = (Row)breakPosIter.getNextChildLM()) != null) {
- childLM.setXOffset(xoffset);
- childLM.setYOffset(yoffset + rowoffset);
- childLM.addAreas(breakPosIter, lc);
- lastheight = childLM.getRowHeight();
- }
- rowoffset += lastheight;
- }
- bodyHeight = rowoffset;
-
- flush();
-
- childBreaks.clear();
- //curBlockArea = null;
- }
-
- /**
- * Get the body height of the body after adjusting.
- * Should only be called after adding the body areas.
- *
- * @return the body height of this body
- */
- public int getBodyHeight() {
- return bodyHeight;
- }
-
- /**
- * Return an Area which can contain the passed childArea. The childArea
- * may not yet have any content, but it has essential traits set.
- * In general, if the LayoutManager already has an Area it simply returns
- * it. Otherwise, it makes a new Area of the appropriate class.
- * It gets a parent area for its area by calling its parent LM.
- * 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 the child area
- * @return the parent are of the child
- */
- public Area getParentArea(Area childArea) {
- return parentLM.getParentArea(childArea);
- }
-
- /**
- * Add the child area.
- * The table-header, table-footer and table-body areas return
- * the areas return by the children.
- *
- * @param childArea the child area to add
- */
- public void addChildArea(Area childArea) {
- parentLM.addChildArea(childArea);
- }
-
- /**
- * Reset the position of the layout manager.
- *
- * @param resetPos the position to reset to
- */
- public void resetPosition(Position resetPos) {
- if (resetPos == null) {
- reset(null);
- }
- }
-
- /**
- * Create a body area.
- * This area has the background and width set.
- *
- * @return the new body area
- */
- public Area createColumnArea() {
- Area curBlockArea = new Block();
-
- TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground());
- return curBlockArea;
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#negotiateBPDAdjustment(int, org.apache.fop.layoutmgr.KnuthElement)
- */
- public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#discardSpace(org.apache.fop.layoutmgr.KnuthGlue)
- */
- public void discardSpace(KnuthGlue spaceGlue) {
- // TODO Auto-generated method stub
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepTogether()
- */
- public boolean mustKeepTogether() {
- return ((BlockLevelLayoutManager)getParent()).mustKeepTogether();
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithPrevious()
- */
- public boolean mustKeepWithPrevious() {
- return false;
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithNext()
- */
- public boolean mustKeepWithNext() {
- return false;
- }
-
-}
-
+++ /dev/null
-/*
- * 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.
- * 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.table;
-
-import org.apache.fop.datatypes.Length;
-import org.apache.fop.layoutmgr.AbstractLayoutManager;
-import org.apache.fop.layoutmgr.BreakPoss;
-import org.apache.fop.layoutmgr.LayoutContext;
-import org.apache.fop.layoutmgr.PositionIterator;
-import org.apache.fop.layoutmgr.TraitSetter;
-import org.apache.fop.fo.flow.TableCell;
-import org.apache.fop.fo.flow.TableColumn;
-import org.apache.fop.area.Area;
-import org.apache.fop.area.Block;
-
-/**
- * LayoutManager for a table-column FO.
- * The table creates an area for the table-column background, this class
- * is used to do the area creation. This is used during the layout to handle
- * column properties.
- */
-public class Column extends AbstractLayoutManager {
-
- private TableColumn fobj;
-
- private Length columnWidth;
-
- /**
- * Create a new column layout manager.
- * @param node the table-column FO
- */
- public Column(TableColumn node) {
- super(node);
- fobj = node;
- columnWidth = fobj.getColumnWidth();
- }
-
- /** @return the table-column FO */
- public TableColumn getFObj() {
- return this.fobj;
- }
-
- /** @return true if the column is the first column */
- public boolean isFirst() {
- return ((TableLayoutManager)getParent()).isFirst(this);
- }
-
- /** @return true if the column is the last column */
- public boolean isLast() {
- return ((TableLayoutManager)getParent()).isLast(this);
- }
-
- /**
- * Get the next break possibility.
- * Columns do not create or return any areas.
- *
- * @param context the layout context
- * @return the break possibility, always null
- */
- public BreakPoss getNextBreakPoss(LayoutContext context) {
- return null;
- }
-
- /**
- * Add the areas.
- * Although this adds no areas it is used to add the id
- * reference of the table-column.
- *
- * @param parentIter the position iterator
- * @param layoutContext the context
- */
- public void addAreas(PositionIterator parentIter,
- LayoutContext layoutContext) {
- }
-
- /**
- * Get the parent area.
- * This does nothing.
- *
- * @param childArea the child area
- * @return always null
- */
- public Area getParentArea(Area childArea) {
- return null;
- }
-
- /**
- * Overrides the default column-with coming from the FO.
- * @param width the new width to use
- */
- public void setWidth(Length width) {
- this.columnWidth = width;
- }
-
- /**
- * Get the width of this column.
- *
- * @return the width of the column
- */
- public Length getWidth() {
- return columnWidth;
- }
-
- /**
- * Create a column area.
- * This area has the background and width set.
- * The Body manager will then set the offset of the column.
- *
- * @return the new column area
- */
- public Area createColumnArea() {
- Area curBlockArea = new Block();
-
- TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground());
- return curBlockArea;
- }
-}
-
+++ /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.table;
-
-import org.apache.fop.fo.flow.Table;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
-
-
-public class OldGridUnit {
-
- /** layout manager for the cell occupying this grid unit, may be null */
- public Cell layoutManager;
- /** layout manager for the column that this grid unit belongs to */
- public Column column;
- /** layout manager for the row that this grid unit belongs to */
- public Row row;
- /** index of grid unit within cell in column direction */
- public int colSpanIndex;
- /** index of grid unit within cell in row direction */
- public int rowSpanIndex;
- /** effective borders for a cell slot (used for collapsing border model) */
- public CommonBorderPaddingBackground effBorders;
-
- public OldGridUnit(Cell layoutManager, int colSpanIndex) {
- this.layoutManager = layoutManager;
- this.colSpanIndex = colSpanIndex;
- this.rowSpanIndex = 0;
- }
-
- public OldGridUnit(Cell layoutManager) {
- this(layoutManager, 0);
- }
-
- /** @return true if the grid unit is the primary of a cell */
- public boolean isPrimaryGridUnit() {
- return (colSpanIndex == 0) && (rowSpanIndex == 0);
- }
-
- /** @return true if the grid unit is the last in column spanning direction */
- public boolean isLastGridUnitColSpan() {
- if (layoutManager != null) {
- return (colSpanIndex == layoutManager.getFObj().getNumberColumnsSpanned() - 1);
- } else {
- return true;
- }
- }
-
- /** @return true if the grid unit is the last in column spanning direction */
- public boolean isLastGridUnitRowSpan() {
- if (layoutManager != null) {
- return (rowSpanIndex == layoutManager.getFObj().getNumberRowsSpanned() - 1);
- } else {
- return true;
- }
- }
-
- /** @return true if the cell is part of a span in column direction */
- public boolean isColSpan() {
- return (colSpanIndex > 0);
- }
-
- public BorderInfo getOriginalBorderInfoForCell(int side) {
- if (layoutManager != null) {
- return layoutManager.getFObj().getCommonBorderPaddingBackground().getBorderInfo(side);
- } else {
- return null;
- }
- }
-
- /**
- * Assign the borders from the given cell to this cell info. Used in
- * case of separate border model.
- * @param current cell to take the borders from
- */
- public void assignBorder(Cell current) {
- if (current != null) {
- this.effBorders = current.getFObj().getCommonBorderPaddingBackground();
- }
- }
-
- /**
- * Assign the borders directly.
- * @param borders the borders to use
- */
- public void assignBorder(CommonBorderPaddingBackground borders) {
- if (borders != null) {
- this.effBorders = borders;
- }
- }
-
- /**
- * Resolve collapsing borders for the given cell and store the resulting
- * borders in this cell info. Use in case of the collapsing border model.
- * @param current cell to resolve borders for
- * @param before cell before the current cell, if any
- * @param after cell after the current cell, if any
- * @param start cell preceeding the current cell, if any
- * @param end cell succeeding of the current cell, if any
- */
- public static void resolveBorder(Table table,
- CommonBorderPaddingBackground target,
- OldGridUnit current, OldGridUnit other, int side) {
- if (current == null) {
- return;
- }
-
- CollapsingBorderModel borderModel = CollapsingBorderModel.getBorderModelFor(
- table.getBorderCollapse());
- /*
- target.setBorderInfo(
- borderModel.determineWinner(current, other,
- side, 0), side);*/
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * 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.
- * 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.table;
-
-import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.flow.Table;
-import org.apache.fop.fo.flow.TableBody;
-import org.apache.fop.fo.flow.TableCell;
-import org.apache.fop.fo.flow.TableRow;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-import org.apache.fop.fo.properties.LengthRangeProperty;
-import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
-import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
-import org.apache.fop.layoutmgr.KnuthElement;
-import org.apache.fop.layoutmgr.KnuthGlue;
-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;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * LayoutManager for a table-row FO.
- * The row contains cells that are organised according to the columns.
- * A break in a table row will contain breaks for each table cell.
- * If there are row spanning cells then these cells belong to this row
- * but effect the occupied columns of future rows.
- */
-public class Row extends BlockStackingLayoutManager implements BlockLevelLayoutManager {
-
- private TableRow fobj;
-
- private List gridUnits = null;
- private List columns = null;
- private int referenceIPD;
- private int rowHeight;
- private int xoffset;
- private int yoffset;
-
- private class RowPosition extends LeafPosition {
- protected List cellBreaks;
- protected RowPosition(LayoutManager lm, int pos, List l) {
- super(lm, pos);
- cellBreaks = l;
- }
- }
-
- /**
- * Create a new row layout manager.
- *
- */
- public Row(TableRow node) {
- super(node);
- fobj = node;
- }
-
- /** @return the table-row FO */
- public TableRow getFObj() {
- return this.fobj;
- }
-
- /**
- * @return the table owning this row
- */
- public Table getTable() {
- FONode node = fobj.getParent();
- while (!(node instanceof Table)) {
- node = node.getParent();
- }
- return (Table)node;
- }
-
- /**
- * Set the columns from the table.
- *
- * @param cols the list of columns for this table
- */
- public void setColumns(List cols) {
- columns = cols;
- }
-
- /** @return true if this is the layout manager for the first row in a body. */
- public boolean isFirstInBody() {
- return ((TableBody)getFObj().getParent()).isFirst(getFObj());
- }
-
- /** @return true if this is the layout manager for the last row in a body. */
- public boolean isLastInBody() {
- return ((TableBody)getFObj().getParent()).isLast(getFObj());
- }
-
- /**
- * Gets the Column at a given index.
- * @param index index of the column (index must be >= 1)
- * @return the requested Column
- */
- private Column getColumn(int index) {
- int size = columns.size();
- if (index > size - 1) {
- return (Column)columns.get(size - 1);
- } else {
- return (Column)columns.get(index - 1);
- }
- }
-
- private void prepareGridUnits() {
- gridUnits = new java.util.ArrayList();
- List availableCells = new java.util.ArrayList();
- // add cells to list
- while (childLMiter.hasNext()) {
- curChildLM = (LayoutManager) childLMiter.next();
- curChildLM.setParent(this);
- curChildLM.initialize();
- availableCells.add(curChildLM);
- }
-
- //Transfer available cells to their slots
- int colnum = 1;
- ListIterator iter = availableCells.listIterator();
- while (iter.hasNext()) {
- Cell cellLM = (Cell)iter.next();
- TableCell cell = cellLM.getFObj();
- if (cell.hasColumnNumber()) {
- colnum = cell.getColumnNumber();
- }
- while (colnum > gridUnits.size()) {
- gridUnits.add(null);
- }
- if (gridUnits.get(colnum - 1) != null) {
- log.error("Overlapping cell at position " + colnum);
- }
- //Add cell info for primary slot
- OldGridUnit info = new OldGridUnit(cellLM);
- info.row = this;
- gridUnits.set(colnum - 1, info);
- info.column = getColumn(colnum);
-
- //Add cell infos on spanned slots if any
- for (int j = 1; j < cell.getNumberColumnsSpanned(); j++) {
- colnum++;
- OldGridUnit infoSpan = new OldGridUnit(cellLM, j);
- infoSpan.row = this;
- infoSpan.column = getColumn(colnum);
- if (colnum > gridUnits.size()) {
- gridUnits.add(infoSpan);
- } else {
- if (gridUnits.get(colnum - 1) != null) {
- log.error("Overlapping cell at position " + colnum);
- //TODO throw layout exception
- }
- gridUnits.set(colnum - 1, infoSpan);
- }
- }
- colnum++;
- }
-
- //Post-processing the list (looking for gaps and resolve start and end borders)
- postProcessGridUnits();
- }
-
- private void postProcessGridUnits() {
- for (int pos = 1; pos <= gridUnits.size(); pos++) {
- OldGridUnit gu = (OldGridUnit)gridUnits.get(pos - 1);
-
- //Empty grid units
- if (gu == null) {
- //Add grid unit
- gu = new OldGridUnit(null);
- gu.row = this;
- gu.column = getColumn(pos);
- gridUnits.set(pos - 1, gu);
- }
- }
-
- //Border resolution now that the empty grid units are filled
- for (int pos = 1; pos <= gridUnits.size(); pos++) {
- OldGridUnit starting = (OldGridUnit)gridUnits.get(pos - 1);
-
- //Border resolution
- if (getTable().isSeparateBorderModel()) {
- starting.assignBorder(starting.layoutManager);
- } else {
- //Neighbouring grid unit at start edge
- OldGridUnit start = null;
- int find = pos - 1;
- while (find >= 1) {
- OldGridUnit candidate = (OldGridUnit)gridUnits.get(find - 1);
- if (candidate.isLastGridUnitColSpan()) {
- start = candidate;
- break;
- }
- find--;
- }
-
- //Ending grid unit for current cell
- OldGridUnit ending = null;
- if (starting.layoutManager != null) {
- pos += starting.layoutManager.getFObj().getNumberColumnsSpanned() - 1;
- }
- ending = (OldGridUnit)gridUnits.get(pos - 1);
-
- //Neighbouring grid unit at end edge
- OldGridUnit end = null;
- find = pos + 1;
- while (find <= gridUnits.size()) {
- OldGridUnit candidate = (OldGridUnit)gridUnits.get(find - 1);
- if (candidate.isPrimaryGridUnit()) {
- end = candidate;
- break;
- }
- find++;
- }
- CommonBorderPaddingBackground borders = new CommonBorderPaddingBackground();
- OldGridUnit.resolveBorder(getTable(), borders, starting,
- (start != null ? start : null),
- CommonBorderPaddingBackground.START);
- starting.effBorders = borders;
- if (starting != ending) {
- borders = new CommonBorderPaddingBackground();
- }
- OldGridUnit.resolveBorder(getTable(), borders, ending,
- (end != null ? end : null),
- CommonBorderPaddingBackground.END);
- ending.effBorders = borders;
- //Only start and end borders here, before and after during layout
- //TODO resolve before and after borders during layout
- }
- }
- }
-
- /**
- * Get the cell info for a cell.
- *
- * @param pos the position of the cell (must be >= 1)
- * @return the cell info object
- */
- protected OldGridUnit getCellInfo(int pos) {
- if (gridUnits == null) {
- prepareGridUnits();
- }
- if (pos <= gridUnits.size()) {
- return (OldGridUnit)gridUnits.get(pos - 1);
- } else {
- return null;
- }
- }
-
- /**
- * Get the next break possibility.
- * A row needs to get the possible breaks for each cell
- * in the row and find a suitable break across all cells.
- *
- * @param context the layout context for getting breaks
- * @return the next break possibility
- */
- public BreakPoss getNextBreakPoss(LayoutContext context) {
- //LayoutManager curLM; // currently active LM
- OldGridUnit curGridUnit; //currently active grid unit
-
- BreakPoss lastPos = null;
- List breakList = new java.util.ArrayList();
-
- int min = 0;
- int opt = 0;
- int max = 0;
-
- // This is used for the displacement of the individual cells
- int ipdOffset = 0;
-
- int startColumn = 1;
- boolean over = false;
-
- while ((curGridUnit = getCellInfo(startColumn)) != null) {
- Cell cellLM = curGridUnit.layoutManager;
- if (curGridUnit.isColSpan()) {
- //skip spanned slots
- startColumn++;
- continue;
- }
-
- List childBreaks = new ArrayList();
- MinOptMax stackSize = new MinOptMax();
-
- // Set up a LayoutContext
- // the ipd is from the current column
- referenceIPD = context.getRefIPD();
- BreakPoss bp;
-
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(
- MinOptMax.subtract(context.getStackLimit(),
- stackSize));
-
- //Determine which columns this cell will occupy
- List spannedGridUnits = new java.util.ArrayList();
- getGridUnitsForCell(cellLM, startColumn, spannedGridUnits);
- int childRefIPD = 0;
- for (int i = 0; i < spannedGridUnits.size(); i++) {
- Column col = ((OldGridUnit)spannedGridUnits.get(i)).column;
- childRefIPD += col.getWidth().getValue();
- }
- childLC.setRefIPD(childRefIPD);
-
- if (cellLM != null) {
- cellLM.addGridUnitsFromRow(spannedGridUnits);
- cellLM.setInRowIPDOffset(ipdOffset);
- while (!cellLM.isFinished()) {
- if ((bp = cellLM.getNextBreakPoss(childLC)) != null) {
- if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) {
- // reset to last break
- if (lastPos != null) {
- LayoutManager lm = lastPos.getLayoutManager();
- lm.resetPosition(lastPos.getPosition());
- if (lm != cellLM) {
- cellLM.resetPosition(null);
- }
- } else {
- cellLM.resetPosition(null);
- }
- over = true;
- break;
- }
- stackSize.add(bp.getStackingSize());
- lastPos = bp;
- childBreaks.add(bp);
-
- if (bp.nextBreakOverflows()) {
- over = true;
- break;
- }
-
- childLC.setStackLimit(MinOptMax.subtract(
- context.getStackLimit(), stackSize));
- }
- }
- startColumn += cellLM.getFObj().getNumberColumnsSpanned();
- } else {
- //Skipping empty cells
- //log.debug("empty cell at pos " + startColumn);
- startColumn++;
- }
-
- //Adjust in-row x offset for individual cells
- ipdOffset += childRefIPD;
-
-
- // the min is the maximum min of all cells
- if (stackSize.min > min) {
- min = stackSize.min;
- }
- // the optimum is the maximum of all optimums
- if (stackSize.opt > opt) {
- opt = stackSize.opt;
- }
- // the maximum is the largest maximum
- if (stackSize.max > max) {
- max = stackSize.max;
- }
-
- if (childBreaks.size() > 0) {
- breakList.add(childBreaks);
- }
- }
- 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;
- startColumn = 1;
- //Check if any of the cell LMs haven't finished, yet
- while ((curGridUnit = getCellInfo(startColumn)) != null) {
- Cell cellLM = curGridUnit.layoutManager;
- if (cellLM == null) {
- //skip empty cell
- startColumn++;
- continue;
- }
- if (!cellLM.isFinished()) {
- fin = false;
- break;
- }
- startColumn += cellLM.getFObj().getNumberColumnsSpanned();
- }
-
- setFinished(fin);
- RowPosition rp = new RowPosition(this, breakList.size() - 1, breakList);
- BreakPoss breakPoss = new BreakPoss(rp);
- if (over) {
- breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
- }
- breakPoss.setStackingSize(rowSize);
- return breakPoss;
- }
-
- /**
- * Determines the grid units that are spanned by the given cell.
- * @param cellLM table-cell LM
- * @param startCell starting cell index (must be >= 1)
- * @param spannedGridUnits List to receive the applicable grid units
- */
- private void getGridUnitsForCell(Cell cellLM, int startCell, List spannedGridUnits) {
- int count;
- if (cellLM != null) {
- count = cellLM.getFObj().getNumberColumnsSpanned();
- } else {
- count = 1;
- }
- spannedGridUnits.clear();
- for (int i = 0; i < count; i++) {
- spannedGridUnits.add(this.gridUnits.get(startCell + i - 1));
- }
- }
-
- /**
- * Reset the layoutmanager "iterator" so that it will start
- * with the passed Position's generating LM
- * on the next call to getChildLM.
- * @param pos a Position returned by a child layout manager
- * representing a potential break decision.
- * If pos is null, then back up to the first child LM.
- */
- protected void reset(Position pos) {
- //LayoutManager curLM; // currently active LM
- OldGridUnit curGridUnit;
- int cellIndex = 1;
-
- if (pos == null) {
- while ((curGridUnit = getCellInfo(cellIndex)) != null) {
- if (curGridUnit.layoutManager != null) {
- curGridUnit.layoutManager.resetPosition(null);
- }
- cellIndex++;
- }
- } else {
- RowPosition rpos = (RowPosition)pos;
- List breaks = rpos.cellBreaks;
-
- while ((curGridUnit = getCellInfo(cellIndex)) != null) {
- if (curGridUnit.layoutManager != null) {
- List childbreaks = (List)breaks.get(cellIndex);
- curGridUnit.layoutManager.resetPosition(
- (Position)childbreaks.get(childbreaks.size() - 1));
- }
- cellIndex++;
- }
- }
-
- setFinished(false);
- }
-
- /**
- * Set the x position offset of this row.
- * This is used to set the position of the areas returned by this row.
- *
- * @param off the x offset
- */
- public void setXOffset(int off) {
- xoffset = off;
- }
-
- /**
- * Set the y position offset of this row.
- * This is used to set the position of the areas returned by this row.
- *
- * @param off the y offset
- */
- public void setYOffset(int off) {
- yoffset = off;
- }
-
- /**
- * Add the areas for the break points.
- * This sets the offset of each cell as it is added.
- *
- * @param parentIter the position iterator
- * @param layoutContext the layout context for adding areas
- */
- public void addAreas(PositionIterator parentIter,
- LayoutContext layoutContext) {
- getParentArea(null);
- BreakPoss bp1 = (BreakPoss)parentIter.peekNext();
- bBogus = !bp1.generatesAreas();
- if (!isBogus()) {
- getPSLM().addIDToPage(fobj.getId());
- }
-
- Cell childLM;
- int iStartPos = 0;
- LayoutContext lc = new LayoutContext(0);
- while (parentIter.hasNext()) {
- RowPosition lfp = (RowPosition) parentIter.next();
-
- //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.addChildArea(rowArea);
- }
-
- for (Iterator iter = lfp.cellBreaks.iterator(); iter.hasNext();) {
- List cellsbr = (List)iter.next();
- BreakPossPosIter breakPosIter;
- breakPosIter = new BreakPossPosIter(cellsbr, 0, cellsbr.size());
- iStartPos = lfp.getLeafPos() + 1;
-
- while ((childLM = (Cell)breakPosIter.getNextChildLM()) != null) {
- childLM.setXOffset(xoffset);
- childLM.setYOffset(yoffset);
- childLM.setRowHeight(rowHeight);
- childLM.addAreas(breakPosIter, lc);
- }
- }
- }
-
- flush();
- }
-
- /**
- * Get the row height of the row after adjusting.
- * Should only be called after adding the row areas.
- *
- * @return the row height of this row after adjustment
- */
- public int getRowHeight() {
- return rowHeight;
- }
-
- /**
- * Return an Area which can contain the passed childArea. The childArea
- * may not yet have any content, but it has essential traits set.
- * In general, if the LayoutManager already has an Area it simply returns
- * it. Otherwise, it makes a new Area of the appropriate class.
- * It gets a parent area for its area by calling its parent LM.
- * 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 the child area
- * @return the parent are for the child
- */
- public Area getParentArea(Area childArea) {
- return parentLM.getParentArea(childArea);
- }
-
- /**
- * Add the child.
- * Rows return the areas returned by the child elements.
- * This simply adds the area to the parent layout manager.
- *
- * @param childArea the child area
- */
- public void addChildArea(Area childArea) {
- parentLM.addChildArea(childArea);
- }
-
- /**
- * Reset the position of this layout manager.
- *
- * @param resetPos the position to reset to
- */
- public void resetPosition(Position resetPos) {
- if (resetPos == null) {
- reset(null);
- }
- }
-
-
- /**
- * Get the area for this row for background.
- *
- * @return the row area
- */
- 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;
- }
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#negotiateBPDAdjustment(int, org.apache.fop.layoutmgr.KnuthElement)
- */
- public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#discardSpace(org.apache.fop.layoutmgr.KnuthGlue)
- */
- public void discardSpace(KnuthGlue spaceGlue) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepTogether()
- */
- public boolean mustKeepTogether() {
- //TODO Keeps will have to be more sophisticated sooner or later
- return ((BlockLevelLayoutManager)getParent()).mustKeepTogether()
- || !fobj.getKeepTogether().getWithinPage().isAuto()
- || !fobj.getKeepTogether().getWithinColumn().isAuto();
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithPrevious()
- */
- public boolean mustKeepWithPrevious() {
- return !fobj.getKeepWithPrevious().getWithinPage().isAuto()
- || !fobj.getKeepWithPrevious().getWithinColumn().isAuto();
- }
-
- /**
- * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithNext()
- */
- public boolean mustKeepWithNext() {
- return !fobj.getKeepWithNext().getWithinPage().isAuto()
- || !fobj.getKeepWithNext().getWithinColumn().isAuto();
- }
-
-}
-
import org.apache.fop.layoutmgr.KnuthPenalty;
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.NonLeafPosition;
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;
private Table fobj;
private TableContentLayoutManager contentLM;
- private List oldColumns = null;
private ColumnSetup columns = null;
private Block curBlockArea;
- private List bodyBreaks = new java.util.ArrayList();
- private BreakPoss headerBreak;
- private BreakPoss footerBreak;
- private boolean firstRowHandled = false;
-
private int referenceIPD;
private boolean autoLayout = true;
}
/**
- * Set the oldColumns for this table.
- *
- * @param cols the list of column layout managers
+ * @return the column setup for this table.
*/
- public void setColumns(List cols) {
- oldColumns = cols;
- }
-
public ColumnSetup getColumns() {
return this.columns;
}
*/
public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
- Body curLM; // currently active LM
+ //Body curLM; // currently active LM
referenceIPD = context.getRefIPD();
if (fobj.getInlineProgressionDimension().getOptimum().getEnum() != EN_AUTO) {
stackSize.add(spaceBefore);
}
- BreakPoss lastPos = null;
-
fobj.setLayoutDimension(PercentBase.BLOCK_IPD, referenceIPD);
fobj.setLayoutDimension(PercentBase.BLOCK_BPD, context.getStackLimit().opt);
fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, referenceIPD);
fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, context.getStackLimit().opt);
- /*
- if (oldColumns == null) {
- createColumnsFromFirstRow();
- }*/
-
// either works out table of column widths or if proportional-column-width function
// is used works out total factor, so that value of single unit can be computed.
int sumCols = 0;
(contentIPD - sumCols) / factors);
}
}
-
- LinkedList headerElements = null;
- LinkedList footerElements = null;
- if (getTable().getTableHeader() != null) {
- Body tableHeader = new Body(getTable().getTableHeader());
- tableHeader.setParent(this);
- headerElements = getKnuthElementsForHeaderFooter(
- tableHeader, context, alignment);
- }
- if (getTable().getTableFooter() != null) {
- Body tableFooter = new Body(getTable().getTableFooter());
- tableFooter.setParent(this);
- footerElements = getKnuthElementsForHeaderFooter(
- tableFooter, context, alignment);
- }
LinkedList returnedList = null;
LinkedList contentList = new LinkedList();
LinkedList returnList = new LinkedList();
- Position returnPosition = new NonLeafPosition(this, null);
- Body prevLM = null;
+ //Position returnPosition = new NonLeafPosition(this, null);
+ //Body prevLM = null;
LayoutContext childLC = new LayoutContext(0);
childLC.setStackLimit(
return returnList;
} else {
+ /*
if (prevLM != null) {
// there is a block handled by prevLM
// before the one handled by curLM
if (mustKeepTogether()
- /*|| prevLM.mustKeepWithNext()
- || curLM.mustKeepWithPrevious()*/) {
+ || prevLM.mustKeepWithNext()
+ || curLM.mustKeepWithPrevious()) {
// add an infinite penalty to forbid a break between
// blocks
contentList.add(new KnuthPenalty(0,
// it is a feasible breakpoint, there is no need to add
// a penalty
}
- }
+ }*/
contentList.addAll(returnedList);
/*
if (returnedList.size() == 0) {
return returnList;
}
- /**
- * Get the next break possibility.
- * The break possibility depends on the height of the header and footer
- * and possible breaks inside the table body.
- *
- * @param context the layout context for finding breaks
- * @return the next break possibility
- *//*
- public BreakPoss getNextBreakPossOLDOLDOLD(LayoutContext context) {
- Body curLM; // currently active LM
-
- referenceIPD = context.getRefIPD();
- if (fobj.getInlineProgressionDimension().getOptimum().getEnum() != EN_AUTO) {
- referenceIPD = fobj.getInlineProgressionDimension().getOptimum().getLength().getValue();
- }
- if (referenceIPD > context.getRefIPD()) {
- log.warn("Allocated IPD exceeds available reference IPD");
- }
- int contentIPD = referenceIPD - getIPIndents();
-
- MinOptMax stackSize = new MinOptMax();
- //Add spacing
- if (spaceAfter != null) {
- stackSize.add(spaceAfter);
- }
- if (spaceBefore != null) {
- stackSize.add(spaceBefore);
- }
-
- BreakPoss lastPos = null;
-
- fobj.setLayoutDimension(PercentBase.BLOCK_IPD, referenceIPD);
- fobj.setLayoutDimension(PercentBase.BLOCK_BPD, context.getStackLimit().opt);
- fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, referenceIPD);
- fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, context.getStackLimit().opt);
-
- if (columns.getColumnCount() == 0) {
- createColumnsFromFirstRow();
- }
-
- // either works out table of column widths or if proportional-column-width function
- // is used works out total factor, so that value of single unit can be computed.
- int sumCols = 0;
- float factors = 0;
- if (oldColumns != null) {
- for (Iterator i = oldColumns.iterator(); i.hasNext(); ) {
- Column column = (Column) i.next();
- Length width = column.getWidth();
- sumCols += width.getValue();
- if (width instanceof TableColLength) {
- factors += ((TableColLength) width).getTableUnits();
- }
- }
- }
- // sets TABLE_UNITS in case where one or more oldColumns is defined using
- // proportional-column-width
- if (sumCols < contentIPD) {
- if (fobj.getLayoutDimension(PercentBase.TABLE_UNITS).floatValue() == 0.0) {
- fobj.setLayoutDimension(PercentBase.TABLE_UNITS,
- (contentIPD - sumCols) / factors);
- }
- }
-
- boolean headerFooterBuilt = false;
-
- while ((curLM = (Body)getChildLM()) != null) {
- if (!headerFooterBuilt) {
- //Calculate the headers and footers only when needed
- MinOptMax headerSize = null;
- if (getTable().getTableHeader() != null) {
- if (!getTable().omitHeaderAtBreak() || !firstRowHandled) {
- Body tableHeader = new Body(getTable().getTableHeader());
- tableHeader.setParent(this);
- headerBreak = getHeightOLDOLDOLD(tableHeader, context);
- headerSize = headerBreak.getStackingSize();
- stackSize.add(headerSize);
- }
- }
-
- //TODO Implement table-omit-footer-at-break once the page breaking
- //is improved, so we don't have to do this twice
- MinOptMax footerSize = null;
- if (getTable().getTableFooter() != null) {
- Body tableFooter = new Body(getTable().getTableFooter());
- tableFooter.setParent(this);
- footerBreak = getHeightOLDOLDOLD(tableFooter, context);
- footerSize = footerBreak.getStackingSize();
- stackSize.add(footerSize);
- }
-
- if (stackSize.opt > context.getStackLimit().max) {
- BreakPoss breakPoss = new BreakPoss(
- new LeafPosition(this, 0));
- breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
- breakPoss.setStackingSize(stackSize);
- return breakPoss;
- }
- headerFooterBuilt = true;
- }
-
- // Make break positions
- // Set up a LayoutContext
- int ipd = context.getRefIPD();
- BreakPoss bp;
-
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(
- MinOptMax.subtract(context.getStackLimit(),
- stackSize));
- childLC.setRefIPD(ipd);
-
- curLM.setColumns(oldColumns);
-
- boolean over = false;
- while (!curLM.isFinished()) {
- if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
- if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) {
- // reset to last break
- if (lastPos != null) {
- LayoutManager lm = lastPos.getLayoutManager();
- lm.resetPosition(lastPos.getPosition());
- if (lm != curLM) {
- curLM.resetPosition(null);
- }
- } else {
- curLM.resetPosition(null);
- }
- over = true;
- break;
- }
- stackSize.add(bp.getStackingSize());
- lastPos = bp;
- bodyBreaks.add(bp);
- firstRowHandled = true;
-
- if (bp.nextBreakOverflows()) {
- over = true;
- break;
- }
-
- childLC.setStackLimit(MinOptMax.subtract(
- context.getStackLimit(), stackSize));
- }
- }
- BreakPoss breakPoss = new BreakPoss(
- new LeafPosition(this, bodyBreaks.size() - 1));
- if (over) {
- breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
- }
- breakPoss.setStackingSize(stackSize);
- return breakPoss;
- }
- setFinished(true);
- return null;
- }*/
-
- /*
- private void createColumnsFromFirstRow() {
- this.oldColumns = new java.util.ArrayList();
- //TODO Create oldColumns from first row here
- //--> rule 2 in "fixed table layout", see CSS2, 17.5.2
- //Alternative: extend oldColumns on-the-fly, but in this case we need the
- //new property evaluation context so proportional-column-width() works
- //correctly.
- if (oldColumns.size() == 0) {
- Column col = new Column(getTable().getDefaultColumn());
- col.setParent(this);
- this.oldColumns.add(col);
- }
- }*/
-
- /**
- * @param column the column to check
- * @return true if the column is the first column
- */
- public boolean isFirst(Column column) {
- return (this.oldColumns.size() == 0 || this.oldColumns.get(0) == column);
- }
-
- /**
- * @param column the column to check
- * @return true if the column is the last column
- */
- public boolean isLast(Column column) {
- return (this.oldColumns.size() == 0 || this.oldColumns.get(oldColumns.size() - 1) == column);
- }
-
- /**
- * Get the break possibility and height of the table header or footer.
- *
- * @param lm the header or footer layout manager
- * @param context the parent layout context
- * @return the break possibility containing the stacking size
- */
- protected LinkedList getKnuthElementsForHeaderFooter(Body lm, LayoutContext context,
- int alignment) {
- int referenceIPD = context.getRefIPD();
- int contentIPD = referenceIPD - getIPIndents();
- BreakPoss bp;
-
- MinOptMax stackSize = new MinOptMax();
-
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(context.getStackLimit());
- childLC.setRefIPD(contentIPD);
-
- lm.setColumns(oldColumns);
-
- LinkedList returnedList = null;
- LinkedList contentList = new LinkedList();
- LinkedList returnList = new LinkedList();
- Position returnPosition = new NonLeafPosition(this, null);
-
- Row curLM; // currently active LM
- Row prevLM = null; // previously active LM
- while ((curLM = (Row)getChildLM()) != null) {
-
- // get elements from curLM
- returnedList = curLM.getNextKnuthElements(childLC, alignment);
- /*
- if (returnedList.size() == 1
- && ((KnuthElement) returnedList.getFirst()).isPenalty()
- && ((KnuthPenalty) returnedList.getFirst()).getP() == -KnuthElement.INFINITE) {
- // a descendant of this block has break-before
- if (returnList.size() == 0) {
- // the first child (or its first child ...) has
- // break-before;
- // all this block, including space before, will be put in
- // the
- // following page
- bSpaceBeforeServed = false;
- }
- contentList.addAll(returnedList);
-
- // "wrap" the Position inside each element
- // moving the elements from contentList to returnList
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- } else*/ {
- if (prevLM != null) {
- // there is a block handled by prevLM
- // before the one handled by curLM
- if (mustKeepTogether()
- || prevLM.mustKeepWithNext()
- || curLM.mustKeepWithPrevious()) {
- // add an infinite penalty to forbid a break between
- // blocks
- contentList.add(new KnuthPenalty(0,
- KnuthElement.INFINITE, false,
- new Position(this), false));
- } else if (!((KnuthElement) contentList.getLast()).isGlue()) {
- // add a null penalty to allow a break between blocks
- contentList.add(new KnuthPenalty(0, 0, false,
- new Position(this), false));
- } else {
- // the last element in contentList is a glue;
- // it is a feasible breakpoint, there is no need to add
- // a penalty
- }
- }
- contentList.addAll(returnedList);
- if (returnedList.size() == 0) {
- //Avoid NoSuchElementException below (happens with empty blocks)
- continue;
- }
- if (((KnuthElement) returnedList.getLast()).isPenalty()
- && ((KnuthPenalty) returnedList.getLast()).getP() == -KnuthElement.INFINITE) {
- // a descendant of this block has break-after
- if (curLM.isFinished()) {
- // there is no other content in this block;
- // it's useless to add space after before a page break
- setFinished(true);
- }
-
- returnedList = new LinkedList();
- wrapPositionElements(contentList, returnList);
-
- return returnList;
- }
- }
- prevLM = curLM;
- }
-
- /*
- List breaks = new java.util.ArrayList();
- while (!lm.isFinished()) {
- if ((bp = lm.getNextBreakPoss(childLC)) != null) {
- stackSize.add(bp.getStackingSize());
- breaks.add(bp);
- childLC.setStackLimit(MinOptMax.subtract(
- context.getStackLimit(), stackSize));
- }
- }
- BreakPoss breakPoss = new BreakPoss(
- new SectionPosition(this, breaks.size() - 1, breaks));
- breakPoss.setStackingSize(stackSize);
- return breakPoss;*/
-
- if (returnList.size() > 0) {
- return returnList;
- } else {
- return null;
- }
-
- }
-
- /**
- * Get the break possibility and height of the table header or footer.
- *
- * @param lm the header or footer layout manager
- * @param context the parent layout context
- * @return the break possibility containing the stacking size
- */
- protected BreakPoss getHeightOLDOLDOLD(Body lm, LayoutContext context) {
- int referenceIPD = context.getRefIPD();
- int contentIPD = referenceIPD - getIPIndents();
- BreakPoss bp;
-
- MinOptMax stackSize = new MinOptMax();
-
- LayoutContext childLC = new LayoutContext(0);
- childLC.setStackLimit(context.getStackLimit());
- childLC.setRefIPD(contentIPD);
-
- lm.setColumns(oldColumns);
-
- List breaks = new java.util.ArrayList();
- while (!lm.isFinished()) {
- if ((bp = lm.getNextBreakPoss(childLC)) != null) {
- stackSize.add(bp.getStackingSize());
- breaks.add(bp);
- childLC.setStackLimit(MinOptMax.subtract(
- context.getStackLimit(), stackSize));
- }
- }
- BreakPoss breakPoss = new BreakPoss(
- new SectionPosition(this, breaks.size() - 1, breaks));
- breakPoss.setStackingSize(stackSize);
- return breakPoss;
- }
-
/**
* The table area is a reference area that contains areas for
* oldColumns, bodies, rows and the contents are in cells.
// add column, body then row areas
int tableHeight = 0;
- Body childLM;
+ //Body childLM;
LayoutContext lc = new LayoutContext(0);
- // add table header areas
- if (headerBreak != null) {
- SectionPosition pos = (SectionPosition)headerBreak.getPosition();
- List list = pos.list;
- PositionIterator breakPosIter = new BreakPossPosIter(list, 0, list.size() + 1);
- while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) {
- childLM.setXOffset(startXOffset);
- childLM.addAreas(breakPosIter, lc);
- tableHeight += childLM.getBodyHeight();
- }
- }
lc.setRefIPD(referenceIPD - getIPIndents());
contentLM.setStartXOffset(startXOffset);
contentLM.addAreas(parentIter, lc);
tableHeight += contentLM.getUsedBPD();
- // add footer areas
- if (footerBreak != null) {
- SectionPosition pos = (SectionPosition)footerBreak.getPosition();
- List list = pos.list;
- PositionIterator breakPosIter = new BreakPossPosIter(list, 0, list.size() + 1);
- while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) {
- childLM.setXOffset(startXOffset);
- childLM.setYOffset(tableHeight);
- childLM.addAreas(breakPosIter, lc);
- tableHeight += childLM.getBodyHeight();
- }
- }
-
curBlockArea.setBPD(tableHeight);
if (fobj.isSeparateBorderModel()) {
// if adjusted space after
addBlockSpacing(adjust, spaceAfter);
- bodyBreaks.clear();
+ //bodyBreaks.clear();
curBlockArea = null;
}