KickJava   Java API By Example, From Geeks To Geeks.

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


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: IncludePageSegment.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  * The Include Page Segment structured field references a page segment resource
30  * object that is to be presented on the page or overlay presentation space. The IPS
31  * specifies a reference point on the including page or overlay coordinate system that
32  * may be used to position objects contained in the page segment. A page segment
33  * can be referenced at any time during page or overlay state, but not during an
34  * object state. The page segment inherits the active environment group definition of
35  * the including page or overlay.
36  *
37  * Note : No use for Triplets.
38  *
39  * A 'real' example for where this will be used is for
40  * the dynamic placing of overlay objects, such as signatures
41  * that may have to be placed at different positions on a document.
42  *
43  */

44 public class IncludePageSegment extends AbstractNamedAFPObject{
45
46     /**
47      * The x position where we need to put this object on the page
48      */

49     private byte [] _xCoor;
50
51     /**
52      * The y position where we need to put this object on the page
53      */

54     private byte [] _yCoor;
55
56     /**
57      * Constructor for the Include Page Segment
58      * @param name Name of the page segment
59      * @param xVal The x position
60      * @param yVal The y position
61      */

62     public IncludePageSegment(String JavaDoc name, int xVal, int yVal){
63
64         super(name);
65         _xCoor = BinaryUtils.convert(xVal, 3);
66         _yCoor = BinaryUtils.convert(yVal, 3);
67
68     }
69
70     /**
71      * Accessor method to write the AFP datastream for the Include Page Segment
72      * @param os The stream to write to
73      * @throws java.io.IOException
74      */

75     public void writeDataStream(OutputStream JavaDoc os)
76         throws IOException JavaDoc {
77
78         byte[] data = new byte[23]; //(9 +14)
79

80         data[0] = 0x5A;
81
82         // Set the total record length
83
byte[] rl1 = BinaryUtils.convert(22, 2); //Ignore first byte
84
data[1] = rl1[0];
85         data[2] = rl1[1];
86
87         // Structured field ID for a IPS
88
data[3] = (byte) 0xD3;
89         data[4] = (byte) 0xAF;
90         data[5] = (byte) 0x5F;
91
92         data[6] = 0x00; // Reserved
93
data[7] = 0x00; // Reserved
94
data[8] = 0x00; // Reserved
95

96         for (int i = 0; i < _nameBytes.length; i++) {
97
98             data[9 + i] = _nameBytes[i];
99
100         }
101
102         data[17] = _xCoor[0]; // x coordinate
103
data[18] = _xCoor[1];
104         data[19] = _xCoor[2];
105
106         data[20] = _yCoor[0]; // y coordinate
107
data[21] = _yCoor[1];
108         data[22] = _yCoor[2];
109
110         os.write(data);
111
112     }
113
114
115 }
116
Popular Tags