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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.area.inline;
  8. import org.apache.fop.area.Area;
  9. import org.apache.fop.render.Renderer;
  10. import java.io.IOException;
  11. import java.awt.geom.Rectangle2D;
  12. /**
  13. * Inline viewport area.
  14. * This is an inline-level viewport area for inline container,
  15. * external graphic and instream foreign object. This viewport
  16. * holds the area and positions it.
  17. */
  18. public class Viewport extends InlineArea {
  19. // contents could be container, foreign object or image
  20. private Area content;
  21. // clipping for the viewport
  22. private boolean clip = false;
  23. // position of the cild area relative to this area
  24. private Rectangle2D contentPosition;
  25. /**
  26. * Create a new viewport area with the content area.
  27. *
  28. * @param child the child content area of this viewport
  29. */
  30. public Viewport(Area child) {
  31. content = child;
  32. }
  33. /**
  34. * Set the clip of this viewport.
  35. *
  36. * @param c true if this viewport should clip
  37. */
  38. public void setClip(boolean c) {
  39. clip = c;
  40. }
  41. /**
  42. * Get the clip of this viewport.
  43. *
  44. * @return true if this viewport should clip
  45. */
  46. public boolean getClip() {
  47. return clip;
  48. }
  49. /**
  50. * Set the position and size of the content of this viewport.
  51. *
  52. * @param cp the position and size to place the content
  53. */
  54. public void setContentPosition(Rectangle2D cp) {
  55. contentPosition = cp;
  56. }
  57. /**
  58. * Get the position and size of the content of this viewport.
  59. *
  60. * @return the position and size to place the content
  61. */
  62. public Rectangle2D getContentPosition() {
  63. return contentPosition;
  64. }
  65. /**
  66. * Get the content area for this viewport.
  67. *
  68. * @return the content area
  69. */
  70. public Area getContent() {
  71. return content;
  72. }
  73. /**
  74. * Render this inline area.
  75. *
  76. * @param renderer the renderer to render this inline area
  77. */
  78. public void render(Renderer renderer) {
  79. renderer.renderViewport(this);
  80. }
  81. private void writeObject(java.io.ObjectOutputStream out)
  82. throws IOException {
  83. out.writeBoolean(contentPosition != null);
  84. if (contentPosition != null) {
  85. out.writeFloat((float) contentPosition.getX());
  86. out.writeFloat((float) contentPosition.getY());
  87. out.writeFloat((float) contentPosition.getWidth());
  88. out.writeFloat((float) contentPosition.getHeight());
  89. }
  90. out.writeBoolean(clip);
  91. out.writeObject(content);
  92. }
  93. private void readObject(java.io.ObjectInputStream in)
  94. throws IOException, ClassNotFoundException {
  95. if (in.readBoolean()) {
  96. contentPosition = new Rectangle2D.Float(in.readFloat(),
  97. in.readFloat(),
  98. in.readFloat(),
  99. in.readFloat());
  100. }
  101. clip = in.readBoolean();
  102. content = (Area) in.readObject();
  103. }
  104. }