View | Details | Raw Unified | Return to bug 46299
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (-19 / +119 lines)
Lines 18-23 Link Here
18
18
19
import java.math.BigInteger;
19
import java.math.BigInteger;
20
20
21
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
21
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
22
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
22
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;
23
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;
23
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
24
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
Lines 27-32 Link Here
27
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
28
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
28
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTUnderline;
29
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTUnderline;
29
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalAlignRun;
30
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalAlignRun;
31
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
32
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
30
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
33
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
31
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
34
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
32
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
35
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
Lines 49-58 Link Here
49
        this.paragraph = p;
52
        this.paragraph = p;
50
    }
53
    }
51
54
55
    /**
56
     * Get the currently used CTR object
57
     * @return ctr object
58
     */
52
    public CTR getCTR() {
59
    public CTR getCTR() {
53
        return run;
60
        return run;
54
    }
61
    }
55
62
63
    /**
64
     * Get the currenty referenced paragraph object
65
     * @return current paragraph
66
     */
56
    public XWPFParagraph getParagraph() {
67
    public XWPFParagraph getParagraph() {
57
        return paragraph;
68
        return paragraph;
58
    }
69
    }
Lines 70-78 Link Here
70
81
71
    /**
82
    /**
72
     * Whether the bold property shall be applied to all non-complex script
83
     * Whether the bold property shall be applied to all non-complex script
73
     * characters in the contents of this run when displayed in a document
84
     * characters in the contents of this run when displayed in a document. 
74
     * <p/>
85
     * <p>
75
     * <p/>
76
     * This formatting property is a toggle property, which specifies that its
86
     * This formatting property is a toggle property, which specifies that its
77
     * behavior differs between its use within a style definition and its use as
87
     * behavior differs between its use within a style definition and its use as
78
     * direct formatting. When used as part of a style definition, setting this
88
     * direct formatting. When used as part of a style definition, setting this
Lines 83-89 Link Here
83
     * direct formatting, setting this property to true or false shall set the
93
     * direct formatting, setting this property to true or false shall set the
84
     * absolute state of the resulting property.
94
     * absolute state of the resulting property.
85
     * </p>
95
     * </p>
86
     * <p/>
96
     * <p>
87
     * If this element is not present, the default value is to leave the
97
     * If this element is not present, the default value is to leave the
88
     * formatting applied at previous level in the style hierarchy. If this
98
     * formatting applied at previous level in the style hierarchy. If this
89
     * element is never applied in the style hierarchy, then bold shall not be
99
     * element is never applied in the style hierarchy, then bold shall not be
Lines 104-111 Link Here
104
     *
114
     *
105
     * @return the text of this text run or <code>null</code> if not set
115
     * @return the text of this text run or <code>null</code> if not set
106
     */
116
     */
107
    public String getText() {
117
    public String getText(int pos) {
108
        return run.sizeOfTArray() == 0 ? null : run.getTArray(0)
118
        return run.sizeOfTArray() == 0 ? null : run.getTArray(pos)
109
                .getStringValue();
119
                .getStringValue();
110
    }
120
    }
111
121
Lines 115-124 Link Here
115
     * @param value the literal text which shall be displayed in the document
125
     * @param value the literal text which shall be displayed in the document
116
     */
126
     */
117
    public void setText(String value) {
127
    public void setText(String value) {
118
        CTText t = run.sizeOfTArray() == 0 ? run.addNewT() : run.getTArray(0);
128
	setText(value,run.getTArray().length);
129
    }
130
131
    /**
132
     * Sets the text of this text run in the 
133
     *
134
     * @param value the literal text which shall be displayed in the document
135
     * @param pos - position in the text array (NB: 0 based)
136
     */
137
    public void setText(String value, int pos) {
138
	if(pos > run.sizeOfTArray()) throw new ArrayIndexOutOfBoundsException("Value too large for the parameter position in XWPFRun.setText(String value,int pos)");
139
        CTText t = (pos < run.sizeOfTArray() && pos >= 0) ? run.getTArray(pos) : run.addNewT();
119
        t.setStringValue(value);
140
        t.setStringValue(value);
120
    }
141
    }
