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.

Viewport.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.inline;
  18. import org.apache.fop.area.Area;
  19. import java.io.IOException;
  20. import java.awt.geom.Rectangle2D;
  21. import java.util.HashMap;
  22. /**
  23. * Inline viewport area.
  24. * This is an inline-level viewport area for inline container,
  25. * external graphic and instream foreign object. This viewport
  26. * holds the area and positions it.
  27. */
  28. public class Viewport extends InlineArea {
  29. // contents could be container, foreign object or image
  30. private Area content;
  31. // clipping for the viewport
  32. private boolean clip = false;
  33. // position of the cild area relative to this area
  34. private Rectangle2D contentPosition;
  35. /**
  36. * Create a new viewport area with the content area.
  37. *
  38. * @param child the child content area of this viewport
  39. */
  40. public Viewport(Area child) {
  41. content = child;
  42. }
  43. /**
  44. * Set the clip of this viewport.
  45. *
  46. * @param c true if this viewport should clip
  47. */
  48. public void setClip(boolean c) {
  49. clip = c;
  50. }
  51. /**
  52. * Get the clip of this viewport.
  53. *
  54. * @return true if this viewport should clip
  55. */
  56. public boolean getClip() {
  57. return clip;
  58. }
  59. /**
  60. * Set the position and size of the content of this viewport.
  61. *
  62. * @param cp the position and size to place the content
  63. */
  64. public void setContentPosition(Rectangle2D cp) {
  65. contentPosition = cp;
  66. }
  67. /**
  68. * Get the position and size of the content of this viewport.
  69. *
  70. * @return the position and size to place the content
  71. */
  72. public Rectangle2D getContentPosition() {
  73. return contentPosition;
  74. }
  75. /**
  76. * Get the content area for this viewport.
  77. *
  78. * @return the content area
  79. */
  80. public Area getContent() {
  81. return content;
  82. }
  83. private void writeObject(java.io.ObjectOutputStream out)
  84. throws IOException {
  85. out.writeBoolean(contentPosition != null);
  86. if (contentPosition != null) {
  87. out.writeFloat((float) contentPosition.getX());
  88. out.writeFloat((float) contentPosition.getY());
  89. out.writeFloat((float) contentPosition.getWidth());
  90. out.writeFloat((float) contentPosition.getHeight());
  91. }
  92. out.writeBoolean(clip);
  93. out.writeObject(props);
  94. out.writeObject(content);
  95. }
  96. private void readObject(java.io.ObjectInputStream in)
  97. throws IOException, ClassNotFoundException {
  98. if (in.readBoolean()) {
  99. contentPosition = new Rectangle2D.Float(in.readFloat(),
  100. in.readFloat(),
  101. in.readFloat(),
  102. in.readFloat());
  103. }
  104. clip = in.readBoolean();
  105. props = (HashMap) in.readObject();
  106. content = (Area) in.readObject();
  107. }
  108. }