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.

InlineViewport.java 4.5KB

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