gmazza 2005/03/26 13:40:07
Modified: src/java/org/apache/fop/layoutmgr Tag:
Temp_KnuthStylePageBreaking
PageSequenceLayoutManager.java
src/java/org/apache/fop/area Tag:
Temp_KnuthStylePageBreaking NormalFlow.java
Span.java
Log:
Moved creation of normal flow areas to area.Span.
Revision Changes Path
No revision
No revision
1.50.2.6 +23 -37
xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
Index: PageSequenceLayoutManager.java
===================================================================
RCS file:
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java,v
retrieving revision 1.50.2.5
retrieving revision 1.50.2.6
diff -u -r1.50.2.5 -r1.50.2.6
--- PageSequenceLayoutManager.java 21 Mar 2005 12:41:34 -0000 1.50.2.5
+++ PageSequenceLayoutManager.java 26 Mar 2005 21:40:06 -0000 1.50.2.6
@@ -25,7 +25,6 @@
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;
@@ -87,8 +86,8 @@
/** 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;
@@ -170,7 +169,7 @@
makeNewPage(false, false);
isFirstPage = true;
- flowIPD = curFlow.getIPD();
+ flowIPD = curSpan.getNormalFlow(curFlowIdx).getIPD();
PageBreaker breaker = new PageBreaker(this);
breaker.doLayout(flowBPD);
@@ -230,8 +229,8 @@
//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());
}
@@ -467,34 +466,28 @@
}
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) {
@@ -512,13 +505,10 @@
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());
@@ -549,12 +539,10 @@
lm.reset(null);
}
-
-
private void finishPage() {
if (curPage == null) {
curSpan = null;
- curFlow = null;
+ curFlowIdx = -1;
return;
}
// Layout side regions
@@ -567,7 +555,7 @@
log.debug("page finished: " + curPage.getPageNumberString() + ",
current num: " + currentPageNum);
curPage = null;
curSpan = null;
- curFlow = null;
+ curFlowIdx = -1;
}
private void prepareNormalFlowArea(Area childArea) {
@@ -613,9 +601,7 @@
bNeedNewSpan = true;
}
if (bNeedNewSpan) {
- createSpan(curPage.getBodyRegion(), (span == Constants.EN_ALL));
- } else if (curFlow == null) { // should not happen
- curFlow = curSpan.addAdditionalNormalFlow();
+ createSpan(numColsNeeded);
}
}
@@ -633,7 +619,7 @@
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);
@@ -668,9 +654,9 @@
*/
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
No revision
No revision
1.1.2.1 +4 -2 xml-fop/src/java/org/apache/fop/area/NormalFlow.java
Index: NormalFlow.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/NormalFlow.java,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- NormalFlow.java 11 Mar 2005 07:23:43 -0000 1.1
+++ NormalFlow.java 26 Mar 2005 21:40:06 -0000 1.1.2.1
@@ -26,9 +26,11 @@
public class NormalFlow extends BlockParent {
/**
* Constructor.
+ * @param ipd of Normal flow object
*/
- public NormalFlow() {
+ public NormalFlow(int ipd) {
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
+ setIPD(ipd);
}
}
1.6.2.2 +27 -42 xml-fop/src/java/org/apache/fop/area/Span.java
Index: Span.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/Span.java,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -u -r1.6.2.1 -r1.6.2.2
--- Span.java 20 Mar 2005 12:46:11 -0000 1.6.2.1
+++ Span.java 26 Mar 2005 21:40:06 -0000 1.6.2.2
@@ -32,36 +32,36 @@
// 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;
}
/**
@@ -70,16 +70,7 @@
* @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;
}
/**
@@ -94,23 +85,17 @@
/**
* 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());
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]