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.9KB

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