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.

ImageSizeParameter.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * Describes the measurement characteristics of the image when it is created.
  24. */
  25. public class ImageSizeParameter extends AbstractAFPObject {
  26. private int hRes = 0;
  27. private int vRes = 0;
  28. private int hSize = 0;
  29. private int vSize = 0;
  30. /**
  31. * Constructor for a ImageSizeParameter for the specified
  32. * resolution, hsize and vsize.
  33. * @param hresol The horizontal resolution of the image.
  34. * @param vresol The vertical resolution of the image.
  35. * @param hsize The horizontal size of the image.
  36. * @param vsize The vertical size of the image.
  37. */
  38. public ImageSizeParameter(int hresol, int vresol, int hsize, int vsize) {
  39. this.hRes = hresol;
  40. this.vRes = vresol;
  41. this.hSize = hsize;
  42. this.vSize = vsize;
  43. }
  44. /**
  45. * Accessor method to write the AFP datastream for the Image Size Parameter
  46. * @param os The stream to write to
  47. * @throws java.io.IOException if an I/O exception occured
  48. */
  49. public void writeDataStream(OutputStream os) throws IOException {
  50. byte[] data = new byte[] {
  51. (byte)0x94, // ID = Image Size Parameter
  52. 0x09, // Length
  53. 0x00, // Unit base - 10 Inches
  54. 0x00, // HRESOL
  55. 0x00, //
  56. 0x00, // VRESOL
  57. 0x00, //
  58. 0x00, // HSIZE
  59. 0x00, //
  60. 0x00, // VSIZE
  61. 0x00, //
  62. };
  63. byte[] x = BinaryUtils.convert(hRes, 2);
  64. data[3] = x[0];
  65. data[4] = x[1];
  66. byte[] y = BinaryUtils.convert(vRes, 2);
  67. data[5] = y[0];
  68. data[6] = y[1];
  69. byte[] w = BinaryUtils.convert(hSize, 2);
  70. data[7] = w[0];
  71. data[8] = w[1];
  72. byte[] h = BinaryUtils.convert(vSize, 2);
  73. data[9] = h[0];
  74. data[10] = h[1];
  75. os.write(data);
  76. }
  77. }