}
}
+ @Override
public Iterator<XSLFTextParagraph> iterator(){
return getTextParagraphs().iterator();
}
public String getText() {
StringBuilder out = new StringBuilder();
for (XSLFTextParagraph p : _paragraphs) {
- if (out.length() > 0) out.append('\n');
+ if (out.length() > 0) {
+ out.append('\n');
+ }
out.append(p.getText());
}
return out.toString();
@Override
public XSLFTextRun appendText(String text, boolean newParagraph) {
- if (text == null) return null;
+ if (text == null) {
+ return null;
+ }
// copy properties from last paragraph / textrun or paragraph end marker
CTTextParagraphProperties otherPPr = null;
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
if(anchor == null) {
- if(bodyPr.isSetAnchor()) bodyPr.unsetAnchor();
+ if(bodyPr.isSetAnchor()) {
+ bodyPr.unsetAnchor();
+ }
} else {
bodyPr.setAnchor(STTextAnchoringType.Enum.forInt(anchor.ordinal() + 1));
}
@Override
public VerticalAlignment getVerticalAlignment(){
PropertyFetcher<VerticalAlignment> fetcher = new TextBodyPropertyFetcher<VerticalAlignment>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetAnchor()){
int val = props.getAnchor().intValue();
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
if (isCentered == null) {
- if (bodyPr.isSetAnchorCtr()) bodyPr.unsetAnchorCtr();
+ if (bodyPr.isSetAnchorCtr()) {
+ bodyPr.unsetAnchorCtr();
+ }
} else {
bodyPr.setAnchorCtr(isCentered);
}
@Override
public boolean isHorizontalCentered(){
PropertyFetcher<Boolean> fetcher = new TextBodyPropertyFetcher<Boolean>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetAnchorCtr()){
setValue(props.getAnchorCtr());
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
if(orientation == null) {
- if(bodyPr.isSetVert()) bodyPr.unsetVert();
+ if(bodyPr.isSetVert()) {
+ bodyPr.unsetVert();
+ }
} else {
bodyPr.setVert(STTextVerticalType.Enum.forInt(orientation.ordinal() + 1));
}
*/
public double getBottomInset(){
PropertyFetcher<Double> fetcher = new TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetBIns()){
double val = Units.toPoints(props.getBIns());
*/
public double getLeftInset(){
PropertyFetcher<Double> fetcher = new TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetLIns()){
double val = Units.toPoints(props.getLIns());
*/
public double getRightInset(){
PropertyFetcher<Double> fetcher = new TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetRIns()){
double val = Units.toPoints(props.getRIns());
*/
public double getTopInset(){
PropertyFetcher<Double> fetcher = new TextBodyPropertyFetcher<Double>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetTIns()){
double val = Units.toPoints(props.getTIns());
public void setBottomInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetBIns();
- else bodyPr.setBIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetBIns();
+ } else {
+ bodyPr.setBIns(Units.toEMU(margin));
+ }
}
}
public void setLeftInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetLIns();
- else bodyPr.setLIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetLIns();
+ } else {
+ bodyPr.setLIns(Units.toEMU(margin));
+ }
}
}
public void setRightInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetRIns();
- else bodyPr.setRIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetRIns();
+ } else {
+ bodyPr.setRIns(Units.toEMU(margin));
+ }
}
}
public void setTopInset(double margin){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(margin == -1) bodyPr.unsetTIns();
- else bodyPr.setTIns(Units.toEMU(margin));
+ if(margin == -1) {
+ bodyPr.unsetTIns();
+ } else {
+ bodyPr.setTIns(Units.toEMU(margin));
+ }
}
}
@Override
public boolean getWordWrap(){
PropertyFetcher<Boolean> fetcher = new TextBodyPropertyFetcher<Boolean>(){
+ @Override
public boolean fetch(CTTextBodyProperties props){
if(props.isSetWrap()){
setValue(props.getWrap() == STTextWrappingType.SQUARE);
public void setTextAutofit(TextAutofit value){
CTTextBodyProperties bodyPr = getTextBodyPr(true);
if (bodyPr != null) {
- if(bodyPr.isSetSpAutoFit()) bodyPr.unsetSpAutoFit();
- if(bodyPr.isSetNoAutofit()) bodyPr.unsetNoAutofit();
- if(bodyPr.isSetNormAutofit()) bodyPr.unsetNormAutofit();
+ if(bodyPr.isSetSpAutoFit()) {
+ bodyPr.unsetSpAutoFit();
+ }
+ if(bodyPr.isSetNoAutofit()) {
+ bodyPr.unsetNoAutofit();
+ }
+ if(bodyPr.isSetNormAutofit()) {
+ bodyPr.unsetNormAutofit();
+ }
switch(value){
case NONE: bodyPr.addNewNoAutofit(); break;
public TextAutofit getTextAutofit(){
CTTextBodyProperties bodyPr = getTextBodyPr();
if (bodyPr != null) {
- if(bodyPr.isSetNoAutofit()) return TextAutofit.NONE;
- else if (bodyPr.isSetNormAutofit()) return TextAutofit.NORMAL;
- else if (bodyPr.isSetSpAutoFit()) return TextAutofit.SHAPE;
+ if(bodyPr.isSetNoAutofit()) {
+ return TextAutofit.NONE;
+ } else if (bodyPr.isSetNormAutofit()) {
+ return TextAutofit.NORMAL;
+ } else if (bodyPr.isSetSpAutoFit()) {
+ return TextAutofit.SHAPE;
+ }
}
return TextAutofit.NORMAL;
}
public Placeholder getTextType(){
CTPlaceholder ph = getCTPlaceholder();
- if (ph == null) return null;
+ if (ph == null) {
+ return null;
+ }
int val = ph.getType().intValue();
return Placeholder.lookupOoxml(val);
*/
public Rectangle2D resizeToFitText(){
Rectangle2D anchor = getAnchor();
- if(anchor.getWidth() == 0.) throw new POIXMLException(
- "Anchor of the shape was not set.");
+
+ if(anchor.getWidth() == 0.) {
+ throw new POIXMLException("Anchor of the shape was not set.");
+ }
double height = getTextHeight();
height += 1; // add a pixel to compensate rounding errors
- anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
+ Insets2D insets = getInsets();
+ anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height+insets.top+insets.bottom);
setAnchor(anchor);
return anchor;
thisTB.setBodyPr((CTTextBodyProperties)otherTB.getBodyPr().copy());
- if (thisTB.isSetLstStyle()) thisTB.unsetLstStyle();
+ if (thisTB.isSetLstStyle()) {
+ thisTB.unsetLstStyle();
+ }
if (otherTB.isSetLstStyle()) {
thisTB.setLstStyle((CTTextListStyle)otherTB.getLstStyle().copy());
}
@Override
public TextPlaceholder getTextPlaceholder() {
Placeholder ph = getTextType();
- if (ph == null) return TextPlaceholder.BODY;
+ if (ph == null) {
+ return TextPlaceholder.BODY;
+ }
switch (ph) {
case BODY: return TextPlaceholder.BODY;
case TITLE: return TextPlaceholder.TITLE;
* Helper method to allow subclasses to provide their own text paragraph
*
* @param p the xml reference
- *
+ *
* @return a new text paragraph
- *
+ *
* @since POI 3.15-beta2
*/
protected XSLFTextParagraph newTextParagraph(CTTextParagraph p) {