From 39229973d4a042d3302a2d0cf50489fe01cdb09d Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sat, 14 May 2005 16:41:45 +0000 Subject: [PATCH] Placed the PSLM.curFlowIdx within the area.Span object, and added a few more convenience accessors to PV. This will give us a little more flexibility in which LM's we place functionality. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198629 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/area/MainReference.java | 2 +- .../org/apache/fop/area/PageViewport.java | 97 +++++++++++-------- src/java/org/apache/fop/area/Span.java | 39 +++++++- .../layoutmgr/PageSequenceLayoutManager.java | 25 ++--- 4 files changed, 102 insertions(+), 61 deletions(-) diff --git a/src/java/org/apache/fop/area/MainReference.java b/src/java/org/apache/fop/area/MainReference.java index 85a5d7ec1..52660b61d 100644 --- a/src/java/org/apache/fop/area/MainReference.java +++ b/src/java/org/apache/fop/area/MainReference.java @@ -45,7 +45,7 @@ public class MainReference extends Area { /** * Add a span area to this area. * - * @param span the span area to add + * @param spanAll whether to make a single-column span */ public Span createSpan(boolean spanAll) { RegionViewport rv = parent.getRegionViewport(); diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index d3e9c6bc0..c27f24b43 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -77,10 +77,11 @@ public class PageViewport implements Resolvable, Cloneable { * Create a page viewport. * @param spm SimplePageMaster indicating the page and region dimensions */ - public PageViewport(SimplePageMaster spm) { + public PageViewport(SimplePageMaster spm, String pageStr) { this.spm = spm; int pageWidth = spm.getPageWidth().getValue(); int pageHeight = spm.getPageHeight().getValue(); + pageNumberString = pageStr; viewArea = new Rectangle(0, 0, pageWidth, pageHeight); page = new Page(spm); } @@ -91,42 +92,13 @@ public class PageViewport implements Resolvable, Cloneable { * @param p Page Reference Area * @param bounds Page Viewport dimensions */ - public PageViewport(SimplePageMaster spm, Page p, Rectangle2D bounds) { + public PageViewport(SimplePageMaster spm, String pageStr, Page p, Rectangle2D bounds) { this.spm = spm; + this.pageNumberString = pageStr; this.page = p; this.viewArea = bounds; } - /** - * Convenience method to get BodyRegion of this PageViewport - * @return BodyRegion object - */ - public BodyRegion getBodyRegion() { - return (BodyRegion) getPage().getRegionViewport( - Constants.FO_REGION_BODY).getRegionReference(); - } - - /** - * Convenience method to create a new Span for this - * this PageViewport. - * - * @param spanAll whether this is a single-column span - * @return Span object created - */ - public Span createSpan(boolean spanAll) { - return getBodyRegion().getMainReference().createSpan(spanAll); - } - - /** - * Convenience method to get the span-reference-area currently - * being processed - * - * @return span currently being processed. - */ - public Span getCurrentSpan() { - return getBodyRegion().getMainReference().getCurrentSpan(); - } - /** * Set if this viewport should clip. * @param c true if this viewport should clip @@ -151,14 +123,6 @@ public class PageViewport implements Resolvable, Cloneable { return page; } - /** - * Set the page number for this page. - * @param num the string representing the page number - */ - public void setPageNumberString(String num) { - pageNumberString = num; - } - /** * Get the page number of this page. * @return the string that represents this page @@ -428,7 +392,8 @@ public class PageViewport implements Resolvable, Cloneable { */ public Object clone() { Page p = (Page)page.clone(); - PageViewport ret = new PageViewport(spm, p, (Rectangle2D)viewArea.clone()); + PageViewport ret = new PageViewport(spm, pageNumberString, + p, (Rectangle2D)viewArea.clone()); return ret; } @@ -456,4 +421,54 @@ public class PageViewport implements Resolvable, Cloneable { public SimplePageMaster getSPM() { return spm; } + + /** + * Convenience method to get BodyRegion of this PageViewport + * @return BodyRegion object + */ + public BodyRegion getBodyRegion() { + return (BodyRegion) getPage().getRegionViewport( + Constants.FO_REGION_BODY).getRegionReference(); + } + + /** + * Convenience method to create a new Span for this + * this PageViewport. + * + * @param spanAll whether this is a single-column span + * @return Span object created + */ + public Span createSpan(boolean spanAll) { + return getBodyRegion().getMainReference().createSpan(spanAll); + } + + /** + * Convenience method to get the span-reference-area currently + * being processed + * + * @return span currently being processed. + */ + public Span getCurrentSpan() { + return getBodyRegion().getMainReference().getCurrentSpan(); + } + + /** + * Convenience method to get the normal-flow-reference-area + * currently being processed + * + * @return span currently being processed. + */ + public NormalFlow getCurrentFlow() { + return getCurrentSpan().getCurrentFlow(); + } + + /** + * Convenience method to increment the Span to the + * next NormalFlow to be processed, and to return that flow. + * + * @return the next NormalFlow in the Span. + */ + public NormalFlow moveToNextFlow() { + return getCurrentSpan().moveToNextFlow(); + } } \ No newline at end of file diff --git a/src/java/org/apache/fop/area/Span.java b/src/java/org/apache/fop/area/Span.java index e080ea599..626719d07 100644 --- a/src/java/org/apache/fop/area/Span.java +++ b/src/java/org/apache/fop/area/Span.java @@ -35,7 +35,8 @@ public class Span extends Area { private int colCount; private int colGap; private int colWidth; // width for each normal flow, calculated value - + private int curFlowIdx; // n-f-r-a currently being processed, zero-based + /** * Create a span area with the number of columns for this span area. * @@ -48,6 +49,7 @@ public class Span extends Area { this.colCount = colCount; this.colGap = colGap; this.ipd = ipd; + curFlowIdx = 0; createNormalFlows(); } @@ -108,5 +110,40 @@ public class Span extends Area { " available."); } } + + /** + * Get the NormalFlow area currently being processed + * + * @return the current NormalFlow + */ + public NormalFlow getCurrentFlow() { + return getNormalFlow(curFlowIdx); + } + + /** + * Indicate to the Span that the next column is being + * processed. + * + * @return the new NormalFlow (in the next column) + */ + public NormalFlow moveToNextFlow() { + if (hasMoreFlows()) { + curFlowIdx++; + return getNormalFlow(curFlowIdx); + } else { + throw new IllegalStateException("(Internal error.)" + + " No more flows left in span."); + } + } + + /** + * Indicates if the Span has unprocessed flows. + * + * @return true if Span can increment to the next flow, + * false otherwise. + */ + public boolean hasMoreFlows() { + return (curFlowIdx < colCount-1); + } } diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index cde2e9097..ad9ccab69 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -67,13 +67,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { */ private PageViewport curPV = null; - /** - * Zero-based index of column (Normal Flow) in span (of the PV) - * being filled. See XSL Rec description of fo:region-body - * and fop.Area package classes for more information. - */ - private int curFlowIdx = -1; - /** * The FlowLayoutManager object, which processes * the single fo:flow of the fo:page-sequence @@ -191,8 +184,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { //algorithm so we have a BPD and IPD. This may subject to change later when we //start handling more complex cases. if (!firstPart) { - if (curFlowIdx < curPV.getCurrentSpan().getColumnCount()-1) { - curFlowIdx++; + if (curPV.getCurrentSpan().hasMoreFlows()) { + curPV.getCurrentSpan().moveToNextFlow(); } else { // if this is the first page that will be created by // the current BlockSequence, it could have a break @@ -408,18 +401,16 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { + spm.getMasterName() + "'. FOP presently " + "does not support this."); } - curPV = new PageViewport(spm); + curPV = new PageViewport(spm, pageNumberString); } catch (FOPException fopex) { throw new IllegalArgumentException("Cannot create page: " + fopex.getMessage()); } - curPV.setPageNumberString(pageNumberString); if (log.isDebugEnabled()) { log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" : "") + "]"); } curPV.createSpan(false); - curFlowIdx = 0; return curPV; } @@ -457,7 +448,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { log.debug("page finished: " + curPV.getPageNumberString() + ", current num: " + currentPageNum); curPV = null; - curFlowIdx = -1; } /** @@ -473,7 +463,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { int aclass = childArea.getAreaClass(); if (aclass == Area.CLASS_NORMAL) { - return curPV.getCurrentSpan().getNormalFlow(curFlowIdx); + return curPV.getCurrentFlow(); } else if (aclass == Area.CLASS_BEFORE_FLOAT) { return curPV.getBodyRegion().getBeforeFloat(); } else if (aclass == Area.CLASS_FOOTNOTE) { @@ -484,16 +474,15 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { } /** - * Depending on the kind of break condition, make new column + * Depending on the kind of break condition, move to next column * or page. May need to make an empty page if next page would * not have the desired "handedness". * @param breakVal - value of break-before or break-after trait. */ private void handleBreakTrait(int breakVal) { if (breakVal == Constants.EN_COLUMN) { - if (curFlowIdx < curPV.getCurrentSpan().getColumnCount()) { - // Move to next column - curFlowIdx++; + if (curPV.getCurrentSpan().hasMoreFlows()) { + curPV.getCurrentSpan().moveToNextFlow(); } else { curPV = makeNewPage(false, false, false); } -- 2.39.5