KickJava   Java API By Example, From Geeks To Geeks.

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


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: ObjectAreaDescriptor.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 Descriptor structured field specifies the size and attributes
28  * of an object area presentation space.
29  *
30  */

31 public class ObjectAreaDescriptor extends AbstractAFPObject {
32
33     private int _width = 0;
34     private int _height = 0;
35
36     /**
37      * Construct an object area descriptor for the specified object width
38      * and object height.
39      * @param width The page width.
40      * @param height The page height.
41      */

42     public ObjectAreaDescriptor(int width, int height) {
43
44         _width = width;
45         _height = height;
46
47     }
48
49     /**
50      * Accessor method to write the AFP datastream for the Object Area Descriptor
51      * @param os The stream to write to
52      * @throws java.io.IOException
53      */

54     public void writeDataStream(OutputStream JavaDoc os)
55         throws IOException JavaDoc {
56
57         byte[] data = new byte[] {
58             0x5A,
59             0x00, // Length
60
0x1C, // Length
61
(byte) 0xD3,
62             (byte) 0xA6,
63             (byte) 0x6B,
64             0x00, // Flags
65
0x00, // Reserved
66
0x00, // Reserved
67
0x03, // Triplet length
68
0x43, // tid = Descriptor Position Triplet
69
0x01, // DesPosId = 1
70
0x08, // Triplet length
71
0x4B, // tid = Measurement Units Triplet
72
0x00, // XaoBase = 10 inches
73
0x00, // YaoBase = 10 inches
74
0x09, // XaoUnits = 2400
75
0x60, // XaoUnits =
76
0x09, // YaoUnits = 2400
77
0x60, // YaoUnits =
78
0x09, // Triplet length
79
0x4C, // tid = Object Area Size
80
0x02, // Size Type
81
0x00, // XoaSize
82
0x00,
83             0x00,
84             0x00, // YoaSize
85
0x00,
86             0x00,
87         };
88
89         byte[] l = BinaryUtils.convert(data.length - 1, 2);
90         data[1] = l[0];
91         data[2] = l[1];
92
93         byte[] x = BinaryUtils.convert(_width, 3);
94         data[23] = x[0];
95         data[24] = x[1];
96         data[25] = x[2];
97
98         byte[] y = BinaryUtils.convert(_height, 3);
99         data[26] = y[0];
100         data[27] = y[1];
101         data[28] = y[2];
102
103         os.write(data);
104
105     }
106
107 }
Popular Tags