From: Karen Lease Date: Fri, 9 Nov 2001 22:02:34 +0000 (+0000) Subject: Add some methods needed by the LayoutManager classes (subject to discussion) X-Git-Tag: fop-0_20_4-doc~220 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=83b0a60b919627a1b8fd45789c2f34e73328433c;p=xmlgraphics-fop.git Add some methods needed by the LayoutManager classes (subject to discussion) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194543 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/area/Area.java b/src/org/apache/fop/area/Area.java index c6a763b3e..2b429d5bc 100644 --- a/src/org/apache/fop/area/Area.java +++ b/src/org/apache/fop/area/Area.java @@ -8,6 +8,7 @@ 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 @@ -33,4 +34,87 @@ public class Area implements Serializable { 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; + } } diff --git a/src/org/apache/fop/area/BeforeFloat.java b/src/org/apache/fop/area/BeforeFloat.java index 034d467d2..643877a6a 100644 --- a/src/org/apache/fop/area/BeforeFloat.java +++ b/src/org/apache/fop/area/BeforeFloat.java @@ -10,7 +10,7 @@ package org.apache.fop.area; 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; @@ -47,4 +47,18 @@ public class BeforeFloat extends Area { 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; + } + } diff --git a/src/org/apache/fop/area/Block.java b/src/org/apache/fop/area/Block.java index 9a7e3b30c..97d07151f 100644 --- a/src/org/apache/fop/area/Block.java +++ b/src/org/apache/fop/area/Block.java @@ -18,7 +18,7 @@ import java.awt.geom.Rectangle2D; // 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 @@ -26,11 +26,6 @@ public class Block extends Area implements Serializable { // 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 @@ -38,7 +33,6 @@ public class Block extends Area implements Serializable { // 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 @@ -46,8 +40,6 @@ public class Block extends Area implements Serializable { int positioning = STACK; - // orientation if reference area - int orientation = ORIENT_0; public void addBlock(Block block) { if (children == null) { @@ -73,10 +65,6 @@ public class Block extends Area implements Serializable { return blocks; } - public List getChildAreas() { - return children; - } - public int getPositioning() { return positioning; } diff --git a/src/org/apache/fop/area/BodyRegion.java b/src/org/apache/fop/area/BodyRegion.java index e6e886404..78693d71f 100644 --- a/src/org/apache/fop/area/BodyRegion.java +++ b/src/org/apache/fop/area/BodyRegion.java @@ -7,25 +7,44 @@ 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); } @@ -40,4 +59,8 @@ public class BodyRegion extends Region { public Footnote getFootnote() { return footnote; } + + public MinOptMax getMaxBPD() { + return maxBPD; + } } diff --git a/src/org/apache/fop/area/Flow.java b/src/org/apache/fop/area/Flow.java index 6cfa09a53..031903b4b 100644 --- a/src/org/apache/fop/area/Flow.java +++ b/src/org/apache/fop/area/Flow.java @@ -12,7 +12,7 @@ import java.util.List; // 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; @@ -26,4 +26,13 @@ public class Flow extends Area { return blocks; } + /** + * Maximum block progression dimension for a Flow is + * the same as that of its parent Span. + */ + public MinOptMax getMaxBPD() { + return parent.getMaxBPD(); + } + + } diff --git a/src/org/apache/fop/area/Footnote.java b/src/org/apache/fop/area/Footnote.java index d36a769bc..cff6fc2fc 100644 --- a/src/org/apache/fop/area/Footnote.java +++ b/src/org/apache/fop/area/Footnote.java @@ -12,7 +12,7 @@ import java.util.List; 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 @@ -42,4 +42,17 @@ public class Footnote implements Serializable { 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; + } } diff --git a/src/org/apache/fop/area/MainReference.java b/src/org/apache/fop/area/MainReference.java index b18008b42..95b3bd82a 100644 --- a/src/org/apache/fop/area/MainReference.java +++ b/src/org/apache/fop/area/MainReference.java @@ -12,7 +12,7 @@ import java.util.ArrayList; 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; @@ -32,4 +32,17 @@ public class MainReference implements Serializable { 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; + } } diff --git a/src/org/apache/fop/area/Page.java b/src/org/apache/fop/area/Page.java index e8b1bfd62..1ee53bccc 100644 --- a/src/org/apache/fop/area/Page.java +++ b/src/org/apache/fop/area/Page.java @@ -18,29 +18,29 @@ public class Page implements Serializable { 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; diff --git a/src/org/apache/fop/area/RegionViewport.java b/src/org/apache/fop/area/RegionViewport.java index 43b320399..260f6ab45 100644 --- a/src/org/apache/fop/area/RegionViewport.java +++ b/src/org/apache/fop/area/RegionViewport.java @@ -11,45 +11,50 @@ import java.awt.geom.Rectangle2D; 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()); } } diff --git a/src/org/apache/fop/area/Span.java b/src/org/apache/fop/area/Span.java index fc8b45913..85012cdb9 100644 --- a/src/org/apache/fop/area/Span.java +++ b/src/org/apache/fop/area/Span.java @@ -8,6 +8,7 @@ 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 { @@ -34,4 +35,21 @@ 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; + } + }