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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. 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. /* $Id$ */
  18. package org.apache.fop.area;
  19. import java.awt.geom.Rectangle2D;
  20. import java.io.IOException;
  21. import java.util.HashMap;
  22. /**
  23. * Region Viewport area.
  24. * This object represents the region-viewport-area. It has a
  25. * region-reference-area as its child. These areas are described
  26. * in the fo:region-body description in the XSL Recommendation.
  27. */
  28. public class RegionViewport extends Area implements Cloneable {
  29. // this rectangle is relative to the page
  30. private RegionReference regionReference;
  31. private Rectangle2D viewArea;
  32. private boolean clip = false;
  33. /**
  34. * Create a new region-viewport-area
  35. *
  36. * @param viewArea the view area of this viewport
  37. */
  38. public RegionViewport(Rectangle2D viewArea) {
  39. this.viewArea = viewArea;
  40. addTrait(Trait.IS_VIEWPORT_AREA, Boolean.TRUE);
  41. }
  42. /**
  43. * Set the region-reference-area for this region viewport.
  44. *
  45. * @param reg the child region-reference-area inside this viewport
  46. */
  47. public void setRegionReference(RegionReference reg) {
  48. regionReference = reg;
  49. }
  50. /**
  51. * Get the region-reference-area for this region viewport.
  52. *
  53. * @return the child region-reference-area inside this viewport
  54. */
  55. public RegionReference getRegionReference() {
  56. return regionReference;
  57. }
  58. /**
  59. * Set the clipping for this region viewport.
  60. *
  61. * @param c the clipping value
  62. */
  63. public void setClip(boolean c) {
  64. clip = c;
  65. }
  66. /** @return true if the viewport should be clipped. */
  67. public boolean isClip() {
  68. return this.clip;
  69. }
  70. /**
  71. * Get the view area of this viewport.
  72. *
  73. * @return the viewport rectangle area
  74. */
  75. public Rectangle2D getViewArea() {
  76. return viewArea;
  77. }
  78. private void writeObject(java.io.ObjectOutputStream out)
  79. throws IOException {
  80. out.writeFloat((float) viewArea.getX());
  81. out.writeFloat((float) viewArea.getY());
  82. out.writeFloat((float) viewArea.getWidth());
  83. out.writeFloat((float) viewArea.getHeight());
  84. out.writeBoolean(clip);
  85. out.writeObject(props);
  86. out.writeObject(regionReference);
  87. }
  88. private void readObject(java.io.ObjectInputStream in)
  89. throws IOException, ClassNotFoundException {
  90. viewArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(),
  91. in.readFloat(), in.readFloat());
  92. clip = in.readBoolean();
  93. props = (HashMap)in.readObject();
  94. setRegionReference((RegionReference) in.readObject());
  95. }
  96. /**
  97. * Clone this region viewport.
  98. * Used when creating a copy from the page master.
  99. *
  100. * @return a new copy of this region viewport
  101. */
  102. public Object clone() {
  103. RegionViewport rv = new RegionViewport((Rectangle2D)viewArea.clone());
  104. rv.regionReference = (RegionReference)regionReference.clone();
  105. if (props != null) {
  106. rv.props = new HashMap(props);
  107. }
  108. if (foreignAttributes != null) {
  109. rv.foreignAttributes = new HashMap(foreignAttributes);
  110. }
  111. return rv;
  112. }
  113. }