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.

IncludePageSegment.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.render.afp.modca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.render.afp.tools.BinaryUtils;
  22. /**
  23. * The Include Page Segment structured field references a page segment resource
  24. * object that is to be presented on the page or overlay presentation space. The IPS
  25. * specifies a reference point on the including page or overlay coordinate system that
  26. * may be used to position objects contained in the page segment. A page segment
  27. * can be referenced at any time during page or overlay state, but not during an
  28. * object state. The page segment inherits the active environment group definition of
  29. * the including page or overlay.
  30. *
  31. * Note : No use for Triplets.
  32. *
  33. * A 'real' example for where this will be used is for
  34. * the dynamic placing of overlay objects, such as signatures
  35. * that may have to be placed at different positions on a document.
  36. *
  37. */
  38. public class IncludePageSegment extends AbstractNamedAFPObject {
  39. /**
  40. * The x position where we need to put this object on the page
  41. */
  42. private byte[] x;
  43. /**
  44. * The y position where we need to put this object on the page
  45. */
  46. private byte[] y;
  47. /**
  48. * Constructor for the Include Page Segment
  49. * @param name Name of the page segment
  50. * @param x The x position
  51. * @param y The y position
  52. */
  53. public IncludePageSegment(String name, int x, int y) {
  54. super(name);
  55. this.x = BinaryUtils.convert(x, 3);
  56. this.y = BinaryUtils.convert(y, 3);
  57. }
  58. /**
  59. * Accessor method to write the AFP datastream for the Include Page Segment
  60. * @param os The stream to write to
  61. * @throws java.io.IOException thrown if an I/O exception of some sort has occurred
  62. */
  63. public void writeDataStream(OutputStream os)
  64. throws IOException {
  65. byte[] data = new byte[23]; //(9 +14)
  66. data[0] = 0x5A;
  67. // Set the total record length
  68. byte[] rl1 = BinaryUtils.convert(22, 2); //Ignore first byte
  69. data[1] = rl1[0];
  70. data[2] = rl1[1];
  71. // Structured field ID for a IPS
  72. data[3] = (byte) 0xD3;
  73. data[4] = (byte) 0xAF;
  74. data[5] = (byte) 0x5F;
  75. data[6] = 0x00; // Reserved
  76. data[7] = 0x00; // Reserved
  77. data[8] = 0x00; // Reserved
  78. for (int i = 0; i < nameBytes.length; i++) {
  79. data[9 + i] = nameBytes[i];
  80. }
  81. data[17] = x[0]; // x coordinate
  82. data[18] = x[1];
  83. data[19] = x[2];
  84. data[20] = y[0]; // y coordinate
  85. data[21] = y[1];
  86. data[22] = y[2];
  87. os.write(data);
  88. }
  89. }