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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. */
  37. public class IMImageObject extends AbstractNamedAFPObject {
  38. /**
  39. * The image output control
  40. */
  41. private ImageOutputControl imageOutputControl;
  42. /**
  43. * The image input descriptor
  44. */
  45. private ImageInputDescriptor imageInputDescriptor;
  46. /**
  47. * The image cell position
  48. */
  49. private ImageCellPosition imageCellPosition;
  50. /**
  51. * The image rastor data
  52. */
  53. private ImageRasterData imageRasterData;
  54. /**
  55. * Constructor for the image object with the specified name,
  56. * the name must be a fixed length of eight characters.
  57. *
  58. * @param name The name of the image.
  59. */
  60. public IMImageObject(String name) {
  61. super(name);
  62. }
  63. /**
  64. * Sets the ImageOutputControl.
  65. *
  66. * @param imageOutputControl The imageOutputControl to set
  67. */
  68. public void setImageOutputControl(ImageOutputControl imageOutputControl) {
  69. this.imageOutputControl = imageOutputControl;
  70. }
  71. /**
  72. * Sets the ImageCellPosition.
  73. *
  74. * @param imageCellPosition The imageCellPosition to set
  75. */
  76. public void setImageCellPosition(ImageCellPosition imageCellPosition) {
  77. this.imageCellPosition = imageCellPosition;
  78. }
  79. /**
  80. * Sets the ImageInputDescriptor.
  81. *
  82. * @param imageInputDescriptor The imageInputDescriptor to set
  83. */
  84. public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) {
  85. this.imageInputDescriptor = imageInputDescriptor;
  86. }
  87. /**
  88. * Sets the ImageRastorData.
  89. *
  90. * @param imageRasterData The imageRasterData to set
  91. */
  92. public void setImageRasterData(ImageRasterData imageRasterData) {
  93. this.imageRasterData = imageRasterData;
  94. }
  95. /** {@inheritDoc} */
  96. protected void writeContent(OutputStream os) throws IOException {
  97. super.writeContent(os);
  98. if (imageOutputControl != null) {
  99. imageOutputControl.writeToStream(os);
  100. }
  101. if (imageInputDescriptor != null) {
  102. imageInputDescriptor.writeToStream(os);
  103. }
  104. if (imageCellPosition != null) {
  105. imageCellPosition.writeToStream(os);
  106. }
  107. if (imageRasterData != null) {
  108. imageRasterData.writeToStream(os);
  109. }
  110. }
  111. /** {@inheritDoc} */
  112. protected void writeStart(OutputStream os) throws IOException {
  113. byte[] data = new byte[17];
  114. copySF(data, Type.BEGIN, Category.IM_IMAGE);
  115. os.write(data);
  116. }
  117. /** {@inheritDoc} */
  118. protected void writeEnd(OutputStream os) throws IOException {
  119. byte[] data = new byte[17];
  120. copySF(data, Type.END, Category.IM_IMAGE);
  121. os.write(data);
  122. }
  123. }