121
142
143
    
122
    /**
144
    /**
123
     * Whether the italic property should be applied to all non-complex script
145
     * Whether the italic property should be applied to all non-complex script
124
     * characters in the contents of this run when displayed in a document.
146
     * characters in the contents of this run when displayed in a document.
Lines 171-177 Link Here
171
    public UnderlinePatterns getUnderline() {
193
    public UnderlinePatterns getUnderline() {
172
        CTRPr pr = run.getRPr();
194
        CTRPr pr = run.getRPr();
173
        return (pr != null && pr.isSetU()) ? UnderlinePatterns.valueOf(pr
195
        return (pr != null && pr.isSetU()) ? UnderlinePatterns.valueOf(pr
174
                .getU().getVal().intValue()) : null;
196
                .getU().getVal().intValue()) : UnderlinePatterns.NONE;
175
    }
197
    }
176
198
177
    /**
199
    /**
Lines 191-197 Link Here
191
     */
213
     */
192
    public void setUnderline(UnderlinePatterns value) {
214
    public void setUnderline(UnderlinePatterns value) {
193
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
215
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
194
        CTUnderline underline = pr.isSetU() ? pr.getU() : pr.addNewU();
216
        CTUnderline underline = (pr.getU() == null) ? pr.addNewU() : pr.getU();
195
        underline.setVal(STUnderline.Enum.forInt(value.getValue()));
217
        underline.setVal(STUnderline.Enum.forInt(value.getValue()));
196
    }
218
    }
197
219
Lines 248-254 Link Here
248
    public VerticalAlign getSubscript() {
270
    public VerticalAlign getSubscript() {
249
        CTRPr pr = run.getRPr();
271
        CTRPr pr = run.getRPr();
250
        return (pr != null && pr.isSetVertAlign()) ? VerticalAlign.valueOf(pr
272
        return (pr != null && pr.isSetVertAlign()) ? VerticalAlign.valueOf(pr
251
                .getVertAlign().getVal().intValue()) : null;
273
                .getVertAlign().getVal().intValue()) : VerticalAlign.BASELINE;
252
    }
274
    }
253
275
254
    /**
276
    /**
Lines 305-313 Link Here
305
     *
327
     *
306
     * @return value representing the font size
328
     * @return value representing the font size
307
     */
329
     */
308
    public BigInteger getFontSize() {
330
    public int getFontSize() {
309
        CTRPr pr = run.getRPr();
331
        CTRPr pr = run.getRPr();
310
        return (pr != null && pr.isSetSz()) ? pr.getSz().getVal().divide(new BigInteger("2")) : null;
332
        return (pr != null && pr.isSetSz()) ? pr.getSz().getVal().divide(new BigInteger("2")).intValue() : -1;
311
    }
333
    }
312
334
313
    /**
335
    /**
Lines 322-331 Link Here
322
     *
344
     *
323
     * @param size
345
     * @param size
324
     */
346
     */
325
    public void setFontSize(BigInteger size) {
347
    public void setFontSize(int size) {
348
	BigInteger bint=new BigInteger(""+size);
326
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
349
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
327
        CTHpsMeasure ctSize = pr.isSetSz() ? pr.getSz() : pr.addNewSz();
350
        CTHpsMeasure ctSize = pr.isSetSz() ? pr.getSz() : pr.addNewSz();
328
        ctSize.setVal(size.multiply(new BigInteger("2")));
351
        ctSize.setVal(bint.multiply(new BigInteger("2")));
329
    }
352
    }
330
353
331
    /**
354
    /**
Lines 336-345 Link Here
336
     *
359
     *
337
     * @return a big integer representing the amount of text shall be "moved"
360
     * @return a big integer representing the amount of text shall be "moved"
338
     */
