KickJava   Java API By Example, From Geeks To Geeks.

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


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: ImageOutputControl.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.modca;
21
22 import java.io.IOException JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import org.apache.fop.render.afp.tools.BinaryUtils;
25
26 /**
27  * The IM Image Output Control structured field specifies the position and
28  * orientation of the IM image object area and the mapping of the image points
29  * to presentation device pels.
30  *
31  */

32 public class ImageOutputControl extends AbstractAFPObject {
33
34     /**
35      * The orientation of the image
36      */

37     private int _orientation = 0;
38
39     /**
40      * Specifies the offset, along the X-axis, of the IM image object area
41      * origin to the origin of the including page
42      */

43     private int _Xcoordinate = 0;
44
45     /**
46      * Specifies the offset, along the Y-axis, of the IM image object area
47      * origin to the origin of the including page
48      */

49     private int _Ycoordinate = 0;
50
51     /**
52      * Map an image point to a single presentation device pel
53      */

54     private boolean _singlepoint = true;
55
56     /**
57      * Constructor for the ImageOutputControl The x parameter specifies the
58      * offset, along the X-axis, of the IM image object area origin to the
59      * origin of the including page and the y parameter specifies the offset
60      * along the Y-axis. The offset is specified in image points and is resolved
61      * using the units of measure specified for the image in the IID structured
62      * field.
63      *
64      * @param x
65      * The X-axis offset.
66      * @param y
67      * The Y-axis offset.
68      */

69     public ImageOutputControl(int x, int y) {
70
71         _Xcoordinate = x;
72         _Ycoordinate = y;
73
74     }
75
76     /**
77      * Accessor method to write the AFP datastream for the Image Output Control
78      * @param os The stream to write to
79      * @throws java.io.IOException
80      */

81     public void writeDataStream(OutputStream JavaDoc os)
82         throws IOException JavaDoc {
83
84         byte[] data = new byte[33];
85
86         data[0] = 0x5A;
87         data[1] = 0x00;
88         data[2] = 0x20;
89         data[3] = (byte) 0xD3;
90         data[4] = (byte) 0xA7;
91         data[5] = (byte) 0x7B;
92         data[6] = 0x00;
93         data[7] = 0x00;
94         data[8] = 0x00;
95
96         // XoaOset
97
byte[] x1 = BinaryUtils.convert(_Xcoordinate, 3);
98         data[9] = x1[0];
99         data[10] = x1[1];
100         data[11] = x1[2];
101
102         // YoaOset
103
byte[] x2 = BinaryUtils.convert(_Ycoordinate, 3);
104         data[12] = x2[0];
105         data[13] = x2[1];
106         data[14] = x2[2];
107
108         switch (_orientation) {
109             case 0:
110                 // 0 and 90 degrees respectively
111
data[15] = 0x00;
112                 data[16] = 0x00;
113                 data[17] = 0x2D;
114                 data[18] = 0x00;
115                 break;
116             case 90:
117                 // 90 and 180 degrees respectively
118
data[15] = 0x2D;
119                 data[16] = 0x00;
120                 data[17] = 0x5A;
121                 data[18] = 0x00;
122                 break;
123             case 180:
124                 // 180 and 270 degrees respectively
125
data[15] = 0x5A;
126                 data[16] = 0x00;
127                 data[17] = (byte) 0x87;
128                 data[18] = 0x00;
129                 break;
130             case 270:
131                 // 270 and 0 degrees respectively
132
data[15] = (byte) 0x87;
133                 data[16] = 0x00;
134                 data[17] = 0x00;
135                 data[18] = 0x00;
136                 break;
137             default:
138                 // 0 and 90 degrees respectively
139
data[15] = 0x00;
140                 data[16] = 0x00;
141                 data[17] = 0x2D;
142                 data[18] = 0x00;
143                 break;
144
145         }
146
147         // Constant Data
148
data[19] = 0x00;
149         data[20] = 0x00;
150         data[21] = 0x00;
151         data[22] = 0x00;
152         data[23] = 0x00;
153         data[24] = 0x00;
154         data[25] = 0x00;
155         data[26] = 0x00;
156
157         if (_singlepoint) {
158             data[27] = 0x03;
159             data[28] = (byte) 0xE8;
160             data[29] = 0x03;
161             data[30] = (byte) 0xE8;
162         } else {
163             data[27] = 0x07;
164             data[28] = (byte) 0xD0;
165             data[29] = 0x07;
166             data[30] = (byte) 0xD0;
167         }
168
169         // Constant Data
170
data[31] = (byte) 0xFF;
171         data[32] = (byte) 0xFF;
172
173         os.write(data);
174
175     }
176
177     /**
178      * Sets the orientation which specifies the amount of clockwise rotation of
179      * the IM image object area.
180      *
181      * @param orientation
182      * The orientation to set.
183      */

184     public void setOrientation(int orientation) {
185
186         if (orientation == 0 || orientation == 90 || orientation == 180
187             || orientation == 270) {
188             _orientation = orientation;
189         } else {
190             throw new IllegalArgumentException JavaDoc(
191                 "The orientation must be one of the values 0, 90, 180, 270");
192         }
193
194     }
195
196     /**
197      * Sets the singlepoint, if true map an image point to a single presentation
198      * device pel in the IM image object area. If false map an image point to
199      * two presentation device pels in the IM image object area (double-dot)
200      *
201      * @param singlepoint
202      * Use the singlepoint basis when true.
203      */

204     public void setSinglepoint(boolean singlepoint) {
205         _singlepoint = singlepoint;
206     }
207
208 }
Popular Tags