Line 0
Link Here
|
|
|
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 |
package org.apache.poi.hwpf.model; |
19 |
|
20 |
import org.apache.poi.util.BitField; |
21 |
import org.apache.poi.util.BitFieldFactory; |
22 |
import org.apache.poi.util.LittleEndian; |
23 |
|
24 |
/** |
25 |
* File Shape Address structure |
26 |
* |
27 |
* @author Squeeself |
28 |
*/ |
29 |
public class FSPA |
30 |
{ |
31 |
public static final int FSPA_SIZE = 26; |
32 |
private int spid; // Shape identifier. Used to get data position |
33 |
private int xaLeft; // Enclosing rectangle |
34 |
private int yaTop; // Enclosing rectangle |
35 |
private int xaRight; // Enclosing rectangle |
36 |
private int yaBottom; // Enclosing rectangle |
37 |
private short options; |
38 |
private static BitField fHdr = BitFieldFactory.getInstance(0x0001); // 1 in undo when in header |
39 |
private static BitField bx = BitFieldFactory.getInstance(0x0006); // x pos relative to anchor CP: 0 - page margin, 1 - top of page, 2 - text, 3 - reserved |
40 |
private static BitField by = BitFieldFactory.getInstance(0x0018); // y pos relative to anchor CP: ditto |
41 |
private static BitField wr = BitFieldFactory.getInstance(0x01E0); // Text wrapping mode: 0 - like 2 w/o absolute, 1 - no text next to shape, 2 - wrap around absolute object, 3 - wrap as if no object, 4 - wrap tightly around object, 5 - wrap tightly, allow holes, 6-15 - reserved |
42 |
private static BitField wrk = BitFieldFactory.getInstance(0x1E00); // Text wrapping mode type (for modes 2&4): 0 - wrap both sides, 1 - wrap only left, 2 - wrap only right, 3 - wrap largest side |
43 |
private static BitField fRcaSimple = BitFieldFactory.getInstance(0x2000); // Overwrites bx if set, forcing rectangle to be page relative |
44 |
private static BitField fBelowText = BitFieldFactory.getInstance(0x4000); // if true, shape is below text, otherwise above |
45 |
private static BitField fAnchorLock = BitFieldFactory.getInstance(0x8000); // if true, anchor is locked |
46 |
private int cTxbx; // Count of textboxes in shape (undo doc only) |
47 |
|
48 |
public FSPA() |
49 |
{ |
50 |
} |
51 |
|
52 |
public FSPA(byte[] bytes, int offset) |
53 |
{ |
54 |
spid = LittleEndian.getInt(bytes, offset); |
55 |
offset += LittleEndian.INT_SIZE; |
56 |
xaLeft = LittleEndian.getInt(bytes, offset); |
57 |
offset += LittleEndian.INT_SIZE; |
58 |
yaTop = LittleEndian.getInt(bytes, offset); |
59 |
offset += LittleEndian.INT_SIZE; |
60 |
xaRight = LittleEndian.getInt(bytes, offset); |
61 |
offset += LittleEndian.INT_SIZE; |
62 |
yaBottom = LittleEndian.getInt(bytes, offset); |
63 |
offset += LittleEndian.INT_SIZE; |
64 |
options = LittleEndian.getShort(bytes, offset); |
65 |
offset += LittleEndian.SHORT_SIZE; |
66 |
cTxbx = LittleEndian.getInt(bytes, offset); |
67 |
} |
68 |
|
69 |
public int getSpid() |
70 |
{ |
71 |
return spid; |
72 |
} |
73 |
|
74 |
public int getXaLeft() |
75 |
{ |
76 |
return xaLeft; |
77 |
} |
78 |
|
79 |
public int getYaTop() |
80 |
{ |
81 |
return yaTop; |
82 |
} |
83 |
|
84 |
public int getXaRight() |
85 |
{ |
86 |
return xaRight; |
87 |
} |
88 |
|
89 |
public int getYaBottom() |
90 |
{ |
91 |
return yaBottom; |
92 |
} |
93 |
|
94 |
public boolean isFHdr() |
95 |
{ |
96 |
return fHdr.isSet(options); |
97 |
} |
98 |
|
99 |
public short getBx() |
100 |
{ |
101 |
return bx.getShortValue(options); |
102 |
} |
103 |
|
104 |
public short getBy() |
105 |
{ |
106 |
return by.getShortValue(options); |
107 |
} |
108 |
|
109 |
public short getWr() |
110 |
{ |
111 |
return wr.getShortValue(options); |
112 |
} |
113 |
|
114 |
public short getWrk() |
115 |
{ |
116 |
return wrk.getShortValue(options); |
117 |
} |
118 |
|
119 |
public boolean isFRcaSimple() |
120 |
{ |
121 |
return fRcaSimple.isSet(options); |
122 |
} |
123 |
|
124 |
public boolean isFBelowText() |
125 |
{ |
126 |
return fBelowText.isSet(options); |
127 |
} |
128 |
|
129 |
public boolean isFAnchorLock() |
130 |
{ |
131 |
return fAnchorLock.isSet(options); |
132 |
} |
133 |
|
134 |
public int getCTxbx() |
135 |
{ |
136 |
return cTxbx; |
137 |
} |
138 |
|
139 |
public byte[] toByteArray() |
140 |
{ |
141 |
int offset = 0; |
142 |
byte[] buf = new byte[FSPA_SIZE]; |
143 |
|
144 |
LittleEndian.putInt(buf, offset, spid); |
145 |
offset += LittleEndian.INT_SIZE; |
146 |
LittleEndian.putInt(buf, offset, xaLeft); |
147 |
offset += LittleEndian.INT_SIZE; |
148 |
LittleEndian.putInt(buf, offset, yaTop); |
149 |
offset += LittleEndian.INT_SIZE; |
150 |
LittleEndian.putInt(buf, offset, xaRight); |
151 |
offset += LittleEndian.INT_SIZE; |
152 |
LittleEndian.putInt(buf, offset, yaBottom); |
153 |
offset += LittleEndian.INT_SIZE; |
154 |
LittleEndian.putShort(buf, offset, options); |
155 |
offset += LittleEndian.SHORT_SIZE; |
156 |
LittleEndian.putInt(buf, offset, cTxbx); |
157 |
offset += LittleEndian.INT_SIZE; |
158 |
|
159 |
return buf; |
160 |
} |
161 |
|
162 |
public String toString() |
163 |
{ |
164 |
StringBuffer buf = new StringBuffer(); |
165 |
buf.append("spid: ").append(spid); |
166 |
buf.append(", xaLeft: ").append(xaLeft); |
167 |
buf.append(", yaTop: ").append(yaTop); |
168 |
buf.append(", xaRight: ").append(xaRight); |
169 |
buf.append(", yaBottom: ").append(yaBottom); |
170 |
buf.append(", options: ").append(options); |
171 |
buf.append(" (fHdr: ").append(isFHdr()); |
172 |
buf.append(", bx: ").append(getBx()); |
173 |
buf.append(", by: ").append(getBy()); |
174 |
buf.append(", wr: ").append(getWr()); |
175 |
buf.append(", wrk: ").append(getWrk()); |
176 |
buf.append(", fRcaSimple: ").append(isFRcaSimple()); |
177 |
buf.append(", fBelowText: ").append(isFBelowText()); |
178 |
buf.append(", fAnchorLock: ").append(isFAnchorLock()); |
179 |
buf.append("), cTxbx: ").append(cTxbx); |
180 |
return buf.toString(); |
181 |
} |
182 |
} |
0 |
+ native |
183 |
+ native |