361
     */
339
    public BigInteger getTextPosition() {
362
    public int getTextPosition() {
340
        CTRPr pr = run.getRPr();
363
        CTRPr pr = run.getRPr();
341
        return (pr != null && pr.isSetPosition()) ? pr.getPosition().getVal()
364
        return (pr != null && pr.isSetPosition()) ? pr.getPosition().getVal().intValue()
342
                : null;
365
                : -1;
343
    }
366
    }
344
367
345
    /**
368
    /**
Lines 364-373 Link Here
364
     *
387
     *
365
     * @param val
388
     * @param val
366
     */
389
     */
367
    public void setTextPosition(BigInteger val) {
390
    public void setTextPosition(int val) {
391
	BigInteger bint=new BigInteger(""+val);
368
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
392
        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
369
        CTSignedHpsMeasure position = pr.isSetPosition() ? pr.getPosition() : pr.addNewPosition();
393
        CTSignedHpsMeasure position = pr.isSetPosition() ? pr.getPosition() : pr.addNewPosition();
370
        position.setVal(val);
394
        position.setVal(bint);
371
    }
395
    }
372
396
397
    /**
398
     * 
399
     */
400
    public void removeBreak() {
401
	// TODO
402
    }
403
404
    /**
405
     * Specifies that a break shall be placed at the current location in the run
406
     * content. 
407
     * A break is a special character which is used to override the
408
     * normal line breaking that would be performed based on the normal layout
409
     * of the documentÕs contents. 
410
     * @see addCarriageReturn()
411
     */
412
    public void addBreak() {
413
	run.addNewBr();
414
    } 
415
416
    /**
417
     * Specifies that a break shall be placed at the current location in the run
418
     * content.
419
     * A break is a special character which is used to override the
420
     * normal line breaking that would be performed based on the normal layout
421
     * of the documentÕs contents.
422
     * <p>
423
     * The behavior of this break character (the
424
     * location where text shall be restarted after this break) shall be
425
     * determined by its type values.
426
     * </p>
427
     * @see BreakType
428
     */
429
    public void addBreak(BreakType type){
430
	CTBr br=run.addNewBr();
431
	br.setType(STBrType.Enum.forInt(type.getValue()));
432
    }
433
434
    
435
    /**
436
     * Specifies that a break shall be placed at the current location in the run
437
     * content. A break is a special character which is used to override the
438
     * normal line breaking that would be performed based on the normal layout
439
     * of the documentÕs contents.
440
     * <p>
441
     * The behavior of this break character (the
442
     * location where text shall be restarted after this break) shall be
443
     * determined by its type (in this case is BreakType.TEXT_WRAPPING as default) and clear attribute values.
444
     * </p>
445
     * @see BreakClear
446
     */
447
    public void addBreak(BreakClear clear){
448
	CTBr br=run.addNewBr();
449
	br.setType(STBrType.Enum.forInt(BreakType.TEXT_WRAPPING.getValue()));
450
	    br.setClear(STBrClear.Enum.forInt(clear.getValue()));
451
    }
452
453
    /**
454
     * Specifies that a carriage return shall be placed at the
455
     * current location in the run content.
456
     * A carriage return is used to end the current line of text in
457
     * Wordprocess.
458
     * The behavior of a carriage return in run content shall be
459
     * identical to a break character with null type and clear attributes, which
460
     * shall end the current line and find the next available line on which to
461
     * continue.
462
     * The carriage return character forced the following text to be
463
     * restarted on the next available line in the document.
464
     */
465
    public void addCarriageReturn() {
466
	run.addNewCr();
467
    }
468
469
    public void removeCarriageReturn() {
470
	//TODO
471
    }    
472
    
