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.

IncludePageOverlay.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.util.BinaryUtils;
  22. /**
  23. *
  24. * The Include Page Overlay structured field references an overlay resource
  25. * definition that is to be positioned on the page. A page overlay can be
  26. * referenced at any time during the page state, but not during an object state.
  27. * The overlay contains its own active environment group definition.
  28. *
  29. * Note: There is no need for the triplets, so I have ignored them.
  30. *
  31. * A real example of where this will be used is for static overlays, such as an
  32. * address on the page.
  33. *
  34. */
  35. public class IncludePageOverlay extends AbstractNamedAFPObject {
  36. /**
  37. * The x coordinate
  38. */
  39. private int x;
  40. /**
  41. * The y coordinate
  42. */
  43. private int y;
  44. /**
  45. * The orientation
  46. */
  47. private int orientation;
  48. /**
  49. * Constructor for the Include Page Overlay
  50. *
  51. * @param overlayName Name of the page segment
  52. * @param x The x position
  53. * @param y The y position
  54. * @param orientation The orientation
  55. */
  56. public IncludePageOverlay(String overlayName, int x, int y, int orientation) {
  57. super(overlayName);
  58. this.x = x;
  59. this.y = y;
  60. setOrientation(orientation);
  61. }
  62. /**
  63. * Sets the orientation to use for the overlay.
  64. *
  65. * @param orientation
  66. * The orientation (0,90, 180, 270)
  67. */
  68. public void setOrientation(int orientation) {
  69. if (orientation == 0 || orientation == 90 || orientation == 180
  70. || orientation == 270) {
  71. this.orientation = orientation;
  72. } else {
  73. throw new IllegalArgumentException(
  74. "The orientation must be one of the values 0, 90, 180, 270");
  75. }
  76. }
  77. /** {@inheritDoc} */
  78. public void writeToStream(OutputStream os) throws IOException {
  79. byte[] data = new byte[25]; //(9 +16)
  80. copySF(data, Type.INCLUDE, Category.PAGE_OVERLAY);
  81. // Set the total record length
  82. byte[] len = BinaryUtils.convert(24, 2); //Ignore first byte
  83. data[1] = len[0];
  84. data[2] = len[1];
  85. byte[] xPos = BinaryUtils.convert(x, 3);
  86. data[17] = xPos[0]; // x coordinate
  87. data[18] = xPos[1];
  88. data[19] = xPos[2];
  89. byte[] yPos = BinaryUtils.convert(y, 3);
  90. data[20] = yPos[0]; // y coordinate
  91. data[21] = yPos[1];
  92. data[22] = yPos[2];
  93. switch (orientation) {
  94. case 90:
  95. data[23] = 0x2D;
  96. data[24] = 0x00;
  97. break;
  98. case 180:
  99. data[23] = 0x5A;
  100. data[24] = 0x00;
  101. break;
  102. case 270:
  103. data[23] = (byte) 0x87;
  104. data[24] = 0x00;
  105. break;
  106. default:
  107. data[23] = 0x00;
  108. data[24] = 0x00;
  109. break;
  110. }
  111. os.write(data);
  112. }
  113. }