Example usage for org.apache.poi.xwpf.usermodel LineSpacingRule AUTO

List of usage examples for org.apache.poi.xwpf.usermodel LineSpacingRule AUTO

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel LineSpacingRule AUTO.

Prototype

LineSpacingRule AUTO

To view the source code for org.apache.poi.xwpf.usermodel LineSpacingRule AUTO.

Click Source Link

Document

Specifies that the line spacing of the parent object shall be automatically determined by the size of its contents, with no predetermined minimum or maximum size.

Usage

From source file:apachepoitest.XWPFParagraphClone.java

License:Apache License

/**
 * Specifies how the spacing between lines is calculated as stored in the
 * line attribute. If this attribute is omitted, then it shall be assumed to
 * be of a value auto if a line attribute value is present.
 *
 * @return rule/* w ww.j  a  v a2  s.  c om*/
 * @see LineSpacingRule
 * @see #setSpacingLineRule(LineSpacingRule)
 */
public LineSpacingRule getSpacingLineRule() {
    CTSpacing spacing = getCTSpacing(false);
    return (spacing != null && spacing.isSetLineRule())
            ? LineSpacingRule.valueOf(spacing.getLineRule().intValue())
            : LineSpacingRule.AUTO;
}

From source file:org.articleEditor.insertContent.POIDocxReader.java

License:Apache License

protected void processParagraph(XWPFParagraph paragraph) throws BadLocationException {
    parAttrs = new SimpleAttributeSet();
    ParagraphAlignment alignment = paragraph.getAlignment();
    if (alignment == ParagraphAlignment.CENTER) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_CENTER);
    } else if (alignment == ParagraphAlignment.LEFT) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_LEFT);
    } else if (alignment == ParagraphAlignment.RIGHT) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_RIGHT);
    } else if (alignment == ParagraphAlignment.BOTH || alignment == ParagraphAlignment.DISTRIBUTE) {
        StyleConstants.setAlignment(parAttrs, StyleConstants.ALIGN_JUSTIFIED);
    }// w w w  .  j ava 2  s  .  co  m
    List<TabStop> tabs = new ArrayList<>();
    int leftIndentation = paragraph.getIndentationLeft();
    if (leftIndentation > 0) {
        float indentation = leftIndentation / INDENTS_MULTIPLIER;
        StyleConstants.setLeftIndent(parAttrs, indentation);
        /*TabStop stop = new TabStop(pos, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
         tabs.add(stop);*/
    }
    int rightIndentation = paragraph.getIndentationRight();
    if (rightIndentation > 0) {
        float indentation = rightIndentation / INDENTS_MULTIPLIER;
        StyleConstants.setLeftIndent(parAttrs, indentation);
        /*TabStop stop = new TabStop(pos, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
         tabs.add(stop);*/
    }
    /*TabSet tabSet = new TabSet(tabs.toArray(new TabStop[tabs.size()]));
     StyleConstants.setTabSet(parAttrs, tabSet);*/
    int firstLineIndentation = paragraph.getIndentationFirstLine();
    if (firstLineIndentation > 0) {
        float indentation = firstLineIndentation / INDENTS_MULTIPLIER;
        StyleConstants.setFirstLineIndent(parAttrs, indentation);
        /*TabStop stop = new TabStop(pos, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
         tabs.add(stop);*/
    }

    int spacingBefore = paragraph.getSpacingBefore();
    if (spacingBefore > 0) {
        int before = spacingBefore / INDENTS_MULTIPLIER;
        StyleConstants.setSpaceAbove(parAttrs, before);
    }
    int spacingAfter = paragraph.getSpacingAfter();
    if (spacingAfter > 0) {
        int after = spacingAfter / INDENTS_MULTIPLIER;
        StyleConstants.setSpaceAbove(parAttrs, after);
    }
    LineSpacingRule spacingLine = paragraph.getSpacingLineRule();
    if (spacingLine == LineSpacingRule.AT_LEAST || spacingLine == LineSpacingRule.AUTO) {
        float spacing = spacingLine.getValue() / 240;
        StyleConstants.setLineSpacing(parAttrs, spacing);
    }
    document.setParagraphAttributes(currentOffset, 1, parAttrs, true);
    for (XWPFRun run : paragraph.getRuns()) {
        processRun(run);
    }
}