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.

RegionViewport.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.area;
  18. import java.awt.geom.Rectangle2D;
  19. import java.io.IOException;
  20. import java.util.HashMap;
  21. import org.apache.fop.traits.BorderProps;
  22. /**
  23. * Region Viewport reference area.
  24. * This area is the viewport for a region and contains a region area.
  25. */
  26. public class RegionViewport extends Area implements Cloneable {
  27. // this rectangle is relative to the page
  28. private RegionReference region;
  29. private Rectangle2D viewArea;
  30. private boolean clip = false;
  31. /**
  32. * Create a new region viewport.
  33. *
  34. * @param viewArea the view area of this viewport
  35. */
  36. public RegionViewport(Rectangle2D viewArea) {
  37. this.viewArea = viewArea;
  38. }
  39. /**
  40. * Set the region for this region viewport.
  41. *
  42. * @param reg the child region inside this viewport
  43. */
  44. public void setRegion(RegionReference reg) {
  45. region = reg;
  46. }
  47. /**
  48. * Get the region for this region viewport.
  49. *
  50. * @return the child region inside this viewport
  51. */
  52. public RegionReference getRegion() {
  53. return region;
  54. }
  55. /**
  56. * Set the clipping for this region viewport.
  57. *
  58. * @param c the clipping value
  59. */
  60. public void setClip(boolean c) {
  61. clip = c;
  62. }
  63. /**
  64. * Get the view area of this viewport.
  65. *
  66. * @return the viewport rectangle area
  67. */
  68. public Rectangle2D getViewArea() {
  69. return viewArea;
  70. }
  71. /**
  72. * Return the sum of region border- and padding-before
  73. *
  74. * @return width in millipoints
  75. */
  76. public int getBorderAndPaddingWidthBefore() {
  77. int margin = 0;
  78. BorderProps bps = (BorderProps) getTrait(Trait.BORDER_BEFORE);
  79. if (bps != null) {
  80. margin = bps.width;
  81. }
  82. Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE);
  83. if (padWidth != null) {
  84. margin += padWidth.intValue();
  85. }
  86. return margin;
  87. }
  88. /**
  89. * Return the sum of region border- and padding-after
  90. *
  91. * @return width in millipoints
  92. */
  93. public int getBorderAndPaddingWidthAfter() {
  94. int margin = 0;
  95. BorderProps bps = (BorderProps) getTrait(Trait.BORDER_AFTER);
  96. if (bps != null) {
  97. margin = bps.width;
  98. }
  99. Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER);
  100. if (padWidth != null) {
  101. margin += padWidth.intValue();
  102. }
  103. return margin;
  104. }
  105. /**
  106. * Return the sum of region border- and padding-start
  107. *
  108. * @return width in millipoints
  109. */
  110. public int getBorderAndPaddingWidthStart() {
  111. int margin = 0;
  112. BorderProps bps = (BorderProps) getTrait(Trait.BORDER_START);
  113. if (bps != null) {
  114. margin = bps.width;
  115. }
  116. Integer padWidth = (Integer) getTrait(Trait.PADDING_START);
  117. if (padWidth != null) {
  118. margin += padWidth.intValue();
  119. }
  120. return margin;
  121. }
  122. /**
  123. * Return the sum of region border- and padding-end
  124. *
  125. * @return width in millipoints
  126. */
  127. public int getBorderAndPaddingWidthEnd() {
  128. int margin = 0;
  129. BorderProps bps = (BorderProps) getTrait(Trait.BORDER_END);
  130. if (bps != null) {
  131. margin = bps.width;
  132. }
  133. Integer padWidth = (Integer) getTrait(Trait.PADDING_END);
  134. if (padWidth != null) {
  135. margin += padWidth.intValue();
  136. }
  137. return margin;
  138. }
  139. private void writeObject(java.io.ObjectOutputStream out)
  140. throws IOException {
  141. out.writeFloat((float) viewArea.getX());
  142. out.writeFloat((float) viewArea.getY());
  143. out.writeFloat((float) viewArea.getWidth());
  144. out.writeFloat((float) viewArea.getHeight());
  145. out.writeBoolean(clip);
  146. out.writeObject(props);
  147. out.writeObject(region);
  148. }
  149. private void readObject(java.io.ObjectInputStream in)
  150. throws IOException, ClassNotFoundException {
  151. viewArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(),
  152. in.readFloat(), in.readFloat());
  153. clip = in.readBoolean();
  154. props = (HashMap)in.readObject();
  155. setRegion((RegionReference) in.readObject());
  156. }
  157. /**
  158. * Clone this region viewport.
  159. * Used when creating a copy from the page master.
  160. *
  161. * @return a new copy of this region viewport
  162. */
  163. public Object clone() {
  164. RegionViewport rv = new RegionViewport((Rectangle2D)viewArea.clone());
  165. rv.region = (RegionReference)region.clone();
  166. if (props != null) {
  167. rv.props = (HashMap)props.clone();
  168. }
  169. return rv;
  170. }
  171. }