KickJava   Java API By Example, From Geeks To Geeks.

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


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: IncludeObject.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 java.io.UnsupportedEncodingException JavaDoc;
25
26 import org.apache.fop.render.afp.tools.BinaryUtils;
27
28 /**
29  * An Include Object structured field references an object on a page or overlay.
30  * It optionally contains parameters that identify the object and that specify
31  * presentation parameters such as object position, size, orientation, mapping,
32  * and default color.
33  * <p>
34  * Where the presentation parameters conflict with parameters specified in the
35  * object's environment group (OEG), the parameters in the Include Object
36  * structured field override. If the referenced object is a page segment, the
37  * IOB parameters override the corresponding environment group parameters on all
38  * data objects in the page segment.
39  * </p>
40  */

41 public class IncludeObject extends AbstractNamedAFPObject {
42
43     /**
44      * The object type
45      */

46     private byte _objectType = (byte) 0x92;
47
48     /**
49      * The orientation on the include object
50      */

51     private int _orientation = 0;
52
53     /**
54      * Constructor for the include object with the specified name, the name must
55      * be a fixed length of eight characters and is the name of the referenced
56      * object.
57      *
58      * @param name
59      * the name of the image
60      */

61     public IncludeObject(String JavaDoc name) {
62
63         super(name);
64         _objectType = (byte) 0xFB;
65
66     }
67
68     /**
69      * Sets the orienation to use for the Include Object.
70      *
71      * @param orientation
72      * The orientation (0,90, 180, 270)
73      */

74     public void setOrientation(int orientation) {
75
76         if (orientation == 0 || orientation == 90 || orientation == 180
77             || orientation == 270) {
78             _orientation = orientation;
79         } else {
80             throw new IllegalArgumentException JavaDoc(
81                 "The orientation must be one of the values 0, 90, 180, 270");
82         }
83
84     }
85
86     /**
87      * Accessor method to write the AFP datastream for the Include Object
88      * @param os The stream to write to
89      * @throws java.io.IOException
90      */

91     public void writeDataStream(OutputStream JavaDoc os)
92         throws IOException JavaDoc {
93
94         byte[] data = new byte[37];
95
96         data[0] = 0x5A;
97
98         // Set the total record length
99
byte[] rl1 = BinaryUtils.convert(36, 2); //Ignore first byte
100
data[1] = rl1[0];
101         data[2] = rl1[1];
102
103         // Structured field ID for a IOB
104
data[3] = (byte) 0xD3;
105         data[4] = (byte) 0xAF;
106         data[5] = (byte) 0xC3;
107
108         data[6] = 0x00; // Reserved
109
data[7] = 0x00; // Reserved
110
data[8] = 0x00; // Reserved
111

112         for (int i = 0; i < _nameBytes.length; i++) {
113             data[9 + i] = _nameBytes[i];
114         }
115
116         data[17] = 0x00;
117         data[18] = _objectType;
118
119         // XoaOset
120
data[20] = (byte) 0xFF;
121         data[21] = (byte) 0xFF;
122         data[22] = (byte) 0xFF;
123
124         // YoaOset
125
data[23] = (byte) 0xFF;
126         data[24] = (byte) 0xFF;
127         data[25] = (byte) 0xFF;
128
129         switch (_orientation) {
130             case 90:
131                 data[26] = 0x2D;
132                 data[27] = 0x00;
133                 data[28] = 0x5A;
134                 data[29] = 0x00;
135                 break;
136             case 180:
137                 data[26] = 0x5A;
138                 data[27] = 0x00;
139                 data[28] = (byte) 0x87;
140                 data[29] = 0x00;
141                 break;
142             case 270:
143                 data[26] = (byte) 0x87;
144                 data[27] = 0x00;
145                 data[28] = 0x00;
146                 data[29] = 0x00;
147                 break;
148             default:
149                 data[26] = 0x00;
150                 data[27] = 0x00;
151                 data[28] = 0x2D;
152                 data[29] = 0x00;
153                 break;
154         }
155
156         // XocaOset
157
data[30] = (byte) 0xFF;
158         data[31] = (byte) 0xFF;
159         data[32] = (byte) 0xFF;
160
161         // YocaOset
162
data[33] = (byte) 0xFF;
163         data[34] = (byte) 0xFF;
164         data[35] = (byte) 0xFF;
165
166         data[36] = 0x01;
167
168         os.write(data);
169
170     }
171
172 }
Popular Tags