Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.goca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import org.apache.fop.afp.util.BinaryUtils;
  22. /**
  23. * A GOCA Image
  24. */
  25. public class GraphicsImage extends AbstractGraphicsDrawingOrder {
  26. /** the maximum image data length */
  27. public static final short MAX_DATA_LEN = 255;
  28. /** x coordinate */
  29. private final int x;
  30. /** y coordinate */
  31. private final int y;
  32. /** width */
  33. private final int width;
  34. /** height */
  35. private final int height;
  36. /** image data */
  37. private final byte[] imageData;
  38. /**
  39. * Main constructor
  40. *
  41. * @param x the x coordinate of the image
  42. * @param y the y coordinate of the image
  43. * @param width the image width
  44. * @param height the image height
  45. * @param imageData the image data
  46. */
  47. public GraphicsImage(int x, int y, int width, int height, byte[] imageData) {
  48. this.x = x;
  49. this.y = y;
  50. this.width = width;
  51. this.height = height;
  52. this.imageData = imageData;
  53. }
  54. /** {@inheritDoc} */
  55. public int getDataLength() {
  56. //TODO:
  57. return 0;
  58. }
  59. byte getOrderCode() {
  60. return (byte)0xD1;
  61. }
  62. /** {@inheritDoc} */
  63. public void writeToStream(OutputStream os) throws IOException {
  64. byte[] xcoord = BinaryUtils.convert(x, 2);
  65. byte[] ycoord = BinaryUtils.convert(y, 2);
  66. byte[] w = BinaryUtils.convert(width, 2);
  67. byte[] h = BinaryUtils.convert(height, 2);
  68. byte[] startData = new byte[] {
  69. getOrderCode(), // GBIMG order code
  70. (byte) 0x0A, // LENGTH
  71. xcoord[0],
  72. xcoord[1],
  73. ycoord[0],
  74. ycoord[1],
  75. 0x00, // FORMAT
  76. 0x00, // RES
  77. w[0], // WIDTH
  78. w[1], //
  79. h[0], // HEIGHT
  80. h[1] //
  81. };
  82. os.write(startData);
  83. byte[] dataHeader = new byte[] {
  84. (byte) 0x92 // GIMD
  85. };
  86. final int lengthOffset = 1;
  87. writeChunksToStream(imageData, dataHeader, lengthOffset, MAX_DATA_LEN, os);
  88. byte[] endData = new byte[] {
  89. (byte) 0x93, // GEIMG order code
  90. 0x00 // LENGTH
  91. };
  92. os.write(endData);
  93. }
  94. /** {@inheritDoc} */
  95. public String toString() {
  96. return "GraphicsImage{x=" + x
  97. + ", y=" + y
  98. + ", width=" + width
  99. + ", height=" + height
  100. + "}";
  101. }
  102. }