Search in sources :

Example 1 with CTSpacing

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing in project poi by apache.

the class TestXWPFParagraph method testSetGetSpacing.

@Test
public void testSetGetSpacing() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    assertEquals(-1, p.getSpacingBefore());
    assertEquals(-1, p.getSpacingAfter());
    assertEquals(-1, p.getSpacingBetween(), 0.1);
    assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
    CTSpacing spacing = ppr.addNewSpacing();
    spacing.setAfter(new BigInteger("10"));
    assertEquals(10, p.getSpacingAfter());
    spacing.setBefore(new BigInteger("10"));
    assertEquals(10, p.getSpacingBefore());
    p.setSpacingAfter(100);
    assertEquals(100, spacing.getAfter().intValue());
    p.setSpacingBefore(100);
    assertEquals(100, spacing.getBefore().intValue());
    p.setSpacingBetween(.25, LineSpacingRule.EXACT);
    assertEquals(.25, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.EXACT, p.getSpacingLineRule());
    p.setSpacingBetween(1.25, LineSpacingRule.AUTO);
    assertEquals(1.25, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
    p.setSpacingBetween(.5, LineSpacingRule.AT_LEAST);
    assertEquals(.5, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
    p.setSpacingBetween(1.15);
    assertEquals(1.15, p.getSpacingBetween(), 0.01);
    assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTSpacing(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing) BigInteger(java.math.BigInteger) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Example 2 with CTSpacing

use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing in project poi by apache.

the class TestXWPFParagraph method testSetGetSpacingLineRule.

@Test
public void testSetGetSpacingLineRule() throws IOException {
    XWPFDocument doc = new XWPFDocument();
    XWPFParagraph p = doc.createParagraph();
    CTP ctp = p.getCTP();
    CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
    assertEquals(STLineSpacingRule.INT_AUTO, p.getSpacingLineRule().getValue());
    CTSpacing spacing = ppr.addNewSpacing();
    spacing.setLineRule(STLineSpacingRule.AT_LEAST);
    assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
    p.setSpacingAfter(100);
    assertEquals(100, spacing.getAfter().intValue());
    doc.close();
}
Also used : CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTSpacing(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)2 CTPPr (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr)2 CTSpacing (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing)2 BigInteger (java.math.BigInteger)1