package org.apache.fop.area;
import java.io.Serializable;
+import org.apache.fop.fo.FObj;
// If the area appears more than once in the output
// or if the area has external data it is cached
public static final int ORIENT_180 = 2;
public static final int ORIENT_270 = 3;
+ // area class values
+ public static final int CLASS_NORMAL = 0;
+ public static final int CLASS_FIXED = 1;
+ public static final int CLASS_ABSOLUTE = 2;
+ public static final int CLASS_BEFORE_FLOAT = 3;
+ public static final int CLASS_FOOTNOTE = 4;
+ public static final int CLASS_SIDE_FLOAT = 5;
+ // IMPORTANT: make sure this is the maximum + 1
+ public static final int CLASS_MAX = CLASS_SIDE_FLOAT+1;
+
+ private int areaClass=CLASS_NORMAL;
+ private FObj genFObj;
+
+ protected Area parent =null; // Doesn't need to be saved in serialization
+
+ public int getAreaClass() {
+ return areaClass;
+ }
+
+ public void setAreaClass(int areaClass) {
+ this.areaClass = areaClass;
+ }
+
+ /**
+ * Return a length range describing the minimum, optimum and maximum
+ * lengths available for content in the block-progression-direction.
+ * This is calculated from the theoretical maximum size of the area
+ * and its current content.
+ */
+ public MinOptMax getAvailBPD() {
+ return MinOptMax.subtract(getMaxBPD(), getContentBPD());
+ }
+
+ /**
+ * Return a length range describing the theoretical maximum size of an
+ * area in the block-progression-direction.
+ * For areas holding normal flowing or floating content in paged media,
+ * this depends on the size of the body. In general the answer is the
+ * gotten from the parent. At the body level, the calculation accounts
+ * for the sizes of the conditional areas.
+ */
+ public MinOptMax getMaxBPD() {
+ if (parent != null) {
+ return parent.getMaxBPD();
+ }
+ else return new MinOptMax();
+ }
+
+ /**
+ * Return a length range describing the minimum, optimum and maximum
+ * lengths of all area content in the block-progression-direction.
+ * This is based on the allocation rectangles of all content in
+ * the area.
+ */
+ public MinOptMax getContentBPD() {
+ return new MinOptMax();
+ }
+
+ /**
+ * Return a length range describing the minimum, optimum and maximum
+ * lengths of the area's allocation rectangle
+ * in the block-progression-direction.
+ * This is based on the allocation rectangles of all content in
+ * the area.
+ * The default implementation simply returns the same as the content BPD.
+ * If an Area has before or after border and padding, these contribute
+ * to the allocation BPD, depending on conditionality.
+ */
+ public MinOptMax getAllocationBPD() {
+ return getContentBPD();
+ }
+
+ public void setParent(Area parent) {
+ this.parent = parent;
+ }
+
+ public void setGeneratingFObj(FObj fobj) {
+ this.genFObj = fobj;
+ }
+
+ public FObj getGeneratingFObj() {
+ return this.genFObj;
+ }
}
import java.util.List;
import java.util.ArrayList;
-public class BeforeFloat extends Area {
+public class BeforeFloat extends BlockParent {
// this is an optional block area that will be rendered
// as the separator only if there are float areas
Block separator = null;
int h = 0;
return h;
}
+
+ public MinOptMax getMaxBPD() {
+ MinOptMax maxbpd = parent.getMaxBPD();
+ BodyRegion body = (BodyRegion)parent;
+ Area a = body.getMainReference();
+ if (a != null) {
+ maxbpd = MinOptMax.subtract(maxbpd, a.getContentBPD());
+ }
+ if ((a=body.getFootnote()) != null) {
+ maxbpd = MinOptMax.subtract(maxbpd, a.getContentBPD());
+ }
+ return maxbpd;
+ }
+
}
// or by relative to the parent for floats, tables and lists
// cacheable object
// has id information
-public class Block extends Area implements Serializable {
+public class Block extends BlockParent implements Serializable {
// normally stacked with other blocks
public static final int STACK = 0;
// placed relative to the parent area
// placed relative to the page or viewport
public static final int ABSOLUTE = 2;
- // this position is used for absolute position
- // or as an indent
- // this has the size in the block progression dimension
- Rectangle2D bounds = null;
-
int stacking = TB;
// list of marker fo objects that are associated with this area
// available markers, markers are discarded once page complete
private ArrayList markers = null;
- ArrayList children = null;
boolean blocks = false;
// a block with may contain the dominant styling info in
// terms of most lines or blocks with info
int positioning = STACK;
- // orientation if reference area
- int orientation = ORIENT_0;
public void addBlock(Block block) {
if (children == null) {
return blocks;
}
- public List getChildAreas() {
- return children;
- }
-
public int getPositioning() {
return positioning;
}
package org.apache.fop.area;
-public class BodyRegion extends Region {
+import java.awt.geom.Rectangle2D;
+
+public class BodyRegion extends RegionReference {
BeforeFloat beforeFloat;
MainReference mainReference;
Footnote footnote;
+ /** Maximum block progression dimension. Note: min=opt=max */
+ private MinOptMax maxBPD;
+
+ /** Referenc inline progression dimension for the body. */
+ private int refIPD;
+
public BodyRegion() {
super(BODY);
}
+ public void setParent(Area area) {
+ super.setParent(area);
+ // Only if not scrolling or overflow !!!
+ Rectangle2D refRect = ((RegionViewport)area).getViewArea();
+ maxBPD = new MinOptMax((int)refRect.getHeight());
+ refIPD = (int)refRect.getWidth();
+ }
+
public void setBeforeFloat(BeforeFloat bf) {
beforeFloat = bf;
+ beforeFloat.setParent(this);
}
public void setMainReference(MainReference mr) {
mainReference = mr;
+ mainReference.setParent(this);
}
public void setFootnote(Footnote foot) {
footnote = foot;
+ footnote.setParent(this);
}
public Footnote getFootnote() {
return footnote;
}
+
+ public MinOptMax getMaxBPD() {
+ return maxBPD;
+ }
}
// this is a normal flow reference area
// it containts a list of block areas from the flow
-public class Flow extends Area {
+public class Flow extends BlockParent {
// the list of blocks created from the flow
ArrayList blocks = new ArrayList();
int stacking = TB;
return blocks;
}
+ /**
+ * Maximum block progression dimension for a Flow is
+ * the same as that of its parent Span.
+ */
+ public MinOptMax getMaxBPD() {
+ return parent.getMaxBPD();
+ }
+
+
}
import java.util.ArrayList;
// may combine with before float into a conditional area
-public class Footnote implements Serializable {
+public class Footnote extends BlockParent {
Block separator = null;
// footnote has an optional separator
public List getBlocks() {
return blocks;
}
+
+ public MinOptMax getMaxBPD() {
+ MinOptMax maxbpd = parent.getMaxBPD();
+ BodyRegion body = (BodyRegion)parent;
+ Area a = body.getMainReference();
+ if (a != null) {
+ maxbpd = MinOptMax.subtract(maxbpd, a.getContentBPD());
+ }
+ if ((a=body.getBeforeFloat()) != null) {
+ maxbpd = MinOptMax.subtract(maxbpd, a.getContentBPD());
+ }
+ return maxbpd;
+ }
}
import java.util.List;
// the area that contains the flow via the span areas
-public class MainReference implements Serializable {
+public class MainReference extends Area implements Serializable {
List spanAreas = new ArrayList();
int columnGap;
int width;
public int getWidth() {
return width;
}
+
+ public MinOptMax getMaxBPD() {
+ MinOptMax maxbpd = parent.getMaxBPD();
+ BodyRegion body = (BodyRegion)parent;
+ Area a = body.getBeforeFloat();
+ if (a != null) {
+ maxbpd = MinOptMax.subtract(maxbpd, a.getContentBPD());
+ }
+ if ((a=body.getFootnote()) != null) {
+ maxbpd = MinOptMax.subtract(maxbpd, a.getContentBPD());
+ }
+ return maxbpd;
+ }
}
RegionViewport regionAfter = null;
public void setRegion(int areaclass, RegionViewport port) {
- if (areaclass == Region.BEFORE) {
+ if (areaclass == RegionReference.BEFORE) {
regionBefore = port;
- } else if (areaclass == Region.START) {
+ } else if (areaclass == RegionReference.START) {
regionStart = port;
- } else if (areaclass == Region.BODY) {
+ } else if (areaclass == RegionReference.BODY) {
regionBody = port;
- } else if (areaclass == Region.END) {
+ } else if (areaclass == RegionReference.END) {
regionEnd = port;
- } else if (areaclass == Region.AFTER) {
+ } else if (areaclass == RegionReference.AFTER) {
regionAfter = port;
}
}
public RegionViewport getRegion(int areaclass) {
- if (areaclass == Region.BEFORE) {
+ if (areaclass == RegionReference.BEFORE) {
return regionBefore;
- } else if (areaclass == Region.START) {
+ } else if (areaclass == RegionReference.START) {
return regionStart;
- } else if (areaclass == Region.BODY) {
+ } else if (areaclass == RegionReference.BODY) {
return regionBody;
- } else if (areaclass == Region.END) {
+ } else if (areaclass == RegionReference.END) {
return regionEnd;
- } else if (areaclass == Region.AFTER) {
+ } else if (areaclass == RegionReference.AFTER) {
return regionAfter;
}
return null;
import java.io.Serializable;
import java.io.IOException;
-public class RegionViewport implements Serializable {
+public class RegionViewport extends Area implements Serializable {
// this rectangle is relative to the page
- Rectangle2D regionArea;
+ RegionReference region;
+ Rectangle2D viewArea;
boolean clip = false;
- Region region;
- public RegionViewport(Rectangle2D area) {
- regionArea = area;
+ public RegionViewport(Rectangle2D viewArea) {
+ this.viewArea =viewArea;
}
- public void setRegion(Region reg) {
+ public void setRegion(RegionReference reg) {
region = reg;
+ region.setParent(this);
}
- public Rectangle2D getViewArea() {
- return regionArea;
+ public RegionReference getRegion() {
+ return region;
}
- public Region getRegion() {
- return region;
+ public void setClip(boolean c) {
+ clip = c;
+ }
+
+ public Rectangle2D getViewArea() {
+ return viewArea;
}
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
- out.writeFloat((float) regionArea.getX());
- out.writeFloat((float) regionArea.getY());
- out.writeFloat((float) regionArea.getWidth());
- out.writeFloat((float) regionArea.getHeight());
+ out.writeFloat((float) viewArea.getX());
+ out.writeFloat((float) viewArea.getY());
+ out.writeFloat((float) viewArea.getWidth());
+ out.writeFloat((float) viewArea.getHeight());
out.writeBoolean(clip);
out.writeObject(region);
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
- regionArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(),
- in.readFloat(), in.readFloat());
+ viewArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(),
+ in.readFloat(), in.readFloat());
clip = in.readBoolean();
- region = (Region) in.readObject();
+ setRegion( (RegionReference) in.readObject());
}
}
package org.apache.fop.area;
import java.util.ArrayList;
+import java.util.Iterator;
// this is a reference area block area with 0 border and padding
public class Span extends Area {
public Flow getFlow(int count) {
return (Flow) flowAreas.get(count);
}
+
+ /**
+ * Maximum available BPD for a Span is the maxBPD for its containing
+ * MainReference less the content BPD of any previous spans
+ */
+ public MinOptMax getMaxBPD() {
+ MinOptMax maxbpd = parent.getMaxBPD();
+ MainReference mainref = (MainReference)parent;
+ Iterator spanIter = mainref.getSpans().iterator();
+ while (spanIter.hasNext()) {
+ Span s = (Span)spanIter.next();
+ if (s == this) break;
+ maxbpd = MinOptMax.subtract(maxbpd, s.getContentBPD());
+ }
+ return maxbpd;
+ }
+
}