1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hwpf.usermodel;
import org.apache.poi.common.Duplicatable;
import org.apache.poi.hwpf.HWPFOldDocument;
import org.apache.poi.hwpf.model.SEPX;
public final class Section extends Range implements Duplicatable {
private final SectionProperties _props;
public Section(Section other) {
super(other);
_props = other._props.copy();
}
public Section( SEPX sepx, Range parent ) {
super( Math.max( parent._start, sepx.getStart() ), Math.min(parent._end, sepx.getEnd() ), parent );
// XXX: temporary workaround for old Word95 document
if ( parent.getDocument() instanceof HWPFOldDocument )
_props = new SectionProperties();
else
_props = sepx.getSectionProperties();
}
@Override
public Section copy() {
return new Section(this);
}
/**
* @return distance to be maintained between columns, in twips. Used when
* {@link #isColumnsEvenlySpaced()} == true
*/
public int getDistanceBetweenColumns()
{
return _props.getDxaColumns();
}
public int getMarginBottom()
{
return _props.getDyaBottom();
}
public int getMarginLeft()
{
return _props.getDxaLeft();
}
public int getMarginRight()
{
return _props.getDxaRight();
}
public int getMarginTop()
{
return _props.getDyaTop();
}
public int getNumColumns()
{
return _props.getCcolM1() + 1;
}
/**
* @return page height (in twips) in current section. Default value is 15840
* twips
*/
public int getPageHeight()
{
return _props.getYaPage();
}
/**
* @return page width (in twips) in current section. Default value is 12240
* twips
*/
public int getPageWidth()
{
return _props.getXaPage();
}
/**
* Set the height of the bottom margin in twips. In the AbstractWordUtils class, a constant
* is defined that indicates how many twips there are per inch and it can be used in setting
* the margins width a little like this;
*
* section.setMarginBottom( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
*
* @param marginWidth A primitive int whose value will indciate how high the margin should
* be - in twips.
*/
public void setMarginBottom(int marginWidth)
{
this._props.setDyaBottom(marginWidth);
}
/**
* Set the width of the left hand margin in twips. In the AbstractWordUtils class, a constant
* is defined that indicates how many twips there are per inch and it can be used in setting
* the margins width a little like this;
*
* section.setMarginLeft( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
*
* @param marginWidth A primitive int whose value will indciate how high the margin should
* be - in twips.
*/
public void setMarginLeft(int marginWidth)
{
this._props.setDxaLeft(marginWidth);
}
/**
* Set the width of the right hand margin in twips. In the AbstractWordUtils class, a constant
* is defined that indicates how many twips there are per inch and it can be used in setting
* the margins width a little like this;
*
* section.setMarginRight( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
*
* @param marginWidth A primitive int whose value will indciate how high the margin should
* be - in twips.
*/
public void setMarginRight(int marginWidth)
{
this._props.setDxaRight(marginWidth);
}
/**
* Set the height of the top margin in twips. In the AbstractWordUtils class, a constant
* is defined that indicates how many twips there are per inch and it can be used in setting
* the margins width a little like this;
*
* section.setMarginTop( (int) 1.5 * AbstractWordUtils.TWIPS_PER_INCH );
*
* @param marginWidth A primitive int whose value will indciate how high the margin should
* be - in twips.
*/
public void setMarginTop(int marginWidth)
{
this._props.setDyaTop(marginWidth);
}
public boolean isColumnsEvenlySpaced()
{
return _props.getFEvenlySpaced();
}
/**
* Get the footnote restart qualifier
*
* <dl>
* <dt>{@code 0x00}</dt><dd>If the numbering is continuous throughout the entire document</dd>
* <dt>{@code 0x01}</dt><dd>If the numbering restarts at the beginning of this section</dd>
* <dt>{@code 0x02}</dt><dd>If the numbering restarts on every page</dd>
* </dl>
*
* @return an Rnc, as described above, specifying when and where footnote numbering restarts
*/
public short getFootnoteRestartQualifier() {
return _props.getRncFtn();
}
/**
* @return an offset to be added to footnote numbers
*/
public int getFootnoteNumberingOffset() {
return _props.getNFtn();
}
/**
* Get the numbering format of embedded footnotes
*
* <p>The full list of possible return values is given in [MS-OSHARED], v20140428, 2.2.1.3</p>
*
* @return an Nfc specifying the numbering format for footnotes
*/
public int getFootnoteNumberingFormat() {
return _props.getNfcFtnRef();
}
/**
* Get the endnote restart qualifier
*
* <dl>
* <dt>{@code 0x00}</dt><dd>If the numbering is continuous throughout the entire document</dd>
* <dt>{@code 0x01}</dt><dd>If the numbering restarts at the beginning of this section</dd>
* <dt>{@code 0x02}</dt><dd>If the numbering restarts on every page</dd>
* </dl>
*
* @return an Rnc, as described above, specifying when and where endnote numbering restarts
*/
public short getEndnoteRestartQualifier() {
return _props.getRncEdn();
}
/**
* @return an offset to be added to endnote numbers
*/
public int getEndnoteNumberingOffset() {
return _props.getNEdn();
}
/**
* Get the numbering format of embedded endnotes
*
* <p>The full list of possible return values is given in [MS-OSHARED], v20140428, 2.2.1.3</p>
*
* @return an Nfc specifying the numbering format for endnotes
*/
public int getEndnoteNumberingFormat() {
return _props.getNfcEdnRef();
}
@Override
public String toString()
{
return "Section [" + getStartOffset() + "; " + getEndOffset() + ")";
}
public int type()
{
return TYPE_SECTION;
}
}
|