01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
23: import java.io.OutputStream;
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 os) throws IOException {
55:
56: byte[] data = new byte[] { 0x5A, 0x00, // Length
57: 0x1C, // Length
58: (byte) 0xD3, (byte) 0xA6, (byte) 0x6B, 0x00, // Flags
59: 0x00, // Reserved
60: 0x00, // Reserved
61: 0x03, // Triplet length
62: 0x43, // tid = Descriptor Position Triplet
63: 0x01, // DesPosId = 1
64: 0x08, // Triplet length
65: 0x4B, // tid = Measurement Units Triplet
66: 0x00, // XaoBase = 10 inches
67: 0x00, // YaoBase = 10 inches
68: 0x09, // XaoUnits = 2400
69: 0x60, // XaoUnits =
70: 0x09, // YaoUnits = 2400
71: 0x60, // YaoUnits =
72: 0x09, // Triplet length
73: 0x4C, // tid = Object Area Size
74: 0x02, // Size Type
75: 0x00, // XoaSize
76: 0x00, 0x00, 0x00, // YoaSize
77: 0x00, 0x00, };
78:
79: byte[] l = BinaryUtils.convert(data.length - 1, 2);
80: data[1] = l[0];
81: data[2] = l[1];
82:
83: byte[] x = BinaryUtils.convert(_width, 3);
84: data[23] = x[0];
85: data[24] = x[1];
86: data[25] = x[2];
87:
88: byte[] y = BinaryUtils.convert(_height, 3);
89: data[26] = y[0];
90: data[27] = y[1];
91: data[28] = y[2];
92:
93: os.write(data);
94:
95: }
96:
97: }
|