From b82d386d3eefbf734ee4a0a0af8ee268a08c7879 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Sun, 2 May 2004 06:23:52 +0000 Subject: [PATCH] Now extends AreaNode. AreaNode aspects removed. IPDim and BPDim values may now be get and set in either millipoints (int) or points (double). All IPDim and BPDim are now maintained in the Rectange2D area, and values are got from and set to the Rectangle2D git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197554 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/area/Area.java | 227 +++++++++++++++++++------ 1 file changed, 179 insertions(+), 48 deletions(-) diff --git a/src/java/org/apache/fop/area/Area.java b/src/java/org/apache/fop/area/Area.java index ce0f1c299..091d79892 100644 --- a/src/java/org/apache/fop/area/Area.java +++ b/src/java/org/apache/fop/area/Area.java @@ -18,23 +18,30 @@ */ package org.apache.fop.area; +import java.awt.geom.Rectangle2D; + import org.apache.fop.datastructs.Node; -import org.apache.fop.datastructs.SyncedNode; import org.apache.fop.fo.FONode; +import org.apache.fop.fo.expr.PropertyException; import org.apache.fop.fo.flow.FoPageSequence; +import org.apache.fop.fo.properties.WritingMode; /** - * The base class for all areas. Area extends Node - * because all areas will find themselves in a tree of some kind. + * The base class for all gemetrical areas. Area extends + * AreaNode because all areas will find themselves in a tree of + * some kind. It represents its geometry with a + * Rectangle2D.Double, whose dimensions are expressed in Java + * and XSL points, i.e. 1/72 of an inch, which facilitates conversions to + * integral millipoints. It also allows the use of Java facilities like + * java.awt.GraphicsConfiguration.getNormalizingTransform() + * which, "Returns a AffineTransform that can be concatenated with the default + * AffineTransform of a GraphicsConfiguration so that 72 units in user space + * equals 1 inch in device space." * @author pbw * @version $Revision$ $Name$ */ -public class Area extends SyncedNode implements Cloneable { +public class Area extends AreaNode implements Cloneable { - /** The page-sequence which generated this area. */ - protected FoPageSequence pageSeq = null; - /** The FO node that generated this node. */ - protected FONode generatedBy = null; /** Current inline progression dimension. May be unknown. */ protected Integer iPDim = null; /** Maximum required inline progression dimension. May be unknown. */ @@ -47,7 +54,28 @@ public class Area extends SyncedNode implements Cloneable { protected Integer bPDimMax = null; /** Mimimum required block progression dimension. May be unknown. */ protected Integer bPDimMin = null; - + /** The geometrical area. The width of this + * Rectangle is the inline-progression-dimension + * of the area, and the height is the + * bllock-progression-dimension. */ + protected Rectangle2D area = null; + /** True if the the writing-mode of the content area is + * horizontal */ + protected boolean contentIsHorizontal = true; + /** True if the the writing-mode of the content area is + * left-to-right */ + protected boolean contentLeftToRight = true; + + private void setup() { + try { + contentIsHorizontal = + WritingMode.isHorizontal(generatedBy.getWritingMode()); + contentLeftToRight = + WritingMode.isLeftToRight(generatedBy.getWritingMode()); + } catch (PropertyException e) { + throw new RuntimeException(e.getMessage()); + } + } /** * @param pageSeq through which this area was generated * @param generatedBy the given FONode generated this @@ -63,9 +91,8 @@ public class Area extends SyncedNode implements Cloneable { int index, Object sync) throws IndexOutOfBoundsException { - super(parent, index, sync); - this.pageSeq = pageSeq; - this.generatedBy = generatedBy; + super(pageSeq, generatedBy, parent, index, sync); + setup(); } /** @@ -80,9 +107,8 @@ public class Area extends SyncedNode implements Cloneable { FONode generatedBy, Node parent, Object sync) { - super(parent, sync); - this.pageSeq = pageSeq; - this.generatedBy = generatedBy; + super(pageSeq, generatedBy, parent, sync); + setup(); } /** @@ -94,47 +120,85 @@ public class Area extends SyncedNode implements Cloneable { public Area( FoPageSequence pageSeq, FONode generatedBy) { - super(); - this.pageSeq = pageSeq; - this.generatedBy = generatedBy; + super(pageSeq, generatedBy); + setup(); } /** - * @return the generatedBy + * Gets the block-progression-dimension of the contents of + * this area in millipoints. This value is taken from the appropriate + * dimension of the Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the zero value is returned. + * @return the block-progression-dimension in millipoints */ - public FONode getGeneratedBy() { - synchronized (sync) { - return generatedBy; - } + public int getBPDim() { + return (int)(getBPDimPts()*1000); } + /** - * @param generatedBy to set + * Gets the block-progression-dimension of the contents of + * this area in points. This value is taken from the appropriate dimension + * of the Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the zero value is returned. + * @return the block-progression-dimension in points */ - public void setGeneratedBy(FONode generatedBy) { + public double getBPDimPts() { synchronized (sync) { - this.generatedBy = generatedBy; + if (area == null) { + return 0; + } + if (contentIsHorizontal) { + return area.getHeight(); + } else { + return area.getWidth(); + } } } + /** - * @return the bPDim + * Sets the block-progression-dimension of the contents of + * this area to the specified value in millipoints. + * This value is applied to the appropriate dimension of the + * Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the value is applied. + * @param millipts block-progression-dimension to set, in + * millipoints */ - public Integer getBPDim() { - synchronized (sync) { - return bPDim; - } + public void setBPDim(int millipts) { + setBPDimPts(millipts/1000.0f); } /** - * @param dim to set + * Sets the block-progression-dimension of the contents of + * this area to the specified value in points. + * This value is applied to the appropriate dimension of the + * Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the value is applied. + * @param pts block-progression-dimension to set, in points */ - public void setBPDim(Integer dim) { + public void setBPDimPts(double pts) { synchronized (sync) { - bPDim = dim; + if (area == null) { + area = new Rectangle2D.Double(); + } + if (contentIsHorizontal) { + area.setRect( + area.getX(),area.getY(), area.getWidth(), pts); + } else { + area.setRect( + area.getX(),area.getY(), pts, area.getHeight()); + } } } /** - * @return the bPDimMax + * Gets the block-progression-dimension maximum value, + * in millipoints + * @return the block-progression-dimension maximum value */ public Integer getBPDimMax() { synchronized (sync) { @@ -143,7 +207,10 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @param dimMax to set + * Sets the block-progression-dimension maximum value, + * in millipoints + * @param dimMax block-progression-dimension maximum value + * to set */ public void setBPDimMax(Integer dimMax) { synchronized (sync) { @@ -152,7 +219,9 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @return the bPDimMin + * Gets the block-progression-dimension minimum value, + * in millipoints + * @return the block-progression-dimension minimum value */ public Integer getBPDimMin() { synchronized (sync) { @@ -161,7 +230,10 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @param dimMin to set + * Sets the block-progression-dimension minimum value, + * in millipoints + * @param dimMin block-progression-dimension minimum value + * to set */ public void setBPDimMin(Integer dimMin) { synchronized (sync) { @@ -170,25 +242,76 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @return the iPDim + * Gets the inline-progression-dimension of the contents of + * this area in millipoints. This value is taken from the appropriate + * dimension of the Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the zero value is returned. + * @return the inline-progression-dimension in millipoints + */ + public int getIPDim() { + return (int)(getIPDimPts()*1000); + } + + /** + * Gets the inline-progression-dimension of the contents of + * this area in points. This value is taken from the appropriate dimension + * of the Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the zero value is returned. + * @return the inline-progression-dimension in points */ - public Integer getIPDim() { + public double getIPDimPts() { synchronized (sync) { - return iPDim; + if (area == null) { + area = new Rectangle2D.Double(); + } + if (contentIsHorizontal){ + return area.getWidth(); + } else { + return area.getHeight(); + } } } /** - * @param dim to set + * Sets the inline-progression-dimension of the contents of + * this area, in millipoints. This value is applied to the appropriate + * dimension of the Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the value is applied. + * @param millipts inline-progression-dimension to set, in + * millipoints + */ + public void setIPDim(int millipts) { + setIPDimPts(millipts/1000.0f); + } + + /** + * Sets the inline-progression-dimension of the contents of + * this area, in points. This value is applied to the appropriate + * dimension of the Rectangle2D representing this area. If no + * Rectangle2D exists, a zero-dimensioned default is first + * created, then the value is applied. + * @param pts inline-progression-dimension to set, in points */ - public void setIPDim(Integer dim) { + public void setIPDimPts(double pts) { synchronized (sync) { - iPDim = dim; + if (area == null) { + area = new Rectangle2D.Double(); + } + if (contentIsHorizontal){ + area.setRect(area.getX(), area.getY(), pts, area.getHeight()); + } else { + area.setRect(area.getX(), area.getY(), area.getWidth(), pts); + } } } /** - * @return the iPDimMax + * Gets the inline-progression-dimension maximum value, + * in millipoints + * @return the inline-progression-dimension maximum value */ public Integer getIPDimMax() { synchronized(sync) { @@ -197,7 +320,10 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @param dimMax to set + * Sets the inline-progression-dimension maximum value, + * in millipoints + * @param dimMax inline-progression-dimension maximum value + * to set */ public void setIPDimMax(Integer dimMax) { synchronized (sync) { @@ -206,7 +332,9 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @return the iPDimMin + * Gets the inline-progression-dimension mimimum value, + * in millipoints + * @return the inline-progression-dimension minimum value */ public Integer getIPDimMin() { synchronized (sync) { @@ -215,7 +343,10 @@ public class Area extends SyncedNode implements Cloneable { } /** - * @param dimMin to set + * Sets the inline-progression-dimension minimum value, + * in millipoints + * @param dimMin inline-progression-dimension minimum value + * to set */ public void setIPDimMin(Integer dimMin) { synchronized (sync) { -- 2.39.5