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.

ImageCellPosition.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.ioca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.modca.AbstractAFPObject;
  22. import org.apache.fop.afp.util.BinaryUtils;
  23. /**
  24. * The IM Image Cell Position structured field specifies the placement,
  25. * size, and replication of IM image cells.
  26. */
  27. public class ImageCellPosition extends AbstractAFPObject {
  28. /** offset of image cell in X direction */
  29. private int xOffset;
  30. /** offset of image cell in Y direction */
  31. private int yOffset;
  32. /** size of image cell in X direction */
  33. private final byte[] xSize = new byte[] {(byte)0xFF, (byte)0xFF};
  34. /** size of image cell in Y direction */
  35. private final byte[] ySize = new byte[] {(byte)0xFF, (byte)0xFF};
  36. /** size of fill rectangle in X direction */
  37. private final byte[] xFillSize = new byte[] {(byte)0xFF, (byte)0xFF};
  38. /** size of fill rectangle in Y direction */
  39. private final byte[] yFillSize = new byte[] {(byte)0xFF, (byte)0xFF};
  40. /**
  41. * Main Constructor
  42. *
  43. * @param x The offset of image cell in X direction
  44. * @param y The offset of image cell in Y direction
  45. */
  46. public ImageCellPosition(int x, int y) {
  47. xOffset = x;
  48. yOffset = y;
  49. }
  50. /** {@inheritDoc} */
  51. public void writeToStream(OutputStream os) throws IOException {
  52. byte[] data = new byte[21];
  53. copySF(data, Type.POSITION, Category.IM_IMAGE);
  54. data[1] = 0x00; // length
  55. data[2] = 0x14;
  56. /**
  57. * Specifies the offset along the Xp direction, in image points,
  58. * of this image cell from the IM image object area origin.
  59. */
  60. byte[] x1 = BinaryUtils.convert(xOffset, 2);
  61. data[9] = x1[0];
  62. data[10] = x1[1];
  63. /**
  64. * Specifies the offset along the Yp direction, in image points,
  65. * of this image cell from the IM image object area origin.
  66. */
  67. byte[] x2 = BinaryUtils.convert(yOffset, 2);
  68. data[11] = x2[0];
  69. data[12] = x2[1];
  70. data[13] = xSize[0];
  71. data[14] = xSize[1];
  72. data[15] = ySize[0];
  73. data[16] = ySize[1];
  74. data[17] = xFillSize[0];
  75. data[18] = xFillSize[1];
  76. data[19] = yFillSize[0];
  77. data[20] = yFillSize[1];
  78. os.write(data);
  79. }
  80. /**
  81. * Specifies the extent in the X direction, in image points,
  82. * of this image cell. A value of X'FFFF' indicates that the
  83. * default extent specified in bytes 28 and 29 of the Image
  84. * Input Descriptor (IID) is to be used.
  85. *
  86. * @param xcSize The size to set.
  87. */
  88. public void setXSize(int xcSize) {
  89. byte[] x = BinaryUtils.convert(xcSize, 2);
  90. xSize[0] = x[0];
  91. xSize[1] = x[1];
  92. }
  93. /**
  94. * Specifies the extent of the fill rectangle in the X direction,
  95. * in image points. This value can be smaller than, equal to, or
  96. * larger than the image cell extent in the X direction (XCSize).
  97. * A value of X'FFFF' indicates that the image cell X-extent should
  98. * be used as the fill rectangle X-extent. The fill rectangle is
  99. * filled in the X direction by repeating the image cell in the
  100. * X direction. The image cell can be truncated to fit the rectangle.
  101. *
  102. * @param size The size to set.
  103. */
  104. public void setXFillSize(int size) {
  105. byte[] x = BinaryUtils.convert(size, 2);
  106. this.xFillSize[0] = x[0];
  107. this.xFillSize[1] = x[1];
  108. }
  109. /**
  110. * Specifies the extent in the Y direction, in image points,
  111. * of this image cell. A value of X'FFFF' indicates that the
  112. * default extent specified in bytes 30 and 31 of the Image
  113. * Input Descriptor (IID) is to be used.
  114. *
  115. * @param size The size to set.
  116. */
  117. public void setYSize(int size) {
  118. byte[] x = BinaryUtils.convert(size, 2);
  119. this.ySize[0] = x[0];
  120. this.ySize[1] = x[1];
  121. }
  122. /**
  123. * Specifies the extent of the fill rectangle in the Y direction,
  124. * in image points. This value can be smaller than, equal to, or
  125. * larger than the image cell extent in the Y direction (YCSize).
  126. * A value of X'FFFF' indicates that the image cell Y-extent should
  127. * be used as the fill rectangle Y-extent. The fill rectangle is
  128. * filled in the Y direction by repeating the image cell in the
  129. * Y direction. The image cell can be truncated to fit the rectangle.
  130. *
  131. * @param size The size to set.
  132. */
  133. public void setYFillSize(int size) {
  134. byte[] x = BinaryUtils.convert(size, 2);
  135. this.yFillSize[0] = x[0];
  136. this.yFillSize[1] = x[1];
  137. }
  138. }