Fix up whitespace / indents to be consistent

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1563491 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-02-01 22:05:23 +00:00
parent 71b6ee9757
commit 40ceccdcbd
2 changed files with 383 additions and 386 deletions

View File

@ -32,68 +32,66 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
public class Paragraph extends Range implements Cloneable public class Paragraph extends Range implements Cloneable {
{
private static POILogger log = POILogFactory.getLogger( Paragraph.class ); private static POILogger log = POILogFactory.getLogger( Paragraph.class );
public final static short SPRM_JC = 0x2403; public final static short SPRM_JC = 0x2403;
public final static short SPRM_FSIDEBYSIDE = 0x2404; public final static short SPRM_FSIDEBYSIDE = 0x2404;
public final static short SPRM_FKEEP = 0x2405; public final static short SPRM_FKEEP = 0x2405;
public final static short SPRM_FKEEPFOLLOW = 0x2406; public final static short SPRM_FKEEPFOLLOW = 0x2406;
public final static short SPRM_FPAGEBREAKBEFORE = 0x2407; public final static short SPRM_FPAGEBREAKBEFORE = 0x2407;
public final static short SPRM_BRCL = 0x2408; public final static short SPRM_BRCL = 0x2408;
public final static short SPRM_BRCP = 0x2409; public final static short SPRM_BRCP = 0x2409;
public final static short SPRM_ILVL = 0x260A; public final static short SPRM_ILVL = 0x260A;
public final static short SPRM_ILFO = 0x460B; public final static short SPRM_ILFO = 0x460B;
public final static short SPRM_FNOLINENUMB = 0x240C; public final static short SPRM_FNOLINENUMB = 0x240C;
public final static short SPRM_CHGTABSPAPX = (short)0xC60D; public final static short SPRM_CHGTABSPAPX = (short)0xC60D;
public final static short SPRM_DXARIGHT = (short)0x840E; public final static short SPRM_DXARIGHT = (short)0x840E;
public final static short SPRM_DXALEFT = (short)0x840F; public final static short SPRM_DXALEFT = (short)0x840F;
public final static short SPRM_DXALEFT1 = (short)0x8411; public final static short SPRM_DXALEFT1 = (short)0x8411;
public final static short SPRM_DYALINE = 0x6412; public final static short SPRM_DYALINE = 0x6412;
public final static short SPRM_DYABEFORE = (short)0xA413; public final static short SPRM_DYABEFORE = (short)0xA413;
public final static short SPRM_DYAAFTER = (short)0xA414; public final static short SPRM_DYAAFTER = (short)0xA414;
public final static short SPRM_CHGTABS = (short)0xC615; public final static short SPRM_CHGTABS = (short)0xC615;
public final static short SPRM_FINTABLE = 0x2416; public final static short SPRM_FINTABLE = 0x2416;
public final static short SPRM_FTTP = 0x2417; public final static short SPRM_FTTP = 0x2417;
public final static short SPRM_DXAABS = (short)0x8418; public final static short SPRM_DXAABS = (short)0x8418;
public final static short SPRM_DYAABS = (short)0x8419; public final static short SPRM_DYAABS = (short)0x8419;
public final static short SPRM_DXAWIDTH = (short)0x841A; public final static short SPRM_DXAWIDTH = (short)0x841A;
public final static short SPRM_PC = 0x261B; public final static short SPRM_PC = 0x261B;
public final static short SPRM_WR = 0x2423; public final static short SPRM_WR = 0x2423;
public final static short SPRM_BRCTOP = 0x6424; public final static short SPRM_BRCTOP = 0x6424;
public final static short SPRM_BRCLEFT = 0x6425; public final static short SPRM_BRCLEFT = 0x6425;
public final static short SPRM_BRCBOTTOM = 0x6426; public final static short SPRM_BRCBOTTOM = 0x6426;
public final static short SPRM_BRCRIGHT = 0x6427; public final static short SPRM_BRCRIGHT = 0x6427;
public final static short SPRM_BRCBAR = 0x6629; public final static short SPRM_BRCBAR = 0x6629;
public final static short SPRM_FNOAUTOHYPH = 0x242A; public final static short SPRM_FNOAUTOHYPH = 0x242A;
public final static short SPRM_WHEIGHTABS = 0x442B; public final static short SPRM_WHEIGHTABS = 0x442B;
public final static short SPRM_DCS = 0x442C; public final static short SPRM_DCS = 0x442C;
public final static short SPRM_SHD80 = 0x442D; public final static short SPRM_SHD80 = 0x442D;
public final static short SPRM_SHD = (short)0xC64D; public final static short SPRM_SHD = (short)0xC64D;
public final static short SPRM_DYAFROMTEXT = (short)0x842E; public final static short SPRM_DYAFROMTEXT = (short)0x842E;
public final static short SPRM_DXAFROMTEXT = (short)0x842F; public final static short SPRM_DXAFROMTEXT = (short)0x842F;
public final static short SPRM_FLOCKED = 0x2430; public final static short SPRM_FLOCKED = 0x2430;
public final static short SPRM_FWIDOWCONTROL = 0x2431; public final static short SPRM_FWIDOWCONTROL = 0x2431;
public final static short SPRM_RULER = (short)0xC632; public final static short SPRM_RULER = (short)0xC632;
public final static short SPRM_FKINSOKU = 0x2433; public final static short SPRM_FKINSOKU = 0x2433;
public final static short SPRM_FWORDWRAP = 0x2434; public final static short SPRM_FWORDWRAP = 0x2434;
public final static short SPRM_FOVERFLOWPUNCT = 0x2435; public final static short SPRM_FOVERFLOWPUNCT = 0x2435;
public final static short SPRM_FTOPLINEPUNCT = 0x2436; public final static short SPRM_FTOPLINEPUNCT = 0x2436;
public final static short SPRM_AUTOSPACEDE = 0x2437; public final static short SPRM_AUTOSPACEDE = 0x2437;
public final static short SPRM_AUTOSPACEDN = 0x2438; public final static short SPRM_AUTOSPACEDN = 0x2438;
public final static short SPRM_WALIGNFONT = 0x4439; public final static short SPRM_WALIGNFONT = 0x4439;
public final static short SPRM_FRAMETEXTFLOW = 0x443A; public final static short SPRM_FRAMETEXTFLOW = 0x443A;
public final static short SPRM_ANLD = (short)0xC63E; public final static short SPRM_ANLD = (short)0xC63E;
public final static short SPRM_PROPRMARK = (short)0xC63F; public final static short SPRM_PROPRMARK = (short)0xC63F;
public final static short SPRM_OUTLVL = 0x2640; public final static short SPRM_OUTLVL = 0x2640;
public final static short SPRM_FBIDI = 0x2441; public final static short SPRM_FBIDI = 0x2441;
public final static short SPRM_FNUMRMLNS = 0x2443; public final static short SPRM_FNUMRMLNS = 0x2443;
public final static short SPRM_CRLF = 0x2444; public final static short SPRM_CRLF = 0x2444;
public final static short SPRM_NUMRM = (short)0xC645; public final static short SPRM_NUMRM = (short)0xC645;
public final static short SPRM_USEPGSUSETTINGS = 0x2447; public final static short SPRM_USEPGSUSETTINGS = 0x2447;
public final static short SPRM_FADJUSTRIGHT = 0x2448; public final static short SPRM_FADJUSTRIGHT = 0x2448;
@Internal @Internal
static Paragraph newParagraph( Range parent, PAPX papx ) static Paragraph newParagraph( Range parent, PAPX papx )
@ -616,46 +614,45 @@ public class Paragraph extends Range implements Cloneable
return getIlfo() != 0x000 && getIlfo() != 0xF801; return getIlfo() != 0x000 && getIlfo() != 0xF801;
} }
/** /**
* clone the ParagraphProperties object associated with this Paragraph so * Clone the ParagraphProperties object associated with this
* that you can apply the same properties to another paragraph. * Paragraph, so that you can apply the same properties to
* * another Paragraph.
*/ */
public ParagraphProperties cloneProperties() { public ParagraphProperties cloneProperties() {
try { try {
return (ParagraphProperties)_props.clone(); return (ParagraphProperties)_props.clone();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
}
} }
}
public Object clone() public Object clone() throws CloneNotSupportedException
throws CloneNotSupportedException {
{ Paragraph p = (Paragraph)super.clone();
Paragraph p = (Paragraph)super.clone(); p._props = (ParagraphProperties)_props.clone();
p._props = (ParagraphProperties)_props.clone(); //p._baseStyle = _baseStyle;
//p._baseStyle = _baseStyle; p._papx = new SprmBuffer(0);
p._papx = new SprmBuffer(0); return p;
return p; }
}
private short getFrameTextFlow() private short getFrameTextFlow()
{
short retVal = 0;
if (_props.isFVertical())
{ {
retVal |= 1; short retVal = 0;
if (_props.isFVertical())
{
retVal |= 1;
}
if (_props.isFBackward())
{
retVal |= 2;
}
if (_props.isFRotateFont())
{
retVal |= 4;
}
return retVal;
} }
if (_props.isFBackward())
{
retVal |= 2;
}
if (_props.isFRotateFont())
{
retVal |= 4;
}
return retVal;
}
@Override @Override
public String toString() public String toString()

