use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP 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();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.
the class TestXWPFParagraph method testSetGetPageBreak.
@Test
public void testSetGetPageBreak() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
CTP ctp = p.getCTP();
CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
CTOnOff pageBreak = ppr.addNewPageBreakBefore();
pageBreak.setVal(STOnOff.FALSE);
assertEquals(false, p.isPageBreak());
p.setPageBreak(true);
assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
doc.close();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.
the class TestXWPFParagraph method testSetGetIndentation.
@Test
public void testSetGetIndentation() throws IOException {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
assertEquals(-1, p.getIndentationLeft());
CTP ctp = p.getCTP();
CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
assertEquals(-1, p.getIndentationLeft());
CTInd ind = ppr.addNewInd();
ind.setLeft(new BigInteger("10"));
assertEquals(10, p.getIndentationLeft());
p.setIndentationLeft(100);
assertEquals(100, ind.getLeft().intValue());
doc.close();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.
the class XWPFHeaderFooter method insertNewParagraph.
/**
* add a new paragraph at position of the cursor
*
* @param cursor
* @return the inserted paragraph
*/
public XWPFParagraph insertNewParagraph(XmlCursor cursor) {
if (isCursorInHdrF(cursor)) {
String uri = CTP.type.getName().getNamespaceURI();
String localPart = "p";
cursor.beginElement(localPart, uri);
cursor.toParent();
CTP p = (CTP) cursor.getObject();
XWPFParagraph newP = new XWPFParagraph(p, this);
XmlObject o = null;
while (!(o instanceof CTP) && (cursor.toPrevSibling())) {
o = cursor.getObject();
}
if ((!(o instanceof CTP)) || (CTP) o == p) {
paragraphs.add(0, newP);
} else {
int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1;
paragraphs.add(pos, newP);
}
int i = 0;
XmlCursor p2 = p.newCursor();
cursor.toCursor(p2);
p2.dispose();
while (cursor.toPrevSibling()) {
o = cursor.getObject();
if (o instanceof CTP || o instanceof CTTbl)
i++;
}
bodyElements.add(i, newP);
p2 = p.newCursor();
cursor.toCursor(p2);
cursor.toEndToken();
p2.dispose();
return newP;
}
return null;
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP in project poi by apache.
the class XWPFHeaderFooter method insertNewTbl.
/**
* @param cursor
* @return the inserted table
*/
public XWPFTable insertNewTbl(final XmlCursor cursor) {
if (isCursorInHdrF(cursor)) {
String uri = CTTbl.type.getName().getNamespaceURI();
String localPart = "tbl";
cursor.beginElement(localPart, uri);
cursor.toParent();
CTTbl t = (CTTbl) cursor.getObject();
XWPFTable newT = new XWPFTable(t, this);
cursor.removeXmlContents();
XmlObject o = null;
while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
o = cursor.getObject();
}
if (!(o instanceof CTTbl)) {
tables.add(0, newT);
} else {
int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
tables.add(pos, newT);
}
int i = 0;
XmlCursor cursor2 = t.newCursor();
while (cursor2.toPrevSibling()) {
o = cursor2.getObject();
if (o instanceof CTP || o instanceof CTTbl) {
i++;
}
}
cursor2.dispose();
bodyElements.add(i, newT);
cursor2 = t.newCursor();
cursor.toCursor(cursor2);
cursor.toEndToken();
cursor2.dispose();
return newT;
}
return null;
}
Aggregations