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.
// 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) {
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.
*/
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);
}
/**
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
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.
* 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());
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.
*
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;
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;
- }
}
/** 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.
*/
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();
protected LayoutContext createLayoutContext() {
LayoutContext lc = new LayoutContext(0);
+ int flowIPD = curPage.getCurrentSpan().getColumnWidth();
lc.setRefIPD(flowIPD);
return lc;
}
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);
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
log.debug("[" + curPage.getPageNumberString() + (bIsBlank ? "*" : "") + "]");
}
- flowBPD = (int) curPage.getBodyRegion().getBPD();
curPage.createSpan(false);
curFlowIdx = 0;
return curPage;
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;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import java.util.Map;
/**
* LayoutManager for an fo:flow object.
* @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;
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());
return null; //TODO NYI
}
- }
-
-
+ }
}