package org.apache.fop.area;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fo.pagination.RegionBody;
/**
- * This class is a container for all areas that may be generated by
+ * This class is a container for the areas that may be generated by
* an fo:region-body. It extends the RegionReference that is used
* directly by the other region classes.
* See fo:region-body definition in the XSL Rec for more information.
private int columnGap;
private int columnCount;
- /**
- * Create a new body region area.
- * This sets the region reference area class to BODY.
- */
- public BodyRegion() {
- super(Constants.FO_REGION_BODY);
- addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
- mainReference = new MainReference(this);
- }
-
/**
* Constructor which can read traits directly
* from an fo:region-body formatting object.
*/
- public BodyRegion(RegionBody rb) {
- this();
- columnCount = rb.getColumnCount();
- columnGap = rb.getColumnGap();
- if ((columnCount > 1) && (rb.getOverflow() == Constants.EN_SCROLL)) {
- // recover by setting 'column-count' to 1. This is allowed but
- // not required by the spec.
- log.error("Setting 'column-count' to 1 because "
- + "'overflow' is set to 'scroll'");
- columnCount = 1;
- }
+ public BodyRegion(int columnCount, int columnGap, RegionViewport parent) {
+ super(Constants.FO_REGION_BODY, parent);
+ this.columnCount = columnCount;
+ this.columnGap = columnGap;
+ mainReference = new MainReference(this);
}
/**
* @return a shallow copy of this object
*/
public Object clone() {
- BodyRegion br = new BodyRegion();
+ BodyRegion br = new BodyRegion(columnCount, columnGap, regionViewport);
br.setCTM(getCTM());
br.setIPD(getIPD());
- br.columnGap = columnGap;
- br.columnCount = columnCount;
br.beforeFloat = beforeFloat;
br.mainReference = mainReference;
br.footnote = footnote;
*
* @param span the span area to add
*/
- public void addSpan(Span span) {
- spanAreas.add(span);
+ public Span createSpan(boolean spanAll) {
+ RegionViewport rv = parent.getRegionViewport();
+ int ipdWidth = (int) parent.getIPD() -
+ rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
+
+ Span newSpan = new Span(((spanAll) ? 1 : getColumnCount()),
+ getColumnGap(), ipdWidth);
+ spanAreas.add(newSpan);
+ return getCurrentSpan();
}
/**
return spanAreas;
}
+ /**
+ * Get the span area currently being filled (i.e., the last span created)
+ *
+ * @return the active span
+ */
+ public Span getCurrentSpan() {
+ return (Span) spanAreas.get(spanAreas.size()-1);
+ }
+
/**
* indicates whether any child areas have been added to this reference area
* this is achieved by looping through each span
return true;
}
else {
- BodyRegion body = (BodyRegion)regionBody.getRegion();
+ BodyRegion body = (BodyRegion)regionBody.getRegionReference();
return body.isEmpty();
}
}
* @return BodyRegion object
*/
public BodyRegion getBodyRegion() {
- return (BodyRegion)
- getPage().getRegionViewport(Constants.FO_REGION_BODY).getRegion();
+ 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);
}
/**
import org.apache.fop.fo.Constants;
/**
- * This is a region reference area for the page regions.
- * This area represents a region on the page. It is cloneable
+ * This is a region reference area for a page regions.
+ * This area is the direct child of a region-viewport-area. It is cloneable
* so the page master can make copies from the original page and regions.
*/
public class RegionReference extends Area implements Cloneable {
private int regionClass = Constants.FO_REGION_BEFORE;
private CTM ctm;
+ private int bpd;
+
// the list of block areas from the static flow
private List blocks = new ArrayList();
-
- private int bpd;
+
+ // the parent RegionViewport for this object
+ protected RegionViewport regionViewport;
/**
* Create a new region reference area.
*
* @param type the region class type
*/
- public RegionReference(int type) {
+ public RegionReference(int type, RegionViewport parent) {
regionClass = type;
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
+ regionViewport = parent;
}
/**
public void setCTM(CTM ctm) {
this.ctm = ctm;
}
+
+ /**
+ * @return Returns the parent RegionViewport.
+ */
+ public RegionViewport getRegionViewport() {
+ return regionViewport;
+ }
/**
* Get the current transform of this region.
* @return a copy of this region reference area
*/
public Object clone() {
- RegionReference rr = new RegionReference(regionClass);
+ RegionReference rr = new RegionReference(regionClass, regionViewport);
rr.ctm = ctm;
rr.setIPD(getIPD());
return rr;
import java.util.HashMap;
/**
- * Region Viewport reference area.
- * This area is the viewport for a region and contains a region area.
+ * Region Viewport area.
+ * This object represents the region-viewport-area. It has a
+ * region-reference-area as its child. These areas are described
+ * in the fo:region-body description in the XSL Recommendation.
*/
public class RegionViewport extends Area implements Cloneable {
// this rectangle is relative to the page
- private RegionReference region;
+ private RegionReference regionReference;
private Rectangle2D viewArea;
private boolean clip = false;
/**
- * Create a new region viewport.
+ * Create a new region-viewport-area
*
* @param viewArea the view area of this viewport
*/
}
/**
- * Set the region for this region viewport.
+ * Set the region-reference-area for this region viewport.
*
- * @param reg the child region inside this viewport
+ * @param reg the child region-reference-area inside this viewport
*/
- public void setRegion(RegionReference reg) {
- region = reg;
+ public void setRegionReference(RegionReference reg) {
+ regionReference = reg;
}
/**
- * Get the region for this region viewport.
+ * Get the region-reference-area for this region viewport.
*
- * @return the child region inside this viewport
+ * @return the child region-reference-area inside this viewport
*/
- public RegionReference getRegion() {
- return region;
+ public RegionReference getRegionReference() {
+ return regionReference;
}
/**
out.writeFloat((float) viewArea.getHeight());
out.writeBoolean(clip);
out.writeObject(props);
- out.writeObject(region);
+ out.writeObject(regionReference);
}
private void readObject(java.io.ObjectInputStream in)
in.readFloat(), in.readFloat());
clip = in.readBoolean();
props = (HashMap)in.readObject();
- setRegion((RegionReference) in.readObject());
+ setRegionReference((RegionReference) in.readObject());
}
/**
*/
public Object clone() {
RegionViewport rv = new RegionViewport((Rectangle2D)viewArea.clone());
- rv.region = (RegionReference)region.clone();
+ rv.regionReference = (RegionReference)regionReference.clone();
if (props != null) {
rv.props = (HashMap)props.clone();
}
return height;
}
+
/**
* Get the normal flow area for a particular column.
*
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.Numeric;
+import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.properties.CommonMarginBlock;
commonMarginBlock = pList.getMarginBlockProps();
columnCount = pList.get(PR_COLUMN_COUNT).getNumeric();
columnGap = pList.get(PR_COLUMN_GAP).getLength();
+
+ if ((getColumnCount() > 1) && (getOverflow() == EN_SCROLL)) {
+ /* This is an error (See XSL Rec, fo:region-body description).
+ * The Rec allows for acting as if "1" is chosen in
+ * these cases, but we will need to be able to change Numeric
+ * values in order to do this.
+ */
+ attributeError("If overflow property is set to \"scroll\"," +
+ " a column-count other than \"1\" may not be specified.");
+ }
}
/**
//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 < curSpan.getColumnCount()) {
+ if (curFlowIdx < curSpan.getColumnCount()-1) {
curFlowIdx++;
} else {
handleBreak(list.getStartOn());
}
flowBPD = (int) curPage.getBodyRegion().getBPD();
- createSpan(curPage.getBodyRegion().getColumnCount());
- return curPage;
- }
-
- /**
- * Creates a new span reference area.
- * @param numCols number of columns needed for new span
- */
- 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
- curSpan = new Span(numCols, bodyRegion.getColumnGap(), ipdWidth);
-
- //curSpan.setPosition(BPD, newpos);
- curPage.getBodyRegion().getMainReference().addSpan(curSpan);
+ curSpan = curPage.createSpan(false);
curFlowIdx = 0;
+ return curPage;
}
private void layoutSideRegion(int regionID) {
+ "for flow " + sc.getFlowName());
}
lm.initialize();
- lm.setRegionReference(rv.getRegion());
+ lm.setRegionReference(rv.getRegionReference());
lm.setParent(this);
/*
LayoutContext childLC = new LayoutContext(0);
childLC.setRefIPD(rv.getRegion().getIPD());
*/
- MinOptMax range = new MinOptMax(rv.getRegion().getIPD());
+ MinOptMax range = new MinOptMax(rv.getRegionReference().getIPD());
lm.doLayout(reg, lm, range);
bNeedNewSpan = true;
}
if (bNeedNewSpan) {
- createSpan(numColsNeeded);
+ curSpan = curPage.createSpan(span == Constants.EN_ALL);
+ curFlowIdx = 0;
}
}
r.setLayoutDimension(PercentBase.BLOCK_IPD, rvp.getIPD());
r.setLayoutDimension(PercentBase.BLOCK_BPD, rvp.getBPD());
if (r.getNameId() == FO_REGION_BODY) {
- rr = new BodyRegion((RegionBody) r);
+ RegionBody rb = (RegionBody) r;
+ rr = new BodyRegion(rb.getColumnCount(), rb.getColumnGap(),
+ rvp);
} else {
- rr = new RegionReference(r.getNameId());
+ rr = new RegionReference(r.getNameId(), rvp);
}
- setRegionPosition(r, rr, rvp.getViewArea());
- rvp.setRegion(rr);
+ setRegionReferencePosition(rr, r, rvp.getViewArea());
+ rvp.setRegionReference(rr);
page.setRegionViewport(r.getNameId(), rvp);
}
}
/**
- * Set the region position inside the region viewport.
+ * Set the region reference position within the region viewport.
* This sets the transform that is used to place the contents of
- * the region.
+ * the region reference.
*
- * @param r the region reference area
+ * @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 setRegionPosition(Region r, RegionReference rr,
+ private void setRegionReferencePosition(RegionReference rr, Region r,
Rectangle2D absRegVPRect) {
FODimension reldims = new FODimension(0, 0);
rr.setCTM(CTM.getCTMandRelDims(r.getReferenceOrientation(),
currentBPPosition = 0;
currentIPPosition = 0;
- RegionReference region = port.getRegion();
+ RegionReference regionReference = port.getRegionReference();
handleRegionTraits(port);
// shouldn't the viewport have the CTM
- startVParea(region.getCTM());
+ startVParea(regionReference.getCTM());
// do after starting viewport area
- if (region.getRegionClass() == FO_REGION_BODY) {
- renderBodyRegion((BodyRegion) region);
+ if (regionReference.getRegionClass() == FO_REGION_BODY) {
+ renderBodyRegion((BodyRegion) regionReference);
} else {
- renderRegion(region);
+ renderRegion(regionReference);
}
endVParea();
}
float width = (float)(viewArea.getWidth() / 1000f);
float height = (float)(viewArea.getHeight() / 1000f);
- if (region.getRegion().getRegionClass() == FO_REGION_BODY) {
+ if (region.getRegionReference().getRegionClass() == FO_REGION_BODY) {
currentBPPosition = region.getBorderAndPaddingWidthBefore();
currentIPPosition = region.getBorderAndPaddingWidthStart();
}
addTraitAttributes(port);
addAttribute("rect", port.getViewArea());
startElement("regionViewport", atts);
- RegionReference region = port.getRegion();
+ RegionReference region = port.getRegionReference();
atts.clear();
addAreaAttributes(region);
addTraitAttributes(region);