// the list of flow reference areas in this span area
private List flowAreas;
private int height;
- private int columnCount;
+ private int colCount;
+ private int colGap;
/**
* Create a span area with the number of columns for this span area.
*
- * @param cols the number of columns in the span
- * @param ipd the ipd of the span
+ * @param colCount the number of columns in the span
+ * @param colGap the column gap between each column
+ * @param ipd the total ipd of the span
*/
- public Span(int cols, int ipd) {
+ public Span(int colCount, int colGap, int ipd) {
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
- columnCount = cols;
+ this.colCount = colCount;
+ this.colGap = colGap;
this.ipd = ipd;
- flowAreas = new java.util.ArrayList(cols);
- addAdditionalNormalFlow(); // one normal flow is required
+ createNormalFlows();
}
/**
- * Create a new normal flow and add it to this span area
- *
- * @return the newly made NormalFlow object
+ * Create the normal flows for this Span
*/
- public NormalFlow addAdditionalNormalFlow() {
- if (!hasMoreAvailableFlows()) { // internal error
- throw new IllegalStateException("Maximum number of flow areas (" +
- columnCount + ") for this span reached.");
+ private void createNormalFlows() {
+ flowAreas = new java.util.ArrayList(colCount);
+
+ int colWidth = (ipd - ((colCount - 1) * colGap)) / colCount;
+ for (int i=0; i< colCount; i++) {
+ NormalFlow newFlow = new NormalFlow(colWidth);
+ newFlow.setIPD(getIPD());
+ flowAreas.add(newFlow);
}
- NormalFlow newFlow = new NormalFlow();
- newFlow.setIPD(getIPD());
- flowAreas.add(newFlow);
- return newFlow;
}
/**
* @return the number of columns defined for this span area
*/
public int getColumnCount() {
- return columnCount;
- }
-
- /**
- * Get the count of normal flows for this span area.
- *
- * @return the number of normal flows attached to this span
- */
- public int getNormalFlowCount() {
- return flowAreas.size();
+ return colCount;
}
/**
/**
* Get the normal flow area for a particular column.
*
- * @param count the column number for the flow
+ * @param colRequested the zero-based column number of the flow
* @return the flow area for the requested column
*/
- public NormalFlow getNormalFlow(int columnNumber) {
- if (columnNumber < flowAreas.size()) {
- return (NormalFlow) flowAreas.get(columnNumber);
- } else {
- return null;
+ public NormalFlow getNormalFlow(int colRequested) {
+ if (colRequested >= 0 && colRequested < colCount) {
+ return (NormalFlow) flowAreas.get(colRequested);
+ } else { // internal error
+ throw new IllegalArgumentException("Invalid column number " +
+ colRequested + " requested; only 0-" + (colCount-1) +
+ " available.");
}
}
-
- /**
- * @return true if this span can provide additional flow areas.
- */
- public boolean hasMoreAvailableFlows() {
- return (getNormalFlowCount() < getColumnCount());
- }
-
}
import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.Area;
import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.NormalFlow;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.Page;
import org.apache.fop.area.RegionViewport;
/** Current span being filled */
private Span curSpan;
- /** Current normal-flow-reference-area being filled. */
- private NormalFlow curFlow;
+ /** Zero-based index of column (Normal Flow) in span being filled. */
+ private int curFlowIdx = -1;
private int flowBPD = 0;
private int flowIPD = 0;
makeNewPage(false, false);
isFirstPage = true;
- flowIPD = curFlow.getIPD();
+ flowIPD = curSpan.getNormalFlow(curFlowIdx).getIPD();
PageBreaker breaker = new PageBreaker(this);
breaker.doLayout(flowBPD);
//algorithm so we have a BPD and IPD. This may subject to change later when we
//start handling more complex cases.
if (!firstPart) {
- if (curSpan.hasMoreAvailableFlows()) {
- curFlow = curSpan.addAdditionalNormalFlow();
+ if (curFlowIdx < curSpan.getColumnCount()) {
+ curFlowIdx++;
} else {
handleBreak(list.getStartOn());
}
}
flowBPD = (int) curPage.getBodyRegion().getBPD();
- createSpan(curPage.getBodyRegion(), false);
+ createSpan(curPage.getBodyRegion().getColumnCount());
return curPage;
}
/**
* Creates a new span reference area.
- * @param bodyRegion The region-body to create the span for
- * @param spanned true if a spanned region should be created
+ * @param numCols number of columns needed for new span
*/
- private void createSpan(BodyRegion bodyRegion, boolean spanned) {
+ private void createSpan(int numCols) {
// get Width or Height as IPD for span
+ BodyRegion bodyRegion = curPage.getBodyRegion();
+
RegionViewport rv = curPage.getPage().getRegionViewport(FO_REGION_BODY);
int ipdWidth = (int) rv.getRegion().getIPD() -
rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
//TODO currently hardcoding to one column, replace with numCols when ready
- if (spanned) {
- curSpan = new Span(1, ipdWidth);
- } else {
- int colWidth
- = (ipdWidth - (bodyRegion.getColumnCount() - 1) * bodyRegion.getColumnGap())
- / bodyRegion.getColumnCount();
- curSpan = new Span(bodyRegion.getColumnCount(), colWidth);
- }
+ curSpan = new Span(numCols, bodyRegion.getColumnGap(), ipdWidth);
//curSpan.setPosition(BPD, newpos);
curPage.getBodyRegion().getMainReference().addSpan(curSpan);
- curFlow = curSpan.getNormalFlow(0);
+ curFlowIdx = 0;
}
private void layoutSideRegion(int regionID) {
try {
lm = (StaticContentLayoutManager)
areaTreeHandler.getLayoutManagerMaker().makeLayoutManager(sc);
- } catch (FOPException e) {
- log.error
- ("Failed to create a StaticContentLayoutManager for flow "
- + sc.getFlowName()
- + "; no static content will be laid out:");
- log.error(e.getMessage());
- return;
+ } catch (FOPException e) { // severe error
+ throw new IllegalStateException(
+ "Internal error: Failed to create a StaticContentLayoutManager "
+ + "for flow " + sc.getFlowName());
}
lm.initialize();
lm.setRegionReference(rv.getRegion());
lm.reset(null);
}
-
-
private void finishPage() {
if (curPage == null) {
curSpan = null;
- curFlow = null;
+ curFlowIdx = -1;
return;
}
// Layout side regions
log.debug("page finished: " + curPage.getPageNumberString() + ", current num: " + currentPageNum);
curPage = null;
curSpan = null;
- curFlow = null;
+ curFlowIdx = -1;
}
private void prepareNormalFlowArea(Area childArea) {
bNeedNewSpan = true;
}
if (bNeedNewSpan) {
- createSpan(curPage.getBodyRegion(), (span == Constants.EN_ALL));
- } else if (curFlow == null) { // should not happen
- curFlow = curSpan.addAdditionalNormalFlow();
+ createSpan(numColsNeeded);
}
}
if (aclass == Area.CLASS_NORMAL) {
//We now do this in PageBreaker
//prepareNormalFlowArea(childArea);
- return curFlow;
+ return curSpan.getNormalFlow(curFlowIdx);
} else {
if (curPage == null) {
makeNewPage(false, false);
*/
private void handleBreak(int breakVal) {
if (breakVal == Constants.EN_COLUMN) {
- if (curSpan != null && curSpan.hasMoreAvailableFlows()) {
+ if (curSpan != null && curFlowIdx < curSpan.getColumnCount()) {
// Move to next column
- curFlow = curSpan.addAdditionalNormalFlow();
+ curFlowIdx++;
return;
}
// else need new page