Lines 17-22
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.poi.xssf.usermodel; |
18 |
package org.apache.poi.xssf.usermodel; |
19 |
|
19 |
|
|
|
20 |
import java.util.ArrayList; |
21 |
import java.util.Iterator; |
22 |
import java.util.List; |
23 |
|
20 |
import org.apache.poi.hssf.util.HSSFColor; |
24 |
import org.apache.poi.hssf.util.HSSFColor; |
21 |
import org.openxmlformats.schemas.drawingml.x2006.main.*; |
25 |
import org.openxmlformats.schemas.drawingml.x2006.main.*; |
22 |
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape; |
26 |
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape; |
Lines 24-38
Link Here
|
24 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt; |
28 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt; |
25 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; |
29 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt; |
26 |
import org.apache.poi.util.Internal; |
30 |
import org.apache.poi.util.Internal; |
|
|
31 |
import org.apache.poi.util.Units; |
32 |
import org.apache.poi.ss.usermodel.VerticalAlignment; |
27 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues; |
33 |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues; |
28 |
|
34 |
|
29 |
/** |
35 |
/** |
30 |
* Represents a shape with a predefined geometry in a SpreadsheetML drawing. |
36 |
* Represents a shape with a predefined geometry in a SpreadsheetML drawing. |
31 |
* Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes} |
37 |
* Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes} |
32 |
* |
|
|
33 |
* @author Yegor Kozlov |
34 |
*/ |
38 |
*/ |
35 |
public class XSSFSimpleShape extends XSSFShape { // TODO - instantiable superclass |
39 |
public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParagraph> { // TODO - instantiable superclass |
|
|
40 |
/** |
41 |
* List of the paragraphs that make up the text in this shape |
42 |
*/ |
43 |
private final List<XSSFTextParagraph> _paragraphs; |
36 |
/** |
44 |
/** |
37 |
* A default instance of CTShape used for creating new shapes. |
45 |
* A default instance of CTShape used for creating new shapes. |
38 |
*/ |
46 |
*/ |
Lines 46-51
Link Here
|
46 |
protected XSSFSimpleShape(XSSFDrawing drawing, CTShape ctShape) { |
54 |
protected XSSFSimpleShape(XSSFDrawing drawing, CTShape ctShape) { |
47 |
this.drawing = drawing; |
55 |
this.drawing = drawing; |
48 |
this.ctShape = ctShape; |
56 |
this.ctShape = ctShape; |
|
|
57 |
|
58 |
_paragraphs = new ArrayList<XSSFTextParagraph>(); |
59 |
|
60 |
// initialize any existing paragraphs - this will be the default body paragraph in a new shape, |
61 |
// or existing paragraphs that have been loaded from the file |
62 |
CTTextBody body = ctShape.getTxBody(); |
63 |
for(int i = 0; i < body.sizeOfPArray(); i++) { |
64 |
_paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape)); |
65 |
} |
49 |
} |
66 |
} |
50 |
|
67 |
|
51 |
/** |
68 |
/** |
Lines 74-107
Link Here
|
74 |
geom.setPrst(STShapeType.RECT); |
91 |
geom.setPrst(STShapeType.RECT); |
75 |
geom.addNewAvLst(); |
92 |
geom.addNewAvLst(); |
76 |
|
93 |
|
77 |
CTShapeStyle style = shape.addNewStyle(); |
|
|
78 |
CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr(); |
79 |
scheme.setVal(STSchemeColorVal.ACCENT_1); |
80 |
scheme.addNewShade().setVal(50000); |
81 |
style.getLnRef().setIdx(2); |
82 |
|
83 |
CTStyleMatrixReference fillref = style.addNewFillRef(); |
84 |
fillref.setIdx(1); |
85 |
fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1); |
86 |
|
87 |
CTStyleMatrixReference effectRef = style.addNewEffectRef(); |
88 |
effectRef.setIdx(0); |
89 |
effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1); |
90 |
|
91 |
CTFontReference fontRef = style.addNewFontRef(); |
92 |
fontRef.setIdx(STFontCollectionIndex.MINOR); |
93 |
fontRef.addNewSchemeClr().setVal(STSchemeColorVal.LT_1); |
94 |
|
95 |
CTTextBody body = shape.addNewTxBody(); |
94 |
CTTextBody body = shape.addNewTxBody(); |
96 |
CTTextBodyProperties bodypr = body.addNewBodyPr(); |
95 |
CTTextBodyProperties bodypr = body.addNewBodyPr(); |
97 |
bodypr.setAnchor(STTextAnchoringType.CTR); |
96 |
bodypr.setAnchor(STTextAnchoringType.T); |
98 |
bodypr.setRtlCol(false); |
97 |
bodypr.setRtlCol(false); |
99 |
CTTextParagraph p = body.addNewP(); |
98 |
CTTextParagraph p = body.addNewP(); |
100 |
p.addNewPPr().setAlgn(STTextAlignType.CTR); |
99 |
p.addNewPPr().setAlgn(STTextAlignType.L); |
101 |
CTTextCharacterProperties endPr = p.addNewEndParaRPr(); |
100 |
CTTextCharacterProperties endPr = p.addNewEndParaRPr(); |
102 |
endPr.setLang("en-US"); |
101 |
endPr.setLang("en-US"); |
103 |
endPr.setSz(1100); |
102 |
endPr.setSz(1100); |
104 |
|
103 |
CTSolidColorFillProperties scfpr = endPr.addNewSolidFill(); |
|
|
104 |
scfpr.addNewSrgbClr().setVal(new byte[] { 0, 0, 0 }); |
105 |
|
105 |
body.addNewLstStyle(); |
106 |
body.addNewLstStyle(); |
106 |
|
107 |
|
107 |
prototype = shape; |
108 |
prototype = shape; |
Lines 114-143
Link Here
|
114 |
return ctShape; |
115 |
return ctShape; |
115 |
} |
116 |
} |
116 |
|
117 |
|
|
|
118 |
|
119 |
public Iterator<XSSFTextParagraph> iterator(){ |
120 |
return _paragraphs.iterator(); |
121 |
} |
122 |
|
117 |
/** |
123 |
/** |
118 |
* Gets the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}. |
124 |
* Returns the text from all paragraphs in the shape. Paragraphs are separated by new lines. |
119 |
* |
125 |
* |
120 |
* @return the shape type |
126 |
* @return text contained within this shape or empty string |
121 |
* @see org.apache.poi.ss.usermodel.ShapeTypes |
|
|
122 |
*/ |
127 |
*/ |
123 |
public int getShapeType() { |
128 |
public String getText() { |
124 |
return ctShape.getSpPr().getPrstGeom().getPrst().intValue(); |
129 |
StringBuilder out = new StringBuilder(); |
|
|
130 |
for (XSSFTextParagraph p : _paragraphs) { |
131 |
if (out.length() > 0) out.append('\n'); |
132 |
out.append(p.getText()); |
133 |
} |
134 |
return out.toString(); |
125 |
} |
135 |
} |
126 |
|
136 |
|
127 |
/** |
137 |
/** |
128 |
* Sets the shape types. |
138 |
* Clear all text from this shape |
129 |
* |
|
|
130 |
* @param type the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}. |
131 |
* @see org.apache.poi.ss.usermodel.ShapeTypes |
132 |
*/ |
139 |
*/ |
133 |
public void setShapeType(int type) { |
140 |
public void clearText(){ |
134 |
ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type)); |
141 |
_paragraphs.clear(); |
|
|
142 |
CTTextBody txBody = ctShape.getTxBody(); |
143 |
txBody.setPArray(null); // remove any existing paragraphs |
135 |
} |
144 |
} |
|
|
145 |
|
146 |
/** |
147 |
* Set a single paragraph of text on the shape. Note this will replace all existing paragraphs created on the shape. |
148 |
* @param text string representing the paragraph text |
149 |
*/ |
150 |
public void setText(String text){ |
151 |
clearText(); |
136 |
|
152 |
|
137 |
protected CTShapeProperties getShapeProperties(){ |
153 |
addNewTextParagraph().addNewTextRun().setText(text); |
138 |
return ctShape.getSpPr(); |
|
|
139 |
} |
154 |
} |
140 |
|
155 |
|
|
|
156 |
/** |
157 |
* Set a single paragraph of text on the shape. Note this will replace all existing paragraphs created on the shape. |
158 |
* @param str rich text string representing the paragraph text |
159 |
*/ |
141 |
public void setText(XSSFRichTextString str){ |
160 |
public void setText(XSSFRichTextString str){ |
142 |
|
161 |
|
143 |
XSSFWorkbook wb = (XSSFWorkbook)getDrawing().getParent().getParent(); |
162 |
XSSFWorkbook wb = (XSSFWorkbook)getDrawing().getParent().getParent(); |
Lines 166-177
Link Here
|
166 |
r.setT(lt.getT()); |
185 |
r.setT(lt.getT()); |
167 |
} |
186 |
} |
168 |
} |
187 |
} |
|
|
188 |
|
189 |
clearText(); |
169 |
ctShape.getTxBody().setPArray(new CTTextParagraph[]{p}); |
190 |
ctShape.getTxBody().setPArray(new CTTextParagraph[]{p}); |
|
|
191 |
_paragraphs.add(new XSSFTextParagraph(ctShape.getTxBody().getPArray(0), ctShape)); |
192 |
} |
193 |
|
194 |
/** |
195 |
* Returns a collection of the XSSFTextParagraphs that are attached to this shape |
196 |
* |
197 |
* @return text paragraphs in this shape |
198 |
*/ |
199 |
public List<XSSFTextParagraph> getTextParagraphs() { |
200 |
return _paragraphs; |
201 |
} |
202 |
|
203 |
/** |
204 |
* Add a new paragraph run to this shape |
205 |
* |
206 |
* @return created paragraph run |
207 |
*/ |
208 |
public XSSFTextParagraph addNewTextParagraph() { |
209 |
CTTextBody txBody = ctShape.getTxBody(); |
210 |
CTTextParagraph p = txBody.addNewP(); |
211 |
XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); |
212 |
_paragraphs.add(paragraph); |
213 |
return paragraph; |
214 |
} |
215 |
|
216 |
/** |
217 |
* Add a new paragraph run to this shape, set to the provided rich text string |
218 |
* |
219 |
* @return created paragraph run |
220 |
*/ |
221 |
public XSSFTextParagraph addNewTextParagraph(XSSFRichTextString str) { |
222 |
CTTextBody txBody = ctShape.getTxBody(); |
223 |
CTTextParagraph p = txBody.addNewP(); |
224 |
|
225 |
if(str.numFormattingRuns() == 0){ |
226 |
CTRegularTextRun r = p.addNewR(); |
227 |
CTTextCharacterProperties rPr = r.addNewRPr(); |
228 |
rPr.setLang("en-US"); |
229 |
rPr.setSz(1100); |
230 |
r.setT(str.getString()); |
231 |
|
232 |
} else { |
233 |
for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) { |
234 |
CTRElt lt = str.getCTRst().getRArray(i); |
235 |
CTRPrElt ltPr = lt.getRPr(); |
236 |
if(ltPr == null) ltPr = lt.addNewRPr(); |
237 |
|
238 |
CTRegularTextRun r = p.addNewR(); |
239 |
CTTextCharacterProperties rPr = r.addNewRPr(); |
240 |
rPr.setLang("en-US"); |
241 |
|
242 |
applyAttributes(ltPr, rPr); |
243 |
|
244 |
r.setT(lt.getT()); |
245 |
} |
246 |
} |
247 |
|
248 |
// Note: the XSSFTextParagraph constructor will create its required XSSFTextRuns from the provided CTTextParagraph |
249 |
XSSFTextParagraph paragraph = new XSSFTextParagraph(p, ctShape); |
250 |
_paragraphs.add(paragraph); |
251 |
|
252 |
return paragraph; |
253 |
} |
254 |
|
255 |
/** |
256 |
* Sets the type of horizontal overflow for the text. |
257 |
* |
258 |
* @param overflow - the type of horizontal overflow. |
259 |
* A <code>null</code> values unsets this property. |
260 |
*/ |
261 |
public void setTextHorizontalOverflow(TextHorizontalOverflow overflow){ |
262 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
263 |
if (bodyPr != null) { |
264 |
if(anchor == null) { |
265 |
if(bodyPr.isSetHorzOverflow()) bodyPr.unsetHorzOverflow(); |
266 |
} else { |
267 |
bodyPr.setHorzOverflow(STTextHorzOverflowType.Enum.forInt(overflow.ordinal() + 1)); |
268 |
} |
269 |
} |
270 |
} |
271 |
|
272 |
/** |
273 |
* Returns the type of horizontal overflow for the text. |
274 |
* |
275 |
* @return the type of horizontal overflow |
276 |
*/ |
277 |
public TextHorizontalOverflow getTextHorizontalOverflow(){ |
278 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
279 |
if(bodyPr != null) { |
280 |
if(bodyPr.isSetHorzOverflow()){ |
281 |
return TextHorizontalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1]; |
282 |
} |
283 |
} |
284 |
return TextHorizontalOverflow.OVERFLOW; |
285 |
} |
286 |
|
287 |
/** |
288 |
* Sets the type of vertical overflow for the text. |
289 |
* |
290 |
* @param overflow - the type of vertical overflow. |
291 |
* A <code>null</code> values unsets this property. |
292 |
*/ |
293 |
public void setTextVerticalOverflow(TextVerticalOverflow overflow){ |
294 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
295 |
if (bodyPr != null) { |
296 |
if(anchor == null) { |
297 |
if(bodyPr.isSetVertOverflow()) bodyPr.unsetVertOverflow(); |
298 |
} else { |
299 |
bodyPr.setVertOverflow(STTextVertOverflowType.Enum.forInt(overflow.ordinal() + 1)); |
300 |
} |
301 |
} |
302 |
} |
303 |
|
304 |
/** |
305 |
* Returns the type of vertical overflow for the text. |
306 |
* |
307 |
* @return the type of vertical overflow |
308 |
*/ |
309 |
public TextVerticalOverflow getTextVerticalOverflow(){ |
310 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
311 |
if(bodyPr != null) { |
312 |
if(bodyPr.isSetVertOverflow()){ |
313 |
return TextVerticalOverflow.values()[bodyPr.getVertOverflow().intValue() - 1]; |
314 |
} |
315 |
} |
316 |
return TextVerticalOverflow.OVERFLOW; |
317 |
} |
318 |
|
319 |
/** |
320 |
* Sets the type of vertical alignment for the text within the shape. |
321 |
* |
322 |
* @param anchor - the type of alignment. |
323 |
* A <code>null</code> values unsets this property. |
324 |
*/ |
325 |
public void setVerticalAlignment(VerticalAlignment anchor){ |
326 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
327 |
if (bodyPr != null) { |
328 |
if(anchor == null) { |
329 |
if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor(); |
330 |
} else { |
331 |
bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1)); |
332 |
} |
333 |
} |
334 |
} |
335 |
|
336 |
/** |
337 |
* Returns the type of vertical alignment for the text within the shape. |
338 |
* |
339 |
* @return the type of vertical alignment |
340 |
*/ |
341 |
public VerticalAlignment getVerticalAlignment(){ |
342 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
343 |
if(bodyPr != null) { |
344 |
if(bodyPr.isSetAnchor()){ |
345 |
return VerticalAlignment.values()[bodyPr.getAnchor().intValue() - 1]; |
346 |
} |
347 |
} |
348 |
return VerticalAlignment.TOP; |
349 |
} |
350 |
|
351 |
/** |
352 |
* Sets the vertical orientation of the text |
353 |
* |
354 |
* @param orientation vertical orientation of the text |
355 |
* A <code>null</code> values unsets this property. |
356 |
*/ |
357 |
public void setTextDirection(TextDirection orientation){ |
358 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
359 |
if (bodyPr != null) { |
360 |
if(orientation == null) { |
361 |
if(bodyPr.isSetVert()) bodyPr.unsetVert(); |
362 |
} else { |
363 |
bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1)); |
364 |
} |
365 |
} |
366 |
} |
367 |
|
368 |
/** |
369 |
* Gets the vertical orientation of the text |
370 |
* |
371 |
* @return vertical orientation of the text |
372 |
*/ |
373 |
public TextDirection getTextDirection(){ |
374 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
375 |
if (bodyPr != null) { |
376 |
STTextVerticalType.Enum val = bodyPr.getVert(); |
377 |
if(val != null){ |
378 |
return TextDirection.values()[val.intValue() - 1]; |
379 |
} |
380 |
} |
381 |
return TextDirection.HORIZONTAL; |
382 |
} |
383 |
|
384 |
|
385 |
/** |
386 |
* Returns the distance (in points) between the bottom of the text frame |
387 |
* and the bottom of the inscribed rectangle of the shape that contains the text. |
388 |
* |
389 |
* @return the bottom inset in points |
390 |
*/ |
391 |
public double getBottomInset(){ |
392 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
393 |
if (bodyPr != null) { |
394 |
if(bodyPr.isSetBIns()){ |
395 |
return Units.toPoints(bodyPr.getBIns()); |
396 |
} |
397 |
} |
398 |
// If this attribute is omitted, then a value of 0.05 inches is implied |
399 |
return 3.6; |
400 |
} |
401 |
|
402 |
/** |
403 |
* Returns the distance (in points) between the left edge of the text frame |
404 |
* and the left edge of the inscribed rectangle of the shape that contains |
405 |
* the text. |
406 |
* |
407 |
* @return the left inset in points |
408 |
*/ |
409 |
public double getLeftInset(){ |
410 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
411 |
if (bodyPr != null) { |
412 |
if(bodyPr.isSetLIns()){ |
413 |
return Units.toPoints(bodyPr.getLIns()); |
414 |
} |
415 |
} |
416 |
// If this attribute is omitted, then a value of 0.05 inches is implied |
417 |
return 3.6; |
418 |
} |
419 |
|
420 |
/** |
421 |
* Returns the distance (in points) between the right edge of the |
422 |
* text frame and the right edge of the inscribed rectangle of the shape |
423 |
* that contains the text. |
424 |
* |
425 |
* @return the right inset in points |
426 |
*/ |
427 |
public double getRightInset(){ |
428 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
429 |
if (bodyPr != null) { |
430 |
if(bodyPr.isSetRIns()){ |
431 |
return Units.toPoints(bodyPr.getRIns()); |
432 |
} |
433 |
} |
434 |
// If this attribute is omitted, then a value of 0.05 inches is implied |
435 |
return 3.6; |
436 |
} |
437 |
|
438 |
/** |
439 |
* Returns the distance (in points) between the top of the text frame |
440 |
* and the top of the inscribed rectangle of the shape that contains the text. |
441 |
* |
442 |
* @return the top inset in points |
443 |
*/ |
444 |
public double getTopInset(){ |
445 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
446 |
if (bodyPr != null) { |
447 |
if(bodyPr.isSetTIns()){ |
448 |
return Units.toPoints(bodyPr.getTIns()); |
449 |
} |
450 |
} |
451 |
// If this attribute is omitted, then a value of 0.05 inches is implied |
452 |
return 3.6; |
453 |
} |
454 |
|
455 |
/** |
456 |
* Sets the bottom inset. |
457 |
* @see #getBottomInset() |
458 |
* |
459 |
* @param margin the bottom margin |
460 |
*/ |
461 |
public void setBottomInset(double margin){ |
462 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
463 |
if (bodyPr != null) { |
464 |
if(margin == -1) bodyPr.unsetBIns(); |
465 |
else bodyPr.setBIns(Units.toEMU(margin)); |
466 |
} |
467 |
} |
468 |
|
469 |
/** |
470 |
* Sets the left inset. |
471 |
* @see #getLeftInset() |
472 |
* |
473 |
* @param margin the left margin |
474 |
*/ |
475 |
public void setLeftInset(double margin){ |
476 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
477 |
if (bodyPr != null) { |
478 |
if(margin == -1) bodyPr.unsetLIns(); |
479 |
else bodyPr.setLIns(Units.toEMU(margin)); |
480 |
} |
481 |
} |
482 |
|
483 |
/** |
484 |
* Sets the right inset. |
485 |
* @see #getRightInset() |
486 |
* |
487 |
* @param margin the right margin |
488 |
*/ |
489 |
public void setRightInset(double margin){ |
490 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
491 |
if (bodyPr != null) { |
492 |
if(margin == -1) bodyPr.unsetRIns(); |
493 |
else bodyPr.setRIns(Units.toEMU(margin)); |
494 |
} |
495 |
} |
496 |
|
497 |
/** |
498 |
* Sets the top inset. |
499 |
* @see #getTopInset() |
500 |
* |
501 |
* @param margin the top margin |
502 |
*/ |
503 |
public void setTopInset(double margin){ |
504 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
505 |
if (bodyPr != null) { |
506 |
if(margin == -1) bodyPr.unsetTIns(); |
507 |
else bodyPr.setTIns(Units.toEMU(margin)); |
508 |
} |
509 |
} |
510 |
|
511 |
|
512 |
/** |
513 |
* @return whether to wrap words within the bounding rectangle |
514 |
*/ |
515 |
public boolean getWordWrap(){ |
516 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
517 |
if (bodyPr != null) { |
518 |
if(bodyPr.isSetWrap()){ |
519 |
return bodyPr.getWrap() == STTextWrappingType.SQUARE; |
520 |
} |
521 |
} |
522 |
return true; |
523 |
} |
524 |
|
525 |
/** |
526 |
* |
527 |
* @param wrap whether to wrap words within the bounding rectangle |
528 |
*/ |
529 |
public void setWordWrap(boolean wrap){ |
530 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
531 |
if (bodyPr != null) { |
532 |
bodyPr.setWrap(wrap ? STTextWrappingType.SQUARE : STTextWrappingType.NONE); |
533 |
} |
534 |
} |
535 |
|
536 |
/** |
537 |
* |
538 |
* Specifies that a shape should be auto-fit to fully contain the text described within it. |
539 |
* Auto-fitting is when text within a shape is scaled in order to contain all the text inside |
540 |
* |
541 |
* @param value type of autofit |
542 |
*/ |
543 |
public void setTextAutofit(TextAutofit value){ |
544 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
545 |
if (bodyPr != null) { |
546 |
if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit(); |
547 |
if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit(); |
548 |
if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit(); |
549 |
|
550 |
switch(value){ |
551 |
case NONE: bodyPr.addNewNoAutofit(); break; |
552 |
case NORMAL: bodyPr.addNewNormAutofit(); break; |
553 |
case SHAPE: bodyPr.addNewSpAutoFit(); break; |
554 |
} |
555 |
} |
556 |
} |
170 |
|
557 |
|
|
|
558 |
/** |
559 |
* |
560 |
* @return type of autofit |
561 |
*/ |
562 |
public TextAutofit getTextAutofit(){ |
563 |
CTTextBodyProperties bodyPr = ctShape.getTxBody().getBodyPr(); |
564 |
if (bodyPr != null) { |
565 |
if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE; |
566 |
else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL; |
567 |
else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE; |
568 |
} |
569 |
return TextAutofit.NORMAL; |
570 |
} |
571 |
|
572 |
/** |
573 |
* Gets the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}. |
574 |
* |
575 |
* @return the shape type |
576 |
* @see org.apache.poi.ss.usermodel.ShapeTypes |
577 |
*/ |
578 |
public int getShapeType() { |
579 |
return ctShape.getSpPr().getPrstGeom().getPrst().intValue(); |
171 |
} |
580 |
} |
172 |
|
581 |
|
173 |
/** |
582 |
/** |
|
|
583 |
* Sets the shape types. |
174 |
* |
584 |
* |
|
|
585 |
* @param type the shape type, one of the constants defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}. |
586 |
* @see org.apache.poi.ss.usermodel.ShapeTypes |
587 |
*/ |
588 |
public void setShapeType(int type) { |
589 |
ctShape.getSpPr().getPrstGeom().setPrst(STShapeType.Enum.forInt(type)); |
590 |
} |
591 |
|
592 |
protected CTShapeProperties getShapeProperties(){ |
593 |
return ctShape.getSpPr(); |
594 |
} |
595 |
|
596 |
/** |
175 |
* org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to |
597 |
* org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to |
176 |
* org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter |
598 |
* org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter |
177 |
*/ |
599 |
*/ |
Lines 186-193
Link Here
|
186 |
} |
608 |
} |
187 |
if(pr.sizeOfIArray() > 0) rPr.setI(pr.getIArray(0).getVal()); |
609 |
if(pr.sizeOfIArray() > 0) rPr.setI(pr.getIArray(0).getVal()); |
188 |
|
610 |
|
189 |
if(pr.sizeOfFamilyArray() > 0) { |
611 |
if(pr.sizeOfRFontArray() > 0) { |
190 |
CTTextFont rFont = rPr.addNewLatin(); |
612 |
CTTextFont rFont = rPr.isSetLatin() ? rPr.getLatin() : rPr.addNewLatin(); |
191 |
rFont.setTypeface(pr.getRFontArray(0).getVal()); |
613 |
rFont.setTypeface(pr.getRFontArray(0).getVal()); |
192 |
} |
614 |
} |
193 |
|
615 |
|