From: Glen Mazza Date: Thu, 14 Apr 2005 00:17:06 +0000 (+0000) Subject: 1.) Moved RegionViewport & Reference creation code from PageViewport to Page(Reference). X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f8518111fd8d962b557472abf87d071e1ce97cd2;p=xmlgraphics-fop.git 1.) Moved RegionViewport & Reference creation code from PageViewport to Page(Reference). 2.) Created new .getColumnWidth() in Span to facilitate its querying in layout code. 3.) Removed unneeded retrieveMarker() method in FLM and never-used addMarker method from SCLM (validation prevents this from occurring) 4.) Removed duplicate flowBPD and flowIPD variables from PSLM (this information is already available in the Area classes) 5.) Removed inaccurate setLayoutDimension() code from PSLM; added the current code in FLM to SCLM in this regard git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_KnuthStylePageBreaking@198582 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/area/Page.java b/src/java/org/apache/fop/area/Page.java index 56294f3b6..858c0722d 100644 --- a/src/java/org/apache/fop/area/Page.java +++ b/src/java/org/apache/fop/area/Page.java @@ -18,10 +18,20 @@ package org.apache.fop.area; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.HashMap; +import java.util.Iterator; +import org.apache.fop.datatypes.FODimension; +import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.Constants; +import org.apache.fop.fo.pagination.Region; +import org.apache.fop.fo.pagination.RegionBody; +import org.apache.fop.fo.pagination.SimplePageMaster; +import org.apache.fop.fo.properties.CommonMarginBlock; +import org.apache.fop.layoutmgr.TraitSetter; /** * The page. @@ -45,13 +55,109 @@ public class Page implements Serializable, Cloneable { // temporary map of unresolved objects used when serializing the page private HashMap unresolved = null; + /** + * Empty constructor, for cloning + */ + public Page() { + } + + /** + * Constructor + * @param spm SimplePageMaster containing the dimensions for this + * page-reference-area + */ + public Page(SimplePageMaster spm) { + int pageWidth = spm.getPageWidth().getValue(); + int pageHeight = spm.getPageHeight().getValue(); + + // Get absolute margin properties (top, left, bottom, right) + CommonMarginBlock mProps = spm.getCommonMarginBlock(); + + /* + * Create the page reference area rectangle (0,0 is at top left + * of the "page media" and y increases + * when moving towards the bottom of the page. + * The media rectangle itself is (0,0,pageWidth,pageHeight). + */ + Rectangle pageRefRect = + new Rectangle(mProps.marginLeft.getValue(), mProps.marginTop.getValue(), + pageWidth - mProps.marginLeft.getValue() - mProps.marginRight.getValue(), + pageHeight - mProps.marginTop.getValue() - mProps.marginBottom.getValue()); + + // Set up the CTM on the page reference area based on writing-mode + // and reference-orientation + FODimension reldims = new FODimension(0, 0); + CTM pageCTM = CTM.getCTMandRelDims(spm.getReferenceOrientation(), + spm.getWritingMode(), pageRefRect, reldims); + + // Create a RegionViewport/ reference area pair for each page region + RegionReference rr = null; + for (Iterator regenum = spm.getRegions().values().iterator(); + regenum.hasNext();) { + Region r = (Region)regenum.next(); + RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM); + r.setLayoutDimension(PercentBase.BLOCK_IPD, rvp.getIPD()); + r.setLayoutDimension(PercentBase.BLOCK_BPD, rvp.getBPD()); + if (r.getNameId() == Constants.FO_REGION_BODY) { + RegionBody rb = (RegionBody) r; + rr = new BodyRegion(rb.getColumnCount(), rb.getColumnGap(), + rvp); + } else { + rr = new RegionReference(r.getNameId(), rvp); + } + setRegionReferencePosition(rr, r, rvp.getViewArea()); + rvp.setRegionReference(rr); + setRegionViewport(r.getNameId(), rvp); + } + } + + /** + * Creates a RegionViewport Area object for this pagination Region. + * @param reldims relative dimensions + * @param pageCTM page coordinate transformation matrix + * @return the new region viewport + */ + private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) { + Rectangle2D relRegionRect = r.getViewportRectangle(reldims); + Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); + // Get the region viewport rectangle in absolute coords by + // transforming it using the page CTM + RegionViewport rv = new RegionViewport(absRegionRect); + rv.setBPD((int)relRegionRect.getHeight()); + rv.setIPD((int)relRegionRect.getWidth()); + TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground()); + rv.setClip(r.getOverflow() == Constants.EN_HIDDEN + || r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); + return rv; + } + + /** + * Set the region reference position within the region viewport. + * This sets the transform that is used to place the contents of + * the region reference. + * + * @param rr the region reference area + * @param r the region-xxx formatting object + * @param absRegVPRect The region viewport rectangle in "absolute" coordinates + * where x=distance from left, y=distance from bottom, width=right-left + * height=top-bottom + */ + private void setRegionReferencePosition(RegionReference rr, Region r, + Rectangle2D absRegVPRect) { + FODimension reldims = new FODimension(0, 0); + rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), + r.getWritingMode(), absRegVPRect, reldims)); + rr.setIPD(reldims.ipd); + rr.setBPD(reldims.bpd); + } + /** * Set the region on this page. * * @param areaclass the area class of the region to set * @param port the region viewport to set */ - public void setRegionViewport(int areaclass, RegionViewport port) { + private void setRegionViewport(int areaclass, RegionViewport port) { if (areaclass == Constants.FO_REGION_BEFORE) { regionBefore = port; } else if (areaclass == Constants.FO_REGION_START) { diff --git a/src/java/org/apache/fop/area/PageViewport.java b/src/java/org/apache/fop/area/PageViewport.java index 15381f6f3..948b1c7c3 100644 --- a/src/java/org/apache/fop/area/PageViewport.java +++ b/src/java/org/apache/fop/area/PageViewport.java @@ -31,14 +31,8 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.datatypes.FODimension; -import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.Constants; -import org.apache.fop.fo.pagination.Region; -import org.apache.fop.fo.pagination.RegionBody; import org.apache.fop.fo.pagination.SimplePageMaster; -import org.apache.fop.fo.properties.CommonMarginBlock; -import org.apache.fop.layoutmgr.TraitSetter; /** * Page viewport that specifies the viewport area and holds the page contents. @@ -85,7 +79,10 @@ public class PageViewport implements Resolvable, Cloneable { */ public PageViewport(SimplePageMaster spm) { this.spm = spm; - createPageAreas(); + int pageWidth = spm.getPageWidth().getValue(); + int pageHeight = spm.getPageHeight().getValue(); + viewArea = new Rectangle(0, 0, pageWidth, pageHeight); + page = new Page(spm); } /** @@ -454,92 +451,4 @@ public class PageViewport implements Resolvable, Cloneable { public SimplePageMaster getSPM() { return spm; } - - private void createPageAreas() { - int pageWidth = spm.getPageWidth().getValue(); - int pageHeight = spm.getPageHeight().getValue(); - - // Get absolute margin properties (top, left, bottom, right) - CommonMarginBlock mProps = spm.getCommonMarginBlock(); - - /* Create the page reference area rectangle (0,0 is at top left - * of the "page media" and y increases - * when moving towards the bottom of the page. - * The media rectangle itself is (0,0,pageWidth,pageHeight). - */ - Rectangle pageRefRect = - new Rectangle(mProps.marginLeft.getValue(), mProps.marginTop.getValue(), - pageWidth - mProps.marginLeft.getValue() - mProps.marginRight.getValue(), - pageHeight - mProps.marginTop.getValue() - mProps.marginBottom.getValue()); - - page = new Page(); // page reference area - - // Set up the CTM on the page reference area based on writing-mode - // and reference-orientation - FODimension reldims = new FODimension(0, 0); - CTM pageCTM = CTM.getCTMandRelDims(spm.getReferenceOrientation(), - spm.getWritingMode(), pageRefRect, reldims); - - // Create a RegionViewport/ reference area pair for each page region - RegionReference rr = null; - for (Iterator regenum = spm.getRegions().values().iterator(); - regenum.hasNext();) { - Region r = (Region)regenum.next(); - RegionViewport rvp = makeRegionViewport(r, reldims, pageCTM); - r.setLayoutDimension(PercentBase.BLOCK_IPD, rvp.getIPD()); - r.setLayoutDimension(PercentBase.BLOCK_BPD, rvp.getBPD()); - if (r.getNameId() == Constants.FO_REGION_BODY) { - RegionBody rb = (RegionBody) r; - rr = new BodyRegion(rb.getColumnCount(), rb.getColumnGap(), - rvp); - } else { - rr = new RegionReference(r.getNameId(), rvp); - } - setRegionReferencePosition(rr, r, rvp.getViewArea()); - rvp.setRegionReference(rr); - page.setRegionViewport(r.getNameId(), rvp); - } - - viewArea = new Rectangle(0, 0, pageWidth, pageHeight); - } - - /** - * Creates a RegionViewport Area object for this pagination Region. - * @param reldims relative dimensions - * @param pageCTM page coordinate transformation matrix - * @return the new region viewport - */ - private RegionViewport makeRegionViewport(Region r, FODimension reldims, CTM pageCTM) { - Rectangle2D relRegionRect = r.getViewportRectangle(reldims); - Rectangle2D absRegionRect = pageCTM.transform(relRegionRect); - // Get the region viewport rectangle in absolute coords by - // transforming it using the page CTM - RegionViewport rv = new RegionViewport(absRegionRect); - rv.setBPD((int)relRegionRect.getHeight()); - rv.setIPD((int)relRegionRect.getWidth()); - TraitSetter.addBackground(rv, r.getCommonBorderPaddingBackground()); - rv.setClip(r.getOverflow() == Constants.EN_HIDDEN - || r.getOverflow() == Constants.EN_ERROR_IF_OVERFLOW); - return rv; - } - - /** - * Set the region reference position within the region viewport. - * This sets the transform that is used to place the contents of - * the region reference. - * - * @param rr the region reference area - * @param r the region-xxx formatting object - * @param absRegVPRect The region viewport rectangle in "absolute" coordinates - * where x=distance from left, y=distance from bottom, width=right-left - * height=top-bottom - */ - private void setRegionReferencePosition(RegionReference rr, Region r, - Rectangle2D absRegVPRect) { - FODimension reldims = new FODimension(0, 0); - rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(), - r.getWritingMode(), absRegVPRect, reldims)); - rr.setIPD(reldims.ipd); - rr.setBPD(reldims.bpd); - } } \ 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 19e6bcabf..e080ea599 100644 --- a/src/java/org/apache/fop/area/Span.java +++ b/src/java/org/apache/fop/area/Span.java @@ -34,6 +34,7 @@ public class Span extends Area { private int height; private int colCount; private int colGap; + private int colWidth; // width for each normal flow, calculated value /** * Create a span area with the number of columns for this span area. @@ -54,9 +55,9 @@ public class Span extends Area { * Create the normal flows for this Span */ private void createNormalFlows() { - flowAreas = new java.util.ArrayList(colCount); - - int colWidth = (ipd - ((colCount - 1) * colGap)) / colCount; + flowAreas = new java.util.ArrayList(colCount); + colWidth = (ipd - ((colCount - 1) * colGap)) / colCount; + for (int i=0; i< colCount; i++) { NormalFlow newFlow = new NormalFlow(colWidth); newFlow.setIPD(getIPD()); @@ -73,6 +74,15 @@ public class Span extends Area { return colCount; } + /** + * Get the width of a single column within this Span + * + * @return the width of a single column + */ + public int getColumnWidth() { + return colWidth; + } + /** * Get the height of this span area. * diff --git a/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java index fceb1c9e0..7a8386dd2 100644 --- a/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -19,7 +19,6 @@ package org.apache.fop.layoutmgr; import org.apache.fop.datatypes.PercentBase; -import org.apache.fop.fo.flow.Marker; import org.apache.fop.fo.pagination.Flow; import org.apache.fop.area.Area; import org.apache.fop.area.BlockParent; @@ -440,17 +439,5 @@ public class FlowLayoutManager extends BlockStackingLayoutManager reset(null); } } - - /** - * Retrieve marker is not allowed in the flow so this reports an - * error and returns null. - * - * @see org.apache.fop.layoutmgr.LayoutManager - */ - public Marker retrieveMarker(String name, int pos, int boundary) { - // error cannot retrieve markers in flow - log.error("Cannot retrieve a marker from the flow"); - return null; - } } diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index ad88b662b..8f6c9a903 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -71,9 +71,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { /** Zero-based index of column (Normal Flow) in span being filled. */ private int curFlowIdx = -1; - private int flowBPD = 0; - private int flowIPD = 0; - /** * AreaTreeHandler which activates this PSLM. */ @@ -141,9 +138,9 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { log.debug("Starting layout"); makeNewPage(false, true, false); - flowIPD = curPage.getCurrentSpan().getNormalFlow(curFlowIdx).getIPD(); PageBreaker breaker = new PageBreaker(this); + int flowBPD = (int) curPage.getBodyRegion().getBPD(); breaker.doLayout(flowBPD); finishPage(); @@ -163,6 +160,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { protected LayoutContext createLayoutContext() { LayoutContext lc = new LayoutContext(0); + int flowIPD = curPage.getCurrentSpan().getColumnWidth(); lc.setRefIPD(flowIPD); return lc; } @@ -254,6 +252,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { childLC.setRefIPD(context.getRefIPD()); if (!curLM.isFinished()) { + int flowIPD = curPage.getCurrentSpan().getColumnWidth(); + int flowBPD = (int) curPage.getBodyRegion().getBPD(); pageSeq.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, flowIPD); pageSeq.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, flowBPD); /*LF*/ returnedList = curLM.getNextKnuthElements(childLC, alignment); @@ -410,12 +410,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { SimplePageMaster spm = pageSeq.getSimplePageMasterToUse( currentPageNum, bIsFirst, bIsBlank); - // Unsure if these four lines are needed - int pageWidth = spm.getPageWidth().getValue(); - int pageHeight = spm.getPageHeight().getValue(); - pageSeq.getRoot().setLayoutDimension(PercentBase.BLOCK_IPD, pageWidth); - pageSeq.getRoot().setLayoutDimension(PercentBase.BLOCK_BPD, pageHeight); - Region body = spm.getRegion(FO_REGION_BODY); if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) { // this is fine by the XSL Rec (fo:flow's flow-name can be mapped to @@ -435,7 +429,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { log.debug("[" + curPage.getPageNumberString() + (bIsBlank ? "*" : "") + "]"); } - flowBPD = (int) curPage.getBodyRegion().getBPD(); curPage.createSpan(false); curFlowIdx = 0; return curPage; diff --git a/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java index 8fdc7b248..5b07501c8 100644 --- a/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java @@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.area.RegionReference; import org.apache.fop.area.Area; import org.apache.fop.area.Block; +import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.pagination.Region; import org.apache.fop.fo.pagination.SideRegion; import org.apache.fop.fo.pagination.StaticContent; @@ -30,7 +31,6 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; -import java.util.Map; /** * LayoutManager for an fo:flow object. @@ -64,6 +64,10 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { * @see org.apache.fop.layoutmgr.LayoutManager#getNextKnuthElements(org.apache.fop.layoutmgr.LayoutContext, int) */ public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { + // set layout dimensions + fobj.setLayoutDimension(PercentBase.BLOCK_IPD, context.getRefIPD()); + fobj.setLayoutDimension(PercentBase.BLOCK_BPD, context.getStackLimit().opt); + //TODO Copied from elsewhere. May be worthwhile to factor out the common parts. // currently active LM BlockLevelLayoutManager curLM; @@ -222,17 +226,6 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { return region; } - /** - * Markers are not allowed in static areas so this reports an - * error and does nothing. - * - * @see org.apache.fop.layoutmgr.LayoutManager - */ - public void addMarker(Map marks, boolean start, boolean isfirst) { - // error markers not allowed in static - log.error("Cannot add marker to static areas"); - } - public void doLayout(SideRegion region, StaticContentLayoutManager lm, MinOptMax ipd) { StaticContentBreaker breaker = new StaticContentBreaker(region, lm, ipd); breaker.doLayout(lm.getRegionReference().getBPD()); @@ -322,8 +315,6 @@ public class StaticContentLayoutManager extends BlockStackingLayoutManager { return null; //TODO NYI } - } - - + } }