From 6123b54cc992f5136102aeef9227d7a9a7d2571c Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 31 Jan 2005 21:16:45 +0000 Subject: [PATCH] Border, Padding and spaces on level fo:table. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198352 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/flow/Table.java | 57 +++++++++---- .../fop/layoutmgr/LayoutManagerMapping.java | 4 +- .../org/apache/fop/layoutmgr/table/Body.java | 14 +++- .../org/apache/fop/layoutmgr/table/Row.java | 21 ++++- .../layoutmgr/table/TableLayoutManager.java | 84 +++++++++++++++---- 5 files changed, 141 insertions(+), 39 deletions(-) diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index 150739d75..3b9d6b81e 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.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. @@ -18,13 +18,9 @@ package org.apache.fop.fo.flow; -// Java -import java.util.ArrayList; import java.util.List; -import java.util.ListIterator; import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; @@ -36,9 +32,6 @@ import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.LengthPairProperty; import org.apache.fop.fo.properties.LengthRangeProperty; -import org.apache.fop.layoutmgr.table.Body; -import org.apache.fop.layoutmgr.table.Column; -import org.apache.fop.layoutmgr.table.TableLayoutManager; /** * Class modelling the fo:table object. @@ -62,21 +55,21 @@ public class Table extends FObj { private String id; private LengthRangeProperty inlineProgressionDimension; private int intrusionDisplace; - private Length height; + //private Length height; private KeepProperty keepTogether; private KeepProperty keepWithNext; private KeepProperty keepWithPrevious; private int tableLayout; private int tableOmitFooterAtBreak; private int tableOmitHeaderAtBreak; - private Length width; + //private Length width; private int writingMode; // End of property values private static final int MINCOLWIDTH = 10000; // 10pt /** collection of columns in this table */ - protected ArrayList columns = null; + protected List columns = null; private TableBody tableHeader = null; private TableBody tableFooter = null; @@ -108,14 +101,14 @@ public class Table extends FObj { id = pList.get(PR_ID).getString(); inlineProgressionDimension = pList.get(PR_INLINE_PROGRESSION_DIMENSION).getLengthRange(); intrusionDisplace = pList.get(PR_INTRUSION_DISPLACE).getEnum(); - height = pList.get(PR_HEIGHT).getLength(); + //height = pList.get(PR_HEIGHT).getLength(); keepTogether = pList.get(PR_KEEP_TOGETHER).getKeep(); keepWithNext = pList.get(PR_KEEP_WITH_NEXT).getKeep(); keepWithPrevious = pList.get(PR_KEEP_WITH_PREVIOUS).getKeep(); tableLayout = pList.get(PR_TABLE_LAYOUT).getEnum(); tableOmitFooterAtBreak = pList.get(PR_TABLE_OMIT_FOOTER_AT_BREAK).getEnum(); tableOmitHeaderAtBreak = pList.get(PR_TABLE_OMIT_HEADER_AT_BREAK).getEnum(); - width = pList.get(PR_WIDTH).getLength(); + //width = pList.get(PR_WIDTH).getLength(); writingMode = pList.get(PR_WRITING_MODE).getEnum(); } @@ -140,7 +133,7 @@ public class Table extends FObj { protected void addChildNode(FONode child) throws FOPException { if (child.getName().equals("fo:table-column")) { if (columns == null) { - columns = new ArrayList(); + columns = new java.util.ArrayList(); } columns.add(((TableColumn)child)); } else if (child.getName().equals("fo:table-footer")) { @@ -153,7 +146,7 @@ public class Table extends FObj { } } - public ArrayList getColumns() { + public List getColumns() { return columns; } @@ -166,21 +159,49 @@ public class Table extends FObj { } /** - * Return the Common Margin Properties-Block. + * @return the "inline-progression-dimension" property. + */ + public LengthRangeProperty getInlineProgressionDimension() { + return inlineProgressionDimension; + } + + /** + * @return the "block-progression-dimension" property. + */ + public LengthRangeProperty getBlockProgressionDimension() { + return blockProgressionDimension; + } + + /** + * @return the Common Margin Properties-Block. */ public CommonMarginBlock getCommonMarginBlock() { return commonMarginBlock; } /** - * Return the Common Border, Padding, and Background Properties. + * @return the Common Border, Padding, and Background Properties. */ public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { return commonBorderPaddingBackground; } /** - * Return the "id" property. + * @return the "break-after" property. + */ + public int getBreakAfter() { + return breakAfter; + } + + /** + * @return the "break-before" property. + */ + public int getBreakBefore() { + return breakBefore; + } + + /** + * @return the "id" property. */ public String getId() { return id; diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java index 4a6f002fb..43c613b40 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2004 The Apache Software Foundation. + * Copyright 2004-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. @@ -320,7 +320,7 @@ public class LayoutManagerMapping implements LayoutManagerMaker { public void make(FONode node, List lms) { Table table = (Table) node; TableLayoutManager tlm = new TableLayoutManager(table); - ArrayList columns = table.getColumns(); + List columns = table.getColumns(); if (columns != null) { ArrayList columnLMs = new ArrayList(); ListIterator iter = columns.listIterator(); diff --git a/src/java/org/apache/fop/layoutmgr/table/Body.java b/src/java/org/apache/fop/layoutmgr/table/Body.java index 6833bd336..d52bbc37b 100644 --- a/src/java/org/apache/fop/layoutmgr/table/Body.java +++ b/src/java/org/apache/fop/layoutmgr/table/Body.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. @@ -46,6 +46,7 @@ public class Body extends BlockStackingLayoutManager { private boolean rows = true; private List columns; + private int xoffset; private int yoffset; private int bodyHeight; @@ -147,6 +148,15 @@ public class Body extends BlockStackingLayoutManager { return null; } + /** + * Set the x offset of this body within the table. + * This is used to set the row offsets. + * @param value + */ + 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. @@ -181,6 +191,7 @@ public class Body extends BlockStackingLayoutManager { 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(); @@ -256,5 +267,6 @@ public class Body extends BlockStackingLayoutManager { TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); return curBlockArea; } + } diff --git a/src/java/org/apache/fop/layoutmgr/table/Row.java b/src/java/org/apache/fop/layoutmgr/table/Row.java index 0aa01c446..49562329f 100644 --- a/src/java/org/apache/fop/layoutmgr/table/Row.java +++ b/src/java/org/apache/fop/layoutmgr/table/Row.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. @@ -49,6 +49,7 @@ public class Row extends BlockStackingLayoutManager { private List cellList = null; private List columns = null; private int rowHeight; + private int xoffset; private int yoffset; private class RowPosition extends LeafPosition { @@ -247,6 +248,16 @@ public class Row extends BlockStackingLayoutManager { 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. @@ -277,7 +288,8 @@ public class Row extends BlockStackingLayoutManager { // Add the block areas to Area int cellcount = 0; - int xoffset = 0; + int x = this.xoffset; + //int x = (TableLayoutManager)getParent()).; for (Iterator iter = lfp.cellBreaks.iterator(); iter.hasNext();) { List cellsbr = (List)iter.next(); PositionIterator breakPosIter; @@ -294,12 +306,12 @@ public class Row extends BlockStackingLayoutManager { } while ((childLM = (Cell)breakPosIter.getNextChildLM()) != null) { - childLM.setXOffset(xoffset); + childLM.setXOffset(x); childLM.setYOffset(yoffset); childLM.setRowHeight(rowHeight); childLM.addAreas(breakPosIter, lc); } - xoffset += col.getWidth().getValue(); + x += col.getWidth().getValue(); } } @@ -367,5 +379,6 @@ public class Row extends BlockStackingLayoutManager { TraitSetter.addBackground(block, fobj.getCommonBorderPaddingBackground()); return block; } + } diff --git a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java index af299f39a..a0dbf5e08 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.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. @@ -34,6 +34,7 @@ import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.area.Area; import org.apache.fop.area.Block; import org.apache.fop.traits.MinOptMax; +import org.apache.fop.traits.SpaceVal; import java.util.ArrayList; import java.util.Iterator; @@ -59,7 +60,14 @@ public class TableLayoutManager extends BlockStackingLayoutManager { private List bodyBreaks = new ArrayList(); private BreakPoss headerBreak; private BreakPoss footerBreak; + + private int referenceIPD; + //TODO space-before|after: handle space-resolution rules + private MinOptMax spaceBefore; + private MinOptMax spaceAfter; + + private class SectionPosition extends LeafPosition { protected List list; protected SectionPosition(LayoutManager lm, int pos, List l) { @@ -106,6 +114,20 @@ public class TableLayoutManager extends BlockStackingLayoutManager { tableFooter.setParent(this); } + /** @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() */ + protected void initProperties() { + super.initProperties(); + spaceBefore = new SpaceVal(fobj.getCommonMarginBlock().spaceBefore).getSpace(); + spaceAfter = new SpaceVal(fobj.getCommonMarginBlock().spaceAfter).getSpace(); + } + + private int getIPIndents() { + int iIndents = 0; + iIndents += fobj.getCommonMarginBlock().startIndent.getValue(); + iIndents += fobj.getCommonMarginBlock().endIndent.getValue(); + return iIndents; + } + /** * Get the next break possibility. * The break possibility depends on the height of the header and footer @@ -117,14 +139,29 @@ public class TableLayoutManager extends BlockStackingLayoutManager { public BreakPoss getNextBreakPoss(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(); - // if starting add space before - // stackSize.add(spaceBefore); + //Add spacing + if (spaceAfter != null) { + stackSize.add(spaceAfter); + } + if (spaceBefore != null) { + stackSize.add(spaceBefore); + } + BreakPoss lastPos = null; - fobj.setLayoutDimension(PercentBase.BLOCK_IPD, context.getRefIPD()); + fobj.setLayoutDimension(PercentBase.BLOCK_IPD, referenceIPD); fobj.setLayoutDimension(PercentBase.BLOCK_BPD, context.getStackLimit().opt); - fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, context.getRefIPD()); + fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, referenceIPD); fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, context.getStackLimit().opt); // either works out table of column widths or if proportional-column-width function @@ -142,10 +179,10 @@ public class TableLayoutManager extends BlockStackingLayoutManager { } } // sets TABLE_UNITS in case where one or more columns is defined using proportional-column-width - if (sumCols < context.getRefIPD()) { + if (sumCols < contentIPD) { if (fobj.getLayoutDimension(PercentBase.TABLE_UNITS).floatValue() == 0.0) { fobj.setLayoutDimension(PercentBase.TABLE_UNITS, - (context.getRefIPD() - sumCols) / factors); + (contentIPD - sumCols) / factors); } } MinOptMax headerSize = null; @@ -236,14 +273,15 @@ public class TableLayoutManager extends BlockStackingLayoutManager { * @return the break possibility containing the stacking size */ protected BreakPoss getHeight(Body lm, LayoutContext context) { - int ipd = context.getRefIPD(); + 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(ipd); + childLC.setRefIPD(contentIPD); lm.setColumns(columns); @@ -274,6 +312,11 @@ public class TableLayoutManager extends BlockStackingLayoutManager { getParentArea(null); addID(fobj.getId()); + // if adjusted space before + double adjust = layoutContext.getSpaceAdjust(); + addBlockSpacing(adjust, spaceBefore); + spaceBefore = null; + // add column, body then row areas int tableHeight = 0; @@ -286,6 +329,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { List list = pos.list; PositionIterator breakPosIter = new BreakPossPosIter(list, 0, list.size() + 1); while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) { + childLM.setXOffset(fobj.getCommonMarginBlock().startIndent.getValue()); childLM.addAreas(breakPosIter, lc); tableHeight += childLM.getBodyHeight(); } @@ -300,6 +344,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { lfp.getLeafPos() + 1); iStartPos = lfp.getLeafPos() + 1; while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) { + childLM.setXOffset(fobj.getCommonMarginBlock().startIndent.getValue()); childLM.setYOffset(tableHeight); childLM.addAreas(breakPosIter, lc); tableHeight += childLM.getBodyHeight(); @@ -312,6 +357,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager { List list = pos.list; PositionIterator breakPosIter = new BreakPossPosIter(list, 0, list.size() + 1); while ((childLM = (Body)breakPosIter.getNextChildLM()) != null) { + childLM.setXOffset(fobj.getCommonMarginBlock().startIndent.getValue()); childLM.setYOffset(tableHeight); childLM.addAreas(breakPosIter, lc); tableHeight += childLM.getBodyHeight(); @@ -322,9 +368,17 @@ public class TableLayoutManager extends BlockStackingLayoutManager { TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground()); TraitSetter.addBackground(curBlockArea, fobj.getCommonBorderPaddingBackground()); + TraitSetter.addMargins(curBlockArea, + fobj.getCommonBorderPaddingBackground(), + fobj.getCommonMarginBlock()); + TraitSetter.addBreaks(curBlockArea, + fobj.getBreakBefore(), fobj.getBreakAfter()); flush(); + // if adjusted space after + addBlockSpacing(adjust, spaceAfter); + bodyBreaks.clear(); curBlockArea = null; } @@ -347,11 +401,12 @@ public class TableLayoutManager extends BlockStackingLayoutManager { curBlockArea = new Block(); // Set up dimensions // Must get dimensions from parent area - Area parentArea = parentLM.getParentArea(curBlockArea); - int referenceIPD = parentArea.getIPD(); - curBlockArea.setIPD(referenceIPD); - // Get reference IPD from parentArea - setCurrentArea(curBlockArea); // ??? for generic operations + /*Area parentArea =*/ parentLM.getParentArea(curBlockArea); + + int contentIPD = referenceIPD - getIPIndents(); + curBlockArea.setIPD(contentIPD); + + setCurrentArea(curBlockArea); } return curBlockArea; } @@ -377,5 +432,6 @@ public class TableLayoutManager extends BlockStackingLayoutManager { reset(null); } } + } -- 2.39.5