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.

IMImageObject.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.ioca.ImageCellPosition;
  22. import org.apache.fop.afp.ioca.ImageInputDescriptor;
  23. import org.apache.fop.afp.ioca.ImageOutputControl;
  24. import org.apache.fop.afp.ioca.ImageRasterData;
  25. /**
  26. * An IM image data object specifies the contents of a raster image and
  27. * its placement on a page, overlay, or page segment. An IM image can be
  28. * either simple or complex. A simple image is composed of one or more Image
  29. * Raster Data (IRD) structured fields that define the raster pattern for the
  30. * entire image. A complex image is divided into regions called image cells.
  31. * Each image cell is composed of one or more IRD structured fields that define
  32. * the raster pattern for the image cell, and one Image Cell Position (ICP)
  33. * structured field that defines the position of the image cell relative to
  34. * the origin of the entire image. Each ICP also specifies the size of the
  35. * image cell and a fill rectangle into which the cell is replicated.
  36. * <p/>
  37. */
  38. public class IMImageObject extends AbstractNamedAFPObject {
  39. /**
  40. * The image output control
  41. */
  42. private ImageOutputControl imageOutputControl;
  43. /**
  44. * The image input descriptor
  45. */
  46. private ImageInputDescriptor imageInputDescriptor;
  47. /**
  48. * The image cell position
  49. */
  50. private ImageCellPosition imageCellPosition;
  51. /**
  52. * The image rastor data
  53. */
  54. private ImageRasterData imageRasterData;
  55. /**
  56. * Constructor for the image object with the specified name,
  57. * the name must be a fixed length of eight characters.
  58. *
  59. * @param name The name of the image.
  60. */
  61. public IMImageObject(String name) {
  62. super(name);
  63. }
  64. /**
  65. * Sets the ImageOutputControl.
  66. *
  67. * @param imageOutputControl The imageOutputControl to set
  68. */
  69. public void setImageOutputControl(ImageOutputControl imageOutputControl) {
  70. this.imageOutputControl = imageOutputControl;
  71. }
  72. /**
  73. * Sets the ImageCellPosition.
  74. *
  75. * @param imageCellPosition The imageCellPosition to set
  76. */
  77. public void setImageCellPosition(ImageCellPosition imageCellPosition) {
  78. this.imageCellPosition = imageCellPosition;
  79. }
  80. /**
  81. * Sets the ImageInputDescriptor.
  82. *
  83. * @param imageInputDescriptor The imageInputDescriptor to set
  84. */
  85. public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) {
  86. this.imageInputDescriptor = imageInputDescriptor;
  87. }
  88. /**
  89. * Sets the ImageRastorData.
  90. *
  91. * @param imageRasterData The imageRasterData to set
  92. */
  93. public void setImageRasterData(ImageRasterData imageRasterData) {
  94. this.imageRasterData = imageRasterData;
  95. }
  96. /** {@inheritDoc} */
  97. protected void writeContent(OutputStream os) throws IOException {
  98. super.writeContent(os);
  99. if (imageOutputControl != null) {
  100. imageOutputControl.writeToStream(os);
  101. }
  102. if (imageInputDescriptor != null) {
  103. imageInputDescriptor.writeToStream(os);
  104. }
  105. if (imageCellPosition != null) {
  106. imageCellPosition.writeToStream(os);
  107. }
  108. if (imageRasterData != null) {
  109. imageRasterData.writeToStream(os);
  110. }
  111. }
  112. /** {@inheritDoc} */
  113. protected void writeStart(OutputStream os) throws IOException {
  114. byte[] data = new byte[17];
  115. copySF(data, Type.BEGIN, Category.IM_IMAGE);
  116. os.write(data);
  117. }
  118. /** {@inheritDoc} */
  119. protected void writeEnd(OutputStream os) throws IOException {
  120. byte[] data = new byte[17];
  121. copySF(data, Type.END, Category.IM_IMAGE);
  122. os.write(data);
  123. }
  124. }