Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Viewport.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 1999-2004,2006 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 child 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. * Sets the content area.
  77. * @param content the content area
  78. */
  79. public void setContent(Area content) {
  80. this.content = content;
  81. }
  82. /**
  83. * Get the content area for this viewport.
  84. *
  85. * @return the content area
  86. */
  87. public Area getContent() {
  88. return content;
  89. }
  90. private void writeObject(java.io.ObjectOutputStream out)
  91. throws IOException {
  92. out.writeBoolean(contentPosition != null);
  93. if (contentPosition != null) {
  94. out.writeFloat((float) contentPosition.getX());
  95. out.writeFloat((float) contentPosition.getY());
  96. out.writeFloat((float) contentPosition.getWidth());
  97. out.writeFloat((float) contentPosition.getHeight());
  98. }
  99. out.writeBoolean(clip);
  100. out.writeObject(props);
  101. out.writeObject(content);
  102. }
  103. private void readObject(java.io.ObjectInputStream in)
  104. throws IOException, ClassNotFoundException {
  105. if (in.readBoolean()) {
  106. contentPosition = new Rectangle2D.Float(in.readFloat(),
  107. in.readFloat(),
  108. in.readFloat(),
  109. in.readFloat());
  110. }
  111. clip = in.readBoolean();
  112. props = (HashMap) in.readObject();
  113. content = (Area) in.readObject();
  114. }
  115. }