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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
|
/* ====================================================================
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.xslf.usermodel;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
import org.apache.poi.xslf.model.ParagraphPropertyFetcher;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.font.TextLayout;
import java.awt.font.TextAttribute;
import java.awt.font.LineBreakMeasurer;
import java.text.AttributedString;
import java.text.AttributedCharacterIterator;
/**
* Represents a paragraph of text within the containing text body.
* The paragraph is the highest level text separation mechanism.
*
* @author Yegor Kozlov
* @since POI-3.8
*/
@Beta
public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
private final CTTextParagraph _p;
private final List<XSLFTextRun> _runs;
private final XSLFTextShape _shape;
private List<TextFragment> _lines;
private TextFragment _bullet;
XSLFTextParagraph(CTTextParagraph p, XSLFTextShape shape){
_p = p;
_runs = new ArrayList<XSLFTextRun>();
_shape = shape;
for (CTRegularTextRun r : _p.getRList()) {
_runs.add(new XSLFTextRun(r, this));
}
for (CTTextField f : _p.getFldList()) {
CTRegularTextRun r = CTRegularTextRun.Factory.newInstance();
r.setT(f.getT());
_runs.add(new XSLFTextRun(r, this));
}
}
public String getText(){
StringBuilder out = new StringBuilder();
for (XSLFTextRun r : _runs) {
out.append(r.getText());
}
return out.toString();
}
@Internal
public CTTextParagraph getXmlObject(){
return _p;
}
XSLFTextShape getParentShape() {
return _shape;
}
public List<XSLFTextRun> getTextRuns(){
return _runs;
}
public Iterator<XSLFTextRun> iterator(){
return _runs.iterator();
}
public XSLFTextRun addNewTextRun(){
CTRegularTextRun r = _p.addNewR();
r.addNewRPr();
XSLFTextRun run = new XSLFTextRun(r, this);
_runs.add(run);
return run;
}
public void addLineBreak(){
_p.addNewBr();
}
/**
* Returns the alignment that is applied to the paragraph.
*
* If this attribute is omitted, then a value of left is implied.
* @return ??? alignment that is applied to the paragraph
*/
public TextAlign getTextAlign(){
ParagraphPropertyFetcher<TextAlign> fetcher = new ParagraphPropertyFetcher<TextAlign>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetAlgn()){
TextAlign val = TextAlign.values()[props.getAlgn().intValue() - 1];
setValue(val);
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? TextAlign.LEFT : fetcher.getValue();
}
/**
* Specifies the alignment that is to be applied to the paragraph.
* Possible values for this include left, right, centered, justified and distributed,
* see {@link org.apache.poi.xslf.usermodel.TextAlign}.
*
* @param align text align
*/
public void setTextAlign(TextAlign align){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
if(align == null) {
if(pr.isSetAlgn()) pr.unsetAlgn();
} else {
pr.setAlgn(STTextAlignType.Enum.forInt(align.ordinal() + 1));
}
}
/**
* @return the font to be used on bullet characters within a given paragraph
*/
public String getBulletFont(){
ParagraphPropertyFetcher<String> fetcher = new ParagraphPropertyFetcher<String>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuFont()){
setValue(props.getBuFont().getTypeface());
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue();
}
/**
* @return the character to be used in place of the standard bullet point
*/
public String getBulletCharacter(){
ParagraphPropertyFetcher<String> fetcher = new ParagraphPropertyFetcher<String>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuChar()){
setValue(props.getBuChar().getChar());
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue();
}
public Color getBulletFontColor(){
final XSLFTheme theme = getParentShape().getSheet().getTheme();
ParagraphPropertyFetcher<Color> fetcher = new ParagraphPropertyFetcher<Color>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuClr()){
setValue(theme.getColor(props.getBuClr()));
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue();
}
public double getBulletFontSize(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuSzPct()){
setValue(props.getBuSzPct().getVal() * 0.001);
return true;
}
if(props.isSetBuSzPts()){
setValue( - props.getBuSzPts().getVal() * 0.01);
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 100 : fetcher.getValue();
}
/**
* Specifies the indent size that will be applied to the first line of text in the paragraph.
*
* @param value the indent in points. The value of -1 unsets the indent attribute
* from the underlying xml bean.
*/
public void setIndent(double value){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
if(value == -1) {
if(pr.isSetIndent()) pr.unsetIndent();
} else {
pr.setIndent(Units.toEMU(value));
}
}
/**
*
* @return the indent applied to the first line of text in the paragraph.
*/
public double getIndent(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetIndent()){
setValue(Units.toPoints(props.getIndent()));
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 0 : fetcher.getValue();
}
/**
* Specifies the left margin of the paragraph. This is specified in addition to the text body
* inset and applies only to this text paragraph. That is the text body Inset and the LeftMargin
* attributes are additive with respect to the text position.
*
* @param value the left margin of the paragraph
*/
public void setLeftMargin(double value){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
pr.setMarL(Units.toEMU(value));
}
/**
*
* @return the left margin of the paragraph
*/
public double getLeftMargin(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetMarL()){
double val = Units.toPoints(props.getMarL());
setValue(val);
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 0 : fetcher.getValue();
}
/**
* This element specifies the vertical line spacing that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
* If linespacing >= 0, then linespacing is a percentage of normal line height
* If linespacing < 0, the absolute value of linespacing is the spacing in points
* </p>
* Examples:
* <pre><code>
* // spacing will be 120% of the size of the largest text on each line
* paragraph.setLineSpacing(120);
*
* // spacing will be 200% of the size of the largest text on each line
* paragraph.setLineSpacing(200);
*
* // spacing will be 48 points
* paragraph.setLineSpacing(-48.0);
* </code></pre>
*
* @param linespacing the vertical line spacing
*/
public void setLineSpacing(double linespacing){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
if(linespacing >= 0) spc.addNewSpcPct().setVal((int)(linespacing*1000));
else spc.addNewSpcPts().setVal((int)(-linespacing*100));
pr.setLnSpc(spc);
}
/**
* Returns the vertical line spacing that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
* If linespacing >= 0, then linespacing is a percentage of normal line height.
* If linespacing < 0, the absolute value of linespacing is the spacing in points
* </p>
*
* @return the vertical line spacing.
*/
public double getLineSpacing(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetLnSpc()){
CTTextSpacing spc = props.getLnSpc();
if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 100 : fetcher.getValue();
}
/**
* Set the amount of vertical white space that will be present before the paragraph.
* This space is specified in either percentage or points:
* <p>
* If spaceBefore >= 0, then space is a percentage of normal line height.
* If spaceBefore < 0, the absolute value of linespacing is the spacing in points
* </p>
* Examples:
* <pre><code>
* // The paragraph will be formatted to have a spacing before the paragraph text.
* // The spacing will be 200% of the size of the largest text on each line
* paragraph.setSpaceBefore(200);
*
* // The spacing will be a size of 48 points
* paragraph.setSpaceBefore(-48.0);
* </code></pre>
*
* @param spaceBefore the vertical white space before the paragraph.
*/
public void setSpaceBefore(double spaceBefore){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
if(spaceBefore >= 0) spc.addNewSpcPct().setVal((int)(spaceBefore*1000));
else spc.addNewSpcPts().setVal((int)(-spaceBefore*100));
pr.setSpcBef(spc);
}
/**
* The amount of vertical white space before the paragraph
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
* If spaceBefore >= 0, then space is a percentage of normal line height.
* If spaceBefore < 0, the absolute value of linespacing is the spacing in points
* </p>
*
* @return the vertical white space before the paragraph
*/
public double getSpaceBefore(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetSpcBef()){
CTTextSpacing spc = props.getSpcBef();
if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 0 : fetcher.getValue();
}
/**
* Set the amount of vertical white space that will be present after the paragraph.
* This space is specified in either percentage or points:
* <p>
* If spaceAfter >= 0, then space is a percentage of normal line height.
* If spaceAfter < 0, the absolute value of linespacing is the spacing in points
* </p>
* Examples:
* <pre><code>
* // The paragraph will be formatted to have a spacing after the paragraph text.
* // The spacing will be 200% of the size of the largest text on each line
* paragraph.setSpaceAfter(200);
*
* // The spacing will be a size of 48 points
* paragraph.setSpaceAfter(-48.0);
* </code></pre>
*
* @param spaceAfter the vertical white space after the paragraph.
*/
public void setSpaceAfter(double spaceAfter){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
if(spaceAfter >= 0) spc.addNewSpcPct().setVal((int)(spaceAfter*1000));
else spc.addNewSpcPts().setVal((int)(-spaceAfter*100));
pr.setSpcAft(spc);
}
/**
* The amount of vertical white space after the paragraph
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
* If spaceBefore >= 0, then space is a percentage of normal line height.
* If spaceBefore < 0, the absolute value of linespacing is the spacing in points
* </p>
*
* @return the vertical white space after the paragraph
*/
public double getSpaceAfter(){
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetSpcAft()){
CTTextSpacing spc = props.getSpcAft();
if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 0 : fetcher.getValue();
}
/**
* Specifies the particular level text properties that this paragraph will follow.
* The value for this attribute formats the text according to the corresponding level
* paragraph properties defined in the SlideMaster.
*
* @param level the level (0 ... 4)
*/
public void setLevel(int level){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
pr.setLvl(level);
}
/**
*
* @return the text level of this paragraph. Default is 0.
*/
public int getLevel(){
CTTextParagraphProperties pr = _p.getPPr();
if(pr == null) return 0;
return pr.getLvl();
}
/**
* Returns whether this paragraph has bullets
*/
public boolean isBullet() {
ParagraphPropertyFetcher<Boolean> fetcher = new ParagraphPropertyFetcher<Boolean>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuNone()) {
setValue(false);
return true;
}
if(props.isSetBuFont()){
setValue(true);
return true;
}
return false;
}
};
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? false : fetcher.getValue();
}
@Override
public String toString(){
return "[" + getClass() + "]" + getText();
}
public List<TextFragment> getTextLines(){
return _lines;
}
public double draw(Graphics2D graphics, double x, double y){
double marginLeft = _shape.getMarginLeft();
double marginRight = _shape.getMarginRight();
Rectangle2D anchor = _shape.getAnchor();
double penY = y;
double textOffset = getLeftMargin();
for(TextFragment line : _lines){
double penX = x;
switch (getTextAlign()) {
case CENTER:
penX += textOffset + (anchor.getWidth() - textOffset - line.getWidth() - marginLeft - marginRight) / 2;
break;
case RIGHT:
penX += (anchor.getWidth() - line.getWidth() - marginLeft - marginRight);
break;
default:
penX = x + textOffset;
break;
}
if(_bullet != null){
_bullet.draw(graphics, penX + getIndent(), penY);
}
line.draw(graphics, penX, penY);
//The vertical line spacing
double spacing = getLineSpacing();
if(spacing > 0) {
// If linespacing >= 0, then linespacing is a percentage of normal line height.
penY += spacing*0.01*line.getHeight();
} else {
// positive value means absolute spacing in points
penY += -spacing;
}
}
return penY - y;
}
static class TextFragment {
private TextLayout _layout;
private AttributedString _str;
TextFragment(TextLayout layout, AttributedString str){
_layout = layout;
_str = str;
}
void draw(Graphics2D graphics, double x, double y){
double yBaseline = y + _layout.getAscent();
graphics.drawString(_str.getIterator(), (float)x, (float)yBaseline );
}
public float getHeight(){
return _layout.getAscent() + _layout.getDescent() + _layout.getLeading();
}
public float getWidth(){
return _layout.getAdvance();
}
}
public AttributedString getAttributedString(){
String text = getText();
AttributedString string = new AttributedString(text);
int startIndex = 0;
for (XSLFTextRun run : _runs){
int length = run.getText().length();
if(length == 0) {
// skip empty runs
continue;
}
int endIndex = startIndex + length;
string.addAttribute(TextAttribute.FOREGROUND, run.getFontColor(), startIndex, endIndex);
string.addAttribute(TextAttribute.FAMILY, run.getFontFamily(), startIndex, endIndex);
string.addAttribute(TextAttribute.SIZE, run.getFontSize(), startIndex, endIndex);
if(run.isBold()) {
string.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIndex, endIndex);
}
if(run.isItalic()) {
string.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIndex, endIndex);
}
if(run.isUnderline()) {
string.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIndex, endIndex);
}
if(run.isStrikethrough()) {
string.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, startIndex, endIndex);
}
startIndex = endIndex;
}
return string;
}
void breakText(Graphics2D graphics){
_lines = new ArrayList<TextFragment>();
AttributedString at = getAttributedString();
AttributedCharacterIterator it = at.getIterator();
if(it.getBeginIndex() == it.getEndIndex()) {
return;
}
LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext());
for (;;) {
int startIndex = measurer.getPosition();
double wrappingWidth = getWrappingWidth() + 1; // add a pixel to compensate rounding errors
TextLayout layout = measurer.nextLayout((float)wrappingWidth, it.getEndIndex(), true);
if (layout == null) {
// layout can be null if the entire word at the current position
// does not fit within the wrapping width. Try with requireNextWord=false.
layout = measurer.nextLayout((float)wrappingWidth, it.getEndIndex(), false);
}
int endIndex = measurer.getPosition();
if(getTextAlign() == TextAlign.JUSTIFY) {
layout = layout.getJustifiedLayout((float)wrappingWidth);
}
AttributedString str = new AttributedString(it, startIndex, endIndex);
TextFragment line = new TextFragment(layout, str);
_lines.add(line);
if(endIndex == it.getEndIndex()) break;
}
if(isBullet()) {
String buCharacter = getBulletCharacter();
String buFont = getBulletFont();
if(buCharacter != null && buFont != null && _lines.size() > 0) {
AttributedString str = new AttributedString(buCharacter);
TextFragment firstLine = _lines.get(0);
AttributedCharacterIterator bit = firstLine._str.getIterator();
Color buColor = getBulletFontColor();
str.addAttribute(TextAttribute.FOREGROUND, buColor == null ?
bit.getAttribute(TextAttribute.FOREGROUND) : buColor);
str.addAttribute(TextAttribute.FAMILY, buFont);
double fontSize = (Double)bit.getAttribute(TextAttribute.SIZE);
double buSz = getBulletFontSize();
if(buSz > 0) fontSize *= buSz* 0.01;
else fontSize = -buSz;
str.addAttribute(TextAttribute.SIZE, fontSize);
TextLayout layout = new TextLayout(str.getIterator(), graphics.getFontRenderContext());
_bullet = new TextFragment(layout, str);
}
}
}
double getWrappingWidth(){
double width;
if(!_shape.getWordWrap()) {
width = _shape.getSheet().getSlideShow().getPageSize().getWidth();
} else {
width = _shape.getAnchor().getWidth() -
_shape.getMarginLeft() - _shape.getMarginRight() - getLeftMargin();
}
return width;
}
CTTextParagraphProperties getDefaultStyle(){
CTPlaceholder ph = _shape.getCTPlaceholder();
String defaultStyleSelector;
if(ph == null) defaultStyleSelector = "otherStyle";
else {
switch(ph.getType().intValue()){
case STPlaceholderType.INT_TITLE:
case STPlaceholderType.INT_CTR_TITLE:
defaultStyleSelector = "titleStyle";
break;
case STPlaceholderType.INT_FTR:
case STPlaceholderType.INT_SLD_NUM:
case STPlaceholderType.INT_DT:
defaultStyleSelector = "otherStyle";
break;
default:
defaultStyleSelector = "bodyStyle";
break;
}
}
int level = getLevel();
XmlObject[] o = _shape.getSheet().getSlideMaster().getXmlObject().selectPath(
"declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' " +
"declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' " +
".//p:txStyles/p:" + defaultStyleSelector +"/a:lvl" +(level+1)+ "pPr");
if(o.length == 1){
return (CTTextParagraphProperties)o[0];
}
throw new IllegalArgumentException("Failed to fetch default style for " +
defaultStyleSelector + " and level=" + level);
}
private boolean fetchParagraphProperty(ParagraphPropertyFetcher visitor){
boolean ok = false;
if(_p.isSetPPr()) ok = visitor.fetch(_p.getPPr());
if(!ok) {
XSLFTextShape shape = getParentShape();
ok = shape.fetchShapeProperty(visitor);
if(!ok) {
CTTextParagraphProperties defaultProps = getDefaultStyle();
if(defaultProps != null) ok = visitor.fetch(defaultProps);
}
}
return ok;
}
}
|