373
}
473
}
(-)src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (-5 / +61 lines)
Lines 20-27 Link Here
20
20
21
import junit.framework.TestCase;
21
import junit.framework.TestCase;
22
22
23
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
23
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
24
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
24
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
25
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
26
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
25
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
27
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
26
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
28
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
27
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
29
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
Lines 39-47 Link Here
39
        p = doc.createParagraph();
41
        p = doc.createParagraph();
40
42
41
        this.ctRun = CTR.Factory.newInstance();
43
        this.ctRun = CTR.Factory.newInstance();
44
        
45
    }
42
46
47
    public void testSetGetText() {
48
	ctRun.addNewT().setStringValue("TEST STRING");	
49
	ctRun.addNewT().setStringValue("TEST2 STRING");	
50
	ctRun.addNewT().setStringValue("TEST3 STRING");
51
	
52
	assertEquals(3,ctRun.sizeOfTArray());
53
	XWPFRun run = new XWPFRun(ctRun, p);
54
	
55
	assertEquals("TEST2 STRING",run.getText(1));
56
	
57
	run.setText("NEW STRING",0);
58
	assertEquals("NEW STRING",run.getText(0));
59
	
60
	//run.setText("xxx",14);
61
	//fail("Position wrong");
43
    }
62
    }
44
63
  
45
    public void testSetGetBold() {
64
    public void testSetGetBold() {
46
        CTRPr rpr = ctRun.addNewRPr();
65
        CTRPr rpr = ctRun.addNewRPr();
47
        rpr.addNewB().setVal(STOnOff.TRUE);
66
        rpr.addNewB().setVal(STOnOff.TRUE);
Lines 118-126 Link Here
118
        rpr.addNewSz().setVal(new BigInteger("14"));
137
        rpr.addNewSz().setVal(new BigInteger("14"));
119
138
120
        XWPFRun run = new XWPFRun(ctRun, p);
139
        XWPFRun run = new XWPFRun(ctRun, p);
121
        assertEquals(7, run.getFontSize().longValue());
140
        assertEquals(7, run.getFontSize());
122
141
123
        run.setFontSize(new BigInteger("24"));
142
        run.setFontSize(24);
124
        assertEquals(48, rpr.getSz().getVal().longValue());
143
        assertEquals(48, rpr.getSz().getVal().longValue());
125
    }
144
    }
126
145
Lines 130-140 Link Here
130
        rpr.addNewPosition().setVal(new BigInteger("4000"));
149
        rpr.addNewPosition().setVal(new BigInteger("4000"));
131
150
132
        XWPFRun run = new XWPFRun(ctRun, p);
151
        XWPFRun run = new XWPFRun(ctRun, p);
133
        assertEquals(4000, run.getTextPosition().longValue());
152
        assertEquals(4000, run.getTextPosition());
134
153
135
        run.setTextPosition(new BigInteger("2400"));
154
        run.setTextPosition(2400);
136
        assertEquals(2400, rpr.getPosition().getVal().longValue());
155
        assertEquals(2400, rpr.getPosition().getVal().longValue());
137
    }
156
    }
138
157
158
    public void testAddCarriageReturn() {
159
	
160
	ctRun.addNewT().setStringValue("TEST STRING");
161
	ctRun.addNewCr();
162
	ctRun.addNewT().setStringValue("TEST2 STRING");
163
	ctRun.addNewCr();
164
	ctRun.addNewT().setStringValue("TEST3 STRING");
165
        assertEquals(2, ctRun.sizeOfCrArray());
166
        
167
        XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), p);
168
        run.setText("T1");
169
        run.addCarriageReturn();
170
        run.addCarriageReturn();
171
        run.setText("T2");
172
        run.addCarriageReturn();
173
        assertEquals(3, run.getCTR().getCrArray().length);
174
        
175
    }
176
177
    public void testAddPageBreak() {
178
	ctRun.addNewT().setStringValue("TEST STRING");
179
	ctRun.addNewBr();
180
	ctRun.addNewT().setStringValue("TEST2 STRING");
181
	CTBr breac=ctRun.addNewBr();
182
	breac.setClear(STBrClear.LEFT);
183
	ctRun.addNewT().setStringValue("TEST3 STRING");
184
        assertEquals(2, ctRun.sizeOfBrArray());
185
        
186
        XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), p);
