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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 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.render.afp.modca;
  18. import java.io.IOException;
  19. import java.io.OutputStream;
  20. import java.io.UnsupportedEncodingException;
  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 [] _xCoor;
  43. /**
  44. * The y position where we need to put this object on the page
  45. */
  46. private byte [] _yCoor;
  47. /**
  48. * Constructor for the Include Page Segment
  49. * @param name Name of the page segment
  50. * @param xVal The x position
  51. * @param yVal The y position
  52. */
  53. public IncludePageSegment(String name, int xVal, int yVal){
  54. super(name);
  55. _xCoor = BinaryUtils.convert(xVal, 3);
  56. _yCoor = BinaryUtils.convert(yVal, 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
  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] = _xCoor[0]; // x coordinate
  82. data[18] = _xCoor[1];
  83. data[19] = _xCoor[2];
  84. data[20] = _yCoor[0]; // y coordinate
  85. data[21] = _yCoor[1];
  86. data[22] = _yCoor[2];
  87. os.write(data);
  88. }
  89. }