KickJava   Java API By Example, From Geeks To Geeks.

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


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: ObjectAreaPosition.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 Object Area Position structured field specifies the origin and
28  * orientation of the object area, and the origin and orientation of the
29  * object content within the object area.
30  */

31 public class ObjectAreaPosition extends AbstractAFPObject {
32
33     private int _x = 0;
34     private int _y = 0;
35     private int _rot = 0;
36
37     /**
38      * Construct an object area position for the specified object y, y position.
39      * @param x The x coordinate.
40      * @param y The y coordinate.
41      * @param rotation The coordinate system rotation (must be 0, 90, 180, 270).
42      */

43     public ObjectAreaPosition(int x, int y, int rotation) {
44
45         _x = x;
46         _y = y;
47         _rot = rotation;
48     }
49
50     /**
51      * Accessor method to write the AFP datastream for the Object Area Position
52      * @param os The stream to write to
53      * @throws java.io.IOException
54      */

55     public void writeDataStream(OutputStream JavaDoc os)
56         throws IOException JavaDoc {
57
58         byte[] data = new byte[] {
59             0x5A,
60             0x00, // Length
61
0x20, // Length
62
(byte) 0xD3,
63             (byte) 0xAC,
64             (byte) 0x6B,
65             0x00, // Flags
66
0x00, // Reserved
67
0x00, // Reserved
68
0x01, // OAPosID = 1
69
0x17, // RGLength = 23
70
0x00, // XoaOSet
71
0x00,
72             0x00,
73             0x00, // YoaOSet
74
0x00,
75             0x00,
76             (byte)(_rot / 2), // XoaOrent
77
0x00,
78             (byte)(_rot / 2 + 45), // YoaOrent
79
0x00,
80             0x00, // Reserved
81
0x00, // XocaOSet
82
0x00,
83             0x00,
84             0x00, // YocaOSet
85
0x00,
86             0x00,
87             0x00, // XocaOrent
88
0x00,
89             0x2D, // YocaOrent
90
0x00,
91             0x01, // RefCSys
92
};
93
94         byte[] l = BinaryUtils.convert(data.length - 1, 2);
95         data[1] = l[0];
96         data[2] = l[1];
97
98         byte[] x = BinaryUtils.convert(_x, 3);
99         data[11] = x[0];
100         data[12] = x[1];
101         data[13] = x[2];
102
103         byte[] y = BinaryUtils.convert(_y, 3);
104         data[14] = y[0];
105         data[15] = y[1];
106         data[16] = y[2];
107
108         os.write(data);
109
110     }
111
112 }
Popular Tags