187
        run.setText("TEXT1");
188
        run.addBreak();
189
        run.setText("TEXT2");
190
        run.addBreak();
191
        assertEquals(2, run.getCTR().sizeOfBrArray());
192
    }
193
    
194
139
}
195
}
140
196
(-)src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java (-20 / +26 lines)
Lines 17-23 Link Here
17
package org.apache.poi.xwpf.usermodel;
17
package org.apache.poi.xwpf.usermodel;
18
18
19
import java.io.FileOutputStream;
19
import java.io.FileOutputStream;
20
import java.math.BigInteger;
21
20
22
/**
21
/**
23
 * A simple WOrdprocessingML document created by POI XWPF API
22
 * A simple WOrdprocessingML document created by POI XWPF API
Lines 46-52 Link Here
46
        r1.setBold(true);
45
        r1.setBold(true);
47
        r1.setFontFamily("Courier");
46
        r1.setFontFamily("Courier");
48
        r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
47
        r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
49
        r1.setTextPosition(new BigInteger("100"));
48
        r1.setTextPosition(100);
50
49
51
        XWPFParagraph p2 = doc.createParagraph();
50
        XWPFParagraph p2 = doc.createParagraph();
52
        p2.setAlignment(ParagraphAlignment.RIGHT);
51
        p2.setAlignment(ParagraphAlignment.RIGHT);
Lines 61-111 Link Here
61
        XWPFRun r2 = p2.createRun();
60
        XWPFRun r2 = p2.createRun();
62
        r2.setText("jumped over the lazy dog");
61
        r2.setText("jumped over the lazy dog");
63
        r2.setStrike(true);
62
        r2.setStrike(true);
64
        r2.setFontSize(new BigInteger("20"));
63
        r2.setFontSize(20);
65
64
66
        XWPFRun r3 = p2.createRun();
65
        XWPFRun r3 = p2.createRun();
67
        r3.setText("and went away");
66
        r3.setText("and went away");
68
        r3.setStrike(true);
67
        r3.setStrike(true);
69
        r3.setFontSize(new BigInteger("20"));
68
        r3.setFontSize(20);
70
        r3.setSubscript(VerticalAlign.SUPERSCRIPT);
69
        r3.setSubscript(VerticalAlign.SUPERSCRIPT);
71
70
72
71
73
        XWPFParagraph p3 = doc.createParagraph();
72
        XWPFParagraph p3 = doc.createParagraph();
74
        p3.setWordWrap(true);
73
        p3.setWordWrap(true);
75
        p3.setPageBreak(true);
74
        p3.setPageBreak(true);
76
        p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
75
                
77
        p3.setIndentationFirstLine(new BigInteger("600"));
76
        //p3.setAlignment(ParagraphAlignment.DISTRIBUTE);
78
        p3.setSpacingAfter(new BigInteger("250"));
77
        p3.setAlignment(ParagraphAlignment.BOTH);
79
        p3.setSpacingBefore(new BigInteger("250"));
78
        p3.setSpacingLineRule(LineSpacingRule.EXACT);
80
79
80
        p3.setIndentationFirstLine(600);
81
        
82
81
        XWPFRun r4 = p3.createRun();
83
        XWPFRun r4 = p3.createRun();
82
        r4.setTextPosition(new BigInteger("20"));
84
        r4.setTextPosition(20);
83
        r4.setText("To be, or not to be: that is the question: "
85
        r4.setText("To be, or not to be: that is the question: "
84
                + "Whether 'tis nobler in the mind to suffer "
86
                + "Whether 'tis nobler in the mind to suffer "
85
                + "The slings and arrows of outrageous fortune, "
87
                + "The slings and arrows of outrageous fortune, "
86
                + "Or to take arms against a sea of troubles, "
88
                + "Or to take arms against a sea of troubles, "
87
                + "And by opposing end them? To die: to sleep; "
89
                + "And by opposing end them? To die: to sleep; ");
88
                + "No more; and by a sleep to say we end "
90
        r4.addBreak(BreakType.PAGE);
91
        r4.setText("No more; and by a sleep to say we end "
89
                + "The heart-ache and the thousand natural shocks "
92
                + "The heart-ache and the thousand natural shocks "
90
                + "That flesh is heir to, 'tis a consummation "
93
                + "That flesh is heir to, 'tis a consummation "
91
                + "Devoutly to be wish'd. To die, to sleep; "
94
                + "Devoutly to be wish'd. To die, to sleep; "
92
                + "To sleep: perchance to dream: ay, there's the rub; "
95
                + "To sleep: perchance to dream: ay, there's the rub; "
93
                + ".......");
96
                + ".......");
94
        r4.setItalic(true);
97
        r4.setItalic(true);
98
//This would imply that this break shall be treated as a simple line break, and break the line after that word:
95
99
96
97
        XWPFRun r5 = p3.createRun();
100
        XWPFRun r5 = p3.createRun();
98
        r5.setTextPosition(new BigInteger("-10"));
101
        r5.setTextPosition(-10);
99
        r5.setText("For in that sleep of death what dreams may come"
102
        r5.setText("For in that sleep of death what dreams may come");
100
                + "When we have shuffled off this mortal coil,"
103
        r5.addCarriageReturn();
104
        r5.setText("When we have shuffled off this mortal coil,"
101
                + "Must give us pause: there's the respect"
105
                + "Must give us pause: there's the respect"
102
                + "That makes calamity of so long life;"
106
                + "That makes calamity of so long life;");
103
                + "For who would bear the whips and scorns of time,"
107
        r5.addBreak();
104
                + "The oppressor's wrong, the proud man's contumely,"
108
        r5.setText("For who would bear the whips and scorns of time,"
105
                + "The pangs of despised love, the law's delay,"
109
                + "The oppressor's wrong, the proud man's contumely,");
110
        
111
        r5.addBreak(BreakClear.ALL);
112
        r5.setText("The pangs of despised love, the law's delay,"
106
                + "The insolence of office and the spurns" + ".......");
113
                + "The insolence of office and the spurns" + ".......");
107
114
108
109
        FileOutputStream out = new FileOutputStream("simple.docx");
115
        FileOutputStream out = new FileOutputStream("simple.docx");
110
        doc.write(out);
116
        doc.write(out);
111
        out.close();
117
        out.close();
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakType.java (+84 lines)
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
package org.apache.poi.xwpf.usermodel;
18
19
import java.util.HashMap;
20
import java.util.Map;
21
22
/**
23
 * Specifies the possible types of break characters in a WordprocessingML
24
 * document.
25
 * The break type determines the next location where text shall be
26
 * placed after this manual break is applied to the text contents
27
 * 
28
 * @author Gisella Bronzetti
29
 */