View File

@ -32,84 +32,84 @@ import org.apache.poi.hwpf.model.StyleSheet;
* properties applied to them. * properties applied to them.
*/ */
public final class TestRangeProperties extends TestCase { public final class TestRangeProperties extends TestCase {
private static final char page_break = (char)12; private static final char page_break = (char)12;
private static final String u_page_1 = private static final String u_page_1 =
"This is a fairly simple word document, over two pages, with headers and footers.\r" + "This is a fairly simple word document, over two pages, with headers and footers.\r" +
"The trick with this one is that it contains some Unicode based strings in it.\r" + "The trick with this one is that it contains some Unicode based strings in it.\r" +
"Firstly, some currency symbols:\r" + "Firstly, some currency symbols:\r" +
"\tGBP - \u00a3\r" + "\tGBP - \u00a3\r" +
"\tEUR - \u20ac\r" + "\tEUR - \u20ac\r" +
"Now, we\u2019ll have some French text, in bold and big:\r" + "Now, we\u2019ll have some French text, in bold and big:\r" +
"\tMoli\u00e8re\r" + "\tMoli\u00e8re\r" +
"And some normal French text:\r" + "And some normal French text:\r" +
"\tL'Avare ou l'\u00c9cole du mensonge\r" + "\tL'Avare ou l'\u00c9cole du mensonge\r" +
"That\u2019s it for page one\r" "That\u2019s it for page one\r"
; ;
private static final String u_page_2 = private static final String u_page_2 =
"This is page two. Les Pr\u00e9cieuses ridicules. The end.\r" "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
; ;
private static final String a_page_1 = private static final String a_page_1 =
"I am a test document\r" + "I am a test document\r" +
"This is page 1\r" + "This is page 1\r" +
"I am Calibri (Body) in font size 11\r" "I am Calibri (Body) in font size 11\r"
; ;
private static final String a_page_2 = private static final String a_page_2 =
"This is page two\r" + "This is page two\r" +
"It\u2019s Arial Black in 16 point\r" + "It\u2019s Arial Black in 16 point\r" +
"It\u2019s also in blue\r" "It\u2019s also in blue\r"
; ;
private HWPFDocument u; private HWPFDocument u;
private HWPFDocument a; private HWPFDocument a;
protected void setUp() { protected void setUp() {
u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc"); u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc"); a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
} }
public void testAsciiTextParagraphs() { public void testAsciiTextParagraphs() {
Range r = a.getRange(); Range r = a.getRange();
assertEquals( assertEquals(
a_page_1 + a_page_1 +
page_break + "\r" + page_break + "\r" +
a_page_2, a_page_2,
r.text() r.text()
); );
assertEquals(1, r.numSections()); assertEquals(1, r.numSections());
assertEquals(1, a.getSectionTable().getSections().size()); assertEquals(1, a.getSectionTable().getSections().size());
Section s = r.getSection(0); Section s = r.getSection(0);
assertEquals( assertEquals(
a_page_1 + a_page_1 +
page_break + "\r" + page_break + "\r" +
a_page_2, a_page_2,
s.text() s.text()
); );
// no PAP reconstruction // no PAP reconstruction
// assertEquals( 7, r.numParagraphs() ); // assertEquals( 7, r.numParagraphs() );
// with PAP reconstructon // with PAP reconstructon
assertEquals( 8, r.numParagraphs() ); assertEquals( 8, r.numParagraphs() );
String[] p1_parts = a_page_1.split("\r"); String[] p1_parts = a_page_1.split("\r");
String[] p2_parts = a_page_2.split("\r"); String[] p2_parts = a_page_2.split("\r");
// Check paragraph contents // Check paragraph contents
assertEquals( assertEquals(
p1_parts[0] + "\r", p1_parts[0] + "\r",
r.getParagraph(0).text() r.getParagraph(0).text()
); );
assertEquals( assertEquals(
p1_parts[1] + "\r", p1_parts[1] + "\r",
r.getParagraph(1).text() r.getParagraph(1).text()
); );
assertEquals( assertEquals(
p1_parts[2] + "\r", p1_parts[2] + "\r",
r.getParagraph(2).text() r.getParagraph(2).text()
); );
// no PAPX reconstruction // no PAPX reconstruction
// assertEquals( page_break + "\r", r.getParagraph( 3 ).text() ); // assertEquals( page_break + "\r", r.getParagraph( 3 ).text() );
@ -125,168 +125,168 @@ public final class TestRangeProperties extends TestCase {
assertEquals( p2_parts[2] + "\r", r.getParagraph( 7 ).text() ); assertEquals( p2_parts[2] + "\r", r.getParagraph( 7 ).text() );
} }
public void testAsciiStyling() { public void testAsciiStyling() {
Range r = a.getRange(); Range r = a.getRange();
Paragraph p1 = r.getParagraph(0); Paragraph p1 = r.getParagraph(0);
Paragraph p7 = r.getParagraph(6); Paragraph p7 = r.getParagraph(6);
assertEquals(1, p1.numCharacterRuns()); assertEquals(1, p1.numCharacterRuns());
assertEquals(1, p7.numCharacterRuns()); assertEquals(1, p7.numCharacterRuns());
CharacterRun c1 = p1.getCharacterRun(0); CharacterRun c1 = p1.getCharacterRun(0);
CharacterRun c7 = p7.getCharacterRun(0); CharacterRun c7 = p7.getCharacterRun(0);
assertEquals("Times New Roman", c1.getFontName()); // No Calibri assertEquals("Times New Roman", c1.getFontName()); // No Calibri
assertEquals("Arial Black", c7.getFontName()); assertEquals("Arial Black", c7.getFontName());
assertEquals(22, c1.getFontSize()); assertEquals(22, c1.getFontSize());
assertEquals(32, c7.getFontSize()); assertEquals(32, c7.getFontSize());
// This document has 15 styles // This document has 15 styles
assertEquals(15, a.getStyleSheet().numStyles()); assertEquals(15, a.getStyleSheet().numStyles());
// Ensure none of the paragraphs refer to one that isn't there, // Ensure none of the paragraphs refer to one that isn't there,
// and none of their character runs either // and none of their character runs either
// Also check all use the default style // Also check all use the default style
StyleSheet ss = a.getStyleSheet(); StyleSheet ss = a.getStyleSheet();
for(int i=0; i<a.getRange().numParagraphs(); i++) { for(int i=0; i<a.getRange().numParagraphs(); i++) {
Paragraph p = a.getRange().getParagraph(i); Paragraph p = a.getRange().getParagraph(i);
int styleIndex = p.getStyleIndex(); int styleIndex = p.getStyleIndex();
assertTrue(styleIndex < 15); assertTrue(styleIndex < 15);
assertEquals("Normal", ss.getStyleDescription(styleIndex).getName()); assertEquals("Normal", ss.getStyleDescription(styleIndex).getName());
} }
for(int i=0; i<a.getRange().numCharacterRuns(); i++) { for(int i=0; i<a.getRange().numCharacterRuns(); i++) {
CharacterRun c = a.getRange().getCharacterRun(i); CharacterRun c = a.getRange().getCharacterRun(i);
int styleIndex = c.getStyleIndex(); int styleIndex = c.getStyleIndex();
assertTrue(styleIndex < 15); assertTrue(styleIndex < 15);
assertEquals("Normal", ss.getStyleDescription(styleIndex).getName()); assertEquals("Normal", ss.getStyleDescription(styleIndex).getName());
} }
} }
/** /**
* Tests the raw definitions of the paragraphs of * Tests the raw definitions of the paragraphs of
* a unicode document * a unicode document
*/ */
public void testUnicodeParagraphDefinitions() { public void testUnicodeParagraphDefinitions() {
Range r = u.getRange(); Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r"); String[] p1_parts = u_page_1.split("\r");
String[] p2_parts = u_page_2.split("\r"); String[] p2_parts = u_page_2.split("\r");
assertEquals( assertEquals(
u_page_1 + page_break + "\r" + u_page_2, u_page_1 + page_break + "\r" + u_page_2,
r.text() r.text()
); );
assertEquals( assertEquals(
408, r.text().length() 408, r.text().length()
); );
assertEquals(1, r.numSections()); assertEquals(1, r.numSections());
assertEquals(1, u.getSectionTable().getSections().size()); assertEquals(1, u.getSectionTable().getSections().size());
Section s = r.getSection(0); Section s = r.getSection(0);
assertEquals( assertEquals(
u_page_1 + u_page_1 +
page_break + "\r" + page_break + "\r" +
u_page_2, u_page_2,
s.text() s.text()
); );
assertEquals(0, s.getStartOffset()); assertEquals(0, s.getStartOffset());
assertEquals(408, s.getEndOffset()); assertEquals(408, s.getEndOffset());
List<PAPX> pDefs = r._paragraphs; List<PAPX> pDefs = r._paragraphs;
// no PAPX reconstruction // no PAPX reconstruction
// assertEquals(36, pDefs.size()); // assertEquals(36, pDefs.size());
// with PAPX reconstruction // with PAPX reconstruction
assertEquals( 36, pDefs.size() ); assertEquals( 36, pDefs.size() );
// Check that the last paragraph ends where it should do // Check that the last paragraph ends where it should do
assertEquals(531, u.getOverallRange().text().length()); assertEquals(531, u.getOverallRange().text().length());
PAPX pLast = pDefs.get(34); PAPX pLast = pDefs.get(34);
// assertEquals(530, pLast.getEnd()); // assertEquals(530, pLast.getEnd());
// Only care about the first few really though // Only care about the first few really though
PAPX p0 = pDefs.get(0); PAPX p0 = pDefs.get(0);
PAPX p1 = pDefs.get(1); PAPX p1 = pDefs.get(1);
PAPX p2 = pDefs.get(2); PAPX p2 = pDefs.get(2);
PAPX p3 = pDefs.get(3); PAPX p3 = pDefs.get(3);
PAPX p4 = pDefs.get(4); PAPX p4 = pDefs.get(4);
// 5 paragraphs should get us to the end of our text // 5 paragraphs should get us to the end of our text
assertTrue(p0.getStart() < 408); assertTrue(p0.getStart() < 408);
assertTrue(p0.getEnd() < 408); assertTrue(p0.getEnd() < 408);
assertTrue(p1.getStart() < 408); assertTrue(p1.getStart() < 408);
assertTrue(p1.getEnd() < 408); assertTrue(p1.getEnd() < 408);
assertTrue(p2.getStart() < 408); assertTrue(p2.getStart() < 408);
assertTrue(p2.getEnd() < 408); assertTrue(p2.getEnd() < 408);
assertTrue(p3.getStart() < 408); assertTrue(p3.getStart() < 408);
assertTrue(p3.getEnd() < 408); assertTrue(p3.getEnd() < 408);
assertTrue(p4.getStart() < 408); assertTrue(p4.getStart() < 408);
assertTrue(p4.getEnd() < 408); assertTrue(p4.getEnd() < 408);
// Paragraphs should match with lines // Paragraphs should match with lines
assertEquals( assertEquals(
0, 0,
p0.getStart() p0.getStart()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1, p1_parts[0].length() + 1,
p0.getEnd() p0.getEnd()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1, p1_parts[0].length() + 1,
p1.getStart() p1.getStart()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1, p1_parts[1].length() + 1,
p1.getEnd() p1.getEnd()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1, p1_parts[1].length() + 1,
p2.getStart() p2.getStart()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1 + p1_parts[1].length() + 1 +
p1_parts[2].length() + 1, p1_parts[2].length() + 1,
p2.getEnd() p2.getEnd()
); );
} }
/** /**
* Tests the paragraph text of a unicode document * Tests the paragraph text of a unicode document
*/ */
public void testUnicodeTextParagraphs() { public void testUnicodeTextParagraphs() {
Range r = u.getRange(); Range r = u.getRange();
assertEquals( assertEquals(
u_page_1 + u_page_1 +
page_break + "\r" + page_break + "\r" +
u_page_2, u_page_2,
r.text() r.text()
); );
// without PAPX reconstruction // without PAPX reconstruction
// assertEquals( 12, r.numParagraphs() ); // assertEquals( 12, r.numParagraphs() );
// with PAPX reconstruction // with PAPX reconstruction
assertEquals( 13, r.numParagraphs() ); assertEquals( 13, r.numParagraphs() );
String[] p1_parts = u_page_1.split("\r"); String[] p1_parts = u_page_1.split("\r");
String[] p2_parts = u_page_2.split("\r"); String[] p2_parts = u_page_2.split("\r");
// Check text all matches up properly // Check text all matches up properly
assertEquals(p1_parts[0] + "\r", r.getParagraph(0).text()); assertEquals(p1_parts[0] + "\r", r.getParagraph(0).text());
assertEquals(p1_parts[1] + "\r", r.getParagraph(1).text()); assertEquals(p1_parts[1] + "\r", r.getParagraph(1).text());
assertEquals(p1_parts[2] + "\r", r.getParagraph(2).text()); assertEquals(p1_parts[2] + "\r", r.getParagraph(2).text());
assertEquals(p1_parts[3] + "\r", r.getParagraph(3).text()); assertEquals(p1_parts[3] + "\r", r.getParagraph(3).text());
assertEquals(p1_parts[4] + "\r", r.getParagraph(4).text()); assertEquals(p1_parts[4] + "\r", r.getParagraph(4).text());
assertEquals(p1_parts[5] + "\r", r.getParagraph(5).text()); assertEquals(p1_parts[5] + "\r", r.getParagraph(5).text());
assertEquals(p1_parts[6] + "\r", r.getParagraph(6).text()); assertEquals(p1_parts[6] + "\r", r.getParagraph(6).text());
assertEquals(p1_parts[7] + "\r", r.getParagraph(7).text()); assertEquals(p1_parts[7] + "\r", r.getParagraph(7).text());
assertEquals(p1_parts[8] + "\r", r.getParagraph(8).text()); assertEquals(p1_parts[8] + "\r", r.getParagraph(8).text());
assertEquals(p1_parts[9] + "\r", r.getParagraph(9).text()); assertEquals(p1_parts[9] + "\r", r.getParagraph(9).text());
// without PAPX reconstruction // without PAPX reconstruction
// assertEquals(page_break + "\r", r.getParagraph(10).text()); // assertEquals(page_break + "\r", r.getParagraph(10).text());
// assertEquals(p2_parts[0] + "\r", r.getParagraph(11).text()); // assertEquals(p2_parts[0] + "\r", r.getParagraph(11).text());
@ -294,118 +294,118 @@ public final class TestRangeProperties extends TestCase {
assertEquals( page_break + "", r.getParagraph( 10 ).text() ); assertEquals( page_break + "", r.getParagraph( 10 ).text() );
assertEquals( "\r", r.getParagraph( 11 ).text() ); assertEquals( "\r", r.getParagraph( 11 ).text() );
assertEquals( p2_parts[0] + "\r", r.getParagraph( 12 ).text() ); assertEquals( p2_parts[0] + "\r", r.getParagraph( 12 ).text() );
} }
public void testUnicodeStyling() { public void testUnicodeStyling() {
Range r = u.getRange(); Range r = u.getRange();
String[] p1_parts = u_page_1.split("\r"); String[] p1_parts = u_page_1.split("\r");
Paragraph p1 = r.getParagraph(0); Paragraph p1 = r.getParagraph(0);
Paragraph p7 = r.getParagraph(6); Paragraph p7 = r.getParagraph(6);
StyleSheet ss = r._doc.getStyleSheet(); StyleSheet ss = r._doc.getStyleSheet();
// Line ending in its own run each time! // Line ending in its own run each time!
assertEquals(2, p1.numCharacterRuns()); assertEquals(2, p1.numCharacterRuns());
assertEquals(2, p7.numCharacterRuns()); assertEquals(2, p7.numCharacterRuns());
CharacterRun c1a = p1.getCharacterRun(0); CharacterRun c1a = p1.getCharacterRun(0);
CharacterRun c1b = p1.getCharacterRun(1); CharacterRun c1b = p1.getCharacterRun(1);
CharacterRun c7a = p7.getCharacterRun(0); CharacterRun c7a = p7.getCharacterRun(0);
CharacterRun c7b = p7.getCharacterRun(1); CharacterRun c7b = p7.getCharacterRun(1);
assertEquals("Times New Roman", c1a.getFontName()); // No Calibri assertEquals("Times New Roman", c1a.getFontName()); // No Calibri
assertEquals(22, c1a.getFontSize()); assertEquals(22, c1a.getFontSize());
assertEquals("Times New Roman", c1b.getFontName()); // No Calibri assertEquals("Times New Roman", c1b.getFontName()); // No Calibri
assertEquals(22, c1b.getFontSize()); assertEquals(22, c1b.getFontSize());
assertEquals("Times New Roman", c7a.getFontName()); assertEquals("Times New Roman", c7a.getFontName());
assertEquals(48, c7a.getFontSize()); assertEquals(48, c7a.getFontSize());
assertEquals("Times New Roman", c7b.getFontName()); assertEquals("Times New Roman", c7b.getFontName());
assertEquals(48, c7b.getFontSize()); assertEquals(48, c7b.getFontSize());
// All use the default base style // All use the default base style
assertEquals("Normal", ss.getStyleDescription(c1a.getStyleIndex()).getName()); assertEquals("Normal", ss.getStyleDescription(c1a.getStyleIndex()).getName());
assertEquals("Normal", ss.getStyleDescription(c1b.getStyleIndex()).getName()); assertEquals("Normal", ss.getStyleDescription(c1b.getStyleIndex()).getName());
assertEquals("Heading 1", ss.getStyleDescription(c7a.getStyleIndex()).getName()); assertEquals("Heading 1", ss.getStyleDescription(c7a.getStyleIndex()).getName());
assertEquals("Heading 1", ss.getStyleDescription(c7b.getStyleIndex()).getName()); assertEquals("Heading 1", ss.getStyleDescription(c7b.getStyleIndex()).getName());
// Now check where they crop up // Now check where they crop up
assertEquals( assertEquals(
0, 0,
c1a.getStartOffset() c1a.getStartOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length(), p1_parts[0].length(),
c1a.getEndOffset() c1a.getEndOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length(), p1_parts[0].length(),
c1b.getStartOffset() c1b.getStartOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length()+1, p1_parts[0].length()+1,
c1b.getEndOffset() c1b.getEndOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1 + p1_parts[1].length() + 1 +
p1_parts[2].length() + 1 + p1_parts[2].length() + 1 +
p1_parts[3].length() + 1 + p1_parts[3].length() + 1 +
p1_parts[4].length() + 1 + p1_parts[4].length() + 1 +
p1_parts[5].length() + 1, p1_parts[5].length() + 1,
c7a.getStartOffset() c7a.getStartOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1 + p1_parts[1].length() + 1 +
p1_parts[2].length() + 1 + p1_parts[2].length() + 1 +
p1_parts[3].length() + 1 + p1_parts[3].length() + 1 +
p1_parts[4].length() + 1 + p1_parts[4].length() + 1 +
p1_parts[5].length() + 1 + p1_parts[5].length() + 1 +
1, 1,
c7a.getEndOffset() c7a.getEndOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1 + p1_parts[1].length() + 1 +
p1_parts[2].length() + 1 + p1_parts[2].length() + 1 +
p1_parts[3].length() + 1 + p1_parts[3].length() + 1 +
p1_parts[4].length() + 1 + p1_parts[4].length() + 1 +
p1_parts[5].length() + 1 + p1_parts[5].length() + 1 +
1, 1,
c7b.getStartOffset() c7b.getStartOffset()
); );
assertEquals( assertEquals(
p1_parts[0].length() + 1 + p1_parts[0].length() + 1 +
p1_parts[1].length() + 1 + p1_parts[1].length() + 1 +
p1_parts[2].length() + 1 + p1_parts[2].length() + 1 +
p1_parts[3].length() + 1 + p1_parts[3].length() + 1 +
p1_parts[4].length() + 1 + p1_parts[4].length() + 1 +
p1_parts[5].length() + 1 + p1_parts[5].length() + 1 +
p1_parts[6].length() + 1, p1_parts[6].length() + 1,
c7b.getEndOffset() c7b.getEndOffset()
); );
// This document also has 22 styles // This document also has 22 styles
assertEquals(22, ss.numStyles()); assertEquals(22, ss.numStyles());
// Ensure none of the paragraphs refer to one that isn't there, // Ensure none of the paragraphs refer to one that isn't there,
// and none of their character runs either // and none of their character runs either
for(int i=0; i<r.numParagraphs(); i++) { for(int i=0; i<r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i); Paragraph p = r.getParagraph(i);
int styleIndex = p.getStyleIndex(); int styleIndex = p.getStyleIndex();
assertTrue(styleIndex < 22); assertTrue(styleIndex < 22);
assertNotNull(ss.getStyleDescription(styleIndex).getName()); assertNotNull(ss.getStyleDescription(styleIndex).getName());
} }
for(int i=0; i<r.numCharacterRuns(); i++) { for(int i=0; i<r.numCharacterRuns(); i++) {
CharacterRun c = r.getCharacterRun(i); CharacterRun c = r.getCharacterRun(i);
int styleIndex = c.getStyleIndex(); int styleIndex = c.getStyleIndex();
assertTrue(styleIndex < 22); assertTrue(styleIndex < 22);
assertNotNull(ss.getStyleDescription(styleIndex).getName()); assertNotNull(ss.getStyleDescription(styleIndex).getName());
} }
} }
} }