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

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