30
public enum BreakType {
31
32
    
33
    /**
34
     * Specifies that the current break shall restart itself on the next page of
35
     * the document when the document is displayed in page view.
36
     */
37
    PAGE(1),
38
39
    /**
40
     * Specifies that the current break shall restart itself on the next column
41
     * available on the current page when the document is displayed in page
42
     * view.
43
     * <p>
44
     * If the current section is not divided into columns, or the column break
45
     * occurs in the last column on the current page when displayed, then the
46
     * restart location for text shall be the next page in the document.
47
     * </p>
48
     */
49
    COLUMN(2),
50
51
    /**
52
     * Specifies that the current break shall restart itself on the next line in
53
     * the document when the document is displayed in page view.
54
     * The determine of the next line shall be done subject to the value of the clear
55
     * attribute on the specified break character.
56
     */
57
    TEXT_WRAPPING(3);
58
59
    private final int value;
60
61
    private BreakType(int val) {
62
	value = val;
63
    }
64
65
    public int getValue() {
66
	return value;
67
    }
68
69
    private static Map<Integer, BreakType> imap = new HashMap<Integer, BreakType>();
70
    static {
71
	for (BreakType p : values()) {
72
	    imap.put(p.getValue(), p);
73
	}
74
    }
75
76
    public static BreakType valueOf(int type) {
77
	BreakType bType = imap.get(type);
78
	if (bType == null)
79
	    throw new IllegalArgumentException("Unknown break type: "
80
		    + type);
81
	return bType;
82
    }
83
84
}
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/BreakClear.java (+111 lines)
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
package org.apache.poi.xwpf.usermodel;
18
19
import java.util.HashMap;
20
import java.util.Map;
21
22
/**
23
 * Specifies the set of possible restart locations which may be used as to
24
 * determine the next available line when a breakÕs type attribute has a value
25
 * of textWrapping.
26
 * 
27
 * @author Gisella Bronzetti
28
 */
