You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ContentRectangle.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. *
  3. * Copyright 2004 The Apache Software Foundation.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * Created on 14/06/2004
  18. * $Id$
  19. */
  20. package org.apache.fop.area;
  21. import org.apache.fop.area.Area.AreaGeometry;
  22. /**
  23. * Defines the <i>content rectangle</i> of an area. It is the central class
  24. * in the management of the layout geometry of areas. The other generated
  25. * rectangular areas are defined in terms of this area.
  26. * @author pbw
  27. * @version $Revision$ $Name$
  28. */
  29. public class ContentRectangle extends AreaGeometry {
  30. private static final String tag = "$Name$";
  31. private static final String revision = "$Revision$";
  32. private final Area area;
  33. /**
  34. * @param area the containing <code>Area</code> instance
  35. */
  36. public ContentRectangle(Area area) {
  37. area.super(area.contentWritingMode);
  38. this.area = area;
  39. padding = new PaddingRectangle(area, this);
  40. }
  41. /**
  42. * @param area the containing <code>Area</code> instance
  43. * @param ipOrigin
  44. * @param bpOrigin
  45. * @param ipDim
  46. * @param bpDim
  47. */
  48. public ContentRectangle(Area area,
  49. double ipOrigin, double bpOrigin, double ipDim, double bpDim) {
  50. area.super(area.contentWritingMode, ipOrigin, bpOrigin, ipDim, bpDim);
  51. // Get the padding writing mode
  52. this.area = area;
  53. padding = new PaddingRectangle(area, this);
  54. }
  55. /**
  56. * Gets the writing-mode applicable to the content-rectangle
  57. * @see org.apache.fop.area.Area.AreaGeometry#getWritingMode()
  58. */
  59. public int getWritingMode() {
  60. return getContentWritingMode();
  61. }
  62. /** The <code>PaddingRectangle</code> <code>AreaFrame</code> around
  63. * <code>this</code> */
  64. private PaddingRectangle padding = null;
  65. /**
  66. * Gets the containing <code>PaddingRectangle</code>
  67. * @return the padding-ractangle
  68. */
  69. public PaddingRectangle getPadding() {
  70. return padding;
  71. }
  72. /**
  73. * Sets the containing <code>PaddingRectangle</code> to the argument
  74. * @param padding the padding-rectangle
  75. */
  76. public void setPadding(PaddingRectangle padding) {
  77. this.padding = padding;
  78. }
  79. /**
  80. * Sets the offset and dimensions for this<i>content-rectangle</i>, and
  81. * then sets <code>this</code> as the contents of the <code>padding</code>
  82. * <code>AreaFrame</code>
  83. * @param ipOrigin {@inheritDoc}
  84. * @param bpOrigin {@inheritDoc}
  85. * @param ipDim {@inheritDoc}
  86. * @param bpDim {@inheritDoc}
  87. * @see org.apache.fop.area.Area.AreaGeometry#setRect(double, double, double, double)
  88. */
  89. public void setRect(
  90. double ipOrigin, double bpOrigin, double ipDim, double bpDim) {
  91. super.setRect(ipOrigin, bpOrigin, ipDim, bpDim);
  92. padding.setContents(this);
  93. }
  94. /* (non-Javadoc)
  95. * @see org.apache.fop.area.Area.AreaGeometry#getFrameRelativeDimensions()
  96. */
  97. public DimensionDbl getFrameRelativeDimensions() {
  98. switch (getRotationToFrame()) {
  99. case 0:
  100. case 180:
  101. return super.getFrameRelativeDimensions();
  102. case 90:
  103. case 270:
  104. return new DimensionDbl(getHeight(), getWidth());
  105. default:
  106. area.log.warning("Illegal rotation: " + getRotationToFrame());
  107. return super.getFrameRelativeDimensions();
  108. }
  109. }
  110. /**
  111. * Gets the width of this <code>AreaGeometry</code> as seen from any
  112. * enclosing frame
  113. * @return the frame-view width
  114. */
  115. protected double getFrameRelativeWidth() {
  116. return getFrameRelativeDimensions().getWidth();
  117. }
  118. /**
  119. * Gets the height of this <code>AreaGeometry</code> as seen from any
  120. * enclosing frame
  121. * @return the frame-view height
  122. */
  123. protected double getFrameRelativeHeight() {
  124. return getFrameRelativeDimensions().getHeight();
  125. }
  126. /**
  127. * {@inheritDoc}
  128. * <p>Any registered listeners are notified of the change in the
  129. * dimension.
  130. */
  131. public void setIPDimPts(double pts) {
  132. super.setIPDimPts(pts);
  133. padding.setContents(this);
  134. area.notifyListeners();
  135. }
  136. /**
  137. * {@inheritDoc}
  138. * <p>Any registered listeners are notified of the change in the
  139. * dimension.
  140. */
  141. public void setBPDimPts(double pts) {
  142. super.setBPDimPts(pts);
  143. padding.setContents(this);
  144. area.notifyListeners();
  145. }
  146. }