From: Peter Bernard West Date: Fri, 11 Jun 2004 14:44:10 +0000 (+0000) Subject: AreaFrame and ContentRectangle made inner classes of Area. X-Git-Tag: Defoe_export~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=26aa1556f477e0de2189212111bc18ae4d7fcaa1;p=xmlgraphics-fop.git AreaFrame and ContentRectangle made inner classes of Area. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197698 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/area/Area.java b/src/java/org/apache/fop/area/Area.java index de7fde3fc..1c21c7ad6 100644 --- a/src/java/org/apache/fop/area/Area.java +++ b/src/java/org/apache/fop/area/Area.java @@ -19,6 +19,9 @@ package org.apache.fop.area; import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.awt.geom.Rectangle2D.Double; import java.util.ArrayList; import org.apache.fop.datastructs.Node; @@ -112,12 +115,26 @@ public class Area extends AreaNode implements Cloneable { protected void setTranslation(AffineTransform translation) { this.translation = translation; } + /** The writing-mode of the generating FO */ + protected int contentWritingMode = 0; /** True if 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; + /** The writing-mode of the parent of the generating FO. This may + * differ from the writing mode of the generating FO if this is a + * reference-area. */ + protected int frameWritingMode = 0; + /** True if the writing-mode of the frames of this area is + * horizontal. May differ from contentIsHorizontal if this is a + * reference-area. */ + protected boolean frameIsHorizontal = true; + /** True if the the writing-mode of the frames of this area is + * left-to-right. May differ from contentIsHorizontal if this is a + * reference-area. */ + protected boolean frameLeftToRight = true; private void setup() { @@ -126,10 +143,13 @@ public class Area extends AreaNode implements Cloneable { borders = padding.getBorders(); spaces = borders.getSpaces(); try { - contentIsHorizontal = - WritingMode.isHorizontal(generatedBy.getWritingMode()); - contentLeftToRight = - WritingMode.isLeftToRight(generatedBy.getWritingMode()); + contentWritingMode = generatedBy.getWritingMode(); + contentIsHorizontal = WritingMode.isHorizontal(contentWritingMode); + contentLeftToRight = WritingMode.isLeftToRight(contentWritingMode); + frameWritingMode = + ((FONode)generatedBy.getParent()).getWritingMode(); + frameIsHorizontal = WritingMode.isHorizontal(frameWritingMode); + frameLeftToRight = WritingMode.isLeftToRight(frameWritingMode); } catch (PropertyException e) { throw new RuntimeException(e.getMessage()); } @@ -355,4 +375,216 @@ public class Area extends AreaNode implements Cloneable { } } + /** + * AreaFrame is the basic type for the geometry of a rectangle + * enclosing another rectangle, e.g., a padding rectangle. + * @author pbw + * @version $Revision: 1.1.2.2 $ $Name: $ + */ + public class AreaFrame extends Rectangle2D.Double { + + /** The framed rectangle */ + protected Rectangle2D contents = null; + /** The offset from this origin to the origin of the framed + * rectangle */ + protected Point2D contentOffset = null; + + /** + * + */ + public AreaFrame() { + super(); + contents = new Rectangle2D.Double(); + contentOffset = new Point2D.Double(); + } + + /** + * Instantiates a frame with 0-width edges. + * @param contents the contained rectangle + */ + public AreaFrame(Rectangle2D contents) { + super(); + setRect(contents); + this.contents = contents; + this.contentOffset = new Point2D.Double(); + } + + /** + * Instantiates a new framing rectangle with the given origin point, the + * given width and height, the given content rectangle, and the given + * offset from the origin of the framing rectangle to the origin of the + * content rectangle. + * @param x x-value of the origin of the framing rectangle in user space + * units + * @param y y-value of the origin of the framing rectangle in user space + * units + * @param w width of the framing rectangle in user space units + * @param h height of the framing rectangle in user space units + * @param contents the framed rectangle + * @param contentOffset the offset to the origin point of the framed + * rectangle from the origin point of this framing rectangle. + */ + public AreaFrame(double x, double y, double w, double h, + Rectangle2D contents, Point2D contentOffset) { + super(x, y, w, h); + this.contents = contents; + this.contentOffset = contentOffset; + } + + /** + * Instantiates a new framing rectangle from the given rectangle, given + * contents, and given offset from the origin of the framing rectangle to + * the origin of the framed rectangle. The dimensions and location of the + * given rectangle are copied into the dimensions of the new framing + * rectangle. + * @param rect the framing rectangle + * @param contents the framed rectangle + * @param contentOffset offset from origin of the framing rectangle to the + * origin of the framed rectangle + */ + public AreaFrame(Rectangle2D rect, Rectangle2D contents, + Point2D contentOffset) { + this(rect.getX(), rect.getY(), + rect.getWidth(), rect.getHeight(), + contents, contentOffset); + } + + /** + * Sets the contents rectangle. The dimensions of this are + * adjusted to the difference between the current framed contents and + * the new framed contents. The offset is not affected. + * @param contents the new framed contents + */ + public void setContents(Rectangle2D contents) { + setRect(getX(), getY(), + getWidth() + (contents.getWidth() - this.contents.getWidth()), + getHeight() + (contents.getWidth() - this.contents.getWidth())); + contents = this.contents; + } + + public Rectangle2D getContents() { + return contents; + } + + /** + * Sets the offset from the origin of this to the origin of + * the framed contents rectangle. The dimensions of the framed contents + * are not affected, but the dimensions of this are changed + * by the difference between the current offset and the new offset in the + * X and Y axes. + * @param offset the new offset to the framed rectangle + */ + public void setContentOffset(Point2D offset) { + setStart(offset.getX()); + setBefore(offset.getY()); + contentOffset = offset; + } + + public Point2D getContentOffset() { + return contentOffset; + } + + /** + * Sets the before edge width of the frame. The contents size + * is unaffected, but the size of the frame (this) will + * change. The height will vary by the difference between the previous and + * new before edge. The contentOffset will also change by the + * same amount. Note that the origin of this frame (getX(), + * getY()) will not change. + * @param before + */ + public void setBefore(double before) { + double diff = before - contentOffset.getY(); + setRect(getX(), getY(), + getWidth(), getHeight() + diff); + contentOffset.setLocation(contentOffset.getX(), before); + } + + /** + * Sets the start edge width of the frame. The contents size + * is unaffected, but the size of the frame (this) will + * change. The width will vary by the difference between the previous and + * new start edge. The contentOffset will also change by the + * same amount. Note that the origin of this frame (getX(), + * getY()) will not change. + * @param start + */ + public void setStart(double start) { + double diff = start - contentOffset.getY(); + setRect(getX(), getY(), + getWidth() + diff, getHeight()); + contentOffset.setLocation(start, contentOffset.getX()); + } + + /** + * Sets the after edge width of the frame. The contents size + * and the contentOffset are unaffected, but the size of the + * frame (this) will change. The height will vary by the + * difference between the previous and new after edge. Note that the + * origin of this frame (getX(), getY()) will not change. + * @param after + */ + public void setAfter(double after) { + double diff = after - (getY() - contentOffset.getY() - contents.getY()); + setRect(getX(), getY(), getWidth(), getHeight() + diff); + } + + /** + * Sets the end edge width of the frame. The contents size + * and the contentOffset are unaffected, but the size of the + * frame (this) will change. The width will vary by the + * difference between the previous and new end edge. Note that the + * origin of this frame (getX(), getY()) will not change. + * @param end + */ + public void setEnd(double end) { + double diff = end - (getX() - contentOffset.getX() - contents.getX()); + setRect(getX(), getY(), getWidth() + diff, getHeight()); + } + } + + /** + * Defines the content rectangle of an area. It is the central class + * in the management of the layout geometry of areas. The other generated + * rectangular areas are accessed through and defined in terms of this area. + * @author pbw + * @version $Revision: 1.1.2.2 $ $Name: $ + */ + public class ContentRectangle extends Double { + + /** + * Creates an empty contents object. + */ + public ContentRectangle() { + super(); + padding = new PaddingRectangle(Area.this); + padding.setContents(this); + } + + /** + * Creates a contents object from the given origin (x, y) + * width (w) and height (h). + * @param x x-origin + * @param y y-origin + * @param w width + * @param h height + */ + public ContentRectangle(double x, double y, double w, double h) { + super(x, y, w, h); + padding = new PaddingRectangle(Area.this); + padding.setContents(this); + } + + private PaddingRectangle padding = null; + + public PaddingRectangle getPadding() { + return padding; + } + + public void setRect(double x, double y, double w, double h) { + super.setRect(x, y, w, h); + padding.setContents(this); + } + } + } diff --git a/src/java/org/apache/fop/area/AreaFrame.java b/src/java/org/apache/fop/area/AreaFrame.java deleted file mode 100644 index 062a504b8..000000000 --- a/src/java/org/apache/fop/area/AreaFrame.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * - * Copyright 2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Created on 5/06/2004 - * $Id$ - */ -package org.apache.fop.area; - -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -/** - * AreaFrame is the basic type for the geometry of a rectangle - * enclosing another rectangle, e.g., a padding rectangle. - * @author pbw - * @version $Revision$ $Name$ - */ -public class AreaFrame extends Rectangle2D.Double { - - /** - * - */ - public AreaFrame() {} - - public AreaFrame(Rectangle2D contents) { - super(); - setRect(contents); - this.contents = contents; - this.contentOffset = new Point2D.Double(); - } - - /** - * Instantiates a new framing rectangle with the given origin point, the - * given width and height, the given content rectangle, and the given - * offset from the origin of the framing rectangle to the origin of the - * content rectangle. - * @param x x-value of the origin of the framing rectangle in user space - * units - * @param y y-value of the origin of the framing rectangle in user space - * units - * @param w width of the framing rectangle in user space units - * @param h height of the framing rectangle in user space units - * @param contents the framed rectangle - * @param contentOffset the offset to the origin point of the framed - * rectangle from the origin point of this framing rectangle. - */ - public AreaFrame(double x, double y, double w, double h, - Rectangle2D contents, Point2D contentOffset) { - super(x, y, w, h); - this.contents = contents; - this.contentOffset = contentOffset; - } - - /** The framed rectangle */ - protected Rectangle2D contents = null; - /** The offset from this origin to the origin of the framed - * rectangle */ - protected Point2D contentOffset = null; - - /** - * Instantiates a new framing rectangle from the given rectangle, given - * contents, and given offset from the origin of the framing rectangle to - * the origin of the framed rectangle. The dimensions and location of the - * given rectangle are copied into the dimensions of the new framing - * rectangle. - * @param rect the framing rectangle - * @param contents the framed rectangle - * @param contentOffset offset from origin of the framing rectangle to the - * origin of the framed rectangle - */ - public AreaFrame( - Rectangle2D rect, Rectangle2D contents, Point2D contentOffset) { - this(rect.getX(), rect.getY(), - rect.getWidth(), rect.getHeight(), - contents, contentOffset); - } - - /** - * Sets the contents rectangle. The dimensions of this are - * adjusted to the difference between the current framed contents and - * the new framed contents. The offset is not affected. - * @param contents the new framed contents - */ - public void setContents(Rectangle2D contents) { - setRect(getX(), getY(), - getWidth() + (contents.getWidth() - this.contents.getWidth()), - getHeight() + (contents.getWidth() - this.contents.getWidth())); - contents = this.contents; - } - - public Rectangle2D getContents() { - return contents; - } - - /** - * Sets the offset from the origin of this to the origin of - * the framed contents rectangle. The dimensions of the framed contents - * are not affected, but the dimensions of this are changed - * by the difference between the current offset and the new offset in the - * X and Y axes. - * @param offset the new offset to the framed rectangle - */ - public void setContentOffset(Point2D offset) { - setStart(offset.getX()); - setBefore(offset.getY()); - contentOffset = offset; - } - - public Point2D getContentOffset() { - return contentOffset; - } - - /** - * Sets the before edge width of the frame. The contents size - * is unaffected, but the size of the frame (this) will - * change. The height will vary by the difference between the previous and - * new before edge. The contentOffset will also change by the - * same amount. Note that the origin of this frame (getX(), - * getY()) will not change. - * @param before - */ - public void setBefore(double before) { - double diff = before - contentOffset.getY(); - setRect(getX(), getY(), - getWidth(), getHeight() + diff); - contentOffset.setLocation(contentOffset.getX(), before); - } - - /** - * Sets the start edge width of the frame. The contents size - * is unaffected, but the size of the frame (this) will - * change. The width will vary by the difference between the previous and - * new start edge. The contentOffset will also change by the - * same amount. Note that the origin of this frame (getX(), - * getY()) will not change. - * @param start - */ - public void setStart(double start) { - double diff = start - contentOffset.getY(); - setRect(getX(), getY(), - getWidth() + diff, getHeight()); - contentOffset.setLocation(start, contentOffset.getX()); - } - - /** - * Sets the after edge width of the frame. The contents size - * and the contentOffset are unaffected, but the size of the - * frame (this) will change. The height will vary by the - * difference between the previous and new after edge. Note that the - * origin of this frame (getX(), getY()) will not change. - * @param after - */ - public void setAfter(double after) { - double diff = after - (getY() - contentOffset.getY() - contents.getY()); - setRect(getX(), getY(), getWidth(), getHeight() + diff); - } - - /** - * Sets the end edge width of the frame. The contents size - * and the contentOffset are unaffected, but the size of the - * frame (this) will change. The width will vary by the - * difference between the previous and new end edge. Note that the - * origin of this frame (getX(), getY()) will not change. - * @param end - */ - public void setEnd(double end) { - double diff = end - (getX() - contentOffset.getX() - contents.getX()); - setRect(getX(), getY(), getWidth() + diff, getHeight()); - } - -} diff --git a/src/java/org/apache/fop/area/BorderRectangle.java b/src/java/org/apache/fop/area/BorderRectangle.java index 7a045ab4d..7ee3e4cdc 100644 --- a/src/java/org/apache/fop/area/BorderRectangle.java +++ b/src/java/org/apache/fop/area/BorderRectangle.java @@ -26,12 +26,13 @@ import java.awt.geom.Rectangle2D; * @author pbw * @version $Revision$ $Name$ */ -public class BorderRectangle extends AreaFrame { +public class BorderRectangle extends Area.AreaFrame { - public BorderRectangle() { - contents = new PaddingRectangle(); + public BorderRectangle(Area area) { + area.super(); + contents = new PaddingRectangle(area); contentOffset = new Point2D.Double(); - spaces = new SpacesRectangle(); + spaces = new SpacesRectangle(area); spaces.setContents(this); } @@ -43,10 +44,10 @@ public class BorderRectangle extends AreaFrame { * @param contents * @param contentOffset */ - public BorderRectangle(double x, double y, double w, double h, + public BorderRectangle(Area area, double x, double y, double w, double h, PaddingRectangle contents, Point2D contentOffset) { - super(x, y, w, h, contents, contentOffset); - spaces = new SpacesRectangle(); + area.super(x, y, w, h, contents, contentOffset); + spaces = new SpacesRectangle(area); spaces.setContents(this); } @@ -55,10 +56,10 @@ public class BorderRectangle extends AreaFrame { * @param contents * @param contentOffset */ - public BorderRectangle(Rectangle2D rect, PaddingRectangle contents, - Point2D contentOffset) { - super(rect, contents, contentOffset); - spaces = new SpacesRectangle(); + public BorderRectangle(Area area, Rectangle2D rect, + PaddingRectangle contents, Point2D contentOffset) { + area.super(rect, contents, contentOffset); + spaces = new SpacesRectangle(area); spaces.setContents(this); } diff --git a/src/java/org/apache/fop/area/ContentRectangle.java b/src/java/org/apache/fop/area/ContentRectangle.java deleted file mode 100644 index e1d1c4d99..000000000 --- a/src/java/org/apache/fop/area/ContentRectangle.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Copyright 2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Created on 6/06/2004 - * $Id$ - */ -package org.apache.fop.area; - -import java.awt.geom.Rectangle2D.Double; - -/** - * Defines the content rectangle of an area. It is the central class - * in the management of the layout geometry of areas. The other generated - * rectangular areas are accessed through and defined in terms of this area. - * @author pbw - * @version $Revision$ $Name$ - */ -public class ContentRectangle extends Double { - - /** - * Creates an empty contents object. - */ - public ContentRectangle() { - super(); - padding = new PaddingRectangle(); - padding.setContents(this); - } - - /** - * Creates a contents object from the given origin (x, y) - * width (w) and height (h). - * @param x x-origin - * @param y y-origin - * @param w width - * @param h height - */ - public ContentRectangle(double x, double y, double w, double h) { - super(x, y, w, h); - padding = new PaddingRectangle(); - padding.setContents(this); - } - - private PaddingRectangle padding = null; - - public PaddingRectangle getPadding() { - return padding; - } - - public void setRect(double x, double y, double w, double h) { - super.setRect(x, y, w, h); - padding.setContents(this); - } -} diff --git a/src/java/org/apache/fop/area/PaddingRectangle.java b/src/java/org/apache/fop/area/PaddingRectangle.java index 2b8d285f7..db6afb01d 100644 --- a/src/java/org/apache/fop/area/PaddingRectangle.java +++ b/src/java/org/apache/fop/area/PaddingRectangle.java @@ -26,12 +26,13 @@ import java.awt.geom.Rectangle2D; * @author pbw * @version $Revision$ $Name$ */ -public class PaddingRectangle extends AreaFrame { +public class PaddingRectangle extends Area.AreaFrame { - public PaddingRectangle() { - contents = new ContentRectangle(); + public PaddingRectangle(Area area) { + area.super(); + contents = area.new ContentRectangle(); contentOffset = new Point2D.Double(); - borders = new BorderRectangle(); + borders = new BorderRectangle(area); borders.setContents(this); } @@ -43,10 +44,10 @@ public class PaddingRectangle extends AreaFrame { * @param contents * @param contentOffset */ - public PaddingRectangle(double x, double y, double w, double h, - ContentRectangle contents, Point2D contentOffset) { - super(x, y, w, h, contents, contentOffset); - borders = new BorderRectangle(); + public PaddingRectangle(Area area, double x, double y, double w, double h, + Area.ContentRectangle contents, Point2D contentOffset) { + area.super(x, y, w, h, contents, contentOffset); + borders = new BorderRectangle(area); borders.setContents(this); } @@ -55,10 +56,10 @@ public class PaddingRectangle extends AreaFrame { * @param contents * @param contentOffset */ - public PaddingRectangle(Rectangle2D rect, ContentRectangle contents, - Point2D contentOffset) { - super(rect, contents, contentOffset); - borders = new BorderRectangle(); + public PaddingRectangle(Area area, Rectangle2D rect, + Area.ContentRectangle contents, Point2D contentOffset) { + area.super(rect, contents, contentOffset); + borders = new BorderRectangle(area); borders.setContents(this); } diff --git a/src/java/org/apache/fop/area/SpacesRectangle.java b/src/java/org/apache/fop/area/SpacesRectangle.java index 699de6afb..dcf87ec19 100644 --- a/src/java/org/apache/fop/area/SpacesRectangle.java +++ b/src/java/org/apache/fop/area/SpacesRectangle.java @@ -26,10 +26,11 @@ import java.awt.geom.Rectangle2D; * @author pbw * @version $Revision$ $Name$ */ -public class SpacesRectangle extends AreaFrame { +public class SpacesRectangle extends Area.AreaFrame { - public SpacesRectangle() { - contents = new BorderRectangle(); + public SpacesRectangle(Area area) { + area.super(); + contents = new BorderRectangle(area); contentOffset = new Point2D.Double(); } @@ -42,9 +43,9 @@ public class SpacesRectangle extends AreaFrame { * @param contents * @param contentOffset */ - public SpacesRectangle(double x, double y, double w, double h, + public SpacesRectangle(Area area, double x, double y, double w, double h, BorderRectangle contents, Point2D contentOffset) { - super(x, y, w, h, contents, contentOffset); + area.super(x, y, w, h, contents, contentOffset); } /** @@ -52,9 +53,9 @@ public class SpacesRectangle extends AreaFrame { * @param contents * @param contentOffset */ - public SpacesRectangle(Rectangle2D rect, BorderRectangle contents, - Point2D contentOffset) { - super(rect, contents, contentOffset); + public SpacesRectangle(Area area, Rectangle2D rect, + BorderRectangle contents, Point2D contentOffset) { + area.super(rect, contents, contentOffset); } }