29
public enum BreakClear {
30
31
    /**
32
     * Specifies that the text wrapping break shall advance the text to the next
33
     * line in the WordprocessingML document, regardless of its position left to
34
     * right or the presence of any floating objects which intersect with the
35
     * line,
36
     * 
37
     * This is the setting for a typical line break in a document.
38
     */
39
40
    NONE(1),
41
42
    /**
43
     * Specifies that the text wrapping break shall behave as follows:
44
     * <ul>
45
     * <li> If this line is broken into multiple regions (a floating object in
46
     * the center of the page has text wrapping on both sides:
47
     * <ul>
48
     * <li> If this is the leftmost region of text flow on this line, advance
49
     * the text to the next position on the line </li>
50
     * <li>Otherwise, treat this as a text wrapping break of type all. </li>
51
     * </ul>
52
     * </li>
53
     * <li> If this line is not broken into multiple regions, then treat this
54
     * break as a text wrapping break of type none. </li>
55
     * </ul>
56
     * <li> If the parent paragraph is right to left, then these behaviors are
57
     * also reversed. </li>
58
     */
59
    LEFT(2),
60
61
    /**
62
     * Specifies that the text wrapping break shall behave as follows:
63
     * <ul>
64
     * <li> If this line is broken into multiple regions (a floating object in
65
     * the center of the page has text wrapping on both sides:
66
     * <ul>
67
     * <li> If this is the rightmost region of text flow on this line, advance
68
     * the text to the next position on the next line </li>
69
     * <li> Otherwise, treat this as a text wrapping break of type all. </li>
70
     * </ul>
71
     * <li> If this line is not broken into multiple regions, then treat this
72
     * break as a text wrapping break of type none. </li>
73
     * <li> If the parent paragraph is right to left, then these beha viors are
74
     * also reversed. </li>
75
     * </ul>
76
     */
77
    RIGHT(3),
78
79
    /**
80
     * Specifies that the text wrapping break shall advance the text to the next
81
     * line in the WordprocessingML document which spans the full width of the
82
     * line.
83
     */
84
    ALL(4);
85
86
    private final int value;
87
88
    private BreakClear(int val) {
89
	value = val;
90
    }
91
92
    public int getValue() {
93
	return value;
94
    }
95
96
    private static Map<Integer, BreakClear> imap = new HashMap<Integer, BreakClear>();
97
    static {
98
	for (BreakClear p : values()) {
99
	    imap.put(p.getValue(), p);
100
	}
101
    }
102
103
    public static BreakClear valueOf(int type) {
104
	BreakClear bType = imap.get(type);
105
	if (bType == null)
106
	    throw new IllegalArgumentException("Unknown break clear type: "
107
		    + type);
108
	return bType;
109
    }
110
111
}

Return to bug 46299