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.

ImageOutputControl.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 Output Control structured field specifies the position and
  25. * orientation of the IM image object area and the mapping of the image points
  26. * to presentation device pels.
  27. *
  28. */
  29. public class ImageOutputControl extends AbstractAFPObject {
  30. /** the orientation of the image */
  31. private int orientation;
  32. /**
  33. * Specifies the offset, along the X-axis, of the IM image object area
  34. * origin to the origin of the including page
  35. */
  36. private int xCoord;
  37. /**
  38. * Specifies the offset, along the Y-axis, of the IM image object area
  39. * origin to the origin of the including page
  40. */
  41. private int yCoord;
  42. /** map an image point to a single presentation device */
  43. private boolean singlePoint = true;
  44. /**
  45. * Constructor for the ImageOutputControl The x parameter specifies the
  46. * offset, along the X-axis, of the IM image object area origin to the
  47. * origin of the including page and the y parameter specifies the offset
  48. * along the Y-axis. The offset is specified in image points and is resolved
  49. * using the units of measure specified for the image in the IID structured
  50. * field.
  51. *
  52. * @param x
  53. * The X-axis offset.
  54. * @param y
  55. * The Y-axis offset.
  56. */
  57. public ImageOutputControl(int x, int y) {
  58. xCoord = x;
  59. yCoord = y;
  60. }
  61. /** {@inheritDoc} */
  62. public void writeToStream(OutputStream os) throws IOException {
  63. byte[] data = new byte[33];
  64. data[0] = 0x5A;
  65. data[1] = 0x00;
  66. data[2] = 0x20;
  67. data[3] = (byte) 0xD3;
  68. data[4] = (byte) 0xA7;
  69. data[5] = (byte) 0x7B;
  70. data[6] = 0x00;
  71. data[7] = 0x00;
  72. data[8] = 0x00;
  73. // XoaOset
  74. byte[] x1 = BinaryUtils.convert(xCoord, 3);
  75. data[9] = x1[0];
  76. data[10] = x1[1];
  77. data[11] = x1[2];
  78. // YoaOset
  79. byte[] x2 = BinaryUtils.convert(yCoord, 3);
  80. data[12] = x2[0];
  81. data[13] = x2[1];
  82. data[14] = x2[2];
  83. switch (orientation) {
  84. case 0:
  85. // 0 and 90 degrees respectively
  86. data[15] = 0x00;
  87. data[16] = 0x00;
  88. data[17] = 0x2D;
  89. data[18] = 0x00;
  90. break;
  91. case 90:
  92. // 90 and 180 degrees respectively
  93. data[15] = 0x2D;
  94. data[16] = 0x00;
  95. data[17] = 0x5A;
  96. data[18] = 0x00;
  97. break;
  98. case 180:
  99. // 180 and 270 degrees respectively
  100. data[15] = 0x5A;
  101. data[16] = 0x00;
  102. data[17] = (byte) 0x87;
  103. data[18] = 0x00;
  104. break;
  105. case 270:
  106. // 270 and 0 degrees respectively
  107. data[15] = (byte) 0x87;
  108. data[16] = 0x00;
  109. data[17] = 0x00;
  110. data[18] = 0x00;
  111. break;
  112. default:
  113. // 0 and 90 degrees respectively
  114. data[15] = 0x00;
  115. data[16] = 0x00;
  116. data[17] = 0x2D;
  117. data[18] = 0x00;
  118. break;
  119. }
  120. // Constant Data
  121. data[19] = 0x00;
  122. data[20] = 0x00;
  123. data[21] = 0x00;
  124. data[22] = 0x00;
  125. data[23] = 0x00;
  126. data[24] = 0x00;
  127. data[25] = 0x00;
  128. data[26] = 0x00;
  129. if (singlePoint) {
  130. data[27] = 0x03;
  131. data[28] = (byte) 0xE8;
  132. data[29] = 0x03;
  133. data[30] = (byte) 0xE8;
  134. } else {
  135. data[27] = 0x07;
  136. data[28] = (byte) 0xD0;
  137. data[29] = 0x07;
  138. data[30] = (byte) 0xD0;
  139. }
  140. // Constant Data
  141. data[31] = (byte) 0xFF;
  142. data[32] = (byte) 0xFF;
  143. os.write(data);
  144. }
  145. /**
  146. * Sets the orientation which specifies the amount of clockwise rotation of
  147. * the IM image object area.
  148. *
  149. * @param orientation
  150. * The orientation to set.
  151. */
  152. public void setOrientation(int orientation) {
  153. if (orientation == 0 || orientation == 90 || orientation == 180
  154. || orientation == 270) {
  155. this.orientation = orientation;
  156. } else {
  157. throw new IllegalArgumentException(
  158. "The orientation must be one of the values 0, 90, 180, 270");
  159. }
  160. }
  161. /**
  162. * Sets the singlepoint, if true map an image point to a single presentation
  163. * device pel in the IM image object area. If false map an image point to
  164. * two presentation device pels in the IM image object area (double-dot)
  165. *
  166. * @param singlepoint
  167. * Use the singlepoint basis when true.
  168. */
  169. public void setSinglepoint(boolean singlepoint) {
  170. singlePoint = singlepoint;
  171. }
  172. }