KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > modca > IMImageObject


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
18 /* $Id: IMImageObject.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.modca;
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.io.UnsupportedEncodingException JavaDoc;
24
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     /**
41      * The image output control
42      */

43     private ImageOutputControl _imageOutputControl = null;
44
45     /**
46      * The image input descriptor
47      */

48     private ImageInputDescriptor _imageInputDescriptor = null;
49
50     /**
51      * The image cell position
52      */

53     private ImageCellPosition _imageCellPosition = null;
54
55     /**
56      * The image rastor data
57      */

58     private ImageRasterData _imageRastorData = null;
59
60     /**
61      * Constructor for the image object with the specified name,
62      * the name must be a fixed length of eight characters.
63      * @param name The name of the image.
64      */

65     public IMImageObject(String JavaDoc name) {
66
67         super(name);
68
69     }
70
71     /**
72      * Sets the ImageOutputControl.
73      * @param imageOutputControl The imageOutputControl to set
74      */

75     public void setImageOutputControl(ImageOutputControl imageOutputControl) {
76         _imageOutputControl = imageOutputControl;
77     }
78
79     /**
80      * Sets the ImageCellPosition.
81      * @param imageCellPosition The imageCellPosition to set
82      */

83     public void setImageCellPosition(ImageCellPosition imageCellPosition) {
84         _imageCellPosition = imageCellPosition;
85     }
86
87     /**
88      * Sets the ImageInputDescriptor.
89      * @param imageInputDescriptor The imageInputDescriptor to set
90      */

91     public void setImageInputDescriptor(ImageInputDescriptor imageInputDescriptor) {
92         _imageInputDescriptor = imageInputDescriptor;
93     }
94
95     /**
96      * Sets the ImageRastorData.
97      * @param imageRastorData The imageRastorData to set
98      */

99     public void setImageRasterData(ImageRasterData imageRastorData) {
100         _imageRastorData = imageRastorData;
101     }
102
103     /**
104      * Accessor method to write the AFP datastream for the IM Image Objetc
105      * @param os The stream to write to
106      * @throws java.io.IOException
107      */

108     public void writeDataStream(OutputStream JavaDoc os)
109         throws IOException JavaDoc {
110
111         writeStart(os);
112
113         if (_imageOutputControl != null) {
114             _imageOutputControl.writeDataStream(os);
115         }
116
117         if (_imageInputDescriptor != null) {
118             _imageInputDescriptor.writeDataStream(os);
119         }
120
121         if (_imageCellPosition != null) {
122             _imageCellPosition.writeDataStream(os);
123         }
124
125         if (_imageRastorData != null) {
126             _imageRastorData.writeDataStream(os);
127         }
128
129         writeEnd(os);
130
131     }
132
133     /**
134      * Helper method to write the start of the IM Image Object.
135      * @param os The stream to write to
136      */

137     private void writeStart(OutputStream JavaDoc os)
138         throws IOException JavaDoc {
139
140         byte[] data = new byte[17];
141
142         data[0] = 0x5A; // Structured field identifier
143
data[1] = 0x00; // Length byte 1
144
data[2] = 0x10; // Length byte 2
145
data[3] = (byte) 0xD3; // Structured field id byte 1
146
data[4] = (byte) 0xA8; // Structured field id byte 2
147
data[5] = (byte) 0x7B; // Structured field id byte 3
148
data[6] = 0x00; // Flags
149
data[7] = 0x00; // Reserved
150
data[8] = 0x00; // Reserved
151

152         for (int i = 0; i < _nameBytes.length; i++) {
153
154             data[9 + i] = _nameBytes[i];
155
156         }
157
158         os.write(data);
159
160     }
161
162     /**
163      * Helper method to write the end of the IM Image Object.
164      * @param os The stream to write to
165      */

166     private void writeEnd(OutputStream JavaDoc os)
167         throws IOException JavaDoc {
168
169         byte[] data = new byte[17];
170
171         data[0] = 0x5A; // Structured field identifier
172
data[1] = 0x00; // Length byte 1
173
data[2] = 0x10; // Length byte 2
174
data[3] = (byte) 0xD3; // Structured field id byte 1
175
data[4] = (byte) 0xA9; // Structured field id byte 2
176
data[5] = (byte) 0x7B; // Structured field id byte 3
177
data[6] = 0x00; // Flags
178
data[7] = 0x00; // Reserved
179
data[8] = 0x00; // Reserved
180

181         for (int i = 0; i < _nameBytes.length; i++) {
182
183             data[9 + i] = _nameBytes[i];
184
185         }
186
187         os.write(data);
188
189     }
190
191 }
192
Popular Tags