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.

PageDescriptor.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Page Descriptor structured field specifies the size and attributes of
  24. * a page or overlay presentation space.
  25. *
  26. */
  27. public class PageDescriptor extends AbstractDescriptor {
  28. /**
  29. * Construct a page descriptor for the specified page width
  30. * and page height.
  31. *
  32. * @param width The page width.
  33. * @param height The page height.
  34. * @param widthRes The page width resolution
  35. * @param heightRes The page height resolution
  36. */
  37. public PageDescriptor(int width, int height, int widthRes, int heightRes) {
  38. super(width, height, widthRes, heightRes);
  39. }
  40. /** {@inheritDoc} */
  41. public void writeToStream(OutputStream os) throws IOException {
  42. byte[] data = new byte[24];
  43. copySF(data, Type.DESCRIPTOR, Category.PAGE);
  44. data[2] = 0x17;
  45. // XpgBase
  46. data[9] = 0x00; // XpgBase = 10 inches
  47. // YpgBase
  48. data[10] = 0x00; // YpgBase = 10 inches
  49. // XpgUnits
  50. byte[] xdpi = BinaryUtils.convert(widthRes * 10, 2);
  51. data[11] = xdpi[0];
  52. data[12] = xdpi[1];
  53. // YpgUnits
  54. byte[] ydpi = BinaryUtils.convert(heightRes * 10, 2);
  55. data[13] = ydpi[0];
  56. data[14] = ydpi[1];
  57. // XpgSize
  58. byte[] x = BinaryUtils.convert(width, 3);
  59. data[15] = x[0];
  60. data[16] = x[1];
  61. data[17] = x[2];
  62. // YpgSize
  63. byte[] y = BinaryUtils.convert(height, 3);
  64. data[18] = y[0];
  65. data[19] = y[1];
  66. data[20] = y[2];
  67. data[21] = 0x00; // Reserved
  68. data[22] = 0x00; // Reserved
  69. data[23] = 0x00; // Reserved
  70. os.write(data);
  71. }
  72. }