aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-02-01 22:05:23 +0000
committerNick Burch <nick@apache.org>2014-02-01 22:05:23 +0000
commit40ceccdcbd5f9b03537e3e78c9090082f010c79e (patch)
tree73931c5eb83254f6c637b06e8146e2cc009d038f /src
parent71b6ee97573daf40b58422b521482bdce9fdde32 (diff)
downloadpoi-40ceccdcbd5f9b03537e3e78c9090082f010c79e.tar.gz
poi-40ceccdcbd5f9b03537e3e78c9090082f010c79e.zip
Fix up whitespace / indents to be consistent
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1563491 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java185
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java630
2 files changed, 406 insertions, 409 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java
index d292396d15..367c3ade7d 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java
@@ -32,68 +32,66 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
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 );
- public final static short SPRM_JC = 0x2403;
- public final static short SPRM_FSIDEBYSIDE = 0x2404;
- public final static short SPRM_FKEEP = 0x2405;
- public final static short SPRM_FKEEPFOLLOW = 0x2406;
- public final static short SPRM_FPAGEBREAKBEFORE = 0x2407;
- public final static short SPRM_BRCL = 0x2408;
- public final static short SPRM_BRCP = 0x2409;
- public final static short SPRM_ILVL = 0x260A;
- public final static short SPRM_ILFO = 0x460B;
- public final static short SPRM_FNOLINENUMB = 0x240C;
- public final static short SPRM_CHGTABSPAPX = (short)0xC60D;
- public final static short SPRM_DXARIGHT = (short)0x840E;
- public final static short SPRM_DXALEFT = (short)0x840F;
- public final static short SPRM_DXALEFT1 = (short)0x8411;
- public final static short SPRM_DYALINE = 0x6412;
- public final static short SPRM_DYABEFORE = (short)0xA413;
- public final static short SPRM_DYAAFTER = (short)0xA414;
- public final static short SPRM_CHGTABS = (short)0xC615;
- public final static short SPRM_FINTABLE = 0x2416;
- public final static short SPRM_FTTP = 0x2417;
- public final static short SPRM_DXAABS = (short)0x8418;
- public final static short SPRM_DYAABS = (short)0x8419;
- public final static short SPRM_DXAWIDTH = (short)0x841A;
- public final static short SPRM_PC = 0x261B;
- public final static short SPRM_WR = 0x2423;
- public final static short SPRM_BRCTOP = 0x6424;
- public final static short SPRM_BRCLEFT = 0x6425;
- public final static short SPRM_BRCBOTTOM = 0x6426;
- public final static short SPRM_BRCRIGHT = 0x6427;
- public final static short SPRM_BRCBAR = 0x6629;
- public final static short SPRM_FNOAUTOHYPH = 0x242A;
- public final static short SPRM_WHEIGHTABS = 0x442B;
- public final static short SPRM_DCS = 0x442C;
- public final static short SPRM_SHD80 = 0x442D;
- public final static short SPRM_SHD = (short)0xC64D;
- public final static short SPRM_DYAFROMTEXT = (short)0x842E;
- public final static short SPRM_DXAFROMTEXT = (short)0x842F;
- public final static short SPRM_FLOCKED = 0x2430;
- public final static short SPRM_FWIDOWCONTROL = 0x2431;
- public final static short SPRM_RULER = (short)0xC632;
- public final static short SPRM_FKINSOKU = 0x2433;
- public final static short SPRM_FWORDWRAP = 0x2434;
- public final static short SPRM_FOVERFLOWPUNCT = 0x2435;
- public final static short SPRM_FTOPLINEPUNCT = 0x2436;
- public final static short SPRM_AUTOSPACEDE = 0x2437;
- public final static short SPRM_AUTOSPACEDN = 0x2438;
- public final static short SPRM_WALIGNFONT = 0x4439;
- public final static short SPRM_FRAMETEXTFLOW = 0x443A;
- public final static short SPRM_ANLD = (short)0xC63E;
- public final static short SPRM_PROPRMARK = (short)0xC63F;
- public final static short SPRM_OUTLVL = 0x2640;
- public final static short SPRM_FBIDI = 0x2441;
- public final static short SPRM_FNUMRMLNS = 0x2443;
- public final static short SPRM_CRLF = 0x2444;
- public final static short SPRM_NUMRM = (short)0xC645;
- public final static short SPRM_USEPGSUSETTINGS = 0x2447;
- public final static short SPRM_FADJUSTRIGHT = 0x2448;
+ public final static short SPRM_JC = 0x2403;
+ public final static short SPRM_FSIDEBYSIDE = 0x2404;
+ public final static short SPRM_FKEEP = 0x2405;
+ public final static short SPRM_FKEEPFOLLOW = 0x2406;
+ public final static short SPRM_FPAGEBREAKBEFORE = 0x2407;
+ public final static short SPRM_BRCL = 0x2408;
+ public final static short SPRM_BRCP = 0x2409;
+ public final static short SPRM_ILVL = 0x260A;
+ public final static short SPRM_ILFO = 0x460B;
+ public final static short SPRM_FNOLINENUMB = 0x240C;
+ public final static short SPRM_CHGTABSPAPX = (short)0xC60D;
+ public final static short SPRM_DXARIGHT = (short)0x840E;
+ public final static short SPRM_DXALEFT = (short)0x840F;
+ public final static short SPRM_DXALEFT1 = (short)0x8411;
+ public final static short SPRM_DYALINE = 0x6412;
+ public final static short SPRM_DYABEFORE = (short)0xA413;
+ public final static short SPRM_DYAAFTER = (short)0xA414;
+ public final static short SPRM_CHGTABS = (short)0xC615;
+ public final static short SPRM_FINTABLE = 0x2416;
+ public final static short SPRM_FTTP = 0x2417;
+ public final static short SPRM_DXAABS = (short)0x8418;
+ public final static short SPRM_DYAABS = (short)0x8419;
+ public final static short SPRM_DXAWIDTH = (short)0x841A;
+ public final static short SPRM_PC = 0x261B;
+ public final static short SPRM_WR = 0x2423;
+ public final static short SPRM_BRCTOP = 0x6424;
+ public final static short SPRM_BRCLEFT = 0x6425;
+ public final static short SPRM_BRCBOTTOM = 0x6426;
+ public final static short SPRM_BRCRIGHT = 0x6427;
+ public final static short SPRM_BRCBAR = 0x6629;
+ public final static short SPRM_FNOAUTOHYPH = 0x242A;
+ public final static short SPRM_WHEIGHTABS = 0x442B;
+ public final static short SPRM_DCS = 0x442C;
+ public final static short SPRM_SHD80 = 0x442D;
+ public final static short SPRM_SHD = (short)0xC64D;
+ public final static short SPRM_DYAFROMTEXT = (short)0x842E;
+ public final static short SPRM_DXAFROMTEXT = (short)0x842F;
+ public final static short SPRM_FLOCKED = 0x2430;
+ public final static short SPRM_FWIDOWCONTROL = 0x2431;
+ public final static short SPRM_RULER = (short)0xC632;
+ public final static short SPRM_FKINSOKU = 0x2433;
+ public final static short SPRM_FWORDWRAP = 0x2434;
+ public final static short SPRM_FOVERFLOWPUNCT = 0x2435;
+ public final static short SPRM_FTOPLINEPUNCT = 0x2436;
+ public final static short SPRM_AUTOSPACEDE = 0x2437;
+ public final static short SPRM_AUTOSPACEDN = 0x2438;
+ public final static short SPRM_WALIGNFONT = 0x4439;
+ public final static short SPRM_FRAMETEXTFLOW = 0x443A;
+ public final static short SPRM_ANLD = (short)0xC63E;
+ public final static short SPRM_PROPRMARK = (short)0xC63F;
+ public final static short SPRM_OUTLVL = 0x2640;
+ public final static short SPRM_FBIDI = 0x2441;
+ public final static short SPRM_FNUMRMLNS = 0x2443;
+ public final static short SPRM_CRLF = 0x2444;
+ public final static short SPRM_NUMRM = (short)0xC645;
+ public final static short SPRM_USEPGSUSETTINGS = 0x2447;
+ public final static short SPRM_FADJUSTRIGHT = 0x2448;
@Internal
static Paragraph newParagraph( Range parent, PAPX papx )
@@ -616,46 +614,45 @@ public class Paragraph extends Range implements Cloneable
return getIlfo() != 0x000 && getIlfo() != 0xF801;
}
- /**
- * clone the ParagraphProperties object associated with this Paragraph so
- * that you can apply the same properties to another paragraph.
- *
- */
- public ParagraphProperties cloneProperties() {
- try {
- return (ParagraphProperties)_props.clone();
- } catch (Exception e) {
- throw new RuntimeException(e);
+ /**
+ * Clone the ParagraphProperties object associated with this
+ * Paragraph, so that you can apply the same properties to
+ * another Paragraph.
+ */
+ public ParagraphProperties cloneProperties() {
+ try {
+ return (ParagraphProperties)_props.clone();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- }
- public Object clone()
- throws CloneNotSupportedException
- {
- Paragraph p = (Paragraph)super.clone();
- p._props = (ParagraphProperties)_props.clone();
- //p._baseStyle = _baseStyle;
- p._papx = new SprmBuffer(0);
- return p;
- }
-
- private short getFrameTextFlow()
- {
- short retVal = 0;
- if (_props.isFVertical())
+ public Object clone() throws CloneNotSupportedException
{
- retVal |= 1;
+ Paragraph p = (Paragraph)super.clone();
+ p._props = (ParagraphProperties)_props.clone();
+ //p._baseStyle = _baseStyle;
+ p._papx = new SprmBuffer(0);
+ return p;
}
- if (_props.isFBackward())
- {
- retVal |= 2;
- }
- if (_props.isFRotateFont())
+
+ private short getFrameTextFlow()
{
- retVal |= 4;
+ short retVal = 0;
+ if (_props.isFVertical())
+ {
+ retVal |= 1;
+ }
+ if (_props.isFBackward())
+ {
+ retVal |= 2;
+ }
+ if (_props.isFRotateFont())
+ {
+ retVal |= 4;
+ }
+ return retVal;
}
- return retVal;
- }
@Override
public String toString()
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
index e1dfd0386e..e0db917ec6 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
@@ -32,84 +32,84 @@ import org.apache.poi.hwpf.model.StyleSheet;
* properties applied to them.
*/
public final class TestRangeProperties extends TestCase {
- private static final char page_break = (char)12;
-
- private static final String u_page_1 =
- "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" +
- "Firstly, some currency symbols:\r" +
- "\tGBP - \u00a3\r" +
- "\tEUR - \u20ac\r" +
- "Now, we\u2019ll have some French text, in bold and big:\r" +
- "\tMoli\u00e8re\r" +
- "And some normal French text:\r" +
- "\tL'Avare ou l'\u00c9cole du mensonge\r" +
- "That\u2019s it for page one\r"
- ;
- private static final String u_page_2 =
- "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
- ;
-
- private static final String a_page_1 =
- "I am a test document\r" +
- "This is page 1\r" +
- "I am Calibri (Body) in font size 11\r"
- ;
- private static final String a_page_2 =
- "This is page two\r" +
- "It\u2019s Arial Black in 16 point\r" +
- "It\u2019s also in blue\r"
- ;
-
- private HWPFDocument u;
- private HWPFDocument a;
-
- protected void setUp() {
- u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
- a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
- }
+ private static final char page_break = (char)12;
+
+ private static final String u_page_1 =
+ "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" +
+ "Firstly, some currency symbols:\r" +
+ "\tGBP - \u00a3\r" +
+ "\tEUR - \u20ac\r" +
+ "Now, we\u2019ll have some French text, in bold and big:\r" +
+ "\tMoli\u00e8re\r" +
+ "And some normal French text:\r" +
+ "\tL'Avare ou l'\u00c9cole du mensonge\r" +
+ "That\u2019s it for page one\r"
+ ;
+ private static final String u_page_2 =
+ "This is page two. Les Pr\u00e9cieuses ridicules. The end.\r"
+ ;
+
+ private static final String a_page_1 =
+ "I am a test document\r" +
+ "This is page 1\r" +
+ "I am Calibri (Body) in font size 11\r"
+ ;
+ private static final String a_page_2 =
+ "This is page two\r" +
+ "It\u2019s Arial Black in 16 point\r" +
+ "It\u2019s also in blue\r"
+ ;
+
+ private HWPFDocument u;
+ private HWPFDocument a;
+
+ protected void setUp() {
+ u = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+ a = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
+ }
- public void testAsciiTextParagraphs() {
- Range r = a.getRange();
- assertEquals(
- a_page_1 +
- page_break + "\r" +
- a_page_2,
- r.text()
- );
-
- assertEquals(1, r.numSections());
- assertEquals(1, a.getSectionTable().getSections().size());
- Section s = r.getSection(0);
- assertEquals(
- a_page_1 +
- page_break + "\r" +
- a_page_2,
- s.text()
- );
+ public void testAsciiTextParagraphs() {
+ Range r = a.getRange();
+ assertEquals(
+ a_page_1 +
+ page_break + "\r" +
+ a_page_2,
+ r.text()
+ );
+
+ assertEquals(1, r.numSections());
+ assertEquals(1, a.getSectionTable().getSections().size());
+ Section s = r.getSection(0);
+ assertEquals(
+ a_page_1 +
+ page_break + "\r" +
+ a_page_2,
+ s.text()
+ );
// no PAP reconstruction
// assertEquals( 7, r.numParagraphs() );
// with PAP reconstructon
assertEquals( 8, r.numParagraphs() );
- String[] p1_parts = a_page_1.split("\r");
- String[] p2_parts = a_page_2.split("\r");
-
- // Check paragraph contents
- assertEquals(
- p1_parts[0] + "\r",
- r.getParagraph(0).text()
- );
- assertEquals(
- p1_parts[1] + "\r",
- r.getParagraph(1).text()
- );
- assertEquals(
- p1_parts[2] + "\r",
- r.getParagraph(2).text()
- );
+ String[] p1_parts = a_page_1.split("\r");
+ String[] p2_parts = a_page_2.split("\r");
+
+ // Check paragraph contents
+ assertEquals(
+ p1_parts[0] + "\r",
+ r.getParagraph(0).text()
+ );
+ assertEquals(
+ p1_parts[1] + "\r",
+ r.getParagraph(1).text()
+ );
+ assertEquals(
+ p1_parts[2] + "\r",
+ r.getParagraph(2).text()
+ );
// no PAPX reconstruction
// 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() );
}
- public void testAsciiStyling() {
- Range r = a.getRange();
-
- Paragraph p1 = r.getParagraph(0);
- Paragraph p7 = r.getParagraph(6);
-
- assertEquals(1, p1.numCharacterRuns());
- assertEquals(1, p7.numCharacterRuns());
-
- CharacterRun c1 = p1.getCharacterRun(0);
- CharacterRun c7 = p7.getCharacterRun(0);
-
- assertEquals("Times New Roman", c1.getFontName()); // No Calibri
- assertEquals("Arial Black", c7.getFontName());
- assertEquals(22, c1.getFontSize());
- assertEquals(32, c7.getFontSize());
-
- // This document has 15 styles
- assertEquals(15, a.getStyleSheet().numStyles());
-
- // Ensure none of the paragraphs refer to one that isn't there,
- // and none of their character runs either
- // Also check all use the default style
+ public void testAsciiStyling() {
+ Range r = a.getRange();
+
+ Paragraph p1 = r.getParagraph(0);
+ Paragraph p7 = r.getParagraph(6);
+
+ assertEquals(1, p1.numCharacterRuns());
+ assertEquals(1, p7.numCharacterRuns());
+
+ CharacterRun c1 = p1.getCharacterRun(0);
+ CharacterRun c7 = p7.getCharacterRun(0);
+
+ assertEquals("Times New Roman", c1.getFontName()); // No Calibri
+ assertEquals("Arial Black", c7.getFontName());
+ assertEquals(22, c1.getFontSize());
+ assertEquals(32, c7.getFontSize());
+
+ // This document has 15 styles
+ assertEquals(15, a.getStyleSheet().numStyles());
+
+ // Ensure none of the paragraphs refer to one that isn't there,
+ // and none of their character runs either
+ // Also check all use the default style
StyleSheet ss = a.getStyleSheet();
- for(int i=0; i<a.getRange().numParagraphs(); i++) {
- Paragraph p = a.getRange().getParagraph(i);
- int styleIndex = p.getStyleIndex();
- assertTrue(styleIndex < 15);
- assertEquals("Normal", ss.getStyleDescription(styleIndex).getName());
- }
+ for(int i=0; i<a.getRange().numParagraphs(); i++) {
+ Paragraph p = a.getRange().getParagraph(i);
+ int styleIndex = p.getStyleIndex();
+ assertTrue(styleIndex < 15);
+ assertEquals("Normal", ss.getStyleDescription(styleIndex).getName());
+ }
for(int i=0; i<a.getRange().numCharacterRuns(); i++) {
CharacterRun c = a.getRange().getCharacterRun(i);
int styleIndex = c.getStyleIndex();
assertTrue(styleIndex < 15);
assertEquals("Normal", ss.getStyleDescription(styleIndex).getName());
}
- }
+ }
- /**
- * Tests the raw definitions of the paragraphs of
- * a unicode document
- */
- public void testUnicodeParagraphDefinitions() {
- Range r = u.getRange();
- String[] p1_parts = u_page_1.split("\r");
- String[] p2_parts = u_page_2.split("\r");
-
- assertEquals(
- u_page_1 + page_break + "\r" + u_page_2,
- r.text()
- );
- assertEquals(
- 408, r.text().length()
- );
-
-
- assertEquals(1, r.numSections());
- assertEquals(1, u.getSectionTable().getSections().size());
- Section s = r.getSection(0);
- assertEquals(
- u_page_1 +
- page_break + "\r" +
- u_page_2,
- s.text()
- );
- assertEquals(0, s.getStartOffset());
- assertEquals(408, s.getEndOffset());
-
-
- List<PAPX> pDefs = r._paragraphs;
+ /**
+ * Tests the raw definitions of the paragraphs of
+ * a unicode document
+ */
+ public void testUnicodeParagraphDefinitions() {
+ Range r = u.getRange();
+ String[] p1_parts = u_page_1.split("\r");
+ String[] p2_parts = u_page_2.split("\r");
+
+ assertEquals(
+ u_page_1 + page_break + "\r" + u_page_2,
+ r.text()
+ );
+ assertEquals(
+ 408, r.text().length()
+ );
+
+
+ assertEquals(1, r.numSections());
+ assertEquals(1, u.getSectionTable().getSections().size());
+ Section s = r.getSection(0);
+ assertEquals(
+ u_page_1 +
+ page_break + "\r" +
+ u_page_2,
+ s.text()
+ );
+ assertEquals(0, s.getStartOffset());
+ assertEquals(408, s.getEndOffset());
+
+
+ List<PAPX> pDefs = r._paragraphs;
// no PAPX reconstruction
// assertEquals(36, pDefs.size());
// with PAPX reconstruction
assertEquals( 36, pDefs.size() );
- // Check that the last paragraph ends where it should do
- assertEquals(531, u.getOverallRange().text().length());
- PAPX pLast = pDefs.get(34);
-// assertEquals(530, pLast.getEnd());
-
- // Only care about the first few really though
- PAPX p0 = pDefs.get(0);
- PAPX p1 = pDefs.get(1);
- PAPX p2 = pDefs.get(2);
- PAPX p3 = pDefs.get(3);
- PAPX p4 = pDefs.get(4);
-
- // 5 paragraphs should get us to the end of our text
- assertTrue(p0.getStart() < 408);
- assertTrue(p0.getEnd() < 408);
- assertTrue(p1.getStart() < 408);
- assertTrue(p1.getEnd() < 408);
- assertTrue(p2.getStart() < 408);
- assertTrue(p2.getEnd() < 408);
- assertTrue(p3.getStart() < 408);
- assertTrue(p3.getEnd() < 408);
- assertTrue(p4.getStart() < 408);
- assertTrue(p4.getEnd() < 408);
-
- // Paragraphs should match with lines
- assertEquals(
- 0,
- p0.getStart()
- );
- assertEquals(
- p1_parts[0].length() + 1,
- p0.getEnd()
- );
-
- assertEquals(
- p1_parts[0].length() + 1,
- p1.getStart()
- );
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1,
- p1.getEnd()
- );
-
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1,
- p2.getStart()
- );
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1,
- p2.getEnd()
- );
+ // Check that the last paragraph ends where it should do
+ assertEquals(531, u.getOverallRange().text().length());
+ PAPX pLast = pDefs.get(34);
+ // assertEquals(530, pLast.getEnd());
+
+ // Only care about the first few really though
+ PAPX p0 = pDefs.get(0);
+ PAPX p1 = pDefs.get(1);
+ PAPX p2 = pDefs.get(2);
+ PAPX p3 = pDefs.get(3);
+ PAPX p4 = pDefs.get(4);
+
+ // 5 paragraphs should get us to the end of our text
+ assertTrue(p0.getStart() < 408);
+ assertTrue(p0.getEnd() < 408);
+ assertTrue(p1.getStart() < 408);
+ assertTrue(p1.getEnd() < 408);
+ assertTrue(p2.getStart() < 408);
+ assertTrue(p2.getEnd() < 408);
+ assertTrue(p3.getStart() < 408);
+ assertTrue(p3.getEnd() < 408);
+ assertTrue(p4.getStart() < 408);
+ assertTrue(p4.getEnd() < 408);
+
+ // Paragraphs should match with lines
+ assertEquals(
+ 0,
+ p0.getStart()
+ );
+ assertEquals(
+ p1_parts[0].length() + 1,
+ p0.getEnd()
+ );
+
+ assertEquals(
+ p1_parts[0].length() + 1,
+ p1.getStart()
+ );
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1,
+ p1.getEnd()
+ );
+
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1,
+ p2.getStart()
+ );
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1,
+ p2.getEnd()
+ );
}
- /**
- * Tests the paragraph text of a unicode document
- */
- public void testUnicodeTextParagraphs() {
- Range r = u.getRange();
- assertEquals(
- u_page_1 +
- page_break + "\r" +
- u_page_2,
- r.text()
- );
+ /**
+ * Tests the paragraph text of a unicode document
+ */
+ public void testUnicodeTextParagraphs() {
+ Range r = u.getRange();
+ assertEquals(
+ u_page_1 +
+ page_break + "\r" +
+ u_page_2,
+ r.text()
+ );
// without PAPX reconstruction
// assertEquals( 12, r.numParagraphs() );
// with PAPX reconstruction
assertEquals( 13, r.numParagraphs() );
- String[] p1_parts = u_page_1.split("\r");
- String[] p2_parts = u_page_2.split("\r");
-
- // Check text all matches up properly
- assertEquals(p1_parts[0] + "\r", r.getParagraph(0).text());
- assertEquals(p1_parts[1] + "\r", r.getParagraph(1).text());
- assertEquals(p1_parts[2] + "\r", r.getParagraph(2).text());
- assertEquals(p1_parts[3] + "\r", r.getParagraph(3).text());
- assertEquals(p1_parts[4] + "\r", r.getParagraph(4).text());
- assertEquals(p1_parts[5] + "\r", r.getParagraph(5).text());
- assertEquals(p1_parts[6] + "\r", r.getParagraph(6).text());
- assertEquals(p1_parts[7] + "\r", r.getParagraph(7).text());
- assertEquals(p1_parts[8] + "\r", r.getParagraph(8).text());
- assertEquals(p1_parts[9] + "\r", r.getParagraph(9).text());
+ String[] p1_parts = u_page_1.split("\r");
+ String[] p2_parts = u_page_2.split("\r");
+
+ // Check text all matches up properly
+ assertEquals(p1_parts[0] + "\r", r.getParagraph(0).text());
+ assertEquals(p1_parts[1] + "\r", r.getParagraph(1).text());
+ assertEquals(p1_parts[2] + "\r", r.getParagraph(2).text());
+ assertEquals(p1_parts[3] + "\r", r.getParagraph(3).text());
+ assertEquals(p1_parts[4] + "\r", r.getParagraph(4).text());
+ assertEquals(p1_parts[5] + "\r", r.getParagraph(5).text());
+ assertEquals(p1_parts[6] + "\r", r.getParagraph(6).text());
+ assertEquals(p1_parts[7] + "\r", r.getParagraph(7).text());
+ assertEquals(p1_parts[8] + "\r", r.getParagraph(8).text());
+ assertEquals(p1_parts[9] + "\r", r.getParagraph(9).text());
// without PAPX reconstruction
// assertEquals(page_break + "\r", r.getParagraph(10).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( "\r", r.getParagraph( 11 ).text() );
assertEquals( p2_parts[0] + "\r", r.getParagraph( 12 ).text() );
- }
- public void testUnicodeStyling() {
- Range r = u.getRange();
- String[] p1_parts = u_page_1.split("\r");
+ }
+ public void testUnicodeStyling() {
+ Range r = u.getRange();
+ String[] p1_parts = u_page_1.split("\r");
+
+ Paragraph p1 = r.getParagraph(0);
+ Paragraph p7 = r.getParagraph(6);
+ StyleSheet ss = r._doc.getStyleSheet();
- Paragraph p1 = r.getParagraph(0);
- Paragraph p7 = r.getParagraph(6);
- StyleSheet ss = r._doc.getStyleSheet();
+ // Line ending in its own run each time!
+ assertEquals(2, p1.numCharacterRuns());
+ assertEquals(2, p7.numCharacterRuns());
- // Line ending in its own run each time!
- assertEquals(2, p1.numCharacterRuns());
- assertEquals(2, p7.numCharacterRuns());
+ CharacterRun c1a = p1.getCharacterRun(0);
+ CharacterRun c1b = p1.getCharacterRun(1);
+ CharacterRun c7a = p7.getCharacterRun(0);
+ CharacterRun c7b = p7.getCharacterRun(1);
- CharacterRun c1a = p1.getCharacterRun(0);
- CharacterRun c1b = p1.getCharacterRun(1);
- CharacterRun c7a = p7.getCharacterRun(0);
- CharacterRun c7b = p7.getCharacterRun(1);
+ assertEquals("Times New Roman", c1a.getFontName()); // No Calibri
+ assertEquals(22, c1a.getFontSize());
- assertEquals("Times New Roman", c1a.getFontName()); // No Calibri
- assertEquals(22, c1a.getFontSize());
+ assertEquals("Times New Roman", c1b.getFontName()); // No Calibri
+ assertEquals(22, c1b.getFontSize());
- assertEquals("Times New Roman", c1b.getFontName()); // No Calibri
- assertEquals(22, c1b.getFontSize());
+ assertEquals("Times New Roman", c7a.getFontName());
+ assertEquals(48, c7a.getFontSize());
- assertEquals("Times New Roman", c7a.getFontName());
- assertEquals(48, c7a.getFontSize());
+ assertEquals("Times New Roman", c7b.getFontName());
+ assertEquals(48, c7b.getFontSize());
- assertEquals("Times New Roman", c7b.getFontName());
- assertEquals(48, c7b.getFontSize());
-
- // All use the default base style
- assertEquals("Normal", ss.getStyleDescription(c1a.getStyleIndex()).getName());
+ // All use the default base style
+ assertEquals("Normal", ss.getStyleDescription(c1a.getStyleIndex()).getName());
assertEquals("Normal", ss.getStyleDescription(c1b.getStyleIndex()).getName());
assertEquals("Heading 1", ss.getStyleDescription(c7a.getStyleIndex()).getName());
assertEquals("Heading 1", ss.getStyleDescription(c7b.getStyleIndex()).getName());
- // Now check where they crop up
- assertEquals(
- 0,
- c1a.getStartOffset()
- );
- assertEquals(
- p1_parts[0].length(),
- c1a.getEndOffset()
- );
-
- assertEquals(
- p1_parts[0].length(),
- c1b.getStartOffset()
- );
- assertEquals(
- p1_parts[0].length()+1,
- c1b.getEndOffset()
- );
-
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
- p1_parts[5].length() + 1,
- c7a.getStartOffset()
- );
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
- p1_parts[5].length() + 1 +
- 1,
- c7a.getEndOffset()
- );
-
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
- p1_parts[5].length() + 1 +
- 1,
- c7b.getStartOffset()
- );
- assertEquals(
- p1_parts[0].length() + 1 +
- p1_parts[1].length() + 1 +
- p1_parts[2].length() + 1 +
- p1_parts[3].length() + 1 +
- p1_parts[4].length() + 1 +
- p1_parts[5].length() + 1 +
- p1_parts[6].length() + 1,
- c7b.getEndOffset()
- );
-
- // This document also has 22 styles
- assertEquals(22, ss.numStyles());
-
- // Ensure none of the paragraphs refer to one that isn't there,
- // and none of their character runs either
- for(int i=0; i<r.numParagraphs(); i++) {
- Paragraph p = r.getParagraph(i);
- int styleIndex = p.getStyleIndex();
- assertTrue(styleIndex < 22);
- assertNotNull(ss.getStyleDescription(styleIndex).getName());
- }
- for(int i=0; i<r.numCharacterRuns(); i++) {
- CharacterRun c = r.getCharacterRun(i);
- int styleIndex = c.getStyleIndex();
- assertTrue(styleIndex < 22);
- assertNotNull(ss.getStyleDescription(styleIndex).getName());
- }
- }
+ // Now check where they crop up
+ assertEquals(
+ 0,
+ c1a.getStartOffset()
+ );
+ assertEquals(
+ p1_parts[0].length(),
+ c1a.getEndOffset()
+ );
+
+ assertEquals(
+ p1_parts[0].length(),
+ c1b.getStartOffset()
+ );
+ assertEquals(
+ p1_parts[0].length()+1,
+ c1b.getEndOffset()
+ );
+
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
+ p1_parts[5].length() + 1,
+ c7a.getStartOffset()
+ );
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
+ p1_parts[5].length() + 1 +
+ 1,
+ c7a.getEndOffset()
+ );
+
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
+ p1_parts[5].length() + 1 +
+ 1,
+ c7b.getStartOffset()
+ );
+ assertEquals(
+ p1_parts[0].length() + 1 +
+ p1_parts[1].length() + 1 +
+ p1_parts[2].length() + 1 +
+ p1_parts[3].length() + 1 +
+ p1_parts[4].length() + 1 +
+ p1_parts[5].length() + 1 +
+ p1_parts[6].length() + 1,
+ c7b.getEndOffset()
+ );
+
+ // This document also has 22 styles
+ assertEquals(22, ss.numStyles());
+
+ // Ensure none of the paragraphs refer to one that isn't there,
+ // and none of their character runs either
+ for(int i=0; i<r.numParagraphs(); i++) {
+ Paragraph p = r.getParagraph(i);
+ int styleIndex = p.getStyleIndex();
+ assertTrue(styleIndex < 22);
+ assertNotNull(ss.getStyleDescription(styleIndex).getName());
+ }
+ for(int i=0; i<r.numCharacterRuns(); i++) {
+ CharacterRun c = r.getCharacterRun(i);
+ int styleIndex = c.getStyleIndex();
+ assertTrue(styleIndex < 22);
+ assertNotNull(ss.getStyleDescription(styleIndex).getName());
+ }
+ }
}