001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hwpf.usermodel;
019:
020: import org.apache.poi.hwpf.model.PAPX;
021: import org.apache.poi.hwpf.sprm.SprmBuffer;
022: import org.apache.poi.hwpf.sprm.TableSprmCompressor;
023:
024: public class Paragraph extends Range implements Cloneable {
025: public final static short SPRM_JC = 0x2403;
026: public final static short SPRM_FSIDEBYSIDE = 0x2404;
027: public final static short SPRM_FKEEP = 0x2405;
028: public final static short SPRM_FKEEPFOLLOW = 0x2406;
029: public final static short SPRM_FPAGEBREAKBEFORE = 0x2407;
030: public final static short SPRM_BRCL = 0x2408;
031: public final static short SPRM_BRCP = 0x2409;
032: public final static short SPRM_ILVL = 0x260A;
033: public final static short SPRM_ILFO = 0x460B;
034: public final static short SPRM_FNOLINENUMB = 0x240C;
035: public final static short SPRM_CHGTABSPAPX = (short) 0xC60D;
036: public final static short SPRM_DXARIGHT = (short) 0x840E;
037: public final static short SPRM_DXALEFT = (short) 0x840F;
038: public final static short SPRM_DXALEFT1 = (short) 0x8411;
039: public final static short SPRM_DYALINE = 0x6412;
040: public final static short SPRM_DYABEFORE = (short) 0xA413;
041: public final static short SPRM_DYAAFTER = (short) 0xA414;
042: public final static short SPRM_CHGTABS = (short) 0xC615;
043: public final static short SPRM_FINTABLE = 0x2416;
044: public final static short SPRM_FTTP = 0x2417;
045: public final static short SPRM_DXAABS = (short) 0x8418;
046: public final static short SPRM_DYAABS = (short) 0x8419;
047: public final static short SPRM_DXAWIDTH = (short) 0x841A;
048: public final static short SPRM_PC = 0x261B;
049: public final static short SPRM_WR = 0x2423;
050: public final static short SPRM_BRCTOP = 0x6424;
051: public final static short SPRM_BRCLEFT = 0x6425;
052: public final static short SPRM_BRCBOTTOM = 0x6426;
053: public final static short SPRM_BRCRIGHT = 0x6427;
054: public final static short SPRM_BRCBAR = 0x6629;
055: public final static short SPRM_FNOAUTOHYPH = 0x242A;
056: public final static short SPRM_WHEIGHTABS = 0x442B;
057: public final static short SPRM_DCS = 0x442C;
058: public final static short SPRM_SHD = 0x442D;
059: public final static short SPRM_DYAFROMTEXT = (short) 0x842E;
060: public final static short SPRM_DXAFROMTEXT = (short) 0x842F;
061: public final static short SPRM_FLOCKED = 0x2430;
062: public final static short SPRM_FWIDOWCONTROL = 0x2431;
063: public final static short SPRM_RULER = (short) 0xC632;
064: public final static short SPRM_FKINSOKU = 0x2433;
065: public final static short SPRM_FWORDWRAP = 0x2434;
066: public final static short SPRM_FOVERFLOWPUNCT = 0x2435;
067: public final static short SPRM_FTOPLINEPUNCT = 0x2436;
068: public final static short SPRM_AUTOSPACEDE = 0x2437;
069: public final static short SPRM_AUTOSPACEDN = 0x2438;
070: public final static short SPRM_WALIGNFONT = 0x4439;
071: public final static short SPRM_FRAMETEXTFLOW = 0x443A;
072: public final static short SPRM_ANLD = (short) 0xC63E;
073: public final static short SPRM_PROPRMARK = (short) 0xC63F;
074: public final static short SPRM_OUTLVL = 0x2640;
075: public final static short SPRM_FBIDI = 0x2441;
076: public final static short SPRM_FNUMRMLNS = 0x2443;
077: public final static short SPRM_CRLF = 0x2444;
078: public final static short SPRM_NUMRM = (short) 0xC645;
079: public final static short SPRM_USEPGSUSETTINGS = 0x2447;
080: public final static short SPRM_FADJUSTRIGHT = 0x2448;
081:
082: protected short _istd;
083: protected ParagraphProperties _props;
084: protected SprmBuffer _papx;
085:
086: protected Paragraph(int startIdx, int endIdx, Table parent) {
087: super (startIdx, endIdx, Range.TYPE_PARAGRAPH, parent);
088: PAPX papx = (PAPX) _paragraphs.get(_parEnd - 1);
089: _props = papx.getParagraphProperties(_doc.getStyleSheet());
090: _papx = papx.getSprmBuf();
091: _istd = papx.getIstd();
092: }
093:
094: protected Paragraph(PAPX papx, Range parent) {
095: super (Math.max(parent._start, papx.getStart()), Math.min(
096: parent._end, papx.getEnd()), parent);
097: _props = papx.getParagraphProperties(_doc.getStyleSheet());
098: _papx = papx.getSprmBuf();
099: _istd = papx.getIstd();
100: }
101:
102: public short getStyleIndex() {
103: return _istd;
104: }
105:
106: public int type() {
107: return TYPE_PARAGRAPH;
108: }
109:
110: public boolean isInTable() {
111: return _props.getFInTable() != 0;
112: }
113:
114: public boolean isTableRowEnd() {
115: return _props.getFTtp() != 0 || _props.getFTtpEmbedded() != 0;
116: }
117:
118: public int getTableLevel() {
119: return _props.getTableLevel();
120: }
121:
122: public boolean isEmbeddedCellMark() {
123: return _props.getEmbeddedCellMark() != 0;
124: }
125:
126: public int getJustification() {
127: return _props.getJc();
128: }
129:
130: public void setJustification(byte jc) {
131: _props.setJc(jc);
132: _papx.updateSprm(SPRM_JC, jc);
133: }
134:
135: public boolean keepOnPage() {
136: return _props.getFKeep() != 0;
137: }
138:
139: public void setKeepOnPage(boolean fKeep) {
140: byte keep = (byte) (fKeep ? 1 : 0);
141: _props.setFKeep(keep);
142: _papx.updateSprm(SPRM_FKEEP, keep);
143: }
144:
145: public boolean keepWithNext() {
146: return _props.getFKeepFollow() != 0;
147: }
148:
149: public void setKeepWithNext(boolean fKeepFollow) {
150: byte keepFollow = (byte) (fKeepFollow ? 1 : 0);
151: _props.setFKeepFollow(keepFollow);
152: _papx.updateSprm(SPRM_FKEEPFOLLOW, keepFollow);
153: }
154:
155: public boolean pageBreakBefore() {
156: return _props.getFPageBreakBefore() != 0;
157: }
158:
159: public void setPageBreakBefore(boolean fPageBreak) {
160: byte pageBreak = (byte) (fPageBreak ? 1 : 0);
161: _props.setFPageBreakBefore(pageBreak);
162: _papx.updateSprm(SPRM_FPAGEBREAKBEFORE, pageBreak);
163: }
164:
165: public boolean isLineNotNumbered() {
166: return _props.getFNoLnn() != 0;
167: }
168:
169: public void setLineNotNumbered(boolean fNoLnn) {
170: byte noLnn = (byte) (fNoLnn ? 1 : 0);
171: _props.setFNoLnn(noLnn);
172: _papx.updateSprm(SPRM_FNOLINENUMB, noLnn);
173: }
174:
175: public boolean isSideBySide() {
176: return _props.getFSideBySide() != 0;
177: }
178:
179: public void setSideBySide(boolean fSideBySide) {
180: byte sideBySide = (byte) (fSideBySide ? 1 : 0);
181: _props.setFSideBySide(sideBySide);
182: _papx.updateSprm(SPRM_FSIDEBYSIDE, sideBySide);
183: }
184:
185: public boolean isAutoHyphenated() {
186: return _props.getFNoAutoHyph() == 0;
187: }
188:
189: public void setAutoHyphenated(boolean autoHyph) {
190: byte auto = (byte) (!autoHyph ? 1 : 0);
191: _props.setFNoAutoHyph(auto);
192: _papx.updateSprm(SPRM_FNOAUTOHYPH, auto);
193: }
194:
195: public boolean isWidowControlled() {
196: return _props.getFWidowControl() != 0;
197: }
198:
199: public void setWidowControl(boolean widowControl) {
200: byte widow = (byte) (widowControl ? 1 : 0);
201: _props.setFWidowControl(widow);
202: _papx.updateSprm(SPRM_FWIDOWCONTROL, widow);
203: }
204:
205: public int getIndentFromRight() {
206: return _props.getDxaRight();
207: }
208:
209: public void setIndentFromRight(int dxaRight) {
210: _props.setDxaRight(dxaRight);
211: _papx.updateSprm(SPRM_DXARIGHT, (short) dxaRight);
212: }
213:
214: public int getIndentFromLeft() {
215: return _props.getDxaLeft();
216: }
217:
218: public void setIndentFromLeft(int dxaLeft) {
219: _props.setDxaLeft(dxaLeft);
220: _papx.updateSprm(SPRM_DXALEFT, (short) dxaLeft);
221: }
222:
223: public int getFirstLineIndent() {
224: return _props.getDxaLeft1();
225: }
226:
227: public void setFirstLineIndent(int first) {
228: _props.setDxaLeft1(first);
229: _papx.updateSprm(SPRM_DXALEFT1, (short) first);
230: }
231:
232: public LineSpacingDescriptor getLineSpacing() {
233: return _props.getLspd();
234: }
235:
236: public void setLineSpacing(LineSpacingDescriptor lspd) {
237: _props.setLspd(lspd);
238: _papx.updateSprm(SPRM_DYALINE, lspd.toInt());
239: }
240:
241: public int getSpacingBefore() {
242: return _props.getDyaBefore();
243: }
244:
245: public void setSpacingBefore(int before) {
246: _props.setDyaBefore(before);
247: _papx.updateSprm(SPRM_DYABEFORE, (short) before);
248: }
249:
250: public int getSpacingAfter() {
251: return _props.getDyaAfter();
252: }
253:
254: public void setSpacingAfter(int after) {
255: _props.setDyaAfter(after);
256: _papx.updateSprm(SPRM_DYAAFTER, (short) after);
257: }
258:
259: public boolean isKinsoku() {
260: return _props.getFKinsoku() != 0;
261: }
262:
263: public void setKinsoku(boolean kinsoku) {
264: byte kin = (byte) (kinsoku ? 1 : 0);
265: _props.setFKinsoku(kin);
266: _papx.updateSprm(SPRM_FKINSOKU, kin);
267: }
268:
269: public boolean isWordWrapped() {
270: return _props.getFWordWrap() != 0;
271: }
272:
273: public void setWordWrapped(boolean wrap) {
274: byte wordWrap = (byte) (wrap ? 1 : 0);
275: _props.setFWordWrap(wordWrap);
276: _papx.updateSprm(SPRM_FWORDWRAP, wordWrap);
277: }
278:
279: public int getFontAlignment() {
280: return _props.getWAlignFont();
281: }
282:
283: public void setFontAlignment(int align) {
284: _props.setWAlignFont(align);
285: _papx.updateSprm(SPRM_WALIGNFONT, (short) align);
286: }
287:
288: public boolean isVertical() {
289: return _props.isFVertical();
290: }
291:
292: public void setVertical(boolean vertical) {
293: _props.setFVertical(vertical);
294: _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
295: }
296:
297: public boolean isBackward() {
298: return _props.isFBackward();
299: }
300:
301: public void setBackward(boolean bward) {
302: _props.setFBackward(bward);
303: _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
304: }
305:
306: public BorderCode getTopBorder() {
307: return _props.getBrcTop();
308: }
309:
310: public void setTopBorder(BorderCode top) {
311: _props.setBrcTop(top);
312: _papx.updateSprm(SPRM_BRCTOP, top.toInt());
313: }
314:
315: public BorderCode getLeftBorder() {
316: return _props.getBrcLeft();
317: }
318:
319: public void setLeftBorder(BorderCode left) {
320: _props.setBrcLeft(left);
321: _papx.updateSprm(SPRM_BRCLEFT, left.toInt());
322: }
323:
324: public BorderCode getBottomBorder() {
325: return _props.getBrcBottom();
326: }
327:
328: public void setBottomBorder(BorderCode bottom) {
329: _props.setBrcBottom(bottom);
330: _papx.updateSprm(SPRM_BRCBOTTOM, bottom.toInt());
331: }
332:
333: public BorderCode getRightBorder() {
334: return _props.getBrcRight();
335: }
336:
337: public void setRightBorder(BorderCode right) {
338: _props.setBrcRight(right);
339: _papx.updateSprm(SPRM_BRCRIGHT, right.toInt());
340: }
341:
342: public BorderCode getBarBorder() {
343: return _props.getBrcBar();
344: }
345:
346: public void setBarBorder(BorderCode bar) {
347: _props.setBrcBar(bar);
348: _papx.updateSprm(SPRM_BRCBAR, bar.toInt());
349: }
350:
351: public ShadingDescriptor getShading() {
352: return _props.getShd();
353: }
354:
355: public void setShading(ShadingDescriptor shd) {
356: _props.setShd(shd);
357: _papx.updateSprm(SPRM_SHD, shd.toShort());
358: }
359:
360: public DropCapSpecifier getDropCap() {
361: return _props.getDcs();
362: }
363:
364: public void setDropCap(DropCapSpecifier dcs) {
365: _props.setDcs(dcs);
366: _papx.updateSprm(SPRM_DCS, dcs.toShort());
367: }
368:
369: public int getIlfo() {
370: return _props.getIlfo();
371: }
372:
373: public int getIlvl() {
374: return _props.getIlvl();
375: }
376:
377: void setTableRowEnd(TableProperties props) {
378: setTableRowEnd((byte) 1);
379: byte[] grpprl = TableSprmCompressor
380: .compressTableProperty(props);
381: _papx.append(grpprl);
382: }
383:
384: private void setTableRowEnd(byte val) {
385: _props.setFTtp(val);
386: _papx.updateSprm(SPRM_FTTP, val);
387: }
388:
389: /**
390: * clone the ParagraphProperties object associated with this Paragraph so
391: * that you can apply the same properties to another paragraph.
392: *
393: */
394: public ParagraphProperties cloneProperties() {
395: try {
396: return (ParagraphProperties) _props.clone();
397: } catch (Exception e) {
398: throw new RuntimeException(e);
399: }
400: }
401:
402: public Object clone() throws CloneNotSupportedException {
403: Paragraph p = (Paragraph) super .clone();
404: p._props = (ParagraphProperties) _props.clone();
405: //p._baseStyle = _baseStyle;
406: p._papx = new SprmBuffer();
407: return p;
408: }
409:
410: private short getFrameTextFlow() {
411: short retVal = 0;
412: if (_props.isFVertical()) {
413: retVal |= 1;
414: }
415: if (_props.isFBackward()) {
416: retVal |= 2;
417: }
418: if (_props.isFRotateFont()) {
419: retVal |= 4;
420: }
421: return retVal;
422: }
423:
424: }
|