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 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * 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 int x;
  43. /**
  44. * The y position where we need to put this object on the page
  45. */
  46. private int y;
  47. /**
  48. * Constructor for the Include Page Segment
  49. *
  50. * @param name Name of the page segment
  51. * @param x The x position
  52. * @param y The y position
  53. */
  54. public IncludePageSegment(String name, int x, int y) {
  55. super(name);
  56. this.x = x;
  57. this.y = y;
  58. }
  59. /** {@inheritDoc} */
  60. public void writeToStream(OutputStream os) throws IOException {
  61. byte[] data = new byte[23]; //(9 +14)
  62. copySF(data, Type.INCLUDE, Category.PAGE_SEGMENT);
  63. // Set the total record length
  64. byte[] len = BinaryUtils.convert(22, 2); //Ignore first byte
  65. data[1] = len[0];
  66. data[2] = len[1];
  67. byte[] xPos = BinaryUtils.convert(x, 3);
  68. data[17] = xPos[0]; // x coordinate
  69. data[18] = xPos[1];
  70. data[19] = xPos[2];
  71. byte[] yPos = BinaryUtils.convert(y, 3);
  72. data[20] = yPos[0]; // y coordinate
  73. data[21] = yPos[1];
  74. data[22] = yPos[2];
  75. os.write(data);
  76. }
  77. }