Support adding tabs to a XWPFRun, and add unit tests on toString() for addTab and addCarriageReturn
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1578921 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e9ea048c00
commit
af381473d0
@ -712,6 +712,18 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
br.setClear(STBrClear.Enum.forInt(clear.getValue()));
|
br.setClear(STBrClear.Enum.forInt(clear.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies that a tab shall be placed at the current location in
|
||||||
|
* the run content.
|
||||||
|
*/
|
||||||
|
public void addTab() {
|
||||||
|
run.addNewTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeTab() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies that a carriage return shall be placed at the
|
* Specifies that a carriage return shall be placed at the
|
||||||
* current location in the run content.
|
* current location in the run content.
|
||||||
@ -897,13 +909,13 @@ public class XWPFRun implements ISDTContents, IRunElement{
|
|||||||
// This bit works around it, and replicates the above
|
// This bit works around it, and replicates the above
|
||||||
// rules for that case
|
// rules for that case
|
||||||
String tagName = o.getDomNode().getNodeName();
|
String tagName = o.getDomNode().getNodeName();
|
||||||
if ("w:tab".equals(tagName)) {
|
if ("w:tab".equals(tagName) || "tab".equals(tagName)) {
|
||||||
text.append("\t");
|
text.append("\t");
|
||||||
}
|
}
|
||||||
if ("w:br".equals(tagName)) {
|
if ("w:br".equals(tagName) || "br".equals(tagName)) {
|
||||||
text.append("\n");
|
text.append("\n");
|
||||||
}
|
}
|
||||||
if ("w:cr".equals(tagName)) {
|
if ("w:cr".equals(tagName) || "cr".equals(tagName)) {
|
||||||
text.append("\n");
|
text.append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,29 @@ public class TestXWPFRun extends TestCase {
|
|||||||
run.setText("T2");
|
run.setText("T2");
|
||||||
run.addCarriageReturn();
|
run.addCarriageReturn();
|
||||||
assertEquals(3, run.getCTR().getCrList().size());
|
assertEquals(3, run.getCTR().getCrList().size());
|
||||||
|
|
||||||
|
assertEquals("T1\n\nT2\n", run.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAddTabsAndLineBreaks() {
|
||||||
|
ctRun.addNewT().setStringValue("TEST STRING");
|
||||||
|
ctRun.addNewCr();
|
||||||
|
ctRun.addNewT().setStringValue("TEST2 STRING");
|
||||||
|
ctRun.addNewTab();
|
||||||
|
ctRun.addNewT().setStringValue("TEST3 STRING");
|
||||||
|
assertEquals(1, ctRun.sizeOfCrArray());
|
||||||
|
assertEquals(1, ctRun.sizeOfTabArray());
|
||||||
|
|
||||||
|
XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), p);
|
||||||
|
run.setText("T1");
|
||||||
|
run.addCarriageReturn();
|
||||||
|
run.setText("T2");
|
||||||
|
run.addTab();
|
||||||
|
run.setText("T3");
|
||||||
|
assertEquals(1, run.getCTR().getCrList().size());
|
||||||
|
assertEquals(1, run.getCTR().getTabList().size());
|
||||||
|
|
||||||
|
assertEquals("T1\nT2\tT3", run.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddPageBreak() {
|
public void testAddPageBreak() {
|
||||||
|
Loading…
Reference in New Issue
Block a user