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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.Rectangle;
  20. import java.awt.geom.Rectangle2D;
  21. import java.io.IOException;
  22. import java.util.TreeMap;
  23. import org.apache.fop.traits.WritingModeTraitsGetter;
  24. /**
  25. * Region Viewport area.
  26. * This object represents the region-viewport-area. It has a
  27. * region-reference-area as its child. These areas are described
  28. * in the fo:region-body description in the XSL Recommendation.
  29. */
  30. public class RegionViewport extends Area implements Viewport {
  31. private static final long serialVersionUID = 505781815165102572L;
  32. // this rectangle is relative to the page
  33. private RegionReference regionReference;
  34. private Rectangle2D viewArea;
  35. private boolean clip;
  36. /**
  37. * Create a new region-viewport-area
  38. *
  39. * @param viewArea the view area of this viewport
  40. */
  41. public RegionViewport(Rectangle2D viewArea) {
  42. this.viewArea = viewArea;
  43. addTrait(Trait.IS_VIEWPORT_AREA, Boolean.TRUE);
  44. }
  45. /**
  46. * Set the region-reference-area for this region viewport.
  47. *
  48. * @param reg the child region-reference-area inside this viewport
  49. */
  50. public void setRegionReference(RegionReference reg) {
  51. regionReference = reg;
  52. }
  53. /**
  54. * Get the region-reference-area for this region viewport.
  55. *
  56. * @return the child region-reference-area inside this viewport
  57. */
  58. public RegionReference getRegionReference() {
  59. return regionReference;
  60. }
  61. /**
  62. * Set the clipping for this region viewport.
  63. *
  64. * @param c the clipping value
  65. */
  66. public void setClip(boolean c) {
  67. clip = c;
  68. }
  69. /** {@inheritDoc} */
  70. public boolean hasClip() {
  71. return this.clip;
  72. }
  73. /** {@inheritDoc} */
  74. public Rectangle getClipRectangle() {
  75. if (clip) {
  76. return new Rectangle(getIPD(), getBPD());
  77. } else {
  78. return null;
  79. }
  80. }
  81. /**
  82. * Get the view area of this viewport.
  83. *
  84. * @return the viewport rectangle area
  85. */
  86. public Rectangle2D getViewArea() {
  87. return viewArea;
  88. }
  89. private void writeObject(java.io.ObjectOutputStream out)
  90. throws IOException {
  91. out.writeFloat((float) viewArea.getX());
  92. out.writeFloat((float) viewArea.getY());
  93. out.writeFloat((float) viewArea.getWidth());
  94. out.writeFloat((float) viewArea.getHeight());
  95. out.writeBoolean(clip);
  96. out.writeObject((TreeMap)traits);
  97. out.writeObject(regionReference);
  98. }
  99. private void readObject(java.io.ObjectInputStream in)
  100. throws IOException, ClassNotFoundException {
  101. viewArea = new Rectangle2D.Float(in.readFloat(), in.readFloat(),
  102. in.readFloat(), in.readFloat());
  103. clip = in.readBoolean();
  104. traits = (TreeMap)in.readObject();
  105. setRegionReference((RegionReference) in.readObject());
  106. }
  107. /** {@inheritDoc} */
  108. public Object clone() throws CloneNotSupportedException {
  109. RegionViewport rv = (RegionViewport) super.clone();
  110. rv.regionReference = (RegionReference) regionReference.clone();
  111. rv.viewArea = (Rectangle2D) viewArea.clone();
  112. return rv;
  113. }
  114. /**
  115. * Sets the writing mode traits for the region reference of
  116. * this region viewport
  117. * @param wmtg a WM traits getter
  118. */
  119. public void setWritingModeTraits(WritingModeTraitsGetter wmtg) {
  120. if (regionReference != null) {
  121. regionReference.setWritingModeTraits(wmtg);
  122. }
  123. }
  124. }