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.

ObjectAreaDescriptor.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 org.apache.fop.render.afp.tools.BinaryUtils;
  21. /**
  22. * The Object Area Descriptor structured field specifies the size and attributes
  23. * of an object area presentation space.
  24. *
  25. */
  26. public class ObjectAreaDescriptor extends AbstractAFPObject {
  27. private int _width = 0;
  28. private int _height = 0;
  29. /**
  30. * Construct an object area descriptor for the specified object width
  31. * and object height.
  32. * @param width The page width.
  33. * @param height The page height.
  34. */
  35. public ObjectAreaDescriptor(int width, int height) {
  36. _width = width;
  37. _height = height;
  38. }
  39. /**
  40. * Accessor method to write the AFP datastream for the Object Area Descriptor
  41. * @param os The stream to write to
  42. * @throws java.io.IOException
  43. */
  44. public void writeDataStream(OutputStream os)
  45. throws IOException {
  46. byte[] data = new byte[] {
  47. 0x5A,
  48. 0x00, // Length
  49. 0x1C, // Length
  50. (byte) 0xD3,
  51. (byte) 0xA6,
  52. (byte) 0x6B,
  53. 0x00, // Flags
  54. 0x00, // Reserved
  55. 0x00, // Reserved
  56. 0x03, // Triplet length
  57. 0x43, // tid = Descriptor Position Triplet
  58. 0x01, // DesPosId = 1
  59. 0x08, // Triplet length
  60. 0x4B, // tid = Measurement Units Triplet
  61. 0x00, // XaoBase = 10 inches
  62. 0x00, // YaoBase = 10 inches
  63. 0x09, // XaoUnits = 2400
  64. 0x60, // XaoUnits =
  65. 0x09, // YaoUnits = 2400
  66. 0x60, // YaoUnits =
  67. 0x09, // Triplet length
  68. 0x4C, // tid = Object Area Size
  69. 0x02, // Size Type
  70. 0x00, // XoaSize
  71. 0x00,
  72. 0x00,
  73. 0x00, // YoaSize
  74. 0x00,
  75. 0x00,
  76. };
  77. byte[] l = BinaryUtils.convert(data.length - 1, 2);
  78. data[1] = l[0];
  79. data[2] = l[1];
  80. byte[] x = BinaryUtils.convert(_width, 3);
  81. data[23] = x[0];
  82. data[24] = x[1];
  83. data[25] = x[2];
  84. byte[] y = BinaryUtils.convert(_height, 3);
  85. data[26] = y[0];
  86. data[27] = y[1];
  87. data[28] = y[2];
  88. os.write(data);
  89. }
  90. }