public final static short SPRM_FELID = 0x486E;
public final static short SPRM_IDCTHINT = 0x286F;
- SprmBuffer _chpx;
- CharacterProperties _props;
+ protected short _istd;
+ protected SprmBuffer _chpx;
+ protected CharacterProperties _props;
/**
*
super(Math.max(parent._start, chpx.getStart()), Math.min(parent._end, chpx.getEnd()), parent);
_props = chpx.getCharacterProperties(ss, istd);
_chpx = chpx.getSprmBuf();
+ _istd = istd;
}
/**
return _props.getLidDefault();
}
+ /**
+ * Returns the index of the base style which applies to
+ * this Run. Details of the style can be looked up
+ * from the {@link StyleSheet}, via
+ * {@link StyleSheet#getStyleDescription(int)}.
+ * Note that runs typically override some of the style
+ * properties from the base, so normally style information
+ * should be fetched directly from the {@link CharacterRun}
+ * itself.
+ */
+ public short getStyleIndex() {
+ return _istd;
+ }
+
public String toString() {
String text = text();
return "CharacterRun of " + text.length() + " characters - " + text;
import java.util.List;
import junit.framework.TestCase;
+
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PAPX;
+import org.apache.poi.hwpf.model.StyleSheet;
/**
* Tests to ensure that our ranges end up with
// 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);
- assertTrue(p.getStyleIndex() < 15);
+ 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());
+ }
}
/**
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("Times New Roman", c7b.getFontName());
assertEquals(48, c7b.getFontSize());
+
+ // 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(
c7b.getEndOffset()
);
- // This document has 15 styles
- assertEquals(15, a.getStyleSheet().numStyles());
+ // 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<a.getRange().numParagraphs(); i++) {
- Paragraph p = a.getRange().getParagraph(i);
- assertTrue(p.getStyleIndex() < 15);
+ 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());
}
}
}