KickJava   Java API By Example, From Geeks To Geeks.

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


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: IncludePageOverlay.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  *
30  * The Include Page Overlay structured field references an overlay resource
31  * definition that is to be positioned on the page. A page overlay can be
32  * referenced at any time during the page state, but not during an object state.
33  * The overlay contains its own active environment group definition.
34  *
35  * Note: There is no need for the triplets, so I have ignored them.
36  *
37  * A real example of where this will be used is for static overlays, such as an
38  * address on the page.
39  *
40  */

41 public class IncludePageOverlay extends AbstractNamedAFPObject {
42
43     /**
44      * The x coordinate
45      */

46     private int _xCoor = 0;
47
48     /**
49      * The y coordinate
50      */

51     private int _yCoor = 0;
52
53     /**
54      * The orientation
55      */

56     private int _orientation = 0;
57
58     /**
59      * Constructor for the Include Page Overlay
60      * @param overlayName Name of the page segment
61      * @param x The x position
62      * @param y The y position
63      * @param orientation The orientation
64      */

65     public IncludePageOverlay(String JavaDoc overlayName, int x, int y, int orientation) {
66
67         super(overlayName);
68
69         _xCoor = x;
70         _yCoor = y;
71         setOrientation(orientation);
72     }
73
74     /**
75      * Sets the orienation to use for the overlay.
76      *
77      * @param orientation
78      * The orientation (0,90, 180, 270)
79      */

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

97     public void writeDataStream(OutputStream JavaDoc os)
98         throws IOException JavaDoc {
99
100         byte[] data = new byte[25]; //(9 +16)
101

102         data[0] = 0x5A;
103
104         // Set the total record length
105
byte[] rl1 = BinaryUtils.convert(24, 2); //Ignore first byte
106
data[1] = rl1[0];
107         data[2] = rl1[1];
108
109         // Structured field ID for a IPO
110
data[3] = (byte) 0xD3;
111         data[4] = (byte) 0xAF;
112         data[5] = (byte) 0xD8;
113
114         data[6] = 0x00; // Reserved
115
data[7] = 0x00; // Reserved
116
data[8] = 0x00; // Reserved
117

118         for (int i = 0; i < _nameBytes.length; i++) {
119
120             data[9 + i] = _nameBytes[i];
121
122         }
123
124         byte[] r2 = BinaryUtils.convert(_xCoor, 3);
125         data[17] = r2[0]; // x coordinate
126
data[18] = r2[1];
127         data[19] = r2[2];
128
129         byte[] r3 = BinaryUtils.convert(_yCoor, 3);
130         data[20] = r3[0]; // y coordinate
131
data[21] = r3[1];
132         data[22] = r3[2];
133
134         switch (_orientation) {
135             case 90:
136                 data[23] = 0x2D;
137                 data[24] = 0x00;
138                 break;
139             case 180:
140                 data[23] = 0x5A;
141                 data[24] = 0x00;
142                 break;
143             case 270:
144                 data[23] = (byte) 0x87;
145                 data[24] = 0x00;
146                 break;
147             default:
148                 data[23] = 0x00;
149                 data[24] = 0x00;
150                 break;
151         }
152
153         os.write(data);
154
155     }
156
157 }
